Skip to content

Commit cbdb616

Browse files
committed
cleanups
1 parent e7f660c commit cbdb616

File tree

13 files changed

+21
-169
lines changed

13 files changed

+21
-169
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ replay_pid*
5959
.attach_pid*
6060

6161
!java-agent/benchmark/releases/*.jar
62+

instrumentation-docs/build.gradle.kts

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ otelJava {
99
dependencies {
1010
implementation("org.yaml:snakeyaml:2.4")
1111
implementation("io.opentelemetry:opentelemetry-sdk-common")
12-
implementation("io.opentelemetry:opentelemetry-sdk-metrics")
13-
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")
14-
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.2")
1512

1613
testImplementation(enforcedPlatform("org.junit:junit-bom:5.12.0"))
1714
testImplementation("org.assertj:assertj-core:3.27.3")

instrumentation-docs/collect.sh

-46
This file was deleted.

instrumentation-docs/readme.md

+8-85
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,9 @@ Runs analysis on instrumentation modules in order to generate documentation.
44

55
## How to use
66

7-
Until this process is ready for all instrumentations, each module will be modified to include a
8-
system property configured for when the tests run:
9-
10-
```kotlin
11-
tasks {
12-
test {
13-
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
14-
...
15-
}
16-
}
17-
```
18-
19-
Prior to running the DocGeneratorApplication, run the following command to collect metadata:
20-
21-
* Run tests to collect metadata
22-
* `./gradlew test -collectMetadata=true`
23-
* Run the doc generator
24-
* `./gradlew :instrumentation-docs:generateDocs`
7+
Run the doc generator:
258

26-
You can also use an environment variable to set it for the entire suite:
27-
28-
`COLLECT_METADATA=true ./gradlew test`
29-
30-
or use the helper script that will run only the currently supported tests:
31-
32-
```bash
33-
./instrumentation-docs/collect.sh
34-
```
9+
`./gradlew :instrumentation-docs:generateDocs`
3510

3611
## Instrumentation Hierarchy
3712

@@ -82,12 +57,7 @@ public class SpringWebInstrumentationModule extends InstrumentationModule
8257
* target_versions
8358
* List of supported versions by the module, broken down by `library` or `javaagent` support
8459
* scope
85-
* The scope of the instrumentation, including the name, version, schemaUrl and attributes
86-
* metrics
87-
* List of metrics that the instrumentation module collects, including the metric name, description, type, and attributes
88-
* span_data
89-
* List of span types that are emitted (internal, client, server)
90-
* List of span data that the instrumentation collects, including the attribute name and type
60+
* Name: The scope name of the instrumentation, `io.opentelemetry.{instrumentation name}`
9161

9262
## Methodology
9363

@@ -110,57 +80,10 @@ We parse gradle files in order to determine the target versions.
11080
- Library versions are determined by the library dependency versions
11181
- when available, latestDepTestLibrary is used to determine the latest supported version
11282

113-
### Scope, Span Data, and Metrics
114-
115-
Since many of our tests generate this information, we can hook into the InstrumentationTestRunner
116-
class and collect the metrics, spans, and scope generated. We can then leverage the `afterTestClass()`
117-
in the Agent and library test runners to then write this information into temporary files.
118-
119-
The data is written into a `.telemetry` directory in the root of the instrumentation module. This data
120-
will be excluded from git and just generated on demand.
83+
### Scope
12184

122-
Since metadata can be generated by multiple classes, we will generate a file per class.
85+
For now, the scope name is the only value that is implemented in our instrumentations. The scope
86+
name is determined by the instrumentation module name: `io.opentelemetry.{instrumentation name}`
12387

124-
Example output:
125-
126-
```
127-
clickhouse:
128-
instrumentations:
129-
- name: clickhouse-client-0.5
130-
description: Instruments the V1 ClickHouseClient, providing database client spans
131-
and metrics.
132-
srcPath: instrumentation/clickhouse-client-0.5
133-
target_versions:
134-
javaagent:
135-
- com.clickhouse.client:clickhouse-client:[0.5.0,)
136-
metrics:
137-
- name: db.client.operation.duration
138-
description: Duration of database client operations.
139-
type: HISTOGRAM
140-
unit: s
141-
attributes:
142-
- name: db.namespace
143-
type: STRING
144-
- name: db.operation.name
145-
type: STRING
146-
- name: db.system.name
147-
type: STRING
148-
- name: server.address
149-
type: STRING
150-
- name: server.port
151-
type: LONG
152-
span_data:
153-
attributes:
154-
- name: server.address
155-
type: STRING
156-
- name: server.port
157-
type: LONG
158-
- name: db.system.name
159-
type: STRING
160-
- name: db.query.text
161-
type: STRING
162-
- name: db.namespace
163-
type: STRING
164-
- name: db.operation.name
165-
type: STRING
166-
```
88+
We will implement gatherers for the schemaUrl and attributes when instrumentations start
89+
implementing them.

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

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.instrumentation.docs.internal;
77

88
import com.google.errorprone.annotations.CanIgnoreReturnValue;
9+
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
910
import java.util.Map;
1011
import java.util.Set;
1112

@@ -18,6 +19,7 @@ public class InstrumentationEntity {
1819
private final String instrumentationName;
1920
private final String namespace;
2021
private final String group;
22+
private final InstrumentationScopeInfo scopeInfo;
2123
private Map<InstrumentationType, Set<String>> targetVersions;
2224

2325
public void setTargetVersions(Map<InstrumentationType, Set<String>> targetVersions) {
@@ -41,6 +43,7 @@ public InstrumentationEntity(Builder builder) {
4143
this.group = builder.group;
4244
this.metadata = builder.metadata;
4345
this.targetVersions = builder.targetVersions;
46+
this.scopeInfo = InstrumentationScopeInfo.create("io.opentelemetry." + instrumentationName);
4447
}
4548

4649
public String getSrcPath() {
@@ -67,6 +70,10 @@ public Map<InstrumentationType, Set<String>> getTargetVersions() {
6770
return targetVersions;
6871
}
6972

73+
public InstrumentationScopeInfo getScopeInfo() {
74+
return scopeInfo;
75+
}
76+
7077
/**
7178
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
7279
* any time.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static void printInstrumentationList(
7070

7171
private static Map<String, Object> getScopeMap(InstrumentationEntity entity) {
7272
Map<String, Object> scopeMap = new LinkedHashMap<>();
73-
scopeMap.put("name", "io.opentelemetry." + entity.getInstrumentationName());
73+
scopeMap.put("name", entity.getScopeInfo().getName());
7474
return scopeMap;
7575
}
7676

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

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ void testConvertToEntities() {
5252
assertThat(log4jEntity.getNamespace()).isEqualTo("log4j");
5353
assertThat(log4jEntity.getGroup()).isEqualTo("log4j");
5454
assertThat(log4jEntity.getSrcPath()).isEqualTo("instrumentation/log4j/log4j-appender-2.17");
55+
assertThat(log4jEntity.getScopeInfo().getName())
56+
.isEqualTo("io.opentelemetry.log4j-appender-2.17");
5557

5658
InstrumentationEntity springEntity =
5759
entities.stream()
@@ -63,5 +65,6 @@ void testConvertToEntities() {
6365
assertThat(springEntity.getNamespace()).isEqualTo("spring");
6466
assertThat(springEntity.getGroup()).isEqualTo("spring");
6567
assertThat(springEntity.getSrcPath()).isEqualTo("instrumentation/spring/spring-web");
68+
assertThat(springEntity.getScopeInfo().getName()).isEqualTo("io.opentelemetry.spring-web");
6669
}
6770
}

instrumentation/alibaba-druid-1.0/javaagent/build.gradle.kts

-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,3 @@ dependencies {
1818

1919
testImplementation(project(":instrumentation:alibaba-druid-1.0:testing"))
2020
}
21-
22-
tasks {
23-
test {
24-
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
25-
}
26-
}

instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ dependencies {
1919
tasks {
2020
withType<Test>().configureEach {
2121
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
22-
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
2322
}
2423
}

instrumentation/clickhouse-client-0.5/javaagent/build.gradle.kts

-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ dependencies {
2424
tasks {
2525
test {
2626
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
27-
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
2827
}
2928

3029
val testStableSemconv by registering(Test::class) {
3130
jvmArgs("-Dotel.semconv-stability.opt-in=database")
32-
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
3331
}
3432

3533
check {

instrumentation/clickhouse-client-0.5/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseClientTest.java

-14
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@
55

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

8-
import static io.opentelemetry.instrumentation.testing.junit.db.DbClientMetricsTestUtil.assertDurationMetric;
98
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
109
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1110
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
1211
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
1312
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME;
14-
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAMESPACE;
1513
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
16-
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION_NAME;
1714
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_STATEMENT;
1815
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
19-
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM_NAME;
2016
import static java.util.Arrays.asList;
2117
import static org.assertj.core.api.Assertions.assertThat;
2218
import static org.assertj.core.api.Assertions.catchThrowable;
@@ -93,7 +89,6 @@ void cleanup() {
9389
}
9490

9591
@Test
96-
@SuppressWarnings("deprecation") // using deprecated semconv
9792
void testConnectionStringWithoutDatabaseSpecifiedStillGeneratesSpans()
9893
throws ClickHouseException {
9994
ClickHouseNode server = ClickHouseNode.of("http://" + host + ":" + port + "?compress=0");
@@ -116,15 +111,6 @@ void testConnectionStringWithoutDatabaseSpecifiedStillGeneratesSpans()
116111
.hasNoParent()
117112
.hasAttributesSatisfyingExactly(
118113
attributeAssertions("select * from " + tableName, "SELECT"))));
119-
120-
assertDurationMetric(
121-
testing,
122-
"io.opentelemetry.clickhouse-client-0.5",
123-
DB_SYSTEM_NAME,
124-
DB_OPERATION_NAME,
125-
DB_NAMESPACE,
126-
SERVER_ADDRESS,
127-
SERVER_PORT);
128114
}
129115

130116
@Test

testing-common/src/main/java/io/opentelemetry/instrumentation/testing/AgentTestRunner.java

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public void afterTestClass() {
5959
assert adviceFailureCount == 0 : adviceFailureCount + " Advice failures during test";
6060
int muzzleFailureCount = TestAgentListenerAccess.getAndResetMuzzleFailureCount();
6161
assert muzzleFailureCount == 0 : muzzleFailureCount + " Muzzle failures during test";
62-
6362
// additional library ignores are ignored during tests, because they can make it really
6463
// confusing for contributors wondering why their instrumentation is not applied
6564
//

testing-common/src/main/java/io/opentelemetry/instrumentation/testing/InstrumentationTestRunner.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
import io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil;
1313
import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable;
1414
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier;
15-
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
1615
import io.opentelemetry.sdk.logs.data.LogRecordData;
1716
import io.opentelemetry.sdk.metrics.data.MetricData;
1817
import io.opentelemetry.sdk.testing.assertj.MetricAssert;
1918
import io.opentelemetry.sdk.testing.assertj.TraceAssert;
2019
import io.opentelemetry.sdk.testing.assertj.TracesAssert;
2120
import io.opentelemetry.sdk.trace.data.SpanData;
22-
import java.io.IOException;
2321
import java.time.Duration;
2422
import java.util.ArrayList;
2523
import java.util.Arrays;
@@ -46,15 +44,13 @@ public abstract class InstrumentationTestRunner {
4644

4745
private final TestInstrumenters testInstrumenters;
4846

49-
protected InstrumentationScopeInfo instrumentationScope;
50-
5147
protected InstrumentationTestRunner(OpenTelemetry openTelemetry) {
5248
testInstrumenters = new TestInstrumenters(openTelemetry);
5349
}
5450

5551
public abstract void beforeTestClass();
5652

57-
public abstract void afterTestClass() throws IOException;
53+
public abstract void afterTestClass();
5854

5955
public abstract void clearAllExportedData();
6056

@@ -68,10 +64,6 @@ protected InstrumentationTestRunner(OpenTelemetry openTelemetry) {
6864

6965
public abstract boolean forceFlushCalled();
7066

71-
protected boolean collectMetadata =
72-
Boolean.getBoolean("collectMetadata")
73-
|| Boolean.parseBoolean(System.getenv("COLLECT_METADATA"));
74-
7567
/** Return a list of all captured traces, where each trace is a sorted list of spans. */
7668
public final List<List<SpanData>> traces() {
7769
return TelemetryDataUtil.groupTraces(getExportedSpans());
@@ -139,7 +131,6 @@ private <T extends Consumer<TraceAssert>> void doAssertTraces(
139131
if (verifyScopeVersion) {
140132
TelemetryDataUtil.assertScopeVersion(traces);
141133
}
142-
143134
if (traceComparator != null) {
144135
traces.sort(traceComparator);
145136
}

0 commit comments

Comments
 (0)