Skip to content
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

Allow registering processor by type for logging retrieved by dependency injection. #3823

Closed
vasililiev opened this issue Oct 26, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@vasililiev
Copy link

Feature Request

There's a discrepancy in the way processors are registered between tracing and logging.
When adding a processor for logging, it requires an instance. Whereas for tracing, registering a type is enough as the actual instance is supplied by the dependency container.

Is your feature request related to a problem?

Our telemetry processor rely on dependency injection to inject certain dependency. When registering OpenTelemetry it's not possible to resolve this dependency and pass it to the options.

Describe the solution you'd like:

Aligning the API for adding processor between logging and tracing.

  loggingBuilder.AddOpenTelemetry(config =>
  {
      config.AddProcessor<MyProcessor>();
  });

Describe alternatives you've considered.

N/A
There are no alternatives

Additional Context

N/A

@CodeBlanch
Copy link
Member

We added LoggerProviderBuilder in 1.9.0 which gives logging the same parity w.r.t. dependency injection as metrics & tracing. This can now be achieved using WithLogging style or via ConfigureOpenTelemetryLoggerProvider.

  • Using OpenTelemetry.Extensions.Hosting:

    builder.Services.AddOpenTelemetry()
        .ConfigureResource(r => r.AddService(builder.Environment.ApplicationName))
        .WithLogging(logging => logging
            .AddProcessor<MyProcessor>());
  • Using OpenTelemetrySdk.Create (1.10.0):

    using var sdk = OpenTelemetrySdk.Create(builder => builder
        .WithLogging(logging => logging
            .AddProcessor<MyProcessor>()));
  • Using LoggerFactory.Create:

   using var loggerFactory = LoggerFactory.Create(builder =>
   {
       builder.Services.ConfigureOpenTelemetryLoggerProvider(logging => logging
           .AddProcessor<MyProcessor>());

       builder.AddOpenTelemetry();
   });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants