Skip to content

T-7532 Take the log level from a JSON message - #13

Merged
PetrHeinz merged 2 commits into
mainfrom
claude/t-7532-json-level
Oct 13, 2026
Merged

PetrHeinz merged 2 commits into
mainfrom
claude/t-7532-json-level

Conversation

@PetrHeinz

@PetrHeinz PetrHeinz commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

CloudWatch log events whose message is a JSON object carry their level inside the JSON as level: Lambda's JSON log format writes {"timestamp":…,"level":"ERROR","requestId":…,"message":…}, and structured loggers such as winston or pino write JSON through console.log. The forwarder only read the level from a [LEVEL] bracket or a LEVEL prefix and otherwise sent info, so an error logged as JSON showed up as info in Better Stack.

The parser now parses a message that is a JSON object and, when it has a non-empty string level, sends that level lowercased.

It overrides the level from the text-format prefix too: in Lambda's text format a JSON logger's line arrives as <timestamp>\t<request id>\tINFO\t{"level":"error",…}, where the prefix only reflects which console method was called. The message itself is sent unchanged, so Better Stack still expands the JSON into fields.

Not covered:

  • Numeric levels such as pino's "level":50 are ignored.
  • timestamp and requestId inside a JSON-format message are not extracted into dt and context.request_id. The text-format prefix still is.

The first commit holds only the tests and is expected to fail CI. The second commit makes them pass.

PetrHeinz and others added 2 commits October 13, 2026 15:59
Pins that a CloudWatch log event whose message is a JSON object with a
string `level` (Lambda's JSON log format, or a structured logger writing
JSON through console.log) gets that level, including when the text-format
prefix says INFO.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
CloudWatch log events whose message is a JSON object with a string
`level` (Lambda's JSON log format, or a structured logger writing JSON
through console.log) kept the Lambda's default `info` level, or the
level from the text-format prefix, so errors logged as JSON showed up
as info in Better Stack. The JSON level now overrides both.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@PetrHeinz
PetrHeinz marked this pull request as ready for review October 13, 2026 16:14
@PetrHeinz
PetrHeinz merged commit 4a19c5d into main Oct 13, 2026
4 checks passed
@PetrHeinz
PetrHeinz deleted the claude/t-7532-json-level branch October 13, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant