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

Integrate Jenkins OpenTelemetry with Gradle OpenTelemetry

Open cyrille-leclerc opened this issue 1 year ago • 4 comments

What feature do you want to see added?

Gradle supports OTel instrumentation through the https://github.com/craigatk/opentelemetry-gradle-plugin We want the same OpenTelemetry integration of Gradle builds with Jenkins as we have with Maven builds.

Upstream changes

Hopefully no change if the OpenTelemetry Gradle Plugin supports context propagation making sense of the TRACEPARENT and TRACESTATE environment variables. Hopefully it's just documentation.

Are you interested in contributing this feature?

Yes. @craigatk would you be interested in this integration that may just be documentation?

cyrille-leclerc avatar May 22 '24 13:05 cyrille-leclerc

Sure, I'd be happy to update the OpenTelemetry Gradle plugin to more seamlessly integrate with the Jenkins OpenTelemetry plugin.

Currently the Gradle plugin looks for the parent trace ID and parent span ID with environment variables (docs), and I can add the specific environment variable names this Jenkins plugin uses.

For grabbing the parent trace ID and parent span ID in the Gradle plugin, is there documentation and/or code that lists what's in the TRACEPARENT and TRACESTATE environment variables published by the Jenkins plugin?

craigatk avatar May 22 '24 13:05 craigatk

Ahh I think I found it in the docs, looks like the Jenkins plugin is already exporting the same TRACE_ID and SPAN_ID environment variables that the Gradle plugin is looking for https://github.com/jenkinsci/opentelemetry-plugin/blob/main/docs/job-traces.md#environment-variables-for-trace-context-propagation-and-integrations

So this may just be a documentation update, as you mentioned.

craigatk avatar May 22 '24 13:05 craigatk

Thanks Craig!

TRACEPARENT and TRACESTATE follow the https://www.w3.org/TR/trace-context/ spec with the subtle nuance of being upper case rather than lower case. The OTel community discusses the standardization of hese environment variables in

  • https://github.com/open-telemetry/opentelemetry-specification/issues/740

The Java code we use to parse TRACEPARENT and TRACESTATE is provided by the OTel SDK:

    TextMapGetter<Map<String, String>> toUpperCaseTextMapGetter = new ToUpperCaseTextMapGetter();
    io.opentelemetry.context.Context context =
        openTelemetrySdkService
            .getPropagators()
            .getTextMapPropagator()
            .extract(
                io.opentelemetry.context.Context.current(),
                System.getenv(),
                toUpperCaseTextMapGetter);

https://github.com/open-telemetry/opentelemetry-java-contrib/blob/0deabdde108c544b1b6a3642578acb7fe88fc294/maven-extension/src/main/java/io/opentelemetry/maven/OtelExecutionListener.java#L138-L146

You can find in many CI/CD tools that support TRACEPARENT and TRACESTATE, including:

cyrille-leclerc avatar May 22 '24 15:05 cyrille-leclerc

pytest-otel also support it

kuisathaverat avatar May 29 '24 08:05 kuisathaverat

Works out of the box image

cyrille-leclerc avatar Sep 09 '24 21:09 cyrille-leclerc