Skip to content

[feature request] Allow ActivityContext to be passed into ILogger explicitly, rather than relying solely on Activity.Current #6085

Open
@Aaronontheweb

Description

@Aaronontheweb

Package

OpenTelemetry

Is your feature request related to a problem?

My scenario might be an edge-case but it also might not be - in the Akka.NET project we have our own logging infrastructure dating back to the beginning of the project (2013) designed to allow logs to be formatted and processed asynchronously using some of our actors. We capture the context from the live running actor and defer the expensive formatting until later - similar in spirit and execution to OpenTelemetry's own processing pipeline.

We capture a LogEvent, emit it via an in-memory topic broker to a LogActor who either renders it live (in batches) on the console or exports it to something like Serilog, NLog, or Microsoft.Extensions.Logging.

An issue I have: akkadotnet/akka.net#7476 - we are trying to add support for capturing an ActivityContext when some of our built-in actors are doing message processing. The issue we have is this:

There's not any means to pass the ActivityContext as a state object to the OTEL ILogger implementation. The only real way to preserve our the ActivityContext is to forward the entire Activity to our LogActor, have it set that as the Activity.Current, and then clear it as soon as the ILogger is done.

What is the expected behavior?

I would love a means of being able to just pass in the ActivityContext explicitly from elsewhere to the Log method and use that as the provided context for the ILogger, so I can keep the processing of log events and the recording of traces temporally decoupled from each other.

Which alternative solutions or features have you considered?

As I mentioned in the first part of the post - we could just keep the entire Activity and temporarily restore it as Activity.Current in order to satisfy the current ILogger implementation. Not totally keen on doing this because it's kind of ugly.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestneeds-triageNew issues which have not been classified or triaged by a community memberpkg:OpenTelemetryIssues related to OpenTelemetry NuGet package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions