From 264795f4d53f3f1a22bb3fd7770f69f97f8adec1 Mon Sep 17 00:00:00 2001 From: Jameson Date: Sun, 14 Jan 2024 02:14:59 +0100 Subject: [PATCH] fix: for dynamically adding java agent we also nee to enable dynamic agent loading in Java --- .../gradle/plugins/opentelemetry/OpenTelemetryPlugin.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/sh/tnn/gradle/plugins/opentelemetry/OpenTelemetryPlugin.kt b/src/main/kotlin/sh/tnn/gradle/plugins/opentelemetry/OpenTelemetryPlugin.kt index 7b9574d..67e385d 100644 --- a/src/main/kotlin/sh/tnn/gradle/plugins/opentelemetry/OpenTelemetryPlugin.kt +++ b/src/main/kotlin/sh/tnn/gradle/plugins/opentelemetry/OpenTelemetryPlugin.kt @@ -3,6 +3,7 @@ package sh.tnn.gradle.plugins.opentelemetry import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.logging.Logging +import org.gradle.process.JavaForkOptions import sh.tnn.gradle.plugins.dotenv.DotEnvPlugin import sh.tnn.gradle.plugins.java_environment.JavaEnvironmentPlugin @@ -51,7 +52,12 @@ class OpenTelemetryPlugin : Plugin { "OTEL_SERVICE_NAME" to resourceName, "OTEL_RESOURCE_ATTRIBUTES_NODE_NAME" to nodeName ) - it.append("JAVA_TOOL_OPTIONS", " -javaagent:${openTelemetryJavaAgentFile.absolutePath}") + } + + project.tasks.all { + if (it is JavaForkOptions) { + it.jvmArgs("-XX:+EnableDynamicAgentLoading", "-javaagent:${openTelemetryJavaAgentFile.absolutePath}") + } } } }