Skip to content

Commit f117aee

Browse files
committed
enable new extended observability wil feature flag
1 parent 023ce5d commit f117aee

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ tasks {
255255
// usually when developing and we want to test the plugin
256256
//see org.digma.intellij.plugin.idea.execution.OtelAgentPathProvider
257257
//don't forget to comment when done testing !
258-
//"digma.agent.override.path" to "/home/shalom/workspace/digma/digma-agent/build/libs/digma-agent-1.0.2.jar"
258+
//"digma.agent.override.path" to "/home/shalom/workspace/digma/digma-agent/build/libs/digma-agent-1.0.8-SNAPSHOT.jar"
259259
//"digma.otel.extension.override.path" to "/home/shalom/workspace/digma/otel-java-instrumentation/agent-extension/build/libs/digma-otel-agent-extension-0.8.12.jar"
260260
//can also change the url from where the jar is downloaded when IDE starts
261261
//"org.digma.otel.extensionUrl" to "some url

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/execution/JavaParametersMerger.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ open class JavaParametersMerger(
9595
protected fun smartMergeJavaToolOptions(myJavaToolOptions: String, currentJavaToolOptions: String): String {
9696

9797
//merge two java tool options strings. values from myJavaToolOptions override values from currentJavaToolOptions
98+
//we want to preserve the order , existing java tool options properties should be first
9899

99-
val myOptions = javaToolOptionsToMap(myJavaToolOptions)
100100
val currentOptions = javaToolOptionsToMap(currentJavaToolOptions)
101+
val myOptions = javaToolOptionsToMap(myJavaToolOptions)
101102

102103
val result = mutableMapOf<String, String?>()
103104
result.putAll(currentOptions)

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/execution/JavaToolOptionsBuilder.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,27 @@ open class JavaToolOptionsBuilder(
3939
}
4040

4141

42-
open fun withOtelAgent(useAgent: Boolean): JavaToolOptionsBuilder {
42+
open fun withOtelAgent(useAgent: Boolean, parametersExtractor: ParametersExtractor): JavaToolOptionsBuilder {
4343

4444
if (useAgent) {
4545
if (!otelAgentPathProvider.hasAgentPath()) {
46-
throw JavaToolOptionsBuilderException("useAgent is true but can't find agent paths")
46+
throw JavaToolOptionsBuilderException("useAgent is true but can't find agent or extension paths")
4747
}
48+
49+
val shouldUseDigmaAgent = parametersExtractor.extractEnvValue(USE_DIGMA_AGENT_PROP_NAME) == "true"
50+
if (shouldUseDigmaAgent) {
51+
if (!otelAgentPathProvider.hasDigmaAgentPath()) {
52+
throw JavaToolOptionsBuilderException("USE_DIGMA_AGENT is true but can't find digma agent paths")
53+
}
54+
55+
javaToolOptions
56+
.append("-javaagent:${otelAgentPathProvider.digmaAgentPath}")
57+
.append(" ")
58+
59+
disableExtendedObservabilityExtension()
60+
}
61+
4862
javaToolOptions
49-
.append("-javaagent:${otelAgentPathProvider.digmaAgentPath}")
50-
.append(" ")
5163
.append("-javaagent:${otelAgentPathProvider.otelAgentPath}")
5264
.append(" ")
5365
.append("-Dotel.javaagent.extensions=${otelAgentPathProvider.digmaExtensionPath}")
@@ -262,12 +274,9 @@ open class JavaToolOptionsBuilder(
262274

263275

264276
open fun build(): String {
265-
disableExtendedObservabilityExtension()
266277
return javaToolOptions.toString()
267278
}
268279

269-
//todo: disabled in this branch because it uses Digma agent that injects @WithSpan instead of the
270-
// digma-methods instrumentation module.
271280
private fun disableExtendedObservabilityExtension() {
272281
javaToolOptions
273282
.append("-Dotel.instrumentation.digma-methods.enabled=false")

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/execution/OtelAgentPathProvider.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ class OtelAgentPathProvider(configuration: RunConfiguration) {
7676

7777

7878
fun hasAgentPath(): Boolean {
79-
return otelAgentPath != null && digmaExtensionPath != null && digmaAgentPath != null
79+
return otelAgentPath != null && digmaExtensionPath != null
80+
}
81+
82+
fun hasDigmaAgentPath(): Boolean {
83+
return digmaAgentPath != null
8084
}
8185

8286
}

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/execution/constants.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const val OTEL_SERVICE_NAME_PROP_NAME = "otel.service.name"
1212

1313
const val DIGMA_MARKER = "-Dorg.digma.marker=true"
1414

15+
//a feature flag to use digma agent for extended instrumentation instead of the otel extension module
16+
const val USE_DIGMA_AGENT_PROP_NAME = "USE_DIGMA_AGENT"
17+
18+
1519
/*
1620
DIGMA_OBSERVABILITY is an environment variable to forces observability when user executes an unsupported
1721
gradle task or maven goal. it should be used only for gradle or maven. it can not force observability for unknown

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/execution/flavor/DefaultInstrumentationFlavor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ open class DefaultInstrumentationFlavor : BaseInstrumentationFlavor() {
118118
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
119119

120120
javaToolOptionsBuilder
121-
.withOtelAgent(useOtelAgent())
121+
.withOtelAgent(useOtelAgent(), parametersExtractor)
122122
.withMockitoSupport(isTest)
123123
.withServiceName(moduleResolver, parametersExtractor, serviceNameProvider)
124124
.withExtendedObservability()

0 commit comments

Comments
 (0)