Skip to content

feat(logs): initial work on develop docs for sdk logging api #12920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Apr 22, 2025

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Mar 4, 2025

resolves #12870

Sentry is exploring an application logging product! More details here in our internal notion: https://www.notion.so/sentry/PRFAQ-Application-Logging-1258b10e4b5d80ea8e98e8ec5505542c.

To get the ball rolling, I'm helping push forward the spec in the SDK. This was initially in Notion (https://www.notion.so/sentry/Logs-in-the-SDK-1a48b10e4b5d80b1827fe14d9fd0236b#1a58b10e4b5d80019d2eef6d84213d4a), but now we're moving it to develop so that we can work more in the open.

This PR documents:

  1. The idealized public api for logs
  2. The idealized sdk options for logs
  3. The otel log envelope format
  4. The recommended internal sdk behavior for logs

You'll notice only the otel_log envelope item is documented. This is what we used for the first alpha release of the SDK, but we'll be moving the SDKs to use the log envelope item instead. Until the logenvelope item protocol is finalized we are avoiding documenting in develop, but we marked it as TODO in the necessary sections. No longer applies log envelope item has been documented.

Rendered Preview:

@AbhiPrasad AbhiPrasad self-assigned this Mar 4, 2025
Copy link

vercel bot commented Mar 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
develop-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 22, 2025 2:51pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
changelog ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 2:51pm
sentry-docs ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 2:51pm

@AbhiPrasad AbhiPrasad changed the title [WIP] feat(logs): intial work on develop docs for sdk logging api feat(logs): intial work on develop docs for sdk logging api Mar 5, 2025
Comment on lines 81 to 86
{
"key": "string_item",
"value": {
"stringValue": "value"
}
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this format quite clunky, is this how OTel does things? If we have some leeway here I think the following would already go a long way towards making this easier to work with:

  1. removing the extra nesting; i.e., not having "value" be a dictionary but rather the flat value
  2. instead of having different names for the key depending on the type, moving the type into its own key

So basically the above would become this:

Suggested change
{
"key": "string_item",
"value": {
"stringValue": "value"
}
},
{
"key": "string_item",
"value": "value",
"type": "string",
},

I'd especially like to do 2. since in Python it otherwise leads to some non-idiomatic code where instead of just accessing the value by key, you have to pop() from the dict instead. It's not a huge deal but I had to work with dicts like this and it felt very clunky.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, this is the format for otel_log so I guess we can't be creative here. :) But maybe we can come up with a nicer format for logs once we get to defining that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking that the format is a bit verbose. But as this is just the otel logs data model https://opentelemetry.io/docs/specs/otel/logs/data-model/ it is fine.

For the logs type I think we should also be as close to potel as possible. As this is an internal format and the user will probably never see this, it does not matter if it is a bit verbose.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may be heading towards using AnyValue proto (the value type you're seeing here, from OTel) in our RPCs, in which case I think we may not want to be creative at all for the transport protocol for sdks since AnyValue will be used essentially everywhere in our product from ingest to rpc to frontend.

It may make more sense for the sdks to offer idiomatic apis that convert into our protocol, especially since the idioms differ anyway (eg. stringValue is fine in js since it's usually camelCase).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've improved this with logs pageload, see 3ff6e56

@@ -273,6 +273,7 @@ By default the SDK should set the following attributes:
5. `sentry.trace.parent_span_id`: The span id of the span that was active when the log was collected. This should not be set if there was no active span.
6. `sentry.sdk.name`: The name of the SDK that sent the log
7. `sentry.sdk.version`: The version of the SDK that sent the log
8. [BACKEND SDKS ONLY] `server.address`: The address of the server that sent the log. Equivalent to `server_name` we attach to errors and transactions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be sentry.server.address?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using the OTEL conventions directly here, so I feel fine with setting it this way. There's nothing specific about this attribute to sentry.

k-fish added a commit to getsentry/relay that referenced this pull request Apr 11, 2025
### Summary
Now that we've mostly finalized the logs protocol with sdks (see
[develop doc for more
info](getsentry/sentry-docs#12920)), we want to
update Relay to allow the 'log' item type to be sent in this format.

SDK's will likely primarily use the `log` ItemType instead of `otel_log`
since we don't need to change timestamp conventions, can send a
simplified `level` (see `OurLogLevel` added in this PR).

#### Schema changes
We've deprecated some fields in the protocol that only exist for OTEL:
- `severity_number` and `severity_text`, we're coercing these to
`level`, but we're keeping the original severity text and number as
attributes as OTel allows custom severity text.
- `observed_timestamp_nanos` is always set by relay regardless of what
is sent because Relay is the 'collector'. We have to leave this as an
attribute as well since it's being used by the existing consumer for
origin timestamp.
- `timestamp_nanos` becomes `timestamp: Timestamp`
- `trace_flags`, this is unused, and the consumer doesn't even store it
in the table. Will decide what to do with this later.

#### Future work
- The `ourlog_merge_otel` function can be trimmed down since we won't
need to fill in deprecated fields to send the same data to the kafka
consumer.
- We may need to transform the `OurLog` protocol from json received from
sdks to a generic EAP "trace items" kafka message that is essentially a
couple fields (eg. traceid) + a KVMap for `attributes`.

---------

Co-authored-by: Michi Hoffmann <[email protected]>
Co-authored-by: David Herberth <[email protected]>
Copy link
Member

@cleptric cleptric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weeee :shipit:

*None*
`item_count`

: **integer, required.** The number of log items in the envelope.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: **integer, required.** The number of log items in the envelope.
: **integer, required.** The number of log entries in the item.

It's just scoped to the item, unfortunately naming clashes here "log item" and "envelope item"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard - good catch, will fix.

@AbhiPrasad
Copy link
Member Author

This is ready to merge, will do so as soon as CI passes.

The only thing major TODO to iterate on this the default attributes section. Because this still has some open Q, I'm going to tackle this in a follow up.

Copy link

codecov bot commented Apr 22, 2025

Bundle Report

Changes will increase total bundle size by 135 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sentry-docs-server-cjs 11.14MB 141 bytes (0.0%) ⬆️
sentry-docs-client-array-push 9.47MB -6 bytes (-0.0%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: sentry-docs-server-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
1729.js -3 bytes 1.75MB -0.0%
../instrumentation.js -3 bytes 1.08MB -0.0%
9523.js -3 bytes 1.05MB -0.0%
../app/[[...path]]/page.js.nft.json 50 bytes 388.48kB 0.01%
../app/platform-redirect/page.js.nft.json 50 bytes 388.39kB 0.01%
../app/sitemap.xml/route.js.nft.json 50 bytes 386.36kB 0.01%
view changes for bundle: sentry-docs-client-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
static/chunks/pages/_app-*.js -3 bytes 868.7kB -0.0%
static/chunks/8165-*.js -3 bytes 410.1kB -0.0%
server/middleware-*.js 5.55kB 6.55kB 555.3% ⚠️
server/middleware-*.js -5.55kB 1.0kB -84.74%
static/ys4-*.js (New) 578 bytes 578 bytes 100.0% 🚀
static/ys4-*.js (New) 77 bytes 77 bytes 100.0% 🚀
static/Yd0cqjRC-*.js (Deleted) -578 bytes 0 bytes -100.0% 🗑️
static/Yd0cqjRC-*.js (Deleted) -77 bytes 0 bytes -100.0% 🗑️

@AbhiPrasad AbhiPrasad merged commit 385e6e6 into master Apr 22, 2025
14 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-logs-sdk-developer-documentation branch April 22, 2025 14:51
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.

Add Logs Section to Develop Docs
10 participants