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

[Exporter.Geneva] Add DI support for GenevaLogExporter #613

Closed
1 of 2 tasks
shenglol opened this issue Aug 29, 2022 · 6 comments
Closed
1 of 2 tasks

[Exporter.Geneva] Add DI support for GenevaLogExporter #613

shenglol opened this issue Aug 29, 2022 · 6 comments
Assignees
Labels
comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva enhancement New feature or request

Comments

@shenglol
Copy link

shenglol commented Aug 29, 2022

Issue with OpenTelemetry.Exporter.Geneva

List of all OpenTelemetry NuGet packages and version that you are using:

Runtime version:

  • net6.0

Is this a feature request or a bug?

  • Feature Request
  • Bug

What is the expected behavior?

It would be great if we can add DI support for GenevaLogExporter, similar to what we have for GenevaMetricExporter and GenevaTraceExporter. This is possible now that open-telemetry/opentelemetry-dotnet#3504 is released.

@shenglol shenglol added the comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva label Aug 29, 2022
@rajkumar-rangaraj
Copy link
Contributor

Could you please let us which method you want to see on Geneva Log Exporter in DI?

@shenglol
Copy link
Author

shenglol commented Sep 1, 2022

Yes, I'm talking about OpenTelemetryLoggerOptions.AddGenevaLogExporter specifically. Within the extension method GenevaExporterOptions is currently created via a constructor, but I think now we can use OpenTelemetryLoggerOptions.ConfigureProvider to get it from the DI container. What I would like to achieve with this is to bind GenevaExporterOptions to an IConfiguration outside of AddGenevaLogExporter.

@Gnol-VN
Copy link

Gnol-VN commented Mar 29, 2023

Hey, I wonder if is this available yet? I would like to have this:

configure.AddOpenTelemetry(options => options.AddProcessor<Custom_Log_Scrubber_Rule_List>());

, where I can add custom scrubbing rules through Host builder @CodeBlanch

@CodeBlanch
Copy link
Member

Update for everyone. This is not available yet. Sorry! We're waiting on the OpenTelemetry Specification to declare log API/SDK specs stable before we do anything. Hoping that will be soon and then we can have parity in logs with the DI API surface we have for tracing & metrics. Current plan is for 1.6 to ship the SDK support and then we can update things like GenevaExporter.

That being said, you can accomplish some stuff today with a bit of ugly code!

Here is a startup snippet which accomplishes what some of the above is requesting...

appBuilder.Logging.AddOpenTelemetry();
appBuilder.Services.AddSingleton<Custom_Log_Scrubber_Rule_List>();
appBuilder.Services.AddOptions<OpenTelemetryLoggerOptions>().Configure<IServiceProvider>((options, sp) =>
{
    options.AddProcessor(sp.GetRequiredService<Custom_Log_Scrubber_Rule_List>());
    options.AddGenevaLogExporter(genevaOptions =>
    {
        appBuilder.Configuration.GetSection("GenevaExporter").Bind(genevaOptions);
    });
});

The key bit of knowledge is that OpenTelemetryLoggerOptions is requested through the Options API today which means you can use the IServiceProvider to modify it.

@vishweshbankwar vishweshbankwar added the enhancement New feature or request label Jan 29, 2024
@CodeBlanch
Copy link
Member

Update...

@CodeBlanch
Copy link
Member

Update...

LoggerProviderBuilder APIs were shipped stable in the 1.9.0 OTel SDK and support the same surface area w.r.t. DI as TracerProviderBuilder and MeterProviderBuilder. New extensions targeting LoggerProviderBuilder were added for GenevaExporter in its 1.9.0 release.

Logging code can now be made to work exactly like tracing & metrics.

  • Using OpenTelemetry.Extensions.Hosting
services
    .AddOpenTelemetry()
    .WithLogging(
        builder =>
        {
            builder.AddProcessor<MyProcessor>(); // Example of calling a DI-friendly API
            builder.AddGenevaLogExporter(o => o.ConnectionString = "<fill out>");
        },
        options => options.IncludeFormattedMessage = true);
  • Using LoggerFactory.Create
using var loggerFactory = LoggerFactory.Create(logging =>
{
    logging.AddOpenTelemetry(options => options.IncludeFormattedMessage = true);

    logging.Services.ConfigureOpenTelemetryLoggerProvider(builder =>
    {
        builder.AddProcessor<MyProcessor>(); // Example of calling a DI-friendly API
        builder.AddGenevaLogExporter(o => o.ConnectionString = "<fill out>");
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants