You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SdkProvidedResource detector currently has to know about all other detectors to correctly set service.name.
Detectors currently fill out resources in a last one wins fashion. In the following situation EnvResourceDetector, upon finding service.name will overwrite the value even if the SdkProvidedResourceDetector obtained it from OTEL_SERVICE_NAME.
let resource = Resource::from_detectors(
time::Duration::from_secs(5),vec![Box::new(SdkProvidedResourceDetector),Box::new(EnvResourceDetector::new()),],);
It's possible to reverse to ordering of the resource detectors to get the right result, but this doesn't support adding other resource detectors.
let resource = Resource::from_detectors(
time::Duration::from_secs(5),vec![Box::new(MyResourceDetector::new()),Box::new(EnvResourceDetector::new()),Box::new(SdkProvidedResourceDetector),],);
In this case SdkProvidedResourceDetector will override any value obtained by MyResourceDetector with unknown_service if it can't find anything from env.
The issue seems to be that if a detector does defaulting then it leads to issues. The following works:
let resource = Resource::from_detectors(
time::Duration::from_secs(5),vec![Box::new(MyResourceDetector::new()),Box::new(EnvResourceDetector::new()),Box::new(EnvServiceNameDetector::new()),//Only sets service.name if it exists in env.],);
Proposal: If instead Resouce itself is responsible for defaulting service name then it can take a look at the attributes after all detectors have been resolved and see if service name is missing.
I'm interested in this as well. I initially made an attempt extending SdkProvidedResourceDetector with a fallback_service_name: Option<String> (deriving Default) and adding a constructor for the fallback name, but it requires everyone to "properly" create an instance (you can't just use SdkProvidedResourceDetector.detect anymore).
I think your approach of letting Resource take care of defaulting a service name if unset is nicer, and I favor it.
SdkProvidedResource
detector currently has to know about all other detectors to correctly set service.name.Detectors currently fill out resources in a last one wins fashion. In the following situation
EnvResourceDetector
, upon findingservice.name
will overwrite the value even if theSdkProvidedResourceDetector
obtained it fromOTEL_SERVICE_NAME
.It's possible to reverse to ordering of the resource detectors to get the right result, but this doesn't support adding other resource detectors.
In this case
SdkProvidedResourceDetector
will override any value obtained byMyResourceDetector
withunknown_service
if it can't find anything from env.Relates to #1295
The text was updated successfully, but these errors were encountered: