Skip to content

EventSourceLogger does not propagate SpanId and TraceId #76718

Closed

Description

@wiktork

Description

Asp.net log scope data collected from an out of process collector such as dotnet-monitor no longer contains Activity information such as TraceId and SpanId. These properties are no longer added as part of the Request scope data (see dotnet/aspnetcore#22376). These properties are no added to loggers using IExternalScopeProvider/ISupportExternalScope, which EventSourceLogger does not support.

Related dotnet-monitor issue dotnet/dotnet-monitor#2545

Reproduction Steps

Create a new asp.net core 6.0 web application.
Install dotnet-monitor tool
Run dotnet-monitor collect --no-auth
Run curl https://localhost:52323/logs?level=Information&pid=<pid of web app>
Issue a request to the web app.

Expected behavior

Log from dotnet-monitor should contain SpanId and TraceId information

Actual behavior

Log entry contains RequestId and RequestPath, but no activity information is displayed.

Regression?

Yes; this behavior worked in 3.1

Known Workarounds

No response

Configuration

Windows .Net 6 x64

The issue is specific to net 6+.

Other information

No response

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Oct 6, 2022
  2. added this to the 8.0.0 milestone on Oct 6, 2022
  3. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Oct 6, 2022
  4. modified the milestones: 8.0.0, 9.0.0 on Jul 25, 2023
  5. modified the milestones: 9.0.0, Future on Nov 20, 2023
  6. CodeBlanch commented on May 30, 2024

    @CodeBlanch
    Contributor

    @tarekgh @noahfalk @samsp-msft

    It may be a good idea to implement ISupportExternalScope on EventSourceLoggerProvider as a perf improvement but I think for correlation what we should do is add TraceId, SpanId, and ActivityTraceFlags from Activity.Current as fields on the events emitted by LoggingEventSource.

    The reason is, users may not want scopes. In OTel we don't recommend scopes at all. Users who have enabled scopes have complained about the amount of data that appears because AspNetCore creates some scopes automatically.

    Why TraceId, SpanId, and ActivityTraceFlags? From an OTel perspective those are the trace context fields added to logs for correlation: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#log-and-event-record-definition

    Also I think we might want to try and get this into .NET 9. We're working on solving out of process monitoring and correlation is very important to that scenario.

  7. modified the milestones: Future, 9.0.0 on Jun 12, 2024
  8. added
    in-prThere is an active PR which will close this issue when it is merged
    on Jun 18, 2024
  9. locked and limited conversation to collaborators on Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Extensions-Loggingin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions