Package io.prometheus.otelagent
Class ResourceAttributesFromOtelAgent
Object
ResourceAttributesFromOtelAgent
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetResourceAttributes
(String instrumentationScopeName) This grabs resource attributes likeservice.name
andservice.instance.id
from the OTel Java agent (if present) and adds them toresult
.
-
Constructor Details
-
ResourceAttributesFromOtelAgent
public ResourceAttributesFromOtelAgent()
-
-
Method Details
-
getResourceAttributes
This grabs resource attributes likeservice.name
andservice.instance.id
from the OTel Java agent (if present) and adds them toresult
.The way this works is as follows: If the OTel Java agent is attached, it modifies the
GlobalOpenTelemetry.get()
method to return an agent-specific object. From that agent-specific object we can get the resource attributes via reflection.So we load the
GlobalOpenTelemetry
class (in a separate class loader from the JAR files that are bundled with this module), call.get()
, and inspect the returned object.After that we discard the class loader so that all OTel specific classes are unloaded. No runtime dependency on any OTel version remains.
The test for this class is in examples/example-exporter-opentelemetry/oats-tests/agent/service-instance-id-check.py
-