Skip to content

Commit 196714e

Browse files
authored
Rename InstrumentationEntity to InstrumentationModule (open-telemetry#13701)
1 parent 7e29c8f commit 196714e

File tree

7 files changed

+105
-101
lines changed

7 files changed

+105
-101
lines changed

instrumentation-docs/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Run the doc generator:
1010

1111
## Instrumentation Hierarchy
1212

13-
An "InstrumentationEntity" represents a module that that targets specific code in a
14-
framework/library/technology. Each entity will have a name, a namespace, and a group.
13+
An "InstrumentationModule" represents a module that that targets specific code in a
14+
framework/library/technology. Each module will have a name, a namespace, and a group.
1515

1616
Using these structures as examples:
1717

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

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

66
package io.opentelemetry.instrumentation.docs;
77

8-
import io.opentelemetry.instrumentation.docs.internal.InstrumentationEntity;
8+
import io.opentelemetry.instrumentation.docs.internal.InstrumentationModule;
99
import io.opentelemetry.instrumentation.docs.utils.FileManager;
1010
import io.opentelemetry.instrumentation.docs.utils.YamlHelper;
1111
import java.io.BufferedWriter;
@@ -22,7 +22,7 @@ public class DocGeneratorApplication {
2222

2323
public static void main(String[] args) {
2424
FileManager fileManager = new FileManager("instrumentation/");
25-
List<InstrumentationEntity> entities = new InstrumentationAnalyzer(fileManager).analyze();
25+
List<InstrumentationModule> modules = new InstrumentationAnalyzer(fileManager).analyze();
2626

2727
try (BufferedWriter writer =
2828
Files.newBufferedWriter(
@@ -31,7 +31,7 @@ public static void main(String[] args) {
3131
writer.write("# The structure and contents are a work in progress and subject to change.\n");
3232
writer.write(
3333
"# For more information see: https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/13468\n\n");
34-
YamlHelper.generateInstrumentationYaml(entities, writer);
34+
YamlHelper.generateInstrumentationYaml(modules, writer);
3535
} catch (IOException e) {
3636
logger.severe("Error writing instrumentation list: " + e.getMessage());
3737
}

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import static io.opentelemetry.instrumentation.docs.parsers.GradleParser.parseGradleFile;
99

1010
import io.opentelemetry.instrumentation.docs.internal.DependencyInfo;
11-
import io.opentelemetry.instrumentation.docs.internal.InstrumentationEntity;
11+
import io.opentelemetry.instrumentation.docs.internal.InstrumentationModule;
1212
import io.opentelemetry.instrumentation.docs.internal.InstrumentationType;
1313
import io.opentelemetry.instrumentation.docs.utils.FileManager;
1414
import io.opentelemetry.instrumentation.docs.utils.InstrumentationPath;
@@ -29,20 +29,21 @@ class InstrumentationAnalyzer {
2929
}
3030

3131
/**
32-
* Converts a list of {@link InstrumentationPath} into a list of {@link InstrumentationEntity},
32+
* Converts a list of {@link InstrumentationPath} into a list of {@link InstrumentationModule},
3333
*
3434
* @param paths the list of {@link InstrumentationPath} objects to be converted
35-
* @return a list of {@link InstrumentationEntity} objects with aggregated types
35+
* @return a list of {@link InstrumentationModule} objects with aggregated types
3636
*/
37-
public static List<InstrumentationEntity> convertToEntities(List<InstrumentationPath> paths) {
38-
Map<String, InstrumentationEntity> entityMap = new HashMap<>();
37+
public static List<InstrumentationModule> convertToInstrumentationModules(
38+
List<InstrumentationPath> paths) {
39+
Map<String, InstrumentationModule> moduleMap = new HashMap<>();
3940

4041
for (InstrumentationPath path : paths) {
4142
String key = path.group() + ":" + path.namespace() + ":" + path.instrumentationName();
42-
if (!entityMap.containsKey(key)) {
43-
entityMap.put(
43+
if (!moduleMap.containsKey(key)) {
44+
moduleMap.put(
4445
key,
45-
new InstrumentationEntity.Builder()
46+
new InstrumentationModule.Builder()
4647
.srcPath(path.srcPath().replace("/javaagent", "").replace("/library", ""))
4748
.instrumentationName(path.instrumentationName())
4849
.namespace(path.namespace())
@@ -51,33 +52,33 @@ public static List<InstrumentationEntity> convertToEntities(List<Instrumentation
5152
}
5253
}
5354

54-
return new ArrayList<>(entityMap.values());
55+
return new ArrayList<>(moduleMap.values());
5556
}
5657

5758
/**
58-
* Analyzes the given root directory to find all instrumentation paths and then analyze them.
59-
* Extracts version information from each instrumentation's build.gradle file. Extracts
59+
* Traverses the given root directory to find all instrumentation paths and then analyzes them.
60+
* Extracts version information from each instrumentation's build.gradle file, and other
6061
* information from metadata.yaml files.
6162
*
62-
* @return a list of {@link InstrumentationEntity}
63+
* @return a list of {@link InstrumentationModule}
6364
*/
64-
List<InstrumentationEntity> analyze() {
65+
List<InstrumentationModule> analyze() {
6566
List<InstrumentationPath> paths = fileManager.getInstrumentationPaths();
66-
List<InstrumentationEntity> entities = convertToEntities(paths);
67+
List<InstrumentationModule> modules = convertToInstrumentationModules(paths);
6768

68-
for (InstrumentationEntity entity : entities) {
69-
List<String> gradleFiles = fileManager.findBuildGradleFiles(entity.getSrcPath());
70-
analyzeVersions(gradleFiles, entity);
69+
for (InstrumentationModule module : modules) {
70+
List<String> gradleFiles = fileManager.findBuildGradleFiles(module.getSrcPath());
71+
analyzeVersions(gradleFiles, module);
7172

72-
String metadataFile = fileManager.getMetaDataFile(entity.getSrcPath());
73+
String metadataFile = fileManager.getMetaDataFile(module.getSrcPath());
7374
if (metadataFile != null) {
74-
entity.setMetadata(YamlHelper.metaDataParser(metadataFile));
75+
module.setMetadata(YamlHelper.metaDataParser(metadataFile));
7576
}
7677
}
77-
return entities;
78+
return modules;
7879
}
7980

80-
void analyzeVersions(List<String> files, InstrumentationEntity entity) {
81+
void analyzeVersions(List<String> files, InstrumentationModule module) {
8182
Map<InstrumentationType, Set<String>> versions = new HashMap<>();
8283
for (String file : files) {
8384
String fileContents = fileManager.readFileToString(file);
@@ -95,9 +96,9 @@ void analyzeVersions(List<String> files, InstrumentationEntity entity) {
9596
.addAll(results.versions());
9697
}
9798
if (results != null && results.minJavaVersionSupported() != null) {
98-
entity.setMinJavaVersion(results.minJavaVersionSupported());
99+
module.setMinJavaVersion(results.minJavaVersionSupported());
99100
}
100101
}
101-
entity.setTargetVersions(versions);
102+
module.setTargetVersions(versions);
102103
}
103104
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
import javax.annotation.Nullable;
1515

1616
/**
17-
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
18-
* any time.
17+
* Represents an instrumentation module and all associated metadata.
18+
*
19+
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
20+
* at any time.
1921
*/
20-
public class InstrumentationEntity {
22+
public class InstrumentationModule {
2123
private final String srcPath;
2224
private final String instrumentationName;
2325
private final String namespace;
@@ -34,7 +36,7 @@ public class InstrumentationEntity {
3436
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
3537
* any time.
3638
*/
37-
public InstrumentationEntity(Builder builder) {
39+
public InstrumentationModule(Builder builder) {
3840
requireNonNull(builder.srcPath, "srcPath required");
3941
requireNonNull(builder.instrumentationName, "instrumentationName required");
4042
requireNonNull(builder.namespace, "namespace required");
@@ -155,8 +157,8 @@ public Builder targetVersions(Map<InstrumentationType, Set<String>> targetVersio
155157
return this;
156158
}
157159

158-
public InstrumentationEntity build() {
159-
return new InstrumentationEntity(this);
160+
public InstrumentationModule build() {
161+
return new InstrumentationModule(this);
160162
}
161163
}
162164
}

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package io.opentelemetry.instrumentation.docs.utils;
77

88
import io.opentelemetry.instrumentation.docs.internal.InstrumentationClassification;
9-
import io.opentelemetry.instrumentation.docs.internal.InstrumentationEntity;
109
import io.opentelemetry.instrumentation.docs.internal.InstrumentationMetaData;
10+
import io.opentelemetry.instrumentation.docs.internal.InstrumentationModule;
1111
import java.io.BufferedWriter;
1212
import java.util.ArrayList;
1313
import java.util.LinkedHashMap;
@@ -33,7 +33,7 @@ public class YamlHelper {
3333
}
3434

3535
public static void generateInstrumentationYaml(
36-
List<InstrumentationEntity> list, BufferedWriter writer) {
36+
List<InstrumentationModule> list, BufferedWriter writer) {
3737
DumperOptions options = new DumperOptions();
3838
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
3939

@@ -55,29 +55,29 @@ public static void generateInstrumentationYaml(
5555
}
5656
}
5757

58-
private static Map<String, Object> getLibraryInstrumentations(List<InstrumentationEntity> list) {
59-
Map<String, List<InstrumentationEntity>> libraryInstrumentations =
58+
private static Map<String, Object> getLibraryInstrumentations(List<InstrumentationModule> list) {
59+
Map<String, List<InstrumentationModule>> libraryInstrumentations =
6060
list.stream()
6161
.filter(
62-
entity ->
63-
entity
62+
module ->
63+
module
6464
.getMetadata()
6565
.getClassification()
6666
.equals(InstrumentationClassification.LIBRARY))
6767
.collect(
6868
Collectors.groupingBy(
69-
InstrumentationEntity::getGroup, TreeMap::new, Collectors.toList()));
69+
InstrumentationModule::getGroup, TreeMap::new, Collectors.toList()));
7070

7171
Map<String, Object> output = new TreeMap<>();
7272
libraryInstrumentations.forEach(
73-
(group, entities) -> {
73+
(group, modules) -> {
7474
List<Map<String, Object>> instrumentations = new ArrayList<>();
75-
for (InstrumentationEntity entity : entities) {
76-
Map<String, Object> entityMap = baseProperties(entity);
75+
for (InstrumentationModule module : modules) {
76+
Map<String, Object> moduleMap = baseProperties(module);
7777

7878
Map<String, Object> targetVersions = new TreeMap<>();
79-
if (entity.getTargetVersions() != null && !entity.getTargetVersions().isEmpty()) {
80-
entity
79+
if (module.getTargetVersions() != null && !module.getTargetVersions().isEmpty()) {
80+
module
8181
.getTargetVersions()
8282
.forEach(
8383
(type, versions) -> {
@@ -86,9 +86,9 @@ private static Map<String, Object> getLibraryInstrumentations(List<Instrumentati
8686
}
8787
});
8888
}
89-
entityMap.put("target_versions", targetVersions);
89+
moduleMap.put("target_versions", targetVersions);
9090

91-
instrumentations.add(entityMap);
91+
instrumentations.add(moduleMap);
9292
}
9393
output.put(group, instrumentations);
9494
});
@@ -102,15 +102,15 @@ private static Map<String, Object> getLibraryInstrumentations(List<Instrumentati
102102
}
103103

104104
private static Map<String, Object> generateBaseYaml(
105-
List<InstrumentationEntity> list, InstrumentationClassification classification) {
106-
List<InstrumentationEntity> filtered =
105+
List<InstrumentationModule> list, InstrumentationClassification classification) {
106+
List<InstrumentationModule> filtered =
107107
list.stream()
108-
.filter(entity -> entity.getMetadata().getClassification().equals(classification))
108+
.filter(module -> module.getMetadata().getClassification().equals(classification))
109109
.toList();
110110

111111
List<Map<String, Object>> instrumentations = new ArrayList<>();
112-
for (InstrumentationEntity entity : filtered) {
113-
instrumentations.add(baseProperties(entity));
112+
for (InstrumentationModule module : filtered) {
113+
instrumentations.add(baseProperties(module));
114114
}
115115

116116
Map<String, Object> newOutput = new TreeMap<>();
@@ -121,34 +121,34 @@ private static Map<String, Object> generateBaseYaml(
121121
return newOutput;
122122
}
123123

124-
private static Map<String, Object> baseProperties(InstrumentationEntity entity) {
125-
Map<String, Object> entityMap = new LinkedHashMap<>();
126-
entityMap.put("name", entity.getInstrumentationName());
124+
private static Map<String, Object> baseProperties(InstrumentationModule module) {
125+
Map<String, Object> moduleMap = new LinkedHashMap<>();
126+
moduleMap.put("name", module.getInstrumentationName());
127127

128-
if (entity.getMetadata() != null) {
129-
if (entity.getMetadata().getDescription() != null) {
130-
entityMap.put("description", entity.getMetadata().getDescription());
128+
if (module.getMetadata() != null) {
129+
if (module.getMetadata().getDescription() != null) {
130+
moduleMap.put("description", module.getMetadata().getDescription());
131131
}
132132

133-
if (entity.getMetadata().getDisabledByDefault()) {
134-
entityMap.put("disabled_by_default", entity.getMetadata().getDisabledByDefault());
133+
if (module.getMetadata().getDisabledByDefault()) {
134+
moduleMap.put("disabled_by_default", module.getMetadata().getDisabledByDefault());
135135
}
136136
}
137137

138-
entityMap.put("source_path", entity.getSrcPath());
138+
moduleMap.put("source_path", module.getSrcPath());
139139

140-
if (entity.getMinJavaVersion() != null) {
141-
entityMap.put("minimum_java_version", entity.getMinJavaVersion());
140+
if (module.getMinJavaVersion() != null) {
141+
moduleMap.put("minimum_java_version", module.getMinJavaVersion());
142142
}
143143

144-
Map<String, Object> scopeMap = getScopeMap(entity);
145-
entityMap.put("scope", scopeMap);
146-
return entityMap;
144+
Map<String, Object> scopeMap = getScopeMap(module);
145+
moduleMap.put("scope", scopeMap);
146+
return moduleMap;
147147
}
148148

149-
private static Map<String, Object> getScopeMap(InstrumentationEntity entity) {
149+
private static Map<String, Object> getScopeMap(InstrumentationModule module) {
150150
Map<String, Object> scopeMap = new LinkedHashMap<>();
151-
scopeMap.put("name", entity.getScopeInfo().getName());
151+
scopeMap.put("name", module.getScopeInfo().getName());
152152
return scopeMap;
153153
}
154154

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import static org.assertj.core.api.Assertions.assertThat;
99

10-
import io.opentelemetry.instrumentation.docs.internal.InstrumentationEntity;
10+
import io.opentelemetry.instrumentation.docs.internal.InstrumentationModule;
1111
import io.opentelemetry.instrumentation.docs.internal.InstrumentationType;
1212
import io.opentelemetry.instrumentation.docs.utils.InstrumentationPath;
1313
import java.util.Arrays;
@@ -17,7 +17,7 @@
1717
class InstrumentationAnalyzerTest {
1818

1919
@Test
20-
void testConvertToEntities() {
20+
void testConvertToInstrumentationModule() {
2121
List<InstrumentationPath> paths =
2222
Arrays.asList(
2323
new InstrumentationPath(
@@ -39,32 +39,33 @@ void testConvertToEntities() {
3939
"spring",
4040
InstrumentationType.LIBRARY));
4141

42-
List<InstrumentationEntity> entities = InstrumentationAnalyzer.convertToEntities(paths);
42+
List<InstrumentationModule> modules =
43+
InstrumentationAnalyzer.convertToInstrumentationModules(paths);
4344

44-
assertThat(entities.size()).isEqualTo(2);
45+
assertThat(modules.size()).isEqualTo(2);
4546

46-
InstrumentationEntity log4jEntity =
47-
entities.stream()
47+
InstrumentationModule log4jModule =
48+
modules.stream()
4849
.filter(e -> e.getInstrumentationName().equals("log4j-appender-2.17"))
4950
.findFirst()
5051
.orElse(null);
5152

52-
assertThat(log4jEntity.getNamespace()).isEqualTo("log4j");
53-
assertThat(log4jEntity.getGroup()).isEqualTo("log4j");
54-
assertThat(log4jEntity.getSrcPath()).isEqualTo("instrumentation/log4j/log4j-appender-2.17");
55-
assertThat(log4jEntity.getScopeInfo().getName())
53+
assertThat(log4jModule.getNamespace()).isEqualTo("log4j");
54+
assertThat(log4jModule.getGroup()).isEqualTo("log4j");
55+
assertThat(log4jModule.getSrcPath()).isEqualTo("instrumentation/log4j/log4j-appender-2.17");
56+
assertThat(log4jModule.getScopeInfo().getName())
5657
.isEqualTo("io.opentelemetry.log4j-appender-2.17");
5758

58-
InstrumentationEntity springEntity =
59-
entities.stream()
59+
InstrumentationModule springModule =
60+
modules.stream()
6061
.filter(e -> e.getInstrumentationName().equals("spring-web"))
6162
.findFirst()
6263
.orElse(null);
6364

64-
assertThat(springEntity).isNotNull();
65-
assertThat(springEntity.getNamespace()).isEqualTo("spring");
66-
assertThat(springEntity.getGroup()).isEqualTo("spring");
67-
assertThat(springEntity.getSrcPath()).isEqualTo("instrumentation/spring/spring-web");
68-
assertThat(springEntity.getScopeInfo().getName()).isEqualTo("io.opentelemetry.spring-web");
65+
assertThat(springModule).isNotNull();
66+
assertThat(springModule.getNamespace()).isEqualTo("spring");
67+
assertThat(springModule.getGroup()).isEqualTo("spring");
68+
assertThat(springModule.getSrcPath()).isEqualTo("instrumentation/spring/spring-web");
69+
assertThat(springModule.getScopeInfo().getName()).isEqualTo("io.opentelemetry.spring-web");
6970
}
7071
}

0 commit comments

Comments
 (0)