jenkinsci / opentelemetry-plugin

Monitor and observe Jenkins with OpenTelemetry.
https://plugins.jenkins.io/opentelemetry/
Apache License 2.0
93 stars 46 forks source link

Integrate Jenkins OpenTelemetry with Gradle OpenTelemetry #850

Open cyrille-leclerc opened 3 weeks ago

cyrille-leclerc commented 3 weeks ago

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?

craigatk commented 3 weeks ago

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 commented 3 weeks ago

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.

cyrille-leclerc commented 3 weeks ago

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

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:

kuisathaverat commented 2 weeks ago

pytest-otel also support it