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

Mapping enrichers with Resource attributes #119

Open
cecilphillip opened this issue Dec 8, 2023 · 2 comments
Open

Mapping enrichers with Resource attributes #119

cecilphillip opened this issue Dec 8, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@cecilphillip
Copy link

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();
@nblumhardt
Copy link
Member

I think this is ultimately where we're heading, but I'm not sure what the mechanics should be.

Since resource attributes are expected to be static for the life of the application it's a bit of a waste to use an enricher in this case, but on the other hand, it leaves nice friendly-named properties for other sinks to consume 🤔

Resource attributes are also shared across the entire batched OTLP payload, so we'd need to think about what happens when multiple values show up for a RA.

@nblumhardt nblumhardt added the enhancement New feature or request label Dec 8, 2023
@alsi-lawr
Copy link
Contributor

alsi-lawr commented Aug 22, 2024

@cecilphillip you can configure the processor at the otel-collector to regroup by whichever labels you wish (groupbyatttrs), which sets the resource labels.

Alternatively, the environment name and machine name are statically read once at startup and cached in those enrichers anyway, so you can just skip the enrichers on the otlp sink and just add them as resource attributes from startup.

I'm not sure it really makes sense for resource attributes to be dynamically read, as OTLP expects those as static for a source's lifetime. The workaround at the otel-collector is easy enough to implement though with a couple of processors to regroup with host name and convert the attribute name to host.name. Or, you can create your own lightweight enricher at the end of the enricher pipeline that converts the property name to dot notation, or converting all non-message properties to dot notation for otlp consistency (I do this with snake case for Loki).

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