-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[Logging.EventSource] Add trace correlation fields #103655
[Logging.EventSource] Add trace correlation fields #103655
Conversation
src/libraries/Microsoft.Extensions.Logging.EventSource/src/LoggingEventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventSource/src/LoggingEventSource.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.EventSource/src/EventSourceLogger.cs
Outdated
Show resolved
Hide resolved
string? activityTraceId; | ||
string? activitySpanId; | ||
string? activityTraceFlags; | ||
if (activity != null && activity.IdFormat == ActivityIdFormat.W3C) |
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 we sure we don't want support non W3C cases too?
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.
Well for non-W3C TraceId is going to spit out 00000000000000000000000000000000
and SpanId is going to spit out 0000000000000000
. We could just push Activity.Id
into the events which would include W3C
, Hierarchical
, and (presumably) anything added in the future. BUT. Accessing Activity.Id
will force an allocation in the process being monitored. And it will force consumers to have to inspect the value and understand the possible formats/differences. Probably also the consumers will have to chop up the Id
into the individual components. In my world of OTel I don't need hierarchical but if you feel there is a need and the tradeoffs are OK, I'm happy to switch 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.
We have been supporting the Hierarchical
cases with external logger scopes.
runtime/src/libraries/Microsoft.Extensions.Logging/src/LoggerFactoryScopeProvider.cs
Line 291 in b93061a
public static string GetSpanId(this Activity activity) |
Also, will it make sense to add the parent Id to the event as we do in scopes?
CC @noahfalk if he has more insight if we should ignore the Hierarchical
cases or not.
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.
Just FYI the reason I went with ActivityTraceId
, ActivitySpanId
, and ActivityTraceFlags
is because those are the only things defined on the OTel Logs Data Model for correlation: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#log-and-event-record-definition
Happy to add other things, but from OTel perspective they aren't required.
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'd be fine omitting support for hierarichal. Worst case I forsee is we get feedback that someone wants Hierarichal support, we decide the scenario in the request is important and then we add that too in a future release. I think that has a pretty low chance of happening.
src/libraries/Microsoft.Extensions.Logging.EventSource/tests/EventSourceLoggerTest.cs
Outdated
Show resolved
Hide resolved
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.
Let's wait @noahfalk approval and then we can proceed merging.
…-correlationfields
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.
LGTM 👍
@CodeBlanch I am seeing test failure in https://helixre107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-103655-merge-e2f8c48b4c15440fa9/Microsoft.Extensions.Logging.EventSource.Tests/1/console.3e8ced58.log?helixlogtype=result which can be related. |
* Add trace correlation fields to Microsoft.Extensions.Logging.EventSource. * Code review. * Code review. * Test fix.
Fixes #76718
Changes
ActivityTraceId
,ActivitySpanId
, andActivityTraceFlags
fromActivity.Current
to log events/cc @noahfalk @tarekgh