Add Gradle client-daemon instrumentation to propagate trace context per-request#3175
Add Gradle client-daemon instrumentation to propagate trace context per-request#3175
Conversation
Co-authored-by: plengauer <100447901+plengauer@users.noreply.github.com>
Co-authored-by: plengauer <100447901+plengauer@users.noreply.github.com>
plengauer
left a comment
There was a problem hiding this comment.
@anthropic-code-agent that cant be the solution. You inject the traceparent when starting the daemon. But we need to propagate the context every single time something is repeated from the daemon
- Changed from daemon-startup context to per-request context propagation - Added CLIENT spans when client sends requests to daemon - Added SERVER spans when daemon receives requests - Uses ByteBuddy to instrument Gradle client-daemon communication - Removed daemon restart since context now propagates per-request - Added reflection-based header injection for traceparent propagation Co-authored-by: plengauer <100447901+plengauer@users.noreply.github.com>
You're absolutely right. I've updated the implementation to propagate trace context on every request to the daemon, not just at daemon startup. The new approach:
The daemon now stays running and handles multiple build requests, each with its own trace context. Commit: 9b7dbd4 |
plengauer
left a comment
There was a problem hiding this comment.
@copilot i get the following error running this changeset:
GradleHttpPropagationAgent.java:41: error: <anonymous GradleHttpPropagationAgent$1> is not abstract and does not override abstract method transform(Builder<?>,TypeDescription,ClassLoader,JavaModule,ProtectionDomain) in Transformer
.transform(new AgentBuilder.Transformer() {
^
GradleHttpPropagationAgent.java:35: error: <anonymous GradleHttpPropagationAgent$2> is not abstract and does not override abstract method transform(Builder<?>,TypeDescription,ClassLoader,JavaModule,ProtectionDomain) in Transformer
.transform(new AgentBuilder.Transformer() {
``` ^
Fixed in commit |
There was a problem hiding this comment.
Pull request overview
This PR introduces a custom Java agent to propagate OpenTelemetry trace context across Gradle client ↔ daemon requests so HTTP spans created inside the long-lived daemon can be correctly parented to each build’s trace.
Changes:
- Adds
GradleHttpPropagationAgent(ByteBuddy-based) to create CLIENT/SERVER spans around Gradle client/daemon request handling and propagatetraceparent. - Wires the new agent into deep Java injection (
-javaagent) so it’s applied during Java auto-instrumentation. - Updates the GitHub Actions build workflow to compile/package
gradlehttppropagationagent.jar.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/usr/share/opentelemetry_shell/agent.instrumentation.java/GradleHttpPropagationAgent.java |
New ByteBuddy Java agent to span and propagate context for Gradle client/daemon communication. |
src/usr/share/opentelemetry_shell/agent.instrumentation.java.sh |
Adds the new agent to the injected Java agent chain and adds a presence check for it. |
.github/workflows/build.yml |
Builds the new agent jar during CI (javac + jar with manifest). |
src/usr/share/opentelemetry_shell/agent.instrumentation.java/GradleHttpPropagationAgent.java
Outdated
Show resolved
Hide resolved
src/usr/share/opentelemetry_shell/agent.instrumentation.java/GradleHttpPropagationAgent.java
Show resolved
Hide resolved
src/usr/share/opentelemetry_shell/agent.instrumentation.java/GradleHttpPropagationAgent.java
Show resolved
Hide resolved
src/usr/share/opentelemetry_shell/agent.instrumentation.java/GradleHttpPropagationAgent.java
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The Gradle daemon makes HTTP requests (Maven dependencies) in a separate long-lived JVM process. When multiple builds run through the same daemon, each build needs its own trace context propagated to connect HTTP spans correctly.
Changes
GradleHttpPropagationAgent.java: Java agent that instruments Gradle client-daemon communication:ClientConnectionAdviceDaemonConnectionAdviceDaemonClientConnectionandDaemonConnectionclassesagent.instrumentation.gradle.sh: Shell wrapper that:GRADLE_OPTSbuild.yml: Added compilation step forgradlehttppropagationagent.jarwith ByteBuddy supportExample
The implementation instruments the client-daemon protocol to create CLIENT/SERVER span pairs for each build request, ensuring trace context flows correctly even when multiple builds use the same daemon instance.
Original prompt