Skip to content

Commit 249447b

Browse files
committed
force observability with DIGMA_OBSERVABILITY
1 parent ec45a37 commit 249447b

11 files changed

+149
-22
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ open class ParametersExtractor(protected val configuration: RunConfiguration, pr
6666
return params.env[OTEL_RESOURCE_ATTRIBUTES]?.contains("$DIGMA_ENVIRONMENT_RESOURCE_ATTRIBUTE=") ?: false
6767
}
6868

69+
70+
fun getDigmaObservability(): DigmaObservabilityType? {
71+
return extractEnvValue(DIGMA_OBSERVABILITY)?.takeIf { it.isNotBlank() }?.let {
72+
DigmaObservabilityType.valueOf(it)
73+
} ?: if (isEnvExists(DIGMA_OBSERVABILITY)) DigmaObservabilityType.app else null
74+
}
75+
76+
6977
fun extractEnvValue(envKeyName: String): String? {
7078

7179
if (configuration is ExternalSystemRunConfiguration &&
@@ -82,5 +90,15 @@ open class ParametersExtractor(protected val configuration: RunConfiguration, pr
8290

8391
}
8492

93+
fun isEnvExists(envKeyName: String): Boolean {
94+
95+
if (configuration is ExternalSystemRunConfiguration) {
96+
return configuration.settings.env.containsKey(envKeyName)
97+
}
98+
99+
return params.env.containsKey(envKeyName)
100+
101+
}
102+
85103

86104
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@ const val OTEL_SERVICE_NAME_PROP_NAME = "otel.service.name"
1212

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

15+
/*
16+
DIGMA_OBSERVABILITY is an environment variable to forces observability when user executes an unsupported
17+
gradle task or maven goal. it should be used only for gradle or maven. it can not force observability for unknown
18+
configuration types because we don't know how to treat unknown configuration types. gradle and maven configuration
19+
types are known to us, we just don't support all possible gradle task names or maven goals.
20+
there can be two values for DIGMA_OBSERVABILITY, app or test. when app, the observability will be treated as regular application,
21+
when test, the observability will be treated as test and is mainly used to add digma.environment LOCAL or LOCAL_TESTS.
22+
when exists and value is empty it will be treated as app.
23+
to force a different instrumentation flavor add INSTRUMENTATION_FLAVOR environment variable with value one of
24+
org.digma.intellij.plugin.idea.execution.flavor.InstrumentationFlavorType.
25+
examples:
26+
if running a task called myTask that we don't support:
27+
DIGMA_OBSERVABILITY or DIGMA_OBSERVABILITY=app -> will be treated as regula application with the default flavor
28+
DIGMA_OBSERVABILITY=test -> will be treated as a test execution.
29+
30+
together with
31+
DIGMA_OBSERVABILITY=test
32+
INSTRUMENTATION_FLAVOR=Quarkus
33+
will be treated as Quarkus flavor and a test execution.
34+
*/
35+
const val DIGMA_OBSERVABILITY = "DIGMA_OBSERVABILITY"
36+
37+
enum class DigmaObservabilityType { app, test }
1538

1639
val KNOWN_IRRELEVANT_TASKS = setOf(
1740
/*
@@ -146,4 +169,4 @@ val KNOWN_IRRELEVANT_TASKS = setOf(
146169
"runIde",
147170
"setupDependencies"
148171

149-
)
172+
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ abstract class BaseInstrumentationFlavor : InstrumentationFlavor {
5252

5353
open fun isTest(
5454
instrumentationService: RunConfigurationInstrumentationService,
55+
parametersExtractor: ParametersExtractor,
5556
configuration: RunConfiguration,
5657
params: SimpleProgramParameters
5758
): Boolean {

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.intellij.execution.configurations.SimpleProgramParameters
77
import org.digma.intellij.plugin.buildsystem.BuildSystem
88
import org.digma.intellij.plugin.errorreporting.ErrorReporter
99
import org.digma.intellij.plugin.execution.RunConfigurationInstrumentationService
10+
import org.digma.intellij.plugin.idea.execution.DigmaObservabilityType
1011
import org.digma.intellij.plugin.idea.execution.JavaToolOptionsBuilder
1112
import org.digma.intellij.plugin.idea.execution.ModuleResolver
1213
import org.digma.intellij.plugin.idea.execution.OtelResourceAttributesBuilder
@@ -114,7 +115,7 @@ open class DefaultInstrumentationFlavor : BaseInstrumentationFlavor() {
114115

115116
return try {
116117

117-
val isTest = isTest(instrumentationService, configuration, params)
118+
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
118119

119120
javaToolOptionsBuilder
120121
.withOtelAgent(useOtelAgent())
@@ -142,7 +143,7 @@ open class DefaultInstrumentationFlavor : BaseInstrumentationFlavor() {
142143
): Map<String, String> {
143144

144145
return try {
145-
val isTest = isTest(instrumentationService, configuration, params)
146+
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
146147

147148
otelResourceAttributesBuilder
148149
.withCommonResourceAttributes(isTest, parametersExtractor)
@@ -157,13 +158,24 @@ open class DefaultInstrumentationFlavor : BaseInstrumentationFlavor() {
157158

158159
override fun isTest(
159160
instrumentationService: RunConfigurationInstrumentationService,
161+
parametersExtractor: ParametersExtractor,
160162
configuration: RunConfiguration,
161163
params: SimpleProgramParameters
162164
): Boolean {
165+
//maybe DIGMA_OBSERVABILITY exists , it can force test if we don't support the running task
166+
// for gradle or maven
167+
val digmaObservability = parametersExtractor.getDigmaObservability()
163168
val buildSystem = instrumentationService.getBuildSystem(configuration)
164169
return when (buildSystem) {
165-
BuildSystem.GRADLE -> hasSupportedGradleTasks(instrumentationService.getTaskNames(configuration), SUPPORTED_GRADLE_TEST_TASKS)
166-
BuildSystem.MAVEN -> hasSupportedMavenGoals(instrumentationService.getTaskNames(configuration), SUPPORTED_MAVEN_TEST_GOALS)
170+
BuildSystem.GRADLE -> {
171+
hasSupportedGradleTasks(instrumentationService.getTaskNames(configuration), SUPPORTED_GRADLE_TEST_TASKS)
172+
|| digmaObservability == DigmaObservabilityType.test
173+
}
174+
175+
BuildSystem.MAVEN -> {
176+
hasSupportedMavenGoals(instrumentationService.getTaskNames(configuration), SUPPORTED_MAVEN_TEST_GOALS)
177+
|| digmaObservability == DigmaObservabilityType.test
178+
}
167179
BuildSystem.INTELLIJ -> configuration is JavaTestConfigurationBase
168180
}
169181
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ interface InstrumentationFlavor {
6262
}
6363
}
6464

65+
@Throws(NoSuchElementException::class)
66+
fun getByType(type: InstrumentationFlavorType): InstrumentationFlavor {
67+
return instrumentationFlavors.first {
68+
it.getFlavor() == type
69+
}
70+
}
6571

6672
private fun getFlavorInEnv(parametersExtractor: ParametersExtractor): InstrumentationFlavorType? {
6773
return try {
@@ -73,6 +79,8 @@ interface InstrumentationFlavor {
7379
null
7480
}
7581
}
82+
83+
7684
}
7785

7886

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class JavaServerInstrumentationFlavor : DefaultInstrumentationFlavor() {
3535

3636
override fun isTest(
3737
instrumentationService: RunConfigurationInstrumentationService,
38+
parametersExtractor: ParametersExtractor,
3839
configuration: RunConfiguration,
3940
params: SimpleProgramParameters
4041
): Boolean {

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.intellij.openapi.module.Module
88
import org.digma.intellij.plugin.buildsystem.BuildSystem
99
import org.digma.intellij.plugin.errorreporting.ErrorReporter
1010
import org.digma.intellij.plugin.execution.RunConfigurationInstrumentationService
11+
import org.digma.intellij.plugin.idea.execution.DigmaObservabilityType
1112
import org.digma.intellij.plugin.idea.execution.JavaToolOptionsBuilder
1213
import org.digma.intellij.plugin.idea.execution.ModuleResolver
1314
import org.digma.intellij.plugin.idea.execution.OtelResourceAttributesBuilder
@@ -105,7 +106,7 @@ class MicronautInstrumentationFlavor : BaseInstrumentationFlavor() {
105106
): String? {
106107
return try {
107108

108-
val isTest = isTest(instrumentationService, configuration, params)
109+
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
109110

110111
javaToolOptionsBuilder
111112
.withMicronautTracing(true)
@@ -134,7 +135,7 @@ class MicronautInstrumentationFlavor : BaseInstrumentationFlavor() {
134135
): Map<String, String> {
135136

136137
return try {
137-
val isTest = isTest(instrumentationService, configuration, params)
138+
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
138139

139140
otelResourceAttributesBuilder
140141
.withCommonResourceAttributes(isTest, parametersExtractor)
@@ -154,13 +155,24 @@ class MicronautInstrumentationFlavor : BaseInstrumentationFlavor() {
154155

155156
override fun isTest(
156157
instrumentationService: RunConfigurationInstrumentationService,
158+
parametersExtractor: ParametersExtractor,
157159
configuration: RunConfiguration,
158160
params: SimpleProgramParameters
159161
): Boolean {
162+
//maybe DIGMA_OBSERVABILITY exists , it can force test if we don't support the running task
163+
// for gradle or maven
164+
val digmaObservability = parametersExtractor.getDigmaObservability()
160165
val buildSystem = instrumentationService.getBuildSystem(configuration)
161166
return when (buildSystem) {
162-
BuildSystem.GRADLE -> hasSupportedGradleTasks(instrumentationService.getTaskNames(configuration), SUPPORTED_GRADLE_TEST_TASKS)
163-
BuildSystem.MAVEN -> hasSupportedMavenGoals(instrumentationService.getTaskNames(configuration), SUPPORTED_MAVEN_TEST_GOALS)
167+
BuildSystem.GRADLE -> {
168+
hasSupportedGradleTasks(instrumentationService.getTaskNames(configuration), SUPPORTED_GRADLE_TEST_TASKS)
169+
|| digmaObservability == DigmaObservabilityType.test
170+
}
171+
172+
BuildSystem.MAVEN -> {
173+
hasSupportedMavenGoals(instrumentationService.getTaskNames(configuration), SUPPORTED_MAVEN_TEST_GOALS)
174+
|| digmaObservability == DigmaObservabilityType.test
175+
}
164176
BuildSystem.INTELLIJ -> configuration is JavaTestConfigurationBase
165177
}
166178
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.intellij.execution.configurations.SimpleProgramParameters
66
import org.digma.intellij.plugin.buildsystem.BuildSystem
77
import org.digma.intellij.plugin.errorreporting.ErrorReporter
88
import org.digma.intellij.plugin.execution.RunConfigurationInstrumentationService
9+
import org.digma.intellij.plugin.idea.execution.DigmaObservabilityType
910
import org.digma.intellij.plugin.idea.execution.JavaToolOptionsBuilder
1011
import org.digma.intellij.plugin.idea.execution.ModuleResolver
1112
import org.digma.intellij.plugin.idea.execution.OtelResourceAttributesBuilder
@@ -84,7 +85,7 @@ class OpenLibertyInstrumentationFlavor : BaseInstrumentationFlavor() {
8485
): String? {
8586
return try {
8687

87-
val isTest = isTest(instrumentationService, configuration, params)
88+
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
8889

8990
javaToolOptionsBuilder
9091
.withOtelSdkDisabledEqualsFalse()
@@ -113,7 +114,7 @@ class OpenLibertyInstrumentationFlavor : BaseInstrumentationFlavor() {
113114
): Map<String, String> {
114115

115116
return try {
116-
val isTest = isTest(instrumentationService, configuration, params)
117+
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
117118

118119
otelResourceAttributesBuilder
119120
.withCommonResourceAttributes(isTest, parametersExtractor)
@@ -128,13 +129,24 @@ class OpenLibertyInstrumentationFlavor : BaseInstrumentationFlavor() {
128129

129130
override fun isTest(
130131
instrumentationService: RunConfigurationInstrumentationService,
132+
parametersExtractor: ParametersExtractor,
131133
configuration: RunConfiguration,
132134
params: SimpleProgramParameters
133135
): Boolean {
136+
//maybe DIGMA_OBSERVABILITY exists , it can force test if we don't support the running task
137+
// for gradle or maven
138+
val digmaObservability = parametersExtractor.getDigmaObservability()
134139
val buildSystem = instrumentationService.getBuildSystem(configuration)
135140
return when (buildSystem) {
136-
BuildSystem.GRADLE -> hasSupportedGradleTasks(instrumentationService.getTaskNames(configuration), SUPPORTED_GRADLE_TEST_TASKS)
137-
BuildSystem.MAVEN -> hasSupportedMavenGoals(instrumentationService.getTaskNames(configuration), SUPPORTED_MAVEN_TEST_GOALS)
141+
BuildSystem.GRADLE -> {
142+
hasSupportedGradleTasks(instrumentationService.getTaskNames(configuration), SUPPORTED_GRADLE_TEST_TASKS)
143+
|| digmaObservability == DigmaObservabilityType.test
144+
}
145+
146+
BuildSystem.MAVEN -> {
147+
hasSupportedMavenGoals(instrumentationService.getTaskNames(configuration), SUPPORTED_MAVEN_TEST_GOALS)
148+
|| digmaObservability == DigmaObservabilityType.test
149+
}
138150
BuildSystem.INTELLIJ -> false
139151
}
140152
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.intellij.openapi.module.Module
88
import org.digma.intellij.plugin.buildsystem.BuildSystem
99
import org.digma.intellij.plugin.errorreporting.ErrorReporter
1010
import org.digma.intellij.plugin.execution.RunConfigurationInstrumentationService
11+
import org.digma.intellij.plugin.idea.execution.DigmaObservabilityType
1112
import org.digma.intellij.plugin.idea.execution.JavaToolOptionsBuilder
1213
import org.digma.intellij.plugin.idea.execution.ModuleResolver
1314
import org.digma.intellij.plugin.idea.execution.OtelResourceAttributesBuilder
@@ -107,7 +108,7 @@ class QuarkusInstrumentationFlavor : BaseInstrumentationFlavor() {
107108
): String? {
108109
return try {
109110

110-
val isTest = isTest(instrumentationService, configuration, params)
111+
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
111112

112113
javaToolOptionsBuilder
113114
.withQuarkusOtelExportedTracesEndpoint()
@@ -155,13 +156,24 @@ class QuarkusInstrumentationFlavor : BaseInstrumentationFlavor() {
155156

156157
override fun isTest(
157158
instrumentationService: RunConfigurationInstrumentationService,
159+
parametersExtractor: ParametersExtractor,
158160
configuration: RunConfiguration,
159161
params: SimpleProgramParameters
160162
): Boolean {
163+
//maybe DIGMA_OBSERVABILITY exists , it can force test if we don't support the running task
164+
// for gradle or maven
165+
val digmaObservability = parametersExtractor.getDigmaObservability()
161166
val buildSystem = instrumentationService.getBuildSystem(configuration)
162167
return when (buildSystem) {
163-
BuildSystem.GRADLE -> hasSupportedGradleTasks(instrumentationService.getTaskNames(configuration), SUPPORTED_GRADLE_TEST_TASKS)
164-
BuildSystem.MAVEN -> hasSupportedMavenGoals(instrumentationService.getTaskNames(configuration), SUPPORTED_MAVEN_TEST_GOALS)
168+
BuildSystem.GRADLE -> {
169+
hasSupportedGradleTasks(instrumentationService.getTaskNames(configuration), SUPPORTED_GRADLE_TEST_TASKS)
170+
|| digmaObservability == DigmaObservabilityType.test
171+
}
172+
173+
BuildSystem.MAVEN -> {
174+
hasSupportedMavenGoals(instrumentationService.getTaskNames(configuration), SUPPORTED_MAVEN_TEST_GOALS)
175+
|| digmaObservability == DigmaObservabilityType.test
176+
}
165177
BuildSystem.INTELLIJ -> configuration is JavaTestConfigurationBase
166178
}
167179
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class SpringBootMicrometerInstrumentationFlavor : DefaultInstrumentationFlavor()
9494
): String? {
9595
return try {
9696

97-
val isTest = isTest(instrumentationService, configuration, params)
97+
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
9898

9999
javaToolOptionsBuilder
100100
.withCommonSpringBootWithMicrometerTracing(true)
@@ -124,7 +124,7 @@ class SpringBootMicrometerInstrumentationFlavor : DefaultInstrumentationFlavor()
124124
): Map<String, String> {
125125

126126
return try {
127-
val isTest = isTest(instrumentationService, configuration, params)
127+
val isTest = isTest(instrumentationService, parametersExtractor, configuration, params)
128128

129129
if (needToAddDigmaEnvironmentAttribute(parametersExtractor)) {
130130
if (isTest) {

0 commit comments

Comments
 (0)