opentelemetry-specification icon indicating copy to clipboard operation
opentelemetry-specification copied to clipboard

No clear API defined for resource detector libraries

Open joaopgrassi opened this issue 1 year ago • 6 comments

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.

joaopgrassi avatar Apr 26 '24 12:04 joaopgrassi

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

  • ~~Go has resource.with<X>~~, see below
  • Erlang has a resource detector behaviour
  • Java has <X>Resource.get()
  • JS has <X>detector.detect(<config>)
  • ...

svrnm avatar Apr 26 '24 13:04 svrnm

  • 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 =/

joaopgrassi avatar Apr 26 '24 14:04 joaopgrassi

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

MrAlias avatar Apr 26 '24 14:04 MrAlias

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.

joaopgrassi avatar Apr 29 '24 14:04 joaopgrassi

A PR to clarify this would be welcome!

austinlparker avatar Jul 23 '24 20:07 austinlparker

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.

jack-berg avatar Jul 23 '24 20:07 jack-berg