Skip to content

Commit a26a32a

Browse files
authored
Add support for library links in metadata (#14622)
1 parent f749f00 commit a26a32a

File tree

56 files changed

+238
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+238
-7
lines changed

docs/contributing/documenting-instrumentation.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ Each instrumentation should have a `metadata.yaml` file in the root of the instr
8080
(`instrumentation/{some instrumentation}/metadata.yaml`) that contains structured metadata about the
8181
instrumentation.
8282

83+
Example:
84+
85+
```yaml
86+
description: "This instrumentation enables..."
87+
disabled_by_default: true
88+
classification: library
89+
library_link: https://github.com/...
90+
configurations:
91+
- name: otel.instrumentation.common.db-statement-sanitizer.enabled
92+
description: Enables statement sanitization for database queries.
93+
type: boolean
94+
default: true
95+
```
96+
8397
### Description (required)
8498
8599
At a minimum, every instrumentation metadata file should include a `description`.
@@ -114,6 +128,10 @@ Some notes when writing descriptions:
114128
* It is not usually necessary to include specific library or framework version numbers in the
115129
description, unless that context is significant in some way.
116130

131+
### Library Link
132+
133+
For library instrumentations, include a `library_link` field with a URL to the library or framework's
134+
main website or documentation, or if those don't exist, the GitHub repository.
117135

118136
### Configurations
119137

docs/instrumentation-list.yaml

Lines changed: 50 additions & 1 deletion
Large diffs are not rendered by default.

instrumentation-docs/readme.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public class SpringWebInstrumentationModule extends InstrumentationModule
114114
* name
115115
* Identifier for instrumentation module, used to enable/disable
116116
* Configured in `InstrumentationModule` code for each module
117+
* library_link
118+
* URL to the library or framework's main website or documentation, or if those don't exist, the
119+
GitHub repository.
117120
* source_path
118121
* Path to the source code of the instrumentation module
119122
* minimum_java_version
@@ -145,9 +148,10 @@ additional information about the instrumentation module.
145148
As of now, the following fields are supported, all of which are optional:
146149

147150
```yaml
148-
description: "Instruments..." # Description of the instrumentation module
149-
disabled_by_default: true # Defaults to `false`
150-
classification: internal # instrumentation classification: library | internal | custom
151+
description: "This instrumentation enables..." # Description of the instrumentation module
152+
disabled_by_default: true # Defaults to `false`
153+
classification: internal # instrumentation classification: library | internal | custom
154+
library_link: https://... # URL to the library or framework's main website or documentation
151155
configurations:
152156
- name: otel.instrumentation.common.db-statement-sanitizer.enabled
153157
description: Enables statement sanitization for database queries.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class InstrumentationMetaData {
2525

2626
private String classification;
2727

28+
@JsonProperty("library_link")
29+
@Nullable
30+
private String libraryLink;
31+
2832
private List<ConfigurationOption> configurations = Collections.emptyList();
2933

3034
public InstrumentationMetaData() {
@@ -35,10 +39,12 @@ public InstrumentationMetaData(
3539
@Nullable String description,
3640
String classification,
3741
@Nullable Boolean disabledByDefault,
42+
@Nullable String libraryLink,
3843
@Nullable List<ConfigurationOption> configurations) {
3944
this.classification = classification;
4045
this.disabledByDefault = disabledByDefault;
4146
this.description = description;
47+
this.libraryLink = libraryLink;
4248
this.configurations = Objects.requireNonNullElse(configurations, Collections.emptyList());
4349
}
4450

@@ -77,4 +83,13 @@ public List<ConfigurationOption> getConfigurations() {
7783
public void setConfigurations(@Nullable List<ConfigurationOption> configurations) {
7884
this.configurations = Objects.requireNonNullElse(configurations, Collections.emptyList());
7985
}
86+
87+
@Nullable
88+
public String getLibraryLink() {
89+
return libraryLink;
90+
}
91+
92+
public void setLibraryLink(@Nullable String libraryLink) {
93+
this.libraryLink = libraryLink;
94+
}
8095
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ private static void addMetadataProperties(
198198
if (module.getMetadata().getDescription() != null) {
199199
moduleMap.put("description", module.getMetadata().getDescription());
200200
}
201+
if (module.getMetadata().getLibraryLink() != null) {
202+
moduleMap.put("library_link", module.getMetadata().getLibraryLink());
203+
}
201204
if (module.getMetadata().getDisabledByDefault()) {
202205
moduleMap.put("disabled_by_default", module.getMetadata().getDisabledByDefault());
203206
}

instrumentation-docs/src/test/java/io/opentelemetry/instrumentation/docs/utils/YamlHelperTest.java

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void testPrintInstrumentationList() throws Exception {
4343
"Spring Web 6.0 instrumentation",
4444
InstrumentationClassification.LIBRARY.toString(),
4545
true,
46+
null,
4647
null);
4748

4849
modules.add(
@@ -114,6 +115,7 @@ void testGenerateInstrumentationYamlSeparatesClassifications() throws Exception
114115
"Spring Web 6.0 instrumentation",
115116
InstrumentationClassification.LIBRARY.toString(),
116117
false,
118+
null,
117119
List.of(
118120
new ConfigurationOption(
119121
"otel.instrumentation.spring-web-6.0.enabled",
@@ -134,7 +136,7 @@ void testGenerateInstrumentationYamlSeparatesClassifications() throws Exception
134136

135137
InstrumentationMetaData internalMetadata =
136138
new InstrumentationMetaData(
137-
null, InstrumentationClassification.INTERNAL.toString(), null, null);
139+
null, InstrumentationClassification.INTERNAL.toString(), null, null, null);
138140

139141
modules.add(
140142
new InstrumentationModule.Builder()
@@ -148,7 +150,7 @@ void testGenerateInstrumentationYamlSeparatesClassifications() throws Exception
148150

149151
InstrumentationMetaData customMetadata =
150152
new InstrumentationMetaData(
151-
null, InstrumentationClassification.CUSTOM.toString(), null, null);
153+
null, InstrumentationClassification.CUSTOM.toString(), null, null, null);
152154

153155
Map<InstrumentationType, Set<String>> externalAnnotationsVersions =
154156
Map.of(
@@ -214,6 +216,7 @@ void testMetadataParser() throws JsonProcessingException {
214216
description: test description
215217
classification: internal
216218
disabled_by_default: true
219+
library_link: https://example.com/test-library
217220
configurations:
218221
- name: otel.instrumentation.common.db-statement-sanitizer.enabled
219222
description: Enables statement sanitization for database queries.
@@ -233,6 +236,7 @@ void testMetadataParser() throws JsonProcessingException {
233236
assertThat(metadata.getClassification()).isEqualTo(InstrumentationClassification.INTERNAL);
234237
assertThat(metadata.getDescription()).isEqualTo("test description");
235238
assertThat(metadata.getDisabledByDefault()).isEqualTo(true);
239+
assertThat(metadata.getLibraryLink()).isEqualTo("https://example.com/test-library");
236240
}
237241

238242
@Test
@@ -241,6 +245,18 @@ void testMetadataParserWithOnlyLibraryEntry() throws JsonProcessingException {
241245
InstrumentationMetaData metadata = YamlHelper.metaDataParser(input);
242246
assertThat(metadata.getClassification()).isEqualTo(InstrumentationClassification.INTERNAL);
243247
assertThat(metadata.getDescription()).isNull();
248+
assertThat(metadata.getLibraryLink()).isNull();
249+
assertThat(metadata.getDisabledByDefault()).isFalse();
250+
assertThat(metadata.getConfigurations()).isEmpty();
251+
}
252+
253+
@Test
254+
void testMetadataParserWithOnlyLibraryLink() throws JsonProcessingException {
255+
String input = "library_link: https://example.com/only-link";
256+
InstrumentationMetaData metadata = YamlHelper.metaDataParser(input);
257+
assertThat(metadata.getClassification()).isEqualTo(InstrumentationClassification.LIBRARY);
258+
assertThat(metadata.getDescription()).isNull();
259+
assertThat(metadata.getLibraryLink()).isEqualTo("https://example.com/only-link");
244260
assertThat(metadata.getDisabledByDefault()).isFalse();
245261
assertThat(metadata.getConfigurations()).isEmpty();
246262
}
@@ -485,4 +501,80 @@ void testTelemetryGroupsAreSorted() throws Exception {
485501

486502
assertThat(yaml1).isEqualTo(yaml2);
487503
}
504+
505+
@Test
506+
void testYamlGenerationWithLibraryLink() throws Exception {
507+
List<InstrumentationModule> modules = new ArrayList<>();
508+
Map<InstrumentationType, Set<String>> targetVersions = new HashMap<>();
509+
targetVersions.put(
510+
InstrumentationType.JAVAAGENT, new HashSet<>(List.of("com.example:test-library:[1.0.0,)")));
511+
512+
InstrumentationMetaData metadataWithLink =
513+
new InstrumentationMetaData(
514+
"Test library instrumentation with link",
515+
InstrumentationClassification.LIBRARY.toString(),
516+
false,
517+
"https://example.com/test-library-docs",
518+
emptyList());
519+
520+
modules.add(
521+
new InstrumentationModule.Builder()
522+
.srcPath("instrumentation/test-lib/test-lib-1.0")
523+
.instrumentationName("test-lib-1.0")
524+
.namespace("test-lib")
525+
.group("test-lib")
526+
.targetVersions(targetVersions)
527+
.metadata(metadataWithLink)
528+
.build());
529+
530+
InstrumentationMetaData metadataWithoutLink =
531+
new InstrumentationMetaData(
532+
"Test library instrumentation without link",
533+
InstrumentationClassification.LIBRARY.toString(),
534+
false,
535+
null,
536+
emptyList());
537+
538+
modules.add(
539+
new InstrumentationModule.Builder()
540+
.srcPath("instrumentation/other-lib/other-lib-1.0")
541+
.instrumentationName("other-lib-1.0")
542+
.namespace("other-lib")
543+
.group("other-lib")
544+
.targetVersions(targetVersions)
545+
.metadata(metadataWithoutLink)
546+
.build());
547+
548+
StringWriter stringWriter = new StringWriter();
549+
BufferedWriter writer = new BufferedWriter(stringWriter);
550+
551+
YamlHelper.generateInstrumentationYaml(modules, writer);
552+
writer.flush();
553+
554+
String expectedYaml =
555+
"""
556+
libraries:
557+
other-lib:
558+
- name: other-lib-1.0
559+
description: Test library instrumentation without link
560+
source_path: instrumentation/other-lib/other-lib-1.0
561+
scope:
562+
name: io.opentelemetry.other-lib-1.0
563+
target_versions:
564+
javaagent:
565+
- com.example:test-library:[1.0.0,)
566+
test-lib:
567+
- name: test-lib-1.0
568+
description: Test library instrumentation with link
569+
library_link: https://example.com/test-library-docs
570+
source_path: instrumentation/test-lib/test-lib-1.0
571+
scope:
572+
name: io.opentelemetry.test-lib-1.0
573+
target_versions:
574+
javaagent:
575+
- com.example:test-library:[1.0.0,)
576+
""";
577+
578+
assertThat(expectedYaml).isEqualTo(stringWriter.toString());
579+
}
488580
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
description: This instrumentation enables HTTP server spans and HTTP server metrics for the ActiveJ HTTP server.
2+
library_link: https://activej.io/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
description: This instrumentation provides context propagation for Akka actors, it does not emit any telemetry on its own.
2+
library_link: https://doc.akka.io/libraries/akka-core/current/typed/index.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
description: This instrumentation provides context propagation for the Akka Fork-Join Pool, it does not emit any telemetry on its own.
2+
library_link: https://doc.akka.io/libraries/akka-core/current/typed/index.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
description: >
22
This instrumentation enables HTTP client spans and metrics for the Akka HTTP client, and HTTP
33
server spans and metrics for the Akka HTTP server.
4+
library_link: https://doc.akka.io/docs/akka-http/current/index.html

0 commit comments

Comments
 (0)