Repository navigation
Update dependency semantic_logger to v5.3.0 - #1310
Merged
Merged
Conversation
GitLab Pipeline ActionGeneral informationLink to pipeline: https://gitlab.com/code0-tech/development/reticulum/-/pipelines/3125504661 Status: Passed Job summariesdocs:previewDocumentation preview available at https://code0-tech.gitlab.io/-/development/telescopium/-/jobs/18445117844/artifacts/out/index.html generate-environmentRETICULUM_CONTAINER_VERSION=0.0.0-experimental-3125504661-df0b597624fcc3a66fa227abd4e83b3ca88c6347 |
Taucher2003
approved these changes
Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR body was truncated due to platform limits.
This PR contains the following updates:
5.2.0→5.3.0Release Notes
reidmorrison/semantic_logger (semantic_logger)
v5.3.0Compare Source
Added
dimensions::json,:raw,:fluentd,:ecs,:syslog_cee, and:new_relic_logsas adimensionsHash,:lokias adimensionsvalue in JSON, and:open_telemetryas asemantic_logger.dimensions.<key>attribute for each one. So do the appenders that use them,such as
:elasticsearch,:splunk_http, and:mongodb. They are written only with a metric, asLog#dimensions?tells a custom formatter. SeeMetrics in log appenders.
the main Ractor writes its entries to the appenders. Before, any log call from such a Ractor raised
Ractor::IsolationError. SeeLog from Ractors.
SemanticLogger.contextreturns a frozen snapshot of the current tags, named tags, and silencelevel, and
SemanticLogger.with_context(context) { ... }applies it in another thread or fiber,such as a thread pool's worker or an Async task. Tags belong to the fiber that set them, so these
hand them over explicitly. See
Hand tags to another thread or fiber.
SemanticLogger.backtrace_cleaner=sets a backtrace cleaner, such asRails.backtrace_cleaner,that leaves out or shortens the lines of each exception's backtrace, and of each exception that
caused it, before they are logged. A cleaner is any object that responds to
#clean, asActiveSupport::BacktraceCleanerdoes, or to#call, such as a Proc. The text formatters(
:default,:color,:pattern,:syslog) and the JSON formatters (:json,:fluentd) useit, and so do the appenders that use
:jsonby default (:http,:elasticsearch_http,:tcp,:udp,:kafka,:rabbitmq,:cloudwatch_logs). The others, including:rawand theformatters written for a particular service, write the full backtrace, and appenders that send the
exception to an error service are not affected. The new
backtrace_cleanerformatter optionchooses for one appender:
truefor the application's cleaner,falsefor the full backtrace,or a cleaner of its own. When a cleaner leaves out every line, or raises, the full backtrace is
logged, and an error it raises is reported to the internal logger. Nothing changes until a
cleaner is set. See
Cleaning backtraces.
Log#backtrace_of(exception, cleaner:)returns an exception's backtrace as a cleaner cleans it,cached on the entry, and
Log#backtrace_to_sacceptscleaner:, for custom formatters.SemanticLogger.sensitive_keys=names the keys, such as passwords and access tokens, whose valuesare replaced with
[FILTERED]in every log entry before any appender writes it (discussion #272).It takes an Array of Symbols and Strings, which match any key whose name contains them, ignoring
case, as in Rails'
config.filter_parameters, and Regexps; or a Regexp; or anActiveSupport::ParameterFilter, or any object that responds to#filter_param; or a Proc. Keysare matched by name, as written and in snake_case, so that
:_keyalso matches"X-Api-Key","apiKey", and"APIKey". The payload, named tags, the context thaton_logsubscribers add,and metric dimensions are redacted at any depth, inside Hashes, Arrays, Sets, Structs, Data,
OpenStructs, and
ActionController::Parameters, once per entry on the thread that writes theentries, so every appender, including error services and appenders of your own, writes the
redacted entry. The application's own Hashes are never changed, and an entry with no sensitive key
is written as it is, unless it holds a structure that holds itself or is nested more than 32
levels deep. When an entry cannot be redacted, the field is replaced with
{redaction_failed: "ErrorClass"}and the error is reported to the internal logger. The message,tags, and exception are not redacted, and
on_logsubscribers and logger filters receive theentry as it was logged. Nothing changes until sensitive keys are set. See
Redacting sensitive data.
SemanticLogger.call_site_level=records where each entry at or above that level was logged: thefile, line, and method of the code that made the log call, in
Log#call_site. Unlikebacktrace_levelit reads only the stack frames up to that code, so it adds about 1.5 µs to a logcall however deep the stack is, where a backtrace adds 16 µs or more. It is off (
nil) by default.With it on, the text formatters show the method after the file name and line number,
:jsonandthe other formatters built on
:rawadd amethodfield,:patternhas a%{method}directive,:ecswriteslog.origin.function,:new_relic_logswritesmethod.name, and:open_telemetrywrites
code.function.name. When a log call supplies abacktrace:, its first line is the callsite.
SemanticLogger.call_site_skip_paths=skips the frames of an application's own logginghelpers, so that entries record the code that called them. See
Recording where each entry was logged.
Resolves discussion #219.
measure_*call, can passcall_site:to say where the entry was logged, as aThread::Backtrace::Locationor aSemanticLogger::CallSite, orcall_site: falsefor an entrywith no such code, which records none without reading the stack for it. For code that logs on
behalf of other code, such as a log subscriber. It is only recorded at or above
call_site_level.See
Recording where each entry was logged.
#batchis all or nothing can now say, from the new#fails_any_batch?(exception), that a message error would fail any batch, whatever it holds, suchas a request refused for its credentials. A batch that fails with such an error is then discarded at
once, rather than split up and each part written again to find the entries at fault. It returns
falseby default, so that every batch is split as before. SeeCustom appenders.
:lokiformatter'sstructured_metadata:option writes the process id, the thread name, orboth, as the structured metadata
pidandthread, instead of as stream labels, so that aprocess restart or a new thread no longer adds a Loki stream. A query can still filter on them,
as in
{application="shop"} | thread="worker-1". A payload key of that name is then written aspayload_pidorpayload_thread, and a named tag or context key as the labelpid_2orthread_2. It needs a Loki that accepts structured metadata, with schema v13 andallow_structured_metadata, on by default since Loki 3.0. Set it withadd_appender(appender: :loki, formatter: {loki: {structured_metadata: [:pid, :thread]}}, ...).The default is still to write them as labels; v6 changes it (see Deprecated). See
pid and thread as structured metadata.
:splunk_httpappender can be added withbatch: true, to send many entries in each request toSplunk's HTTP Event Collector, as event objects stacked one after the other, each one what it sends
for that entry on its own, with its
index:andsource_type:. Before, with its default formatter,every batch failed, so nothing was written. When the collector rejects a batch at one of its
entries, such as with "Invalid data format", it has already indexed those before it: that entry is
discarded, and only the entries after it are sent again, so that none is indexed twice. Batching
needs a formatter that formats each entry as exactly one event object, as the default formatter
does. It is still not batched by default. See Splunk HTTP.
can say which one from
#rejected_entry(exception): the messages before it are counted as written,it is discarded, and only those after it are written again, rather than the batch split up and
written again in parts. See
Custom appenders.
Log#capture(key, value)andLog#captured(key)keep an object with a log entry for anappender's own use, such as state of the logging thread captured by an
on_logsubscriber, whereformatters do not write it, unlike
Log#set_context. SeeHelper methods.
Changed
where it added a deprecated appender, and starts with
SemanticLogger:, as inconfig/initializers/logging.rb:12: warning: SemanticLogger: .... Before, it named no line. Asbefore, Ruby only shows it while
Warning[:deprecated]is true. SeeSeeing deprecation warnings.
:open_telemetryappender no longer sends metric-only entries, which have a metric but nomessage and no exception, by default. It sent each one as a log record with no body, never as an
OpenTelemetry metric; they are meant for the metric subscribers. Add the appender with
metrics: trueto keep sending them. See thev5.3 upgrade notes.
:statsdand:new_relicmetric subscribers record a metric that hasdimensionsunder itsname alone, leaving out the dimensions, which neither the
statsd-rubyclient nor the New Relicagent's metric API accepts. Before, they left such a metric out altogether. The
:statsdsubscriber now also takes the options of every subscriber, such as
level:andfilter:, as theother metric subscribers do. See the
v5.3 upgrade notes.
#loggerof an appender added withlogger:orappender: :open_telemetryreturns itsinternal logger, the one it reports its own problems to, as for every other appender, and
#logger=replaces that internal logger. Before, they returned and replaced the logger that theappender writes to; a
logger:appender's is now#wrapped_logger, which the appender returnedby
add_appender(logger: ..., async: true)also answers. See thev5.3 upgrade notes.
log_exception: :partial, the default formeasure_*blocks, now also adds each exception thatcaused the logged one to the message, as
-- Cause: Class: message, so that it names the sameexceptions as
log_exception: :full. A cause's message is left out when it is empty, is its classname, or is already in the message, as when the exception that wraps it copied it into its own:
-- Exception: ActionDispatch::Http::MimeNegotiation::InvalidType: "foo/bar" is not a valid MIME type -- Cause: Mime::Type::InvalidMimeType. Before, the causes were left out. See thev5.3 upgrade notes.
:httpappender, and the appenders derived from it, such as:loki,:splunk_http,:elasticsearch_http, andmetric: :signalfx, close their connection when they are closed, suchas when removed with
SemanticLogger.remove_appender, or bySemanticLogger.close. Before, it wasleft open. One that is added again opens a new connection for its next request, and keeps it for
the requests that follow.
SemanticLogger.remove_appenderwaits, asSemanticLogger.flushdoes, until the log messagesalready logged are written to the other appenders, and those are flushed, before it closes the
appender. Before, it closed the appender at once, while the processor could still be writing a
message to it, such as on the socket of a
:tcpappender, or the connection of an:httpappender, which could then open a new connection that was left open. Called on the processor's own
thread, such as by an appender as it writes, it still closes the appender at once. Called on the
thread of an appender added with
async: trueor in batches, such as by that appender as itwrites, removing itself or another appender, it does not wait, since the processor's thread may be
waiting for that thread: it returns
trueat once, and the processor's thread, once it has writtenthe messages logged before, closes the appender between writes, then removes it. See
Adding and removing appenders.
Log#each_exceptionaccepts the exception to start from, for custom formatters and appenders thatwalk the causes of an exception the entry does not keep.
call_sitekey of a logged Hash is now thecall_site:argument when its value isfalse, aThread::Backtrace::Location, or a well-formedSemanticLogger::CallSite, and is no longer loggedin the payload. A
nilvalue counts as not supplied, as for the other arguments, and is not loggedeither. Other values, such as a String, are still logged in the payload.
SemanticLogger.host=,application=, andenvironment=store a frozen copy of the valuesupplied, so that code in a Ractor can read it, and the default host name is frozen too.
The value supplied is left as it is.
:open_telemetryappender sends the message as the body of each log record, as documented,instead of a map of the whole log entry. The named tags become attributes of their own alongside
the payload, and the entry's own fields become attributes: the exception as
exception.type,exception.message, andexception.stacktrace, the file and line ascode.file.pathandcode.line.number, plusthread.name,process.pid,semantic_logger.name,semantic_logger.tags,semantic_logger.duration_ms,semantic_logger.metric, andsemantic_logger.metric_amount. The host, application, and environment are no longer sent, sinceOpenTelemetry reports them in its resource (
OTEL_SERVICE_NAME,OTEL_RESOURCE_ATTRIBUTES).The formatter now returns the keyword arguments for the OpenTelemetry
Logger#on_emit, so acustom formatter for this appender must do the same. See the
v5.3 upgrade notes. Resolves #428.
:elasticsearchand:opensearchappenders send again the entries of a bulk request that theserver rejected with status 429 because its write queue was full, which are likely to be indexed a
little later. Before, they were reported to the internal logger and discarded with the entries that
failed for any other reason. Only those entries are sent again, so that none is indexed twice, up to
3 times, after waiting 0.2, 0.4, then 0.8 seconds. That holds up the thread that writes the entries
for waits of at most 1.4 seconds for a request, plus up to 3 more bulk requests. The entries still
not indexed are reported and discarded, as before. See
Elasticsearch and the
v5.3 upgrade notes.
async: trueor in batches sends an entry or batch that its destinationcould not take again once it has backed off, rather than discarding it, when the appender says that
the write wrote nothing and is worth trying again. Once the destination has answered it with a
failure after it was sent again 3 times, it is discarded, and the thread carries on with the next
one; a write that never reached the destination, such as one that could not connect, is not
counted, so an outage loses no entries until the thread gives up after
async_max_retries. The:http,:elasticsearch_http,:splunk_http, and:lokiappenders, and the:signalfxmetricsubscriber, say so for a 408, 429, or 503, such as a 503 while Loki restarts, and for a request
they could not send because they could not connect. A 500, 502, or 504, and a request that failed
once it was sent, such as one whose answer timed out, are still discarded. A custom appender says
so from the new
#wrote_nothing?(exception), and that the write never reached the destinationfrom
#not_sent?(exception), both of which returnfalseby default.A flush or close, including the flush at exit, no longer waits out the back-offs during an outage:
submitting one ends the back-off under way, and until it has run, an entry or batch that fails is
discarded, counted as
failed, without backing off, and so are the entries queued after it, aheadof the flush or close (see below). Before, a flush with 5 entries queued during an outage waited
1 + 2 + 3 + 4 + 5 seconds. See
Retry a failing appender
and the v5.3 upgrade notes.
async: trueor in batches, theprocess exits within seconds, rather than hours. A flush or close, including the flush at exit,
now discards the entries queued ahead of it once a write fails because of the destination, counted
as
failed, rather than send each one in turn, which against a server that does not answer tookup to its
open_timeouteach. At exit, each such appender is also told that the process isexiting before the flush, directly rather than through the main queue, so that it stops backing off
and sending again what failed even while the thread that writes to every appender is held up
handing it an entry. A destination that takes the entries still gets every one of them. See
Retry a failing appender
and the v5.3 upgrade notes.
async: true, and not inbatches, such as a plain
:http,:splunk_http,:tcp, or:udp, the process exits withinseconds too. Such an appender has no queue of its own, and the thread that writes to every
appender does not back off when it fails, so the flush at exit waited while each queued entry
failed in turn, up to the
read_timeoutoropen_timeoutof an HTTP based appender each. Now,once its write fails because of its destination while the process exits, rather than the content
of the entry, it is given no more entries for the rest of the flush at exit, and the number it was
not given is reported to the internal logger at the flush, which then still flushes it, so that it
delivers the entries it already accepted, such as those that the producer of a
:kafkaappenderholds. The other appenders still get every entry. See
Retry a failing appender
and the v5.3 upgrade notes.
Deprecated
:lokiformatter withoutstructured_metadata:, as adding the:lokiappender doesunless it is given
formatter: {loki: {structured_metadata: ...}}. It still writespidandthreadas stream labels, but v6 writes them as structured metadata by default, so it now reportsa deprecation warning. Pass
structured_metadata: []to keep them as labels, orstructured_metadata: [:pid, :thread]to write them as structured metadata. See thev5.3 upgrade notes.
:kafka,:rabbitmq, or:udpappender withoutmetrics:. They still sendmetric-only entries by default, which have a metric but no message and no exception, but v6 leaves
them out by default, as the other log appenders do, so they now report a deprecation warning. Pass
metrics: trueto keep sending them, ormetrics: falseto leave them out. See thev5.3 upgrade notes.
add_appendera formatter block, or the options of an appender, such aslevel:,formatter:, orfilter:, with an appender or metric subscriber instance, such asadd_appender(appender: my_appender, level: :warn). The instance was created with its own options,so they were ignored without a word. They still are, but
add_appendernow reports a deprecationwarning that names them, and v6 raises
ArgumentErrorfor them. Set them on the instance itself.An option given as
nilsets nothing, and is not reported. The options ofadd_appenderitself,such as
async:andbatch:, still apply to an instance. See thev5.3 upgrade notes.
add_appendermore than one destination, such asadd_appender(file_name: "log/app.log", io: $stdout). It added only the first offile_name:,io:,logger:,appender:, andmetric:, and ignored the others without a word, so nothingwas written to
$stdout. It still does, but now reports a deprecation warning that names thedestination it uses and those it ignores, and v6 raises
ArgumentErrorfor them. Calladd_appenderonce for each destination. A destination given asnilis not reported. See thev5.3 upgrade notes.
metric_amounton a log call or ameasure_*call with ametric:, such aslogger.info(metric: "cart/items", metric_amount: -1). It is still logged and sent to themetric subscribers as before, but v6 counts a metric only upward and drops a negative amount, so it
now reports a deprecation warning, once per process, at the line of the first such call. Count
what goes down as a metric of its own, such as
cart/items_removed. SeeNegative metric amounts.
Removed
logger_measure_method, an experiment thatSemanticLogger::Loggableadded to each class, andthat was never part of the documented API. To log how long a method takes, wrap its body in a
measure_*block, and passmetric:to keep the metric it logged, such aslogger.measure_info("#run", metric: "MyClass/run") { ... }. To trace it, use OpenTelemetry'stracer.in_span, or the method tracer of an APM agent. See thev5.3 upgrade notes.
Fixed
or by an appender added with
async: trueor in batches, made at most once everydropped_message_report_seconds, are timed with the monotonic clock. Before, when the system clockstepped back, as NTP can, the next report was held back until the clock had caught up again, for
as long as it had stepped back.
SemanticLogger.flush,SemanticLogger.close, andSemanticLogger.clear_appenders!returnfalseat once, without flushing, when called on the thread of an appender added withasync: trueor in batches, such as by a custom appender as it writes, and the first such call isreported to the internal logger. Before, they waited forever, since the processor's thread waited
for that thread to flush its appender, and once the processor's queue was full, so did every
thread that logged. See Flushing.
async: trueor in batches, such as by alibrary that the appender calls as it writes, is dropped at once, and counted as dropped, when it
finds the processor's queue full while that appender's own queue is full too, or a flush or close
of that appender is waiting, whoever asked for it. Before, it could wait forever: the processor's
thread, which makes room, can itself be waiting for room on that appender's full queue, or for that
appender to flush, and then so did every thread that logged.
add_appenderraisesArgumentErrorwhen it would batch an appender whose formatter cannotformat a batch, such as
formatter: :defaultor a Proc given to:http,:loki, ormetric: :signalfxwithbatch: true, and now also a formatter block (see the entry on blocksbelow), and says what to do instead. Before, it added the appender, but every batch failed
on the appender's worker thread, which backed off and tried again, so nothing was ever written,
and once its queue was full, logging blocked, unless it was added with
non_blocking: true. Theerror names the formatter. A custom appender whose
#batchformats each entry withformat_logis batched with any formatter, as before, and one that cannot be batched in some configuration can
say why from
#batch_refusal. Whenadd_appenderfails after creating the appender, such as forone that it cannot batch, it closes the appender. See the
v5.3 upgrade notes.
add_appender(appender: :elasticsearch_http, batch: true)raisesArgumentError, and says to usethe
:elasticsearchappender, which sends its entries in bulk requests, to send them in batches.Before, it posted each batch as a JSON array to the url's own path, such as
/, whichElasticsearch rejects, since it indexes a batch only through its bulk API, so nothing was ever
indexed. A custom appender can refuse to be batched in the same way, with a reason of its own, by
returning it from
#batch_refusal. See thev5.3 upgrade notes.
:statsdmetric subscriber records metrics as soon as it is added. Before, it created itsStatsd client only when reopened, such as after a fork, so in a process that did not fork, such as
a single Puma or Sidekiq process, every metric failed with
NoMethodErrorand was reported to theinternal logger instead. A
url:that is notudp://, or whose host cannot be resolved, now raisesas the subscriber is added, as for the
:udpappender, and an IPv6 address such asudp://[::1]:8125is now accepted. Reopening it, such as after a fork, now reconnects its client,which closes the socket the client had, instead of leaving it open, and leaves the client as it
was when the host cannot be resolved.
add_appender(metric: ...)with a value that is neither a Symbol nor aSemanticLogger::Subscribernow names that value in its
ArgumentError. Before, the message named theappender:optionin its place, usually as
not: nil.add_appenderformats the entries of an appender or metric subscriber named by aSymbol, such as
add_appender(appender: :tcp, server: "localhost:514") { |log| log.message }, asit does for
io:,file_name:, andlogger:, taking precedence overformatter:. Before, theblock was ignored, and the appender used its
formatter:or its default formatter, so what such anappender sends changes. With
batch: true,:http,:loki, andmetric: :signalfxraiseArgumentErrorfor such a block (see above). Remove the block to keep the output of v5.2. See thev5.3 upgrade notes.
:elasticsearchand:opensearchappenders acceptmetrics: true, to also index metric-onlyentries: a metric without a message or an exception. Before,
metrics:was passed on to theElasticsearch or OpenSearch client, and those appenders always left metric-only entries out.
measure_*andbenchmark_*methods, andmeasureandbenchmark, keep adimensions:option, such as
metric: "supplier/add_user", dimensions: {supplier: "acme"}, with a block orwith
duration:. Before, the entry had no dimensions, so the:signalfxmetric subscriber couldnot break the metric down by them, and the structured formatters did not write them. A
dimensions:value that is not a Hash is ignored, as the other measure options ignore a valuethat is not valid for them. SignalFx now sends such a metric under its own name, as it sends any
metric with dimensions, instead of as
Application.averageandApplication.counter, andwithout the named tags listed in its own
dimensions:option, which it only adds to a metricwithout dimensions, so put those values in the metric's
dimensions:. SignalFx also treats emptydimensions, such as
dimensions: {}or{supplier: nil}.compact, as none, asLog#dimensions?does, on a log call too. Before, a metric logged with them was sent under its own name, and a
duration without a count, without the
classandactiontaken from its name, or the named tagslisted in the subscriber's
dimensions:option. See thev5.3 upgrade notes.
:lokiformatter writes a metric'smetric_valueas a String, such as"3", and leaves it outfor a metric without an amount. Loki accepts only Strings in structured metadata, and rejected the
whole push with
400 Bad Requestfor a number ornull, so every entry with a metric was lost,and with
batch: trueso was every other entry in its batch. The appender reported eachrejection to the internal logger. The
metric_valueand thedurationare written as LogQL readsnumbers, to compare or
unwrapthem: an Integer as it is, and any other number as a decimal, suchas
"1.5". A Rationaldurationwas written as5/2, which made every query that unwrapped itfail. The
exception_nameof an exception whose class is anonymous, and theexception_messageof one whose
#messagereturns nil, which werenulltoo, are now Strings: the name as the textformatters write it, such as
#<Class:0x000...>, and an empty message.:lokiformatter writes a payload key named like one of its own structured metadata fields,metric,metric_value,dimensions,duration,duration_human,exception_name,exception_message, orstack_trace, with apayload_prefix, as inpayload_duration, as:logfmtand:open_telemetryprefix theirs withpayload.. It wrote the payload's value and itsown under the same name, and Loki keeps only the last, so the payload's value was lost. A payload
key that Loki stores under one of those names, such as
metric.value,metric__value, or onewith an invisible character, replaced the formatter's value instead, so that a query that
unwrapsmetric_valuefailed. The key is prefixed whether or not the entry has that field, sothat each of these names always holds the formatter's value. It is written under the name Loki
stores it as, such as
payload_metric_valueformetric.value, and with the prefix again whenanother payload key has that name once Loki has stored it, as in
payload_payload_metric_value,so that Loki keeps the value of each prefixed key. A key that is exactly one of these names gets
the name with one prefix, whatever the order of the keys. See
Upgrading to v5.3
and Grafana Loki.
:lokiformatter no longer loses an entry, with every other entry pushed with it, for a namedtag or context key that Loki does not accept as a label name, such as
request-id,1st, or anempty key, or for a payload key without an ASCII letter or digit, such as an empty key,
-, orthe
_that jQuery adds to the parameters of a request it keeps from being cached. Loki rejectedthe push with
400 Bad Request("couldn't parse labels") or500("label name is empty"). Such alabel name is now written as Loki writes the names of structured metadata: each run of characters
other than ASCII letters and digits replaced with one
_, andkey_before a name that wouldstart with a digit, or is empty. So
request-idis written asrequest_id, and1staskey_1st. When another label already has that name with another value, as Loki stores it, anumber is added, as in
request_id_2, so that both are kept. Such a payload key is written withthe
payload_prefix, as Loki stores it, so an empty key aspayload_, and with the prefix againwhen another key has that name, so that Loki keeps the value of each. A named tag that is nil, and a nil host, are left out,
instead of being written as the label
null.:lokiformatter keeps both values of a named tag or context key that has the name of anotherlabel. Loki keeps one value of a label, so a named tag such as
host,level, orpidreplacedthe formatter's own label, and an
:infoentry taggedlevel: "warn"was stored aslevel="warn".A context key replaced a named tag of the same name, and so did a named tag given both as a Symbol
and as a String. Now the formatter's own labels, the named tags, and the context are written under
their own names, in that order, then each one whose name Loki does not accept under the name that
replaces it, when no label has that name yet, and then each of the rest, with the first number
added that no other label has, as in
host_2, so that the number is never another label's name,whatever the order of the keys. It is written once when the label of that name, or of a numbered
name before it, has the same value, as Loki stores it. The stream's label names are now Strings,
so a subclass of the formatter that reads, replaces, or deletes a label in
stream[:stream]uses aString key, such as
"host". A label that a subclass writes under a Symbol, as v5.2 did, iswritten under its name as a String, numbered when a label written before it has that name. See
Upgrading to v5.3
and Grafana Loki.
:lokiformatter no longer loses an entry, with every other entry pushed with it, for a streamwith more than 15 labels, such as an entry with ten named tags, a label name longer than 1024
bytes, or a label value longer than 2048 bytes, such as many tags. Loki rejected the push with
400 Bad Request. Such a label is now written to the structured metadata instead, as a String,where a query can still filter on it: the labels after the 15th in the order the formatter writes
them (its own, then the named tags and the context under their own names, then those whose names
were taken or replaced), and any label with a longer name or value.
The new formatter options
max_label_names_per_series,max_label_name_length, andmax_label_value_lengthset these limits for a Loki that raises them, as informatter: {loki: {max_label_names_per_series: 30}}. SeeLoki's label limits.
:open_telemetryappender, and an appender added withlogger:, work withasync: true.Before, the worker thread stopped as it started, with
NoMethodError(undefined method 'trace'),so the appender wrote nothing, and unless it was added with
non_blocking: true, every log callblocked once its queue was full. With a
logger:that has atracemethod, the worker threadwrote its own messages to that logger instead. Their
#loggerreturned the logger they write to,rather than the internal logger that every appender reports its own problems to, which the worker
thread uses; it now returns the internal logger (see Changed). The
:open_telemetryappender alsoreports a failure to flush or shut down to its internal logger, as the other appenders do, rather
than to
SemanticLogger::Processor.logger, so that the report names the appender. The workerthread of any appender run with
async: trueor in batches now also keeps running when theappender's internal logger cannot take the thread's own messages, such as a Ruby Logger returned
by a custom appender's own
#logger, which has notracemethod and takes no exception. Such alogger now gets each of those reports that it can take, with the exception, if there is one, added
to the message. Before, it got none of the reports with an exception, such as a discarded message,
a restart, or the thread stopping. See the
v5.3 upgrade notes.
SemanticLogger.reopen(force: true)in a process that has not forked, such as after a logrotation, no longer loses track of the thread that writes the log entries, or of the thread of
an appender added with
async: trueor in batches. Before, the thread it replaced, as it ended,cleared the new one, so that
SemanticLogger.flushreturnedfalsewithout waiting for thequeued entries, and entries still queued at exit could be lost.
:kafkaappender keeps itsrequired_acks:after it is flushed, such as withSemanticLogger.flush. Before, a flush replaced the appender's producer with one built withoutit, so ruby-kafka's default of
:all, which waits for every in-sync replica to acknowledge eachdelivery, replaced the appender's default of
1, or the value given.LoadErrorraised when the:kafkaappender is added without theruby-kafkagem namesKafka. It said that the gem is required for logging to Elasticsearch.
:kafkaappender in the same process, such as withSemanticLogger.reopen(force: true), no longer leaves the producer it replaces running, with itstwo threads, and its connections open. The next time the appender logs, it starts a thread that
shuts that producer down, which delivers the entries it still holds, and closes its client.
Flushing or closing the appender waits for that thread, or shuts the producer down itself.
Neither reopening nor logging waits for the delivery, so that reopening still works in a signal
trap, where ruby-kafka cannot shut down a producer, and the thread that writes to every appender
does not stop while Kafka cannot be reached. Since the new producer delivers meanwhile, the
entries of the one it replaced can reach Kafka after newer ones. An error shutting that producer
down is reported to the internal logger, rather than raised. After a fork, the child still leaves
the producer and client it inherited alone, since shutting them down there would send the
parent's undelivered entries a second time, over the parent's own connections. When the appender
cannot build a new producer, such as after setting a negative
delivery_threshold, flushing itnow keeps the producer it has, which still delivers, rather than the one it had just shut down,
and reopening it in the same process keeps both its client and producer. In a forked child it
then has none, and logging to it raises
IOErroruntil a reopen builds one. Flushing the appenderafter closing it no longer raises
NoMethodError, and logging to it raisesIOErrorinstead.:udpappender sends to an IPv6 address written in brackets, as a URL writes it, such asserver: "[::1]:8088". Before, it split the server at every colon, and its socket was IPv4 only,so it could not be given an IPv6 address. A host name with an IPv4 address still uses it. A
server:that is not"host:port", such as one without a port, or an IPv6 address withoutbrackets, now raises
ArgumentError, which names the form to use, as the appender is added.Before, a missing port was taken as port 0.
:udpappender is reopened, such as after a fork, and cannot connect to its server, suchas for a host name that no longer resolves, it keeps the socket it had, which still sends to the
address it connected to. It raises the error as before, which
SemanticLogger.reopenreports tothe internal logger. Before, it closed that socket first, and kept a new one that was not
connected, so every entry after it failed with
Errno::EDESTADDRREQuntil the next reopen.:udpappender sends to a host name that has only IPv6 addresses, over IPv6. Before, itssocket was IPv4 only, so adding it raised
SocketError, since the name has no IPv4 address. Aname with both is still sent to over IPv4, whichever address the resolver returns first, unless
it cannot connect over IPv4, such as on a host with no IPv4 route, when it now uses IPv6 instead
of raising. It looks up a name's IPv6 addresses only when the resolver answers that the name has
no IPv4 address, or when it cannot connect to any of them, so that a resolver that does not answer
for them does not delay it otherwise. When looking up the IPv4 addresses fails for another reason,
such as a resolver that does not answer in time, it raises that
SocketErrorat once, as before,rather than sending over IPv6 to a name that may have IPv4 addresses. On Ruby 3.2 and JRuby, whose
SocketErrordoes not say why a lookup failed, it looks up the IPv6 addresses after any failure.When it cannot connect to any address, it raises the error from the first one it tried, an IPv4
address when the name has one. A name that does not resolve raises
SocketErroras before.log_exception: :partial, the default formeasure_*blocks, no longer raisesEncoding::CompatibilityErrorwhen the log message and the exception's message are inincompatible encodings, such as a UTF-8 message with accented letters and a binary exception message
that holds bytes outside ASCII. Before, the log call raised, and a
measure_*block raised thaterror in place of its own exception. Now, when joining the message, the exception's class name, and
its message would raise, or would make an ASCII message binary, they are converted to valid UTF-8
first: binary text is read as the UTF-8 it usually holds, and invalid bytes are dropped. Text in
another encoding, such as ISO-8859-1, otherwise stays in it.
Encoding::CompatibilityErrorwhen the String that a block returns isin an encoding incompatible with the message, such as
logger.info("Café") { response.body }with a binary body that holds bytes outside ASCII, or when the second argument is such a String,
as in
logger.info("Café", response.body). Before, the error was raised into the application.Now they are joined the way
log_exception: :partialjoins the message and the exception'smessage. So a binary String added to an ASCII message is now read as UTF-8 too, and the message
stays UTF-8, without the String's bytes that are not valid UTF-8, rather than becoming binary.
:default,:color, and:patternwithoutescape_control_chars, and:syslogwithescape_control_chars: false, no longer lose an entry whose texts are in incompatible encodings,such as a UTF-8 message logged with an exception whose message is binary and holds bytes outside
ASCII, a binary message after a logger name with accented letters, the text of tags or named tags
in different encodings, or the binary message of an exception that caused the logged one. A UTF-16
message no longer loses the entry either, and neither does such a cause in the stack trace that
:lokiand:open_telemetrywrite. Before, formatting raisedEncoding::CompatibilityError, andthe appender reported the error to the internal logger instead of writing the entry. Now a String
that holds bytes outside ASCII in an encoding other than UTF-8 is converted to UTF-8 before it is
written, as
:one_line,:syslogwith its default escaping, andescape_control_chars: truealready do: binary text is read as the UTF-8 it usually holds, and its invalid bytes are dropped,
and text in another encoding, such as ISO-8859-1, is converted. So these formatters now always
write UTF-8, also for an entry whose text is all in one other encoding, which they used to write
in that encoding. A
:patternortime_formatin another encoding is converted to UTF-8 when theformatter is built, and the host, application, and environment names that
:patternwrites areconverted too, such as an application name read from the environment where no locale is set.
See Upgrading to v5.3.
:one_linenow also removes the Unicode next line (U+0085), line separator (U+2028), andparagraph separator (U+2029) from every text field, or escapes them as
\u0085,\u2028, and\u2029withescape_control_chars: true. Editors, browsers, and some log viewers start a newline at each, so logged text that held one, such as a user's input, could show an entry over
two lines. Exception details are also split into lines at them, and joined with a space.
in a payload, tag, named tag, or exception message no longer prints "warning: JSON.generate:
UTF-8 string passed as BINARY, this will raise an encoding error in json 3.0" to standard error,
once for each such String every time a JSON based formatter or
:logfmtwrites the entry,including in the appenders that use them, and
:graylog. The JSON is unchanged: the String iswritten as UTF-8, as it is with json 3.1. On those json versions Semantic Logger prepends a
module to Ruby's
Warningthat drops that one warning when it comes from serializing log data;the application's own JSON, including an exception's own
#message, still warns.:graylognowhands the gelf gem a copy with such Strings converted to UTF-8, since the gem serializes it
itself, and so does
:sentry_ruby.measure_*block that raises an exception whose#messageraises, such as one that reads arecord that is nil, now re-raises its own exception. Before, with
log_exception: :partial(thedefault), the error that
#messageraised replaced it, without it as the cause, and nothing waslogged; a log call with
log_exception: :partialraised that error too. Now:partialwrites themessage the exception was raised with instead, or its class name when it was raised without one,
as in
Saving -- Exception: OrderError: OrderError, and does the same for each exception thatcaused it.
:json,:raw,:fluentd,:ecs,:loki, ...),:logfmt,:one_line,:open_telemetry,:syslog, the other text formatters withescape_control_chars: true, and:cloudwatch_logsno longer drop the characters of a binaryString that holds UTF-8, such as a response body, Base64-decoded text, or a C extension's error
message, or of a US-ASCII String that holds UTF-8, such as a file read or an environment variable
Configuration
📅 Schedule: (UTC)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.