Class ResourceAttributesFromOtelAgent

Object
ResourceAttributesFromOtelAgent

  • Constructor Details

  • Method Details

    • getResourceAttributes

      public static Map<String,String> getResourceAttributes(String instrumentationScopeName)
      This grabs resource attributes like service.name and service.instance.id from the OTel Java agent (if present) and adds them to result.

      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