Skip to content

Commit 8bf97c5

Browse files
Anty0claude
andcommitted
fix: attach OTEL javaagent directly in bootRunWithObservability
The previous approach set OTEL_JAVAAGENT_ENABLED via `environment` in a doFirst block, but bootRun's System.getenv() check runs at Gradle configuration time (before any task executes), so the javaagent flag was never added. Fix by adding jvmArgs directly in the doFirst block. Also clarify copyOtelAgent comment: it's a standalone helper for IntelliJ run configurations, not used by bootRun or bootRunWithObservability. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f66ffce commit 8bf97c5

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

backend/app/build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ bootRun {
298298
}
299299
}
300300

301-
// Copy OTEL agent to a predictable location for IntelliJ usage
301+
// Copy OTEL agent JAR to a predictable location for manual IntelliJ run configuration.
302+
// Not used by bootRun or bootRunWithObservability (they resolve the agent from Gradle's dependency cache).
303+
// Usage: ./gradlew server-app:copyOtelAgent → build/otel/opentelemetry-javaagent.jar
304+
// Then add -javaagent:backend/app/build/otel/opentelemetry-javaagent.jar to your IntelliJ VM options.
302305
// See: docs/observability/
303306
tasks.register('copyOtelAgent', Copy) {
304307
from configurations.otelAgent
@@ -317,6 +320,12 @@ tasks.register('bootRunWithObservability') {
317320
// Spring profile
318321
args '--spring.profiles.active=dev'
319322

323+
// Attach the OTEL javaagent directly. We cannot rely on bootRun's
324+
// System.getenv("OTEL_JAVAAGENT_ENABLED") check because that runs at Gradle
325+
// configuration time (before any task executes), while this doFirst block
326+
// runs at execution time.
327+
jvmArgs "-javaagent:${configurations.otelAgent.singleFile.absolutePath}"
328+
320329
// OTEL configuration
321330
environment 'OTEL_JAVAAGENT_ENABLED', 'true'
322331
environment 'OTEL_SERVICE_NAME', 'tolgee-platform'

0 commit comments

Comments
 (0)