Skip to content

Commit d80e36a

Browse files
committed
sort modules and enable spans for a few more exmaples
1 parent d492ac8 commit d80e36a

File tree

13 files changed

+877
-694
lines changed

13 files changed

+877
-694
lines changed

docs/instrumentation-list.yaml

Lines changed: 762 additions & 657 deletions
Large diffs are not rendered by default.

instrumentation-docs/collect.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ readonly INSTRUMENTATIONS=(
2121
"apache-dbcp-2.0:javaagent:test"
2222
"apache-dbcp-2.0:javaagent:testStableSemconv"
2323
"apache-httpclient:apache-httpclient-5.0:javaagent:test"
24+
"apache-dubbo-2.7:javaagent:testDubbo"
2425
"c3p0-0.9:javaagent:test"
2526
"c3p0-0.9:javaagent:testStableSemconv"
2627
"clickhouse-client-0.5:javaagent:test"

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/internal/TelemetryAttribute.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.instrumentation.docs.internal;
77

8+
import java.util.Objects;
9+
810
/**
911
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
1012
* any time.
@@ -38,4 +40,22 @@ public String getType() {
3840
public void setType(String type) {
3941
this.type = type;
4042
}
43+
44+
// Overriding equals and hashCode to compare TelemetryAttribute objects based on name and type
45+
// This is important for our deduplication logic in the documentation generation process.
46+
@Override
47+
public boolean equals(Object o) {
48+
if (this == o) {
49+
return true;
50+
}
51+
if (!(o instanceof TelemetryAttribute that)) {
52+
return false;
53+
}
54+
return Objects.equals(name, that.name) && Objects.equals(type, that.type);
55+
}
56+
57+
@Override
58+
public int hashCode() {
59+
return Objects.hash(name, type);
60+
}
4161
}

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/parsers/SpanParser.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
*/
2424
public class SpanParser {
2525

26+
// We want to ignore test related attributes
27+
private static final List<String> EXCLUDED_ATTRIBUTES = List.of("x-test-", "test-baggage-");
28+
2629
/**
2730
* Pull spans from the `.telemetry` directory, filter them by scope, and set them in the module.
2831
*
@@ -107,7 +110,10 @@ private static void addSpanAttributes(
107110
}
108111

109112
for (TelemetryAttribute attr : span.getAttributes()) {
110-
attributes.add(new TelemetryAttribute(attr.getName(), attr.getType()));
113+
boolean excluded = EXCLUDED_ATTRIBUTES.stream().anyMatch(ex -> attr.getName().contains(ex));
114+
if (!excluded) {
115+
attributes.add(new TelemetryAttribute(attr.getName(), attr.getType()));
116+
}
111117
}
112118
}
113119

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/utils/YamlHelper.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ private static Map<String, Object> getLibraryInstrumentations(List<Instrumentati
7777
.equals(InstrumentationClassification.LIBRARY))
7878
.collect(
7979
Collectors.groupingBy(
80-
InstrumentationModule::getGroup, TreeMap::new, Collectors.toList()));
80+
InstrumentationModule::getGroup,
81+
TreeMap::new,
82+
Collectors.collectingAndThen(
83+
Collectors.toList(),
84+
modules ->
85+
modules.stream()
86+
.sorted(
87+
Comparator.comparing(
88+
InstrumentationModule::getInstrumentationName))
89+
.collect(Collectors.toList()))));
8190

8291
Map<String, Object> output = new TreeMap<>();
8392
libraryInstrumentations.forEach(
@@ -146,7 +155,7 @@ private static Map<String, Object> baseProperties(InstrumentationModule module)
146155
new ArrayList<>(module.getMetrics().getOrDefault(group, Collections.emptyList()));
147156
List<Map<String, Object>> metricsList = new ArrayList<>();
148157

149-
// sort metrics by name for some determinism in the order
158+
// sort by name for determinism in the order
150159
metrics.sort(Comparator.comparing(EmittedMetrics.Metric::getName));
151160

152161
for (EmittedMetrics.Metric metric : metrics) {
@@ -160,7 +169,7 @@ private static Map<String, Object> baseProperties(InstrumentationModule module)
160169
new ArrayList<>(module.getSpans().getOrDefault(group, Collections.emptyList()));
161170
List<Map<String, Object>> spanList = new ArrayList<>();
162171

163-
// sort metrics by name for some determinism in the order
172+
// sort by name for determinism in the order
164173
spans.sort(Comparator.comparing(EmittedSpans.Span::getSpanKind));
165174

166175
for (EmittedSpans.Span span : spans) {

instrumentation-docs/src/test/java/io/opentelemetry/instrumentation/docs/InstrumentationAnalyzerTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,21 @@ void testModuleConverterCreatesUniqueModules() {
7878
new InstrumentationPath(
7979
"same-name",
8080
"instrumentation/test1/same-name/library",
81-
"group1",
8281
"namespace1",
82+
"group1",
8383
InstrumentationType.LIBRARY),
8484
new InstrumentationPath(
8585
"same-name",
8686
"instrumentation/test2/same-name/library",
87-
"group2",
8887
"namespace2",
88+
"group2",
8989
InstrumentationType.LIBRARY));
9090

9191
List<InstrumentationModule> modules = ModuleParser.convertToModules("test", paths);
9292

9393
// Should create 2 separate modules because they have different group/namespace combinations
9494
assertThat(modules.size()).isEqualTo(2);
9595

96-
// Verify both modules exist with correct properties
9796
assertThat(
9897
modules.stream()
9998
.anyMatch(

instrumentation-docs/src/test/java/io/opentelemetry/instrumentation/docs/ModuleConverterTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,4 @@ void testSanitizePathNameRemovesRootAndKnownFolders() throws Exception {
5858
sanitized = ModuleParser.sanitizePathName("/root", "/root/other");
5959
assertThat(sanitized).isEqualTo("/other");
6060
}
61-
62-
@Test
63-
void testCreateModuleKeyIsConsistent() throws Exception {
64-
InstrumentationPath path = mock(InstrumentationPath.class);
65-
when(path.group()).thenReturn("g");
66-
when(path.namespace()).thenReturn("n");
67-
when(path.instrumentationName()).thenReturn("i");
68-
69-
var method = ModuleParser.class.getDeclaredMethod("createModuleKey", InstrumentationPath.class);
70-
method.setAccessible(true);
71-
72-
String key = (String) method.invoke(null, path);
73-
assertThat(key).isEqualTo("g:n:i");
74-
}
7561
}

instrumentation-docs/src/test/java/io/opentelemetry/instrumentation/docs/parsers/SpanParserTest.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ void getSpansFromFilesCombinesFilesCorrectly(@TempDir Path tempDir) throws IOExc
7272

7373
Files.writeString(telemetryDir.resolve("spans-1.yaml"), file1Content);
7474
Files.writeString(telemetryDir.resolve("spans-2.yaml"), file2Content);
75+
// duplicate span contents to test deduplication
76+
Files.writeString(telemetryDir.resolve("spans-3.yaml"), file2Content);
7577

7678
try (MockedStatic<FileManager> fileManagerMock = mockStatic(FileManager.class)) {
7779
fileManagerMock
@@ -80,6 +82,9 @@ void getSpansFromFilesCombinesFilesCorrectly(@TempDir Path tempDir) throws IOExc
8082
fileManagerMock
8183
.when(() -> FileManager.readFileToString(telemetryDir.resolve("spans-2.yaml").toString()))
8284
.thenReturn(file2Content);
85+
fileManagerMock
86+
.when(() -> FileManager.readFileToString(telemetryDir.resolve("spans-3.yaml").toString()))
87+
.thenReturn(file2Content);
8388

8489
Map<String, EmittedSpans> result =
8590
EmittedSpanParser.getSpansByScopeFromFiles(tempDir.toString(), "");
@@ -95,6 +100,20 @@ void getSpansFromFilesCombinesFilesCorrectly(@TempDir Path tempDir) throws IOExc
95100
.orElse(null);
96101
assertThat(clickHouseSpans).hasSize(2);
97102

103+
EmittedSpans.Span serverSpan =
104+
clickHouseSpans.stream()
105+
.filter(item -> item.getSpanKind().equals("SERVER"))
106+
.findFirst()
107+
.orElse(null);
108+
EmittedSpans.Span clientSpan =
109+
clickHouseSpans.stream()
110+
.filter(item -> item.getSpanKind().equals("CLIENT"))
111+
.findFirst()
112+
.orElse(null);
113+
114+
assertThat(serverSpan.getAttributes()).hasSize(1);
115+
assertThat(clientSpan.getAttributes()).hasSize(6);
116+
98117
List<EmittedSpans.Span> testSpans =
99118
spans.getSpansByScope().stream()
100119
.filter(item -> item.getScope().equals("test"))
@@ -111,9 +130,19 @@ void testSpanAggregatorFiltersAndAggregatesCorrectly() {
111130
String targetScopeName = "my-instrumentation-scope";
112131

113132
EmittedSpans.Span span1 =
114-
new EmittedSpans.Span("CLIENT", List.of(new TelemetryAttribute("my.operation", "STRING")));
133+
new EmittedSpans.Span(
134+
"CLIENT",
135+
List.of(
136+
new TelemetryAttribute("my.operation", "STRING"),
137+
new TelemetryAttribute("http.request.header.x-test-request", "STRING_ARRAY"),
138+
new TelemetryAttribute("http.response.header.x-test-response", "STRING_ARRAY")));
115139
EmittedSpans.Span span2 =
116-
new EmittedSpans.Span("SERVER", List.of(new TelemetryAttribute("my.operation", "STRING")));
140+
new EmittedSpans.Span(
141+
"SERVER",
142+
List.of(
143+
new TelemetryAttribute("my.operation", "STRING"),
144+
new TelemetryAttribute("test-baggage-key-1", "STRING"),
145+
new TelemetryAttribute("test-baggage-key-2", "STRING")));
117146

118147
// Create test span for a different scope (should be filtered out)
119148
EmittedSpans.Span testSpan =
@@ -143,5 +172,27 @@ void testSpanAggregatorFiltersAndAggregatesCorrectly() {
143172
List<String> spanKinds =
144173
result.get("default").stream().map(EmittedSpans.Span::getSpanKind).toList();
145174
assertThat(spanKinds).containsExactlyInAnyOrder("CLIENT", "SERVER");
175+
176+
// Verify test attributes are filtered out
177+
List<TelemetryAttribute> clientAttributes =
178+
result.get("default").stream()
179+
.filter(span -> span.getSpanKind().equals("CLIENT"))
180+
.flatMap(span -> span.getAttributes().stream())
181+
.toList();
182+
assertThat(clientAttributes)
183+
.hasSize(1)
184+
.extracting(TelemetryAttribute::getName)
185+
.containsExactly("my.operation");
186+
187+
List<TelemetryAttribute> serverAttributes =
188+
result.get("default").stream()
189+
.filter(span -> span.getSpanKind().equals("SERVER"))
190+
.flatMap(span -> span.getAttributes().stream())
191+
.toList();
192+
193+
assertThat(serverAttributes)
194+
.hasSize(1)
195+
.extracting(TelemetryAttribute::getName)
196+
.containsExactly("my.operation");
146197
}
147198
}

instrumentation/akka/akka-http-10.0/javaagent/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ tasks {
6666

6767
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
6868
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
69+
systemProperty("collectSpans", true)
6970
}
7071

7172
check {

instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ tasks.withType<Test>().configureEach {
4545
jvmArgs("--add-opens=java.base/java.math=ALL-UNNAMED")
4646
// required on jdk17
4747
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
48+
49+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
50+
systemProperty("collectSpans", true)
4851
}
4952

5053
tasks {

0 commit comments

Comments
 (0)