-
-
Notifications
You must be signed in to change notification settings - Fork 224
WIP fix: Ensure structured logs from an SDK integration has sentry.origin #4566
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
base: main
Are you sure you want to change the base?
WIP fix: Ensure structured logs from an SDK integration has sentry.origin #4566
Conversation
@sentry review |
bugbot review |
This comment has been minimized.
This comment has been minimized.
🚨 Bugbot couldn't runSomething went wrong. Try again by commenting "Cursor review" or "bugbot run", or contact support (requestId: serverGenReqId_8ec61e90-31f9-40d2-9718-56e6535d466d). |
bugbot review |
@sentry review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4566 +/- ##
==========================================
+ Coverage 73.45% 73.47% +0.01%
==========================================
Files 480 482 +2
Lines 17589 17683 +94
Branches 3469 3495 +26
==========================================
+ Hits 12920 12992 +72
- Misses 3785 3800 +15
- Partials 884 891 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100 % convinced of the origin names that we use right now, but also don't have a concrete suggestion in store ... if you don't mind, I'll let my mind wander a bit and will get back to you soon.
Also, feedback from other reviewers appreciated. @jamescrosswell what do you think?
From memory, we started setting the
|
}; | ||
|
||
log.SetDefaultAttributes(_options, _sdk); | ||
log.SetOrigin("auto.log.microsoft_extensions"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these always supposed to be auto
for structured logs? If the SDK user does ILogger.Log(...)
then shouldn't this be manual
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good point. The docs indeed say we should set the type to manual
when the user manually sends a log... I'll fix it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, upon more thinking, this has more nuance than I thought. Wouldn't the SDK user pretty much always have to call ILogger.Log(...)
to log something? Does that mean that sentry.origin
should always be manual.[...]
?
The documentation linked above states that:
traces
Required. Can be either manual or auto. manual indicates that the user created the trace or span, auto indicates that the SDK or some integration created it.
It doesn't mention logs, but I assume if a user creates a log, then we put manual
. So is it always manual
, since logs cannot be created without some kind of user code calling ILogger.Log(...)
?
@Flash0ver Do you have any input for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what the docs say for SDK Integration Attributes:
If a log is generated by an SDK integration, the SDK should also set the sentry.origin attribute, as per the Trace Origin documentation. It is assumed that logs without a sentry.origin attribute are manually created by the user.
{
"sentry.origin": "auto.db.graphql"
}
So maybe we differentiate when a user calls ILogger.Log(...)
vs. ILogger.LogInformation(...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexsohn1126 sorry I might have sent you on a goose chase there.
Speaking with @Flash0ver about this it might be that:
- If the logs are coming via one of our integrations (e.g. Sentry.Extensions.Logging or Sentry.Serilog) then you'd set this to
auto
(since we automatically converted a serilog log or an ILogger log to a Sentry Structured one in that case). - However if an SDK user used the Sentry API to create a log directly then that would be
manual
@Flash0ver were you able to confirm this as the desired behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes things clear! Thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clarified with @AbhiPrasad 🥔
- the SDK-Logger (via
SentrySdk.Logger.Log*
) never sendssentry.origin
... the absence ofsentry.origin
indicates the Log was captured through the Logger of the respective SDK (sentry.sdk.name
) - all integrations always send
auto. ..
, regardless of the Log-Message being created through the integration from user-code or Application-code/Library-code
Co-authored-by: James Crosswell <[email protected]>
Co-authored-by: James Crosswell <[email protected]>
Whoops, forgot to mention that we will be consolidating the category for |
Fixes #4560
Problem
According to our SDK specification, we have to set
sentry.origin
whenever a log is sent from an integration.Solution
sentry-dotnet
has a few integrations that send out logs. This PR affects the following integrations:Sentry.Extensions.Logging
Sentry.Serilog
And affects other integrations that references
Sentry.Extensions.Logging
, or references it transitively.Comparison
Before, logs from

Sentry.Serilog
didn't havesentry.origin
:After, logs from

Sentry.Serilog
hassentry.origin
populated: