serilog-sinks-opentelemetry icon indicating copy to clipboard operation
serilog-sinks-opentelemetry copied to clipboard

Mapping enrichers with Resource attributes

Open cecilphillip opened this issue 1 year ago • 2 comments

Given a configuration similar to the following, would it possible to flow enriched properties to OTEL Resource attributes. For instances, I'd want to be able to set the host.name attribute with the value from WithMachineName.

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Information()
    .Enrich.FromLogContext()
    .Enrich.WithThreadId()
    .Enrich.WithEnvironmentName()
    .Enrich.WithMachineName()
    .WriteTo.Console(outputTemplate: outputTemplate)
    .WriteTo.OpenTelemetry(opts =>
    {
        opts.ResourceAttributes = new Dictionary<string, object>
        {
            ["service.name"] = "BackendApiService"
        };
    })
    .CreateLogger();

cecilphillip avatar Dec 08 '23 02:12 cecilphillip