Skip to content

Commit 98b177e

Browse files
jaydelucalaurit
andauthored
Enable documenting semconv info in metadata (#14670)
Co-authored-by: Lauri Tulmin <[email protected]>
1 parent 8218e63 commit 98b177e

File tree

18 files changed

+201
-0
lines changed

18 files changed

+201
-0
lines changed

docs/contributing/documenting-instrumentation.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ Example:
8484

8585
```yaml
8686
description: "This instrumentation enables..."
87+
semantic_conventions:
88+
- HTTP_CLIENT_SPANS
89+
- DATABASE_CLIENT_SPANS
90+
- JVM_RUNTIME_METRICS
8791
disabled_by_default: true
8892
classification: library
8993
library_link: https://github.com/...
@@ -128,6 +132,32 @@ Some notes when writing descriptions:
128132
* It is not usually necessary to include specific library or framework version numbers in the
129133
description, unless that context is significant in some way.
130134

135+
136+
### Semantic Conventions
137+
138+
If the instrumentation adheres to one or more specific semantic conventions, include a
139+
`semantic_conventions` field with a list of the relevant semantic convention categories.
140+
141+
List of possible options:
142+
143+
* [HTTP_CLIENT_SPANS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client)
144+
* [HTTP_CLIENT_METRICS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md#http-client)
145+
* [HTTP_SERVER_SPANS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-server)
146+
* [HTTP_SERVER_METRICS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md#http-server)
147+
* [RPC_CLIENT_SPANS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-spans.md#client-attributes)
148+
* [RPC_CLIENT_METRICS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-metrics.md#rpc-client)
149+
* [RPC_SERVER_SPANS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-spans.md#server-attributes)
150+
* [RPC_SERVER_METRICS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-metrics.md#rpc-server)
151+
* [MESSAGING_SPANS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/messaging/messaging-spans.md)
152+
* [DATABASE_CLIENT_SPANS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md)
153+
* [DATABASE_CLIENT_METRICS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-metrics.md)
154+
* [DATABASE_POOL_METRICS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-metrics.md)
155+
* [JVM_RUNTIME_METRICS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/runtime/jvm-metrics.md)
156+
* [GRAPHQL_SERVER_SPANS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/graphql/graphql-spans.md)
157+
* [FAAS_SERVER_SPANS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/faas/faas-spans.md)
158+
* [GENAI_CLIENT_SPANS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-spans.md)
159+
* [GENAI_CLIENT_METRICS](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-metrics.md#generative-ai-client-metrics)
160+
131161
### Library Link
132162

133163
For library instrumentations, include a `library_link` field with a URL to the library or framework's

docs/instrumentation-list.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ libraries:
1010
display_name: ActiveJ
1111
description: This instrumentation enables HTTP server spans and HTTP server metrics
1212
for the ActiveJ HTTP server.
13+
semantic_conventions:
14+
- HTTP_SERVER_SPANS
15+
- HTTP_SERVER_METRICS
1316
library_link: https://activej.io/
1417
source_path: instrumentation/activej-http-6.0
1518
minimum_java_version: 17
@@ -92,6 +95,11 @@ libraries:
9295
display_name: Akka HTTP
9396
description: |
9497
This instrumentation enables HTTP client spans and metrics for the Akka HTTP client, and HTTP server spans and metrics for the Akka HTTP server.
98+
semantic_conventions:
99+
- HTTP_CLIENT_SPANS
100+
- HTTP_CLIENT_METRICS
101+
- HTTP_SERVER_SPANS
102+
- HTTP_SERVER_METRICS
95103
library_link: https://doc.akka.io/docs/akka-http/current/index.html
96104
source_path: instrumentation/akka/akka-http-10.0
97105
scope:
@@ -181,6 +189,8 @@ libraries:
181189
- name: alibaba-druid-1.0
182190
description: |
183191
The Alibaba Druid instrumentation generates database connection pool metrics for druid data sources.
192+
semantic_conventions:
193+
- DATABASE_POOL_METRICS
184194
library_link: https://github.com/alibaba/druid
185195
source_path: instrumentation/alibaba-druid-1.0
186196
scope:
@@ -274,9 +284,12 @@ libraries:
274284
type: STRING
275285
apache:
276286
- name: apache-dbcp-2.0
287+
display_name: Apache DBCP
277288
description: |
278289
This instrumentation enables database connection pools metrics for Apache DBCP.
279290
The instrumentation uses `MBeanRegistration` methods for lifecycle detection, therefore it only activates if the `BasicDataSource` is registered to an `MBeanServer`. If using Spring Boot, this happens automatically as all Spring beans that support JMX registration are automatically registered by default.
291+
semantic_conventions:
292+
- DATABASE_POOL_METRICS
280293
library_link: https://commons.apache.org/proper/commons-dbcp/
281294
source_path: instrumentation/apache-dbcp-2.0
282295
scope:
@@ -354,10 +367,14 @@ libraries:
354367
- name: db.client.connection.pool.name
355368
type: STRING
356369
- name: apache-dubbo-2.7
370+
display_name: Apache Dubbo
357371
description: The Apache Dubbo instrumentation provides RPC client spans and RPC
358372
server spans for Apache Dubbo RPC calls. Each call produces a span named after
359373
the Dubbo method, enriched with standard RPC attributes (system, service, method),
360374
network attributes, and error details if an exception occurs.
375+
semantic_conventions:
376+
- RPC_CLIENT_SPANS
377+
- RPC_SERVER_SPANS
361378
library_link: https://github.com/apache/dubbo/
362379
source_path: instrumentation/apache-dubbo-2.7
363380
scope:
@@ -399,8 +416,12 @@ libraries:
399416
- name: rpc.system
400417
type: STRING
401418
- name: apache-httpasyncclient-4.1
419+
display_name: Apache HttpAsyncClient
402420
description: This instrumentation enables HTTP client spans and HTTP client metrics
403421
for the Apache HttpAsyncClient.
422+
semantic_conventions:
423+
- HTTP_CLIENT_SPANS
424+
- HTTP_CLIENT_METRICS
404425
library_link: https://hc.apache.org/index.html
405426
source_path: instrumentation/apache-httpasyncclient-4.1
406427
scope:
@@ -446,8 +467,12 @@ libraries:
446467
- name: url.full
447468
type: STRING
448469
- name: apache-httpclient-2.0
470+
display_name: Apache HttpClient
449471
description: This instrumentation enables HTTP client spans and HTTP client metrics
450472
for versions 2 and 3 of the Apache HttpClient.
473+
semantic_conventions:
474+
- HTTP_CLIENT_SPANS
475+
- HTTP_CLIENT_METRICS
451476
library_link: https://hc.apache.org/index.html
452477
source_path: instrumentation/apache-httpclient/apache-httpclient-2.0
453478
scope:
@@ -491,8 +516,12 @@ libraries:
491516
- name: url.full
492517
type: STRING
493518
- name: apache-httpclient-4.0
519+
display_name: Apache HttpClient
494520
description: This instrumentation enables HTTP client spans and HTTP client metrics
495521
for version 4 of the Apache HttpClient.
522+
semantic_conventions:
523+
- HTTP_CLIENT_SPANS
524+
- HTTP_CLIENT_METRICS
496525
library_link: https://hc.apache.org/index.html
497526
source_path: instrumentation/apache-httpclient/apache-httpclient-4.0
498527
scope:
@@ -539,8 +568,12 @@ libraries:
539568
- name: url.full
540569
type: STRING
541570
- name: apache-httpclient-4.3
571+
display_name: Apache HttpClient
542572
description: This instrumentation provides a library integration that enables
543573
HTTP client spans and HTTP client metrics for the Apache HttpClient.
574+
semantic_conventions:
575+
- HTTP_CLIENT_SPANS
576+
- HTTP_CLIENT_METRICS
544577
library_link: https://hc.apache.org/index.html
545578
source_path: instrumentation/apache-httpclient/apache-httpclient-4.3
546579
scope:
@@ -588,8 +621,12 @@ libraries:
588621
- name: url.full
589622
type: STRING
590623
- name: apache-httpclient-5.0
624+
display_name: Apache HttpClient
591625
description: This instrumentation enables HTTP client spans and HTTP client metrics
592626
for version 5 of the Apache HttpClient.
627+
semantic_conventions:
628+
- HTTP_CLIENT_SPANS
629+
- HTTP_CLIENT_METRICS
593630
library_link: https://hc.apache.org/index.html
594631
source_path: instrumentation/apache-httpclient/apache-httpclient-5.0
595632
scope:
@@ -635,8 +672,12 @@ libraries:
635672
- name: url.full
636673
type: STRING
637674
- name: apache-httpclient-5.2
675+
display_name: Apache HttpClient
638676
description: This instrumentation provides a library integration that enables
639677
HTTP client spans and HTTP client metrics for the Apache HttpClient.
678+
semantic_conventions:
679+
- HTTP_CLIENT_SPANS
680+
- HTTP_CLIENT_METRICS
640681
library_link: https://hc.apache.org/index.html
641682
source_path: instrumentation/apache-httpclient/apache-httpclient-5.2
642683
scope:

instrumentation-docs/readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ 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+
* semantic_conventions
118+
* The semantic conventions that the instrumentation module adheres to
119+
* Options are:
120+
* HTTP_CLIENT_SPANS
121+
* HTTP_CLIENT_METRICS
122+
* HTTP_SERVER_SPANS
123+
* HTTP_SERVER_METRICS
124+
* RPC_CLIENT_SPANS
125+
* RPC_CLIENT_METRICS
126+
* RPC_SERVER_SPANS
127+
* RPC_SERVER_METRICS
128+
* MESSAGING_SPANS
129+
* DATABASE_CLIENT_SPANS
130+
* DATABASE_CLIENT_METRICS
131+
* DATABASE_POOL_METRICS
132+
* JVM_RUNTIME_METRICS
133+
* GRAPHQL_SERVER_SPANS
134+
* FAAS_SERVER_SPANS
135+
* GENAI_CLIENT_SPANS
136+
* GENAI_CLIENT_METRIC
117137
* library_link
118138
* URL to the library or framework's main website or documentation, or if those don't exist, the
119139
GitHub repository.
@@ -149,6 +169,10 @@ As of now, the following fields are supported, all of which are optional:
149169

150170
```yaml
151171
description: "This instrumentation enables..." # Description of the instrumentation module
172+
semantic_conventions: # List of semantic conventions the instrumentation adheres to
173+
- HTTP_CLIENT_SPANS
174+
- DATABASE_CLIENT_SPANS
175+
- JVM_RUNTIME_METRICS
152176
disabled_by_default: true # Defaults to `false`
153177
classification: internal # instrumentation classification: library | internal | custom
154178
library_link: https://... # URL to the library or framework's main website or documentation

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public class InstrumentationMetadata {
3737

3838
private List<ConfigurationOption> configurations = emptyList();
3939

40+
@JsonProperty("semantic_conventions")
41+
private List<SemanticConvention> semanticConventions = emptyList();
42+
4043
public InstrumentationMetadata() {
4144
this.classification = InstrumentationClassification.LIBRARY.name();
4245
}
@@ -47,12 +50,14 @@ public InstrumentationMetadata(
4750
String classification,
4851
@Nullable String libraryLink,
4952
@Nullable String displayName,
53+
@Nullable List<SemanticConvention> semanticConventions,
5054
@Nullable List<ConfigurationOption> configurations) {
5155
this.classification = classification;
5256
this.disabledByDefault = disabledByDefault;
5357
this.description = description;
5458
this.libraryLink = libraryLink;
5559
this.displayName = displayName;
60+
this.semanticConventions = Objects.requireNonNullElse(semanticConventions, emptyList());
5661
this.configurations = Objects.requireNonNullElse(configurations, emptyList());
5762
}
5863

@@ -101,6 +106,14 @@ public void setConfigurations(@Nullable List<ConfigurationOption> configurations
101106
this.configurations = Objects.requireNonNullElse(configurations, emptyList());
102107
}
103108

109+
public List<SemanticConvention> getSemanticConventions() {
110+
return semanticConventions;
111+
}
112+
113+
public void setSemanticConventions(@Nullable List<SemanticConvention> semanticConventions) {
114+
this.semanticConventions = Objects.requireNonNullElse(semanticConventions, emptyList());
115+
}
116+
104117
@Nullable
105118
public String getLibraryLink() {
106119
return libraryLink;
@@ -122,6 +135,7 @@ public static class Builder {
122135
@Nullable private String libraryLink;
123136
@Nullable private String displayName;
124137
private List<ConfigurationOption> configurations = emptyList();
138+
private List<SemanticConvention> semanticConventions = emptyList();
125139

126140
@CanIgnoreReturnValue
127141
public Builder description(@Nullable String description) {
@@ -159,13 +173,20 @@ public Builder configurations(@Nullable List<ConfigurationOption> configurations
159173
return this;
160174
}
161175

176+
@CanIgnoreReturnValue
177+
public Builder semanticConventions(@Nullable List<SemanticConvention> semanticConventions) {
178+
this.semanticConventions = Objects.requireNonNullElse(semanticConventions, emptyList());
179+
return this;
180+
}
181+
162182
public InstrumentationMetadata build() {
163183
return new InstrumentationMetadata(
164184
description,
165185
disabledByDefault,
166186
classification != null ? classification : InstrumentationClassification.LIBRARY.name(),
167187
libraryLink,
168188
displayName,
189+
semanticConventions,
169190
configurations);
170191
}
171192
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.docs.internal;
7+
8+
/**
9+
* Represents the data in a metadata.yaml file. This class is internal and is hence not for public
10+
* use. Its APIs are unstable and can change at any time.
11+
*/
12+
public enum SemanticConvention {
13+
HTTP_CLIENT_SPANS,
14+
HTTP_CLIENT_METRICS,
15+
HTTP_SERVER_SPANS,
16+
HTTP_SERVER_METRICS,
17+
RPC_CLIENT_SPANS,
18+
RPC_CLIENT_METRICS,
19+
RPC_SERVER_SPANS,
20+
RPC_SERVER_METRICS,
21+
MESSAGING_SPANS,
22+
DATABASE_CLIENT_SPANS,
23+
DATABASE_CLIENT_METRICS,
24+
DATABASE_POOL_METRICS,
25+
JVM_RUNTIME_METRICS,
26+
GRAPHQL_SERVER_SPANS,
27+
FAAS_SERVER_SPANS,
28+
GENAI_CLIENT_SPANS,
29+
GENAI_CLIENT_METRICS
30+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ private static void addMetadataProperties(
201201
if (module.getMetadata().getDescription() != null) {
202202
moduleMap.put("description", module.getMetadata().getDescription());
203203
}
204+
if (module.getMetadata().getSemanticConventions() != null
205+
&& !module.getMetadata().getSemanticConventions().isEmpty()) {
206+
List<String> conventionNames =
207+
module.getMetadata().getSemanticConventions().stream()
208+
.map(Enum::name)
209+
.collect(Collectors.toList());
210+
moduleMap.put("semantic_conventions", conventionNames);
211+
}
204212
if (module.getMetadata().getLibraryLink() != null) {
205213
moduleMap.put("library_link", module.getMetadata().getLibraryLink());
206214
}

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

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

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

8+
import static io.opentelemetry.instrumentation.docs.internal.SemanticConvention.DATABASE_CLIENT_METRICS;
9+
import static io.opentelemetry.instrumentation.docs.internal.SemanticConvention.DATABASE_CLIENT_SPANS;
810
import static java.util.Collections.emptyList;
911
import static org.assertj.core.api.Assertions.assertThat;
1012

@@ -44,6 +46,7 @@ void testPrintInstrumentationList() throws Exception {
4446
.displayName("Spring Web")
4547
.classification(InstrumentationClassification.LIBRARY.name())
4648
.disabledByDefault(true)
49+
.semanticConventions(List.of(DATABASE_CLIENT_METRICS, DATABASE_CLIENT_SPANS))
4750
.build();
4851

4952
modules.add(
@@ -84,6 +87,9 @@ void testPrintInstrumentationList() throws Exception {
8487
- name: spring-web-6.0
8588
display_name: Spring Web
8689
description: Spring Web 6.0 instrumentation
90+
semantic_conventions:
91+
- DATABASE_CLIENT_METRICS
92+
- DATABASE_CLIENT_SPANS
8793
disabled_by_default: true
8894
source_path: instrumentation/spring/spring-web/spring-web-6.0
8995
minimum_java_version: 11
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
display_name: ActiveJ
22
description: This instrumentation enables HTTP server spans and HTTP server metrics for the ActiveJ HTTP server.
33
library_link: https://activej.io/
4+
semantic_conventions:
5+
- HTTP_SERVER_SPANS
6+
- HTTP_SERVER_METRICS

instrumentation/akka/akka-http-10.0/metadata.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ description: >
33
This instrumentation enables HTTP client spans and metrics for the Akka HTTP client, and HTTP
44
server spans and metrics for the Akka HTTP server.
55
library_link: https://doc.akka.io/docs/akka-http/current/index.html
6+
semantic_conventions:
7+
- HTTP_CLIENT_SPANS
8+
- HTTP_CLIENT_METRICS
9+
- HTTP_SERVER_SPANS
10+
- HTTP_SERVER_METRICS

instrumentation/alibaba-druid-1.0/metadata.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ description: >
22
The Alibaba Druid instrumentation generates database connection pool metrics for druid data
33
sources.
44
library_link: https://github.com/alibaba/druid
5+
semantic_conventions:
6+
- DATABASE_POOL_METRICS

0 commit comments

Comments
 (0)