Skip to content

Commit d92fb55

Browse files
committed
Hystrix metadata
1 parent 68fdead commit d92fb55

File tree

8 files changed

+137
-46
lines changed

8 files changed

+137
-46
lines changed

docs/instrumentation-list.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,12 +3722,35 @@ libraries:
37223722
type: STRING
37233723
hystrix:
37243724
- name: hystrix-1.4
3725+
description: This instrumentation enables the generation of INTERNAL spans for
3726+
Hystrix command executions and fallbacks.
37253727
source_path: instrumentation/hystrix-1.4
37263728
scope:
37273729
name: io.opentelemetry.hystrix-1.4
37283730
target_versions:
37293731
javaagent:
37303732
- com.netflix.hystrix:hystrix-core:[1.4.0,)
3733+
configurations:
3734+
- name: otel.instrumentation.hystrix.experimental-span-attributes
3735+
description: Enables capturing the experimental `hystrix.command`, `hystrix.circuit_open`
3736+
and `hystrix.group` span attributes.
3737+
type: boolean
3738+
default: false
3739+
telemetry:
3740+
- when: default
3741+
spans:
3742+
- span_kind: INTERNAL
3743+
attributes: []
3744+
- when: otel.instrumentation.hystrix.experimental-span-attributes=true
3745+
spans:
3746+
- span_kind: INTERNAL
3747+
attributes:
3748+
- name: hystrix.circuit_open
3749+
type: BOOLEAN
3750+
- name: hystrix.command
3751+
type: STRING
3752+
- name: hystrix.group
3753+
type: STRING
37313754
influxdb:
37323755
- name: influxdb-2.4
37333756
source_path: instrumentation/influxdb-2.4

instrumentation-docs/instrumentations.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ readonly INSTRUMENTATIONS=(
149149
"hibernate:hibernate-4.0:javaagent:testExperimental"
150150
"hibernate:hibernate-6.0:javaagent:test"
151151
"hibernate:hibernate-6.0:javaagent:testExperimental"
152+
"hystrix-1.4:javaagent:test"
153+
"hystrix-1.4:javaagent:testExperimental"
152154
)
153155

154156
# Some instrumentation test suites don't run ARM, so we use colima to run them in an x86_64

instrumentation/hystrix-1.4/javaagent/build.gradle.kts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,27 @@ dependencies {
2020
library("io.reactivex:rxjava:1.0.8")
2121
}
2222

23-
tasks.withType<Test>().configureEach {
24-
// TODO run tests both with and without experimental span attributes
25-
jvmArgs("-Dotel.instrumentation.hystrix.experimental-span-attributes=true")
26-
// Disable so failure testing below doesn't inadvertently change the behavior.
27-
jvmArgs("-Dhystrix.command.default.circuitBreaker.enabled=false")
28-
jvmArgs("-Dio.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext=false")
29-
30-
// Uncomment for debugging:
31-
// jvmArgs("-Dhystrix.command.default.execution.timeout.enabled=false")
23+
tasks {
24+
withType<Test>().configureEach {
25+
// Disable so failure testing below doesn't inadvertently change the behavior.
26+
jvmArgs("-Dhystrix.command.default.circuitBreaker.enabled=false")
27+
jvmArgs("-Dio.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext=false")
28+
29+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
30+
31+
// Uncomment for debugging:
32+
// jvmArgs("-Dhystrix.command.default.execution.timeout.enabled=false")
33+
}
34+
35+
val testExperimental by registering(Test::class) {
36+
testClassesDirs = sourceSets.test.get().output.classesDirs
37+
classpath = sourceSets.test.get().runtimeClasspath
38+
39+
jvmArgs("-Dotel.instrumentation.hystrix.experimental-span-attributes=true")
40+
systemProperty("metadataConfig", "otel.instrumentation.hystrix.experimental-span-attributes=true")
41+
}
42+
43+
check {
44+
dependsOn(testExperimental)
45+
}
3246
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.hystrix;
7+
8+
import static io.opentelemetry.api.common.AttributeKey.booleanKey;
9+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
10+
11+
import io.opentelemetry.api.common.AttributeKey;
12+
import javax.annotation.Nullable;
13+
14+
class ExperimentalTestHelper {
15+
private static final boolean isEnabled =
16+
Boolean.getBoolean("otel.instrumentation.hystrix.experimental-span-attributes");
17+
18+
static final AttributeKey<String> HYSTRIX_COMMAND = stringKey("hystrix.command");
19+
static final AttributeKey<String> HYSTRIX_GROUP = stringKey("hystrix.group");
20+
static final AttributeKey<Boolean> HYSTRIX_CIRCUIT_OPEN = booleanKey("hystrix.circuit_open");
21+
22+
@Nullable
23+
static String experimental(String value) {
24+
if (isEnabled) {
25+
return value;
26+
}
27+
return null;
28+
}
29+
30+
@Nullable
31+
static Boolean experimental(Boolean value) {
32+
if (isEnabled) {
33+
return value;
34+
}
35+
return null;
36+
}
37+
38+
private ExperimentalTestHelper() {}
39+
}

instrumentation/hystrix-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/hystrix/HystrixObservableChainTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
package io.opentelemetry.javaagent.instrumentation.hystrix;
77

8-
import static io.opentelemetry.api.common.AttributeKey.booleanKey;
9-
import static io.opentelemetry.api.common.AttributeKey.stringKey;
8+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.HYSTRIX_CIRCUIT_OPEN;
9+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.HYSTRIX_COMMAND;
10+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.HYSTRIX_GROUP;
11+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.experimental;
1012
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1113
import static org.assertj.core.api.Assertions.assertThat;
1214

@@ -24,7 +26,7 @@
2426
class HystrixObservableChainTest {
2527

2628
@RegisterExtension
27-
protected static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
29+
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
2830

2931
@Test
3032
@SuppressWarnings("RxReturnValueIgnored")
@@ -93,9 +95,9 @@ protected Observable<String> construct() {
9395
span.hasName("ExampleGroup.TestCommand.execute")
9496
.hasParent(trace.getSpan(0))
9597
.hasAttributesSatisfyingExactly(
96-
equalTo(stringKey("hystrix.command"), "TestCommand"),
97-
equalTo(stringKey("hystrix.group"), "ExampleGroup"),
98-
equalTo(booleanKey("hystrix.circuit_open"), false)),
98+
equalTo(HYSTRIX_COMMAND, experimental("TestCommand")),
99+
equalTo(HYSTRIX_GROUP, experimental("ExampleGroup")),
100+
equalTo(HYSTRIX_CIRCUIT_OPEN, experimental(false))),
99101
span ->
100102
span.hasName("tracedMethod")
101103
.hasParent(trace.getSpan(1))
@@ -104,9 +106,9 @@ protected Observable<String> construct() {
104106
span.hasName("OtherGroup.AnotherTestCommand.execute")
105107
.hasParent(trace.getSpan(1))
106108
.hasAttributesSatisfyingExactly(
107-
equalTo(stringKey("hystrix.command"), "AnotherTestCommand"),
108-
equalTo(stringKey("hystrix.group"), "OtherGroup"),
109-
equalTo(booleanKey("hystrix.circuit_open"), false)),
109+
equalTo(HYSTRIX_COMMAND, experimental("AnotherTestCommand")),
110+
equalTo(HYSTRIX_GROUP, experimental("OtherGroup")),
111+
equalTo(HYSTRIX_CIRCUIT_OPEN, experimental(false))),
110112
span ->
111113
span.hasName("anotherTracedMethod")
112114
.hasParent(trace.getSpan(3))

instrumentation/hystrix-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/hystrix/HystrixObservableTest.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
package io.opentelemetry.javaagent.instrumentation.hystrix;
77

8-
import static io.opentelemetry.api.common.AttributeKey.booleanKey;
9-
import static io.opentelemetry.api.common.AttributeKey.stringKey;
8+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.HYSTRIX_CIRCUIT_OPEN;
9+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.HYSTRIX_COMMAND;
10+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.HYSTRIX_GROUP;
11+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.experimental;
1012
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1113
import static org.assertj.core.api.Assertions.assertThat;
1214
import static org.assertj.core.api.Assertions.catchException;
@@ -36,7 +38,7 @@
3638
class HystrixObservableTest {
3739

3840
@RegisterExtension
39-
protected static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
41+
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
4042

4143
@ParameterizedTest
4244
@MethodSource("provideCommandActionArguments")
@@ -83,9 +85,9 @@ protected Observable<String> construct() {
8385
span.hasName("ExampleGroup.TestCommand.execute")
8486
.hasParent(trace.getSpan(0))
8587
.hasAttributesSatisfyingExactly(
86-
equalTo(stringKey("hystrix.command"), "TestCommand"),
87-
equalTo(stringKey("hystrix.group"), "ExampleGroup"),
88-
equalTo(booleanKey("hystrix.circuit_open"), false)),
88+
equalTo(HYSTRIX_COMMAND, experimental("TestCommand")),
89+
equalTo(HYSTRIX_GROUP, experimental("ExampleGroup")),
90+
equalTo(HYSTRIX_CIRCUIT_OPEN, experimental(false))),
8991
span ->
9092
span.hasName("tracedMethod")
9193
.hasParent(trace.getSpan(1))
@@ -292,9 +294,9 @@ protected Observable<String> resumeWithFallback() {
292294
span.hasName("ExampleGroup.TestCommand.fallback")
293295
.hasParent(trace.getSpan(1))
294296
.hasAttributesSatisfyingExactly(
295-
equalTo(stringKey("hystrix.command"), "TestCommand"),
296-
equalTo(stringKey("hystrix.group"), "ExampleGroup"),
297-
equalTo(booleanKey("hystrix.circuit_open"), false))));
297+
equalTo(HYSTRIX_COMMAND, experimental("TestCommand")),
298+
equalTo(HYSTRIX_GROUP, experimental("ExampleGroup")),
299+
equalTo(HYSTRIX_CIRCUIT_OPEN, experimental(false)))));
298300
}
299301

300302
private static Stream<Arguments> provideCommandFallbackArguments() {
@@ -383,17 +385,17 @@ protected Observable<String> construct() {
383385
.hasStatus(StatusData.error())
384386
.hasException(exception.getCause())
385387
.hasAttributesSatisfyingExactly(
386-
equalTo(stringKey("hystrix.command"), "TestCommand"),
387-
equalTo(stringKey("hystrix.group"), "FailingGroup"),
388-
equalTo(booleanKey("hystrix.circuit_open"), false)),
388+
equalTo(HYSTRIX_COMMAND, experimental("TestCommand")),
389+
equalTo(HYSTRIX_GROUP, experimental("FailingGroup")),
390+
equalTo(HYSTRIX_CIRCUIT_OPEN, experimental(false))),
389391
span ->
390392
span.hasName("FailingGroup.TestCommand.fallback")
391393
.hasParent(trace.getSpan(1))
392394
.hasException(hystrixRuntimeException.getFallbackException())
393395
.hasAttributesSatisfyingExactly(
394-
equalTo(stringKey("hystrix.command"), "TestCommand"),
395-
equalTo(stringKey("hystrix.group"), "FailingGroup"),
396-
equalTo(booleanKey("hystrix.circuit_open"), false))));
396+
equalTo(HYSTRIX_COMMAND, experimental("TestCommand")),
397+
equalTo(HYSTRIX_GROUP, experimental("FailingGroup")),
398+
equalTo(HYSTRIX_CIRCUIT_OPEN, experimental(false)))));
397399
}
398400

399401
private static Stream<Arguments> provideCommandNoFallbackResultsInErrorArguments() {

instrumentation/hystrix-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/hystrix/HystrixTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
package io.opentelemetry.javaagent.instrumentation.hystrix;
77

8-
import static io.opentelemetry.api.common.AttributeKey.booleanKey;
9-
import static io.opentelemetry.api.common.AttributeKey.stringKey;
8+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.HYSTRIX_CIRCUIT_OPEN;
9+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.HYSTRIX_COMMAND;
10+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.HYSTRIX_GROUP;
11+
import static io.opentelemetry.javaagent.instrumentation.hystrix.ExperimentalTestHelper.experimental;
1012
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1113
import static org.assertj.core.api.Assertions.assertThat;
1214
import static org.junit.jupiter.api.Named.named;
@@ -31,7 +33,7 @@
3133
class HystrixTest {
3234

3335
@RegisterExtension
34-
protected static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
36+
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
3537

3638
@ParameterizedTest
3739
@MethodSource("provideCommandActionArguments")
@@ -42,7 +44,7 @@ class TestCommand extends HystrixCommand<String> {
4244
}
4345

4446
@Override
45-
protected String run() throws Exception {
47+
protected String run() {
4648
return tracedMethod();
4749
}
4850

@@ -65,9 +67,9 @@ private String tracedMethod() {
6567
span.hasName("ExampleGroup.TestCommand.execute")
6668
.hasParent(trace.getSpan(0))
6769
.hasAttributesSatisfyingExactly(
68-
equalTo(stringKey("hystrix.command"), "TestCommand"),
69-
equalTo(stringKey("hystrix.group"), "ExampleGroup"),
70-
equalTo(booleanKey("hystrix.circuit_open"), false)),
70+
equalTo(HYSTRIX_COMMAND, experimental("TestCommand")),
71+
equalTo(HYSTRIX_GROUP, experimental("ExampleGroup")),
72+
equalTo(HYSTRIX_CIRCUIT_OPEN, experimental(false))),
7173
span ->
7274
span.hasName("tracedMethod")
7375
.hasParent(trace.getSpan(1))
@@ -108,16 +110,16 @@ protected String getFallback() {
108110
.hasStatus(StatusData.error())
109111
.hasException(new IllegalArgumentException())
110112
.hasAttributesSatisfyingExactly(
111-
equalTo(stringKey("hystrix.command"), "TestCommand"),
112-
equalTo(stringKey("hystrix.group"), "ExampleGroup"),
113-
equalTo(booleanKey("hystrix.circuit_open"), false)),
113+
equalTo(HYSTRIX_COMMAND, experimental("TestCommand")),
114+
equalTo(HYSTRIX_GROUP, experimental("ExampleGroup")),
115+
equalTo(HYSTRIX_CIRCUIT_OPEN, experimental(false))),
114116
span ->
115117
span.hasName("ExampleGroup.TestCommand.fallback")
116118
.hasParent(trace.getSpan(1))
117119
.hasAttributesSatisfyingExactly(
118-
equalTo(stringKey("hystrix.command"), "TestCommand"),
119-
equalTo(stringKey("hystrix.group"), "ExampleGroup"),
120-
equalTo(booleanKey("hystrix.circuit_open"), false))));
120+
equalTo(HYSTRIX_COMMAND, experimental("TestCommand")),
121+
equalTo(HYSTRIX_GROUP, experimental("ExampleGroup")),
122+
equalTo(HYSTRIX_CIRCUIT_OPEN, experimental(false)))));
121123
}
122124

123125
private static Stream<Arguments> provideCommandActionArguments() {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
description: This instrumentation enables the generation of INTERNAL spans for Hystrix command executions and fallbacks.
2+
configurations:
3+
- name: otel.instrumentation.hystrix.experimental-span-attributes
4+
description: Enables capturing the experimental `hystrix.command`, `hystrix.circuit_open` and `hystrix.group` span attributes.
5+
type: boolean
6+
default: false
7+

0 commit comments

Comments
 (0)