Skip to content

Commit 786512b

Browse files
authored
Add scope name to metadata (#13531)
1 parent 511a9c9 commit 786512b

File tree

28 files changed

+1153
-231
lines changed

28 files changed

+1153
-231
lines changed

docs/instrumentation-list.yaml

Lines changed: 538 additions & 53 deletions
Large diffs are not rendered by default.

instrumentation-docs/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ otelJava {
88

99
dependencies {
1010
implementation("org.yaml:snakeyaml:2.4")
11+
implementation("io.opentelemetry:opentelemetry-sdk-common")
1112

1213
testImplementation(enforcedPlatform("org.junit:junit-bom:5.12.1"))
1314
testImplementation("org.assertj:assertj-core:3.27.3")

instrumentation-docs/readme.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Runs analysis on instrumentation modules in order to generate documentation.
44

5+
## How to use
6+
7+
Run the doc generator:
8+
9+
`./gradlew :instrumentation-docs:generateDocs`
10+
511
## Instrumentation Hierarchy
612

713
An "InstrumentationEntity" represents a module that that targets specific code in a framework/library/technology.
@@ -46,10 +52,15 @@ public class SpringWebInstrumentationModule extends InstrumentationModule
4652
* Configured in `InstrumentationModule` code for each module
4753
* srcPath
4854
* Path to the source code of the instrumentation module
55+
* minimumJavaVersion
56+
* Minimum Java version required by the instrumentation module. If not specified, it is assumed to
57+
be Java 8
4958
* description
5059
* Short description of what the instrumentation does
5160
* target_versions
5261
* List of supported versions by the module, broken down by `library` or `javaagent` support
62+
* scope
63+
* Name: The scope name of the instrumentation, `io.opentelemetry.{instrumentation name}`
5364

5465
## Methodology
5566

@@ -62,12 +73,25 @@ As of now, the following fields are supported:
6273

6374
```yaml
6475
description: "Description of what the instrumentation does."
76+
77+
# used to mark modules that do not instrument traditional libraries (e.g. methods, annotations)
78+
# defaults to true
79+
isLibraryInstrumentation: false
6580
```
6681

67-
### Versions targeted
82+
### Gradle File Derived Information
6883

69-
We parse gradle files in order to determine the target versions.
84+
We parse gradle files in order to determine several pieces of metadata:
7085

7186
- Javaagent versions are determined by the `muzzle` plugin configurations
7287
- Library versions are determined by the library dependency versions
7388
- when available, latestDepTestLibrary is used to determine the latest supported version
89+
- Minimum Java version is determined by the `otelJava` configurations
90+
91+
### Scope
92+
93+
For now, the scope name is the only value that is implemented in our instrumentations. The scope
94+
name is determined by the instrumentation module name: `io.opentelemetry.{instrumentation name}`
95+
96+
We will implement gatherers for the schemaUrl and scope attributes when instrumentations start
97+
implementing them.

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/DocGeneratorApplication.java

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

66
package io.opentelemetry.instrumentation.docs;
77

8+
import io.opentelemetry.instrumentation.docs.internal.InstrumentationEntity;
89
import io.opentelemetry.instrumentation.docs.utils.FileManager;
910
import io.opentelemetry.instrumentation.docs.utils.YamlHelper;
1011
import java.io.BufferedWriter;
@@ -26,6 +27,10 @@ public static void main(String[] args) {
2627
try (BufferedWriter writer =
2728
Files.newBufferedWriter(
2829
Paths.get("docs/instrumentation-list.yaml"), Charset.defaultCharset())) {
30+
writer.write("# This file is generated and should not be manually edited.\n");
31+
writer.write("# The structure and contents are a work in progress and subject to change.\n");
32+
writer.write(
33+
"# For more information see: https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/13468\n\n");
2934
YamlHelper.printInstrumentationList(entities, writer);
3035
} catch (IOException e) {
3136
logger.severe("Error writing instrumentation list: " + e.getMessage());

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/InstrumentationAnalyzer.java

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

66
package io.opentelemetry.instrumentation.docs;
77

8-
import static io.opentelemetry.instrumentation.docs.GradleParser.parseGradleFile;
8+
import static io.opentelemetry.instrumentation.docs.parsers.GradleParser.parseGradleFile;
99

10+
import io.opentelemetry.instrumentation.docs.internal.DependencyInfo;
11+
import io.opentelemetry.instrumentation.docs.internal.InstrumentationEntity;
12+
import io.opentelemetry.instrumentation.docs.internal.InstrumentationType;
1013
import io.opentelemetry.instrumentation.docs.utils.FileManager;
1114
import io.opentelemetry.instrumentation.docs.utils.InstrumentationPath;
1215
import io.opentelemetry.instrumentation.docs.utils.YamlHelper;
@@ -42,11 +45,12 @@ public static List<InstrumentationEntity> convertToEntities(List<Instrumentation
4245
if (!entityMap.containsKey(key)) {
4346
entityMap.put(
4447
key,
45-
new InstrumentationEntity(
46-
path.srcPath().replace("/javaagent", "").replace("/library", ""),
47-
path.instrumentationName(),
48-
path.namespace(),
49-
path.group()));
48+
new InstrumentationEntity.Builder()
49+
.srcPath(path.srcPath().replace("/javaagent", "").replace("/library", ""))
50+
.instrumentationName(path.instrumentationName())
51+
.namespace(path.namespace())
52+
.group(path.group())
53+
.build());
5054
}
5155
}
5256

@@ -80,15 +84,21 @@ void analyzeVersions(List<String> files, InstrumentationEntity entity) {
8084
Map<InstrumentationType, Set<String>> versions = new HashMap<>();
8185
for (String file : files) {
8286
String fileContents = fileSearch.readFileToString(file);
87+
DependencyInfo results = null;
8388

8489
if (file.contains("/javaagent/")) {
85-
Set<String> results = parseGradleFile(fileContents, InstrumentationType.JAVAAGENT);
90+
results = parseGradleFile(fileContents, InstrumentationType.JAVAAGENT);
8691
versions
8792
.computeIfAbsent(InstrumentationType.JAVAAGENT, k -> new HashSet<>())
88-
.addAll(results);
93+
.addAll(results.versions());
8994
} else if (file.contains("/library/")) {
90-
Set<String> results = parseGradleFile(fileContents, InstrumentationType.LIBRARY);
91-
versions.computeIfAbsent(InstrumentationType.LIBRARY, k -> new HashSet<>()).addAll(results);
95+
results = parseGradleFile(fileContents, InstrumentationType.LIBRARY);
96+
versions
97+
.computeIfAbsent(InstrumentationType.LIBRARY, k -> new HashSet<>())
98+
.addAll(results.versions());
99+
}
100+
if (results != null && results.minJavaVersionSupported() != null) {
101+
entity.setMinJavaVersion(results.minJavaVersionSupported());
92102
}
93103
}
94104
entity.setTargetVersions(versions);

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

Lines changed: 0 additions & 74 deletions
This file was deleted.

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/InstrumentationMetaData.java

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.docs.internal;
7+
8+
import java.util.Set;
9+
10+
/**
11+
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
12+
* any time.
13+
*/
14+
public record DependencyInfo(Set<String> versions, Integer minJavaVersionSupported) {}

0 commit comments

Comments
 (0)