iand675 / hs-opentelemetry

OpenTelemetry support for the Haskell programming language
https://iankduncan.com/projects/opentelemetry
BSD 3-Clause "New" or "Revised" License
73 stars 34 forks source link

Is there a way to set up resource attributes? #147

Closed geraldus closed 1 week ago

geraldus commented 2 months ago

Hello! I've noticed that adding span attributes (also known as tags) seems straightforward, but I'm having difficulty understanding if there's an approach to configure resource attributes (also known as process tags). In my situation, they are static, determined at startup, and remain consistent across all spans (such as environment, application name, version, etc.).

michaelpj commented 1 month ago

I think the SDK honours OTEL_RESOURCE_ATTRIBUTES, but I'm not sure if there's a way to set them programmatically, currently.

ehofreiter commented 1 week ago

There are two ways to provide resource attributes directly:

  1. Provide a Resource in code to getTracerProviderInitializationOptions' during initialization.
  2. Set the OTEL_RESOURCE_ATTRIBUTES environment variable.

These are considered user-provided resource attributes, and will be merged with any attributes gathered from built-in resource detectors or SDK defaults. This sounds like it fits your use case, and has been sufficient in my own experience. More sophisticated resource configuration is likely possible with custom resource detectors.

Note: The user-provided resource attributes should be prioritized over the built-in resource detectors, but due Issue #111 the merge priority was reversed. This is likely fixed by PR #156. See the tests added in that PR for some examples on how to implement these approaches.

geraldus commented 1 week ago

Thanks, I've already found this out from sources, setting OTEL_RESOURCE_ATTRIBUTES works as expected. Closing this for now.

geraldus commented 1 week ago

Resolved