Skip to content

Commit 9b8a87b

Browse files
authored
Mongo Metadata and instrumenter refactor (#15500)
1 parent e30b93f commit 9b8a87b

File tree

28 files changed

+535
-81
lines changed

28 files changed

+535
-81
lines changed

docs/instrumentation-list.yaml

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8250,6 +8250,13 @@ libraries:
82508250
- io.micrometer:micrometer-core:1.5.0
82518251
mongo:
82528252
- name: mongo-3.1
8253+
display_name: MongoDB Driver
8254+
description: |
8255+
This instrumentation enables database client spans and database client metrics for the MongoDB Java driver.
8256+
semantic_conventions:
8257+
- DATABASE_CLIENT_SPANS
8258+
- DATABASE_CLIENT_METRICS
8259+
library_link: https://www.mongodb.com/docs/drivers/java-drivers/
82538260
source_path: instrumentation/mongo/mongo-3.1
82548261
scope:
82558262
name: io.opentelemetry.mongo-3.1
@@ -8258,28 +8265,317 @@ libraries:
82588265
- org.mongodb:mongo-java-driver:[3.1,)
82598266
library:
82608267
- org.mongodb:mongo-java-driver:3.1.0
8268+
configurations:
8269+
- name: otel.instrumentation.mongo.statement-sanitizer.enabled
8270+
description: |
8271+
Enables statement sanitization for MongoDB queries. Takes precedence over otel.instrumentation.common.db-statement-sanitizer.enabled.
8272+
type: boolean
8273+
default: true
8274+
- name: otel.instrumentation.common.db-statement-sanitizer.enabled
8275+
description: Enables statement sanitization for database queries.
8276+
type: boolean
8277+
default: true
8278+
telemetry:
8279+
- when: default
8280+
spans:
8281+
- span_kind: CLIENT
8282+
attributes:
8283+
- name: db.connection_string
8284+
type: STRING
8285+
- name: db.mongodb.collection
8286+
type: STRING
8287+
- name: db.name
8288+
type: STRING
8289+
- name: db.operation
8290+
type: STRING
8291+
- name: db.statement
8292+
type: STRING
8293+
- name: db.system
8294+
type: STRING
8295+
- name: server.address
8296+
type: STRING
8297+
- name: server.port
8298+
type: LONG
8299+
- when: otel.semconv-stability.opt-in=database
8300+
metrics:
8301+
- name: db.client.operation.duration
8302+
description: Duration of database client operations.
8303+
type: HISTOGRAM
8304+
unit: s
8305+
attributes:
8306+
- name: db.collection.name
8307+
type: STRING
8308+
- name: db.namespace
8309+
type: STRING
8310+
- name: db.operation.name
8311+
type: STRING
8312+
- name: db.system.name
8313+
type: STRING
8314+
- name: server.address
8315+
type: STRING
8316+
- name: server.port
8317+
type: LONG
8318+
spans:
8319+
- span_kind: CLIENT
8320+
attributes:
8321+
- name: db.collection.name
8322+
type: STRING
8323+
- name: db.namespace
8324+
type: STRING
8325+
- name: db.operation.name
8326+
type: STRING
8327+
- name: db.query.text
8328+
type: STRING
8329+
- name: db.system.name
8330+
type: STRING
8331+
- name: server.address
8332+
type: STRING
8333+
- name: server.port
8334+
type: LONG
82618335
- name: mongo-3.7
8336+
display_name: MongoDB Driver
8337+
description: |
8338+
This instrumentation enables database client spans and database client metrics for the MongoDB Java driver.
8339+
semantic_conventions:
8340+
- DATABASE_CLIENT_SPANS
8341+
- DATABASE_CLIENT_METRICS
8342+
library_link: https://www.mongodb.com/docs/drivers/java-drivers/
82628343
source_path: instrumentation/mongo/mongo-3.7
82638344
scope:
82648345
name: io.opentelemetry.mongo-3.7
82658346
target_versions:
82668347
javaagent:
82678348
- org.mongodb:mongodb-driver-core:[3.7, 4.0)
82688349
- org.mongodb:mongo-java-driver:[3.7, 4.0)
8350+
configurations:
8351+
- name: otel.instrumentation.mongo.statement-sanitizer.enabled
8352+
description: |
8353+
Enables statement sanitization for MongoDB queries. Takes precedence over otel.instrumentation.common.db-statement-sanitizer.enabled.
8354+
type: boolean
8355+
default: true
8356+
- name: otel.instrumentation.common.db-statement-sanitizer.enabled
8357+
description: Enables statement sanitization for database queries.
8358+
type: boolean
8359+
default: true
8360+
telemetry:
8361+
- when: default
8362+
spans:
8363+
- span_kind: CLIENT
8364+
attributes:
8365+
- name: db.connection_string
8366+
type: STRING
8367+
- name: db.mongodb.collection
8368+
type: STRING
8369+
- name: db.name
8370+
type: STRING
8371+
- name: db.operation
8372+
type: STRING
8373+
- name: db.statement
8374+
type: STRING
8375+
- name: db.system
8376+
type: STRING
8377+
- name: server.address
8378+
type: STRING
8379+
- name: server.port
8380+
type: LONG
8381+
- when: otel.semconv-stability.opt-in=database
8382+
metrics:
8383+
- name: db.client.operation.duration
8384+
description: Duration of database client operations.
8385+
type: HISTOGRAM
8386+
unit: s
8387+
attributes:
8388+
- name: db.collection.name
8389+
type: STRING
8390+
- name: db.namespace
8391+
type: STRING
8392+
- name: db.operation.name
8393+
type: STRING
8394+
- name: db.system.name
8395+
type: STRING
8396+
- name: server.address
8397+
type: STRING
8398+
- name: server.port
8399+
type: LONG
8400+
spans:
8401+
- span_kind: CLIENT
8402+
attributes:
8403+
- name: db.collection.name
8404+
type: STRING
8405+
- name: db.namespace
8406+
type: STRING
8407+
- name: db.operation.name
8408+
type: STRING
8409+
- name: db.query.text
8410+
type: STRING
8411+
- name: db.system.name
8412+
type: STRING
8413+
- name: server.address
8414+
type: STRING
8415+
- name: server.port
8416+
type: LONG
82698417
- name: mongo-4.0
8418+
display_name: MongoDB Driver
8419+
description: |
8420+
This instrumentation enables database client spans and database client metrics for the MongoDB Java driver.
8421+
semantic_conventions:
8422+
- DATABASE_CLIENT_SPANS
8423+
- DATABASE_CLIENT_METRICS
8424+
library_link: https://www.mongodb.com/docs/drivers/java-drivers/
82708425
source_path: instrumentation/mongo/mongo-4.0
82718426
scope:
82728427
name: io.opentelemetry.mongo-4.0
82738428
target_versions:
82748429
javaagent:
82758430
- org.mongodb:mongodb-driver-core:[4.0,)
8431+
configurations:
8432+
- name: otel.instrumentation.mongo.statement-sanitizer.enabled
8433+
description: |
8434+
Enables statement sanitization for MongoDB queries. Takes precedence over otel.instrumentation.common.db-statement-sanitizer.enabled.
8435+
type: boolean
8436+
default: true
8437+
- name: otel.instrumentation.common.db-statement-sanitizer.enabled
8438+
description: Enables statement sanitization for database queries.
8439+
type: boolean
8440+
default: true
8441+
telemetry:
8442+
- when: default
8443+
spans:
8444+
- span_kind: CLIENT
8445+
attributes:
8446+
- name: db.connection_string
8447+
type: STRING
8448+
- name: db.mongodb.collection
8449+
type: STRING
8450+
- name: db.name
8451+
type: STRING
8452+
- name: db.operation
8453+
type: STRING
8454+
- name: db.statement
8455+
type: STRING
8456+
- name: db.system
8457+
type: STRING
8458+
- name: server.address
8459+
type: STRING
8460+
- name: server.port
8461+
type: LONG
8462+
- when: otel.semconv-stability.opt-in=database
8463+
metrics:
8464+
- name: db.client.operation.duration
8465+
description: Duration of database client operations.
8466+
type: HISTOGRAM
8467+
unit: s
8468+
attributes:
8469+
- name: db.collection.name
8470+
type: STRING
8471+
- name: db.namespace
8472+
type: STRING
8473+
- name: db.operation.name
8474+
type: STRING
8475+
- name: db.system.name
8476+
type: STRING
8477+
- name: server.address
8478+
type: STRING
8479+
- name: server.port
8480+
type: LONG
8481+
spans:
8482+
- span_kind: CLIENT
8483+
attributes:
8484+
- name: db.collection.name
8485+
type: STRING
8486+
- name: db.namespace
8487+
type: STRING
8488+
- name: db.operation.name
8489+
type: STRING
8490+
- name: db.query.text
8491+
type: STRING
8492+
- name: db.system.name
8493+
type: STRING
8494+
- name: server.address
8495+
type: STRING
8496+
- name: server.port
8497+
type: LONG
82768498
- name: mongo-async-3.3
8499+
display_name: MongoDB Driver (Async)
8500+
description: |
8501+
This instrumentation enables database client spans and database client metrics for the MongoDB async Java driver.
8502+
semantic_conventions:
8503+
- DATABASE_CLIENT_SPANS
8504+
- DATABASE_CLIENT_METRICS
8505+
library_link: https://www.mongodb.com/docs/drivers/java-drivers/
82778506
source_path: instrumentation/mongo/mongo-async-3.3
82788507
scope:
82798508
name: io.opentelemetry.mongo-async-3.3
82808509
target_versions:
82818510
javaagent:
82828511
- org.mongodb:mongodb-driver-async:[3.3,)
8512+
configurations:
8513+
- name: otel.instrumentation.mongo.statement-sanitizer.enabled
8514+
description: |
8515+
Enables statement sanitization for MongoDB queries. Takes precedence over otel.instrumentation.common.db-statement-sanitizer.enabled.
8516+
type: boolean
8517+
default: true
8518+
- name: otel.instrumentation.common.db-statement-sanitizer.enabled
8519+
description: Enables statement sanitization for database queries.
8520+
type: boolean
8521+
default: true
8522+
telemetry:
8523+
- when: default
8524+
spans:
8525+
- span_kind: CLIENT
8526+
attributes:
8527+
- name: db.connection_string
8528+
type: STRING
8529+
- name: db.mongodb.collection
8530+
type: STRING
8531+
- name: db.name
8532+
type: STRING
8533+
- name: db.operation
8534+
type: STRING
8535+
- name: db.statement
8536+
type: STRING
8537+
- name: db.system
8538+
type: STRING
8539+
- name: server.address
8540+
type: STRING
8541+
- name: server.port
8542+
type: LONG
8543+
- when: otel.semconv-stability.opt-in=database
8544+
metrics:
8545+
- name: db.client.operation.duration
8546+
description: Duration of database client operations.
8547+
type: HISTOGRAM
8548+
unit: s
8549+
attributes:
8550+
- name: db.collection.name
8551+
type: STRING
8552+
- name: db.namespace
8553+
type: STRING
8554+
- name: db.operation.name
8555+
type: STRING
8556+
- name: db.system.name
8557+
type: STRING
8558+
- name: server.address
8559+
type: STRING
8560+
- name: server.port
8561+
type: LONG
8562+
spans:
8563+
- span_kind: CLIENT
8564+
attributes:
8565+
- name: db.collection.name
8566+
type: STRING
8567+
- name: db.namespace
8568+
type: STRING
8569+
- name: db.operation.name
8570+
type: STRING
8571+
- name: db.query.text
8572+
type: STRING
8573+
- name: db.system.name
8574+
type: STRING
8575+
- name: server.address
8576+
type: STRING
8577+
- name: server.port
8578+
type: LONG
82838579
mybatis:
82848580
- name: mybatis-3.2
82858581
display_name: MyBatis

instrumentation-docs/instrumentations.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ readonly INSTRUMENTATIONS=(
166166
"lettuce:lettuce-5.0:javaagent:testStableSemconv"
167167
"lettuce:lettuce-5.1:javaagent:test"
168168
"lettuce:lettuce-5.1:javaagent:testStableSemconv"
169+
"mongo:mongo-3.1:javaagent:test"
170+
"mongo:mongo-3.1:javaagent:testStableSemconv"
171+
"mongo:mongo-3.7:javaagent:test"
172+
"mongo:mongo-3.7:javaagent:testStableSemconv"
173+
"mongo:mongo-4.0:javaagent:test"
174+
"mongo:mongo-4.0:javaagent:testStableSemconv"
175+
"mongo:mongo-async-3.3:javaagent:test"
176+
"mongo:mongo-async-3.3:javaagent:testStableSemconv"
169177
"mybatis-3.2:javaagent:test"
170178
"nats:nats-2.17:javaagent:test"
171179
"nats:nats-2.17:javaagent:testExperimental"

instrumentation/mongo/mongo-3.1/javaagent/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ dependencies {
2626
tasks {
2727
withType<Test>().configureEach {
2828
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
29+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
2930
}
3031

3132
val testStableSemconv by registering(Test::class) {
3233
testClassesDirs = sourceSets.test.get().output.classesDirs
3334
classpath = sourceSets.test.get().runtimeClasspath
3435
jvmArgs("-Dotel.semconv-stability.opt-in=database")
36+
systemProperty("metadataConfig", "otel.semconv-stability.opt-in=database")
3537
}
3638

3739
check {

instrumentation/mongo/mongo-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v3_1/MongoInstrumentationSingletons.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@
66
package io.opentelemetry.javaagent.instrumentation.mongo.v3_1;
77

88
import com.mongodb.event.CommandListener;
9+
import com.mongodb.event.CommandStartedEvent;
910
import io.opentelemetry.api.GlobalOpenTelemetry;
10-
import io.opentelemetry.instrumentation.mongo.v3_1.MongoTelemetry;
11+
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
12+
import io.opentelemetry.instrumentation.mongo.v3_1.internal.MongoInstrumenterFactory;
13+
import io.opentelemetry.instrumentation.mongo.v3_1.internal.TracingCommandListener;
1114
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig;
1215
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
1316

1417
public final class MongoInstrumentationSingletons {
1518

16-
public static final CommandListener LISTENER =
17-
MongoTelemetry.builder(GlobalOpenTelemetry.get())
18-
.setStatementSanitizationEnabled(
19-
AgentInstrumentationConfig.get()
20-
.getBoolean(
21-
"otel.instrumentation.mongo.statement-sanitizer.enabled",
22-
AgentCommonConfig.get().isStatementSanitizationEnabled()))
23-
.build()
24-
.newCommandListener();
19+
private static final Instrumenter<CommandStartedEvent, Void> INSTRUMENTER =
20+
MongoInstrumenterFactory.createInstrumenter(
21+
GlobalOpenTelemetry.get(),
22+
"io.opentelemetry.mongo-3.1",
23+
AgentInstrumentationConfig.get()
24+
.getBoolean(
25+
"otel.instrumentation.mongo.statement-sanitizer.enabled",
26+
AgentCommonConfig.get().isStatementSanitizationEnabled()));
27+
28+
public static final CommandListener LISTENER = new TracingCommandListener(INSTRUMENTER);
2529

2630
public static boolean isTracingListener(CommandListener listener) {
2731
return listener.getClass().getName().equals(LISTENER.getClass().getName());

0 commit comments

Comments
 (0)