Integrate Jenkins OpenTelemetry with Gradle OpenTelemetry
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?
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?
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.
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:
pytest-otel also support it
Works out of the box