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

accept standard OpenTelemetry environmental variables for configuration

Open loomis opened this issue 2 years ago • 6 comments

See the OpenTelemetry environmental variable definitions.

loomis avatar Jan 03 '23 14:01 loomis

Just a pointer on this one: ideally, it should be supported via Extensions.Configuration using IOptions, so that the settings are honored no matter how they are passed to the application (either via actual envvars, or via any other config source as long as the setting names are consistent).

The initial implementation of the OTEL libraries were only considering actual env vars and not using the configuration system to read them and that was a mistake (it has since been changed).

julealgon avatar Jan 03 '23 15:01 julealgon

@nblumhardt Is there another sink that uses the IOptions pattern for configuration? I'm finding it difficult to understand how to integrate this and a concrete example would be helpful.

loomis avatar Feb 12 '23 22:02 loomis

Splitting WriteTo.OpenTelemetry(..) might need to be split into the one we have today, and one that accepts an IConfiguration or similar and no additional args.

Trying to meld the two (explicit parameters for endpoints etc. + default ones from configuration) seems fraught with difficulties, so better if the user decides which style they're after.

IIRC the Serilog.Sinks.MSSqlServer sink does some special options support along these lines (not sure if it's the model to follow, but might help).

HTH!

nblumhardt avatar Feb 14 '23 01:02 nblumhardt

Thanks! Will take a look.

loomis avatar Feb 14 '23 10:02 loomis

Just adding another note for when we're back around to this; the typical way for Serilog to interact with external configuration is via ReadFrom.X() where X() today is one of Configuration()/Settings()/KeyValuePairs().

Given that the OTel variables are already defined and won't conform to any schema Serilog currently recognizes, we might be best off adding a ReadFrom.OpenTelemetryEnvironment() option that would just do the obvious thing - look for environment variables and (internally) pass these to WriteTo.OpenTelemetry() in strongly-typed args.

There's no restriction preventing e.g. an IConfiguration, or a bunch of defaults, being passed through to the ReadFrom extension, either.

Edit: clarifying - this would be called instead of WriteTo.OpenTelemetry() when using the sink. The sink would still provide WriteTo.OpenTelemetry() for purely programmatic configuration, but where the environment should be consulted, consumers would use ReadFrom.OpenTelemetryEnvironment() instead, potentially passing in default values for when the standard variables are absent.

nblumhardt avatar Apr 12 '23 22:04 nblumhardt

The opentelemetry-dotnet project's OtlpExporterOptions class might be a helpful example of merging these environment variables with dotnet's Options pattern.

collinkostichuk-unity3d avatar Jan 18 '24 22:01 collinkostichuk-unity3d

@nblumhardt I've created a PR #141

Can you review please?

AlbertoMonteiro avatar Jun 20 '24 03:06 AlbertoMonteiro

@AlbertoMonteiro I found another environment variables which seems to be missing in the PR:

OTEL_SERVICE_NAME https://opentelemetry.io/docs/languages/sdk-configuration/general/#otel_service_name

Could you add support for this aswell?

prochnowc avatar Jul 19 '24 09:07 prochnowc

@prochnowc 4.0.0-dev-00317 now includes this.

nblumhardt avatar Jul 23 '24 06:07 nblumhardt

@nblumhardt Many thanks. It's really helpfull when using Aspire.

prochnowc avatar Jul 23 '24 06:07 prochnowc