open-telemetry / opentelemetry-specification

Specifications for OpenTelemetry
https://opentelemetry.io
Apache License 2.0
3.75k stars 889 forks source link

No clear API defined for resource detector libraries #4016

Open joaopgrassi opened 6 months ago

joaopgrassi commented 6 months ago

What are you trying to achieve?

We have specified the way to load resource attributes from the environment via resource detector packages.

The Resource SDK spec says:

Resource detector packages MUST provide a method that returns a resource. This can then be associated with TracerProvider or MeterProvider instances as described above.

But it never defined exactly what the method is called. This may end up in a situation where each library exposes a method with a different name which then creates problems if such packages are to be loaded/invoked automatically (e.g., by an agent). This would make implementing something like #2948 impossible.

What did you expect to see?

Clear specification of what a resource detector package must provide, giving which method it must have, similar to what we do for Samplers for example.

svrnm commented 6 months ago

Since many languages have resource detectors implemented already, a few pointers how it looks like right now:

joaopgrassi commented 6 months ago
  • Go has resource.with<X>

  • Erlang has a resource detector behaviour

  • Java has <X>Resource.get()

  • JS has <X>detector.detect(<config>)

As I expected, already inconsistent behavior =/

MrAlias commented 6 months ago

For Go it is Detector.Detect: https://pkg.go.dev/go.opentelemetry.io/otel/sdk/resource#Detector

joaopgrassi commented 6 months ago

For C++ and Envoy it's also Detect.

So I think we should add this method to the specification. It seems it's the most common denominator.

austinlparker commented 3 months ago

A PR to clarify this would be welcome!

jack-berg commented 3 months ago

For java its ResourceProvider. Detectors that implement this interface are able to contribute to the resource generated by opentelemetry-sdk-extension-autoconfigure, which is java's tool for automatically configuring the SDK based on environment.