Skip to content

Commit d59055c

Browse files
Split db.namespace into separate attributes: service name, instance ID, and PDB && update the driver version to 23.26.0.0.0
1 parent 63f5ba0 commit d59055c

File tree

5 files changed

+28
-33
lines changed

5 files changed

+28
-33
lines changed

ojdbc-provider-observability/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ When `OTEL_SEMCONV_STABILITY_OPT_IN=database` or `database/dup`:
3838

3939
* **Required/Recommended Attributes**
4040
* `db.system.name` - Always set to `"oracle.db"`
41-
* `db.namespace` - Format: `{instance_name}|{database_name}|{service_name}`
41+
* `db.namespace` - Service name (or TNS alias if used)
4242
* `db.operation.name` - Database operation being executed
4343
* `db.query.summary` - Low cardinality query summary (SQL type)
4444
* `server.address` - Database server hostname
4545
* `server.port` - Database server port (if non-default, i.e., not 1521)
46+
* `oracle.db.instance.id` - Oracle database instance identifier
47+
* `oracle.db.pdb` - Oracle PDB name
4648
* `oracle.db.query.sql.id` - Oracle SQL_ID
4749
* `oracle.db.session.id` - Oracle session ID
4850
* `oracle.db.server.pid` - Oracle server process ID

ojdbc-provider-observability/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<dependency>
2525
<groupId>com.oracle.database.jdbc</groupId>
2626
<artifactId>ojdbc11</artifactId>
27+
<version>23.26.0.0.0</version>
2728
</dependency>
2829
<dependency>
2930
<groupId>io.opentelemetry</groupId>

ojdbc-provider-observability/src/main/java/oracle/jdbc/provider/observability/tracers/otel/OTelTracer.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,16 @@ private Span initAndGetSpan(TraceContext traceContext, String spanName) {
329329
if (emitStable) {
330330
spanBuilder.setAttribute(DB_SYSTEM_ATTRIBUTE, DB_SYSTEM_VALUE_ORACLE);
331331

332-
String namespace = buildDbNamespace(traceContext);
333-
if (namespace != null && !namespace.isEmpty()) {
334-
spanBuilder.setAttribute(DB_NAMESPACE_ATTRIBUTE, namespace);
332+
if (traceContext.getServiceName() != null && !traceContext.getServiceName().isEmpty()) {
333+
spanBuilder.setAttribute(DB_NAMESPACE_ATTRIBUTE, traceContext.getServiceName());
334+
}
335+
336+
if (traceContext.getInstanceName() != null && !traceContext.getInstanceName().isEmpty()) {
337+
spanBuilder.setAttribute(ORACLE_INSTANCE_ID_ATTRIBUTE, traceContext.getInstanceName());
338+
}
339+
340+
if (traceContext.getDatabaseName() != null && !traceContext.getDatabaseName().isEmpty()) {
341+
spanBuilder.setAttribute(ORACLE_PDB_ATTRIBUTE, traceContext.getDatabaseName());
335342
}
336343

337344
if (traceContext.getServerAddress() != null && !traceContext.getServerAddress().isEmpty()) {
@@ -458,32 +465,6 @@ private String initAndGetTraceState(Span span) {
458465
return String.format(TRACE_STATE_FORMAT, stringBuilder);
459466
}
460467

461-
/**
462-
* Builds the db.namespace attribute according to Oracle Database
463-
* semantic conventions.
464-
* Format: {instance_name}|{database_name}|{service_name}
465-
* Missing components and their separators are omitted.
466-
*/
467-
private String buildDbNamespace(TraceContext traceContext) {
468-
StringBuilder ns = new StringBuilder();
469-
470-
if (traceContext.getInstanceName() != null && !traceContext.getInstanceName().isEmpty()) {
471-
ns.append(traceContext.getInstanceName());
472-
}
473-
474-
if (traceContext.getDatabaseName() != null && !traceContext.getDatabaseName().isEmpty()) {
475-
if (ns.length() > 0) ns.append('|');
476-
ns.append(traceContext.getDatabaseName());
477-
}
478-
479-
if (traceContext.getServiceName() != null && !traceContext.getServiceName().isEmpty()) {
480-
if (ns.length() > 0) ns.append('|');
481-
ns.append(traceContext.getServiceName());
482-
}
483-
484-
return ns.length() > 0 ? ns.toString() : null;
485-
}
486-
487468
/**
488469
* Returns true if stable database semantic conventions should be emitted.
489470
* This checks if OTEL_SEMCONV_STABILITY_OPT_IN contains "database" or "database/dup"

ojdbc-provider-observability/src/main/java/oracle/jdbc/provider/observability/tracers/otel/OtelSemanticConventions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ private OtelSemanticConventions() {
148148
*/
149149
static final String ORACLE_SERVER_PID_ATTRIBUTE = "oracle.db.server.pid";
150150

151+
/**
152+
* Attribute key for Oracle database instance identifier.
153+
*/
154+
static final String ORACLE_INSTANCE_ID_ATTRIBUTE = "oracle.db.instance.id";
155+
156+
/**
157+
* Attribute key for Oracle PDB name.
158+
*/
159+
static final String ORACLE_PDB_ATTRIBUTE = "oracle.db.pdb";
160+
151161
/**
152162
* Attribute key for Oracle shard name.
153163
*/

ojdbc-provider-observability/src/test/java/oracle/jdbc/provider/observability/ObservabilityTraceEventListenerTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.sql.DriverManager;
5151
import java.sql.ResultSet;
5252
import java.sql.Statement;
53+
import java.time.Instant;
5354

5455
import org.junit.jupiter.params.ParameterizedTest;
5556
import org.junit.jupiter.params.provider.ValueSource;
@@ -204,15 +205,15 @@ public void OTELTraceTest(boolean sensitiveDataEnabled) throws Exception {
204205
Mockito.verify(spanBuilder, Mockito.times(1)).setAttribute("Database Operation", DatabaseFunction.EXECUTE_QUERY.getDescription());
205206
Mockito.verify(spanBuilder, Mockito.times(1)).setAttribute("Database Operation", DatabaseFunction.LOGOFF.getDescription());
206207
if (sensitiveDataEnabled) {
207-
Mockito.verify(spanBuilder, Mockito.times(4)).setAttribute("Database User", userName);
208+
Mockito.verify(spanBuilder, Mockito.times(4)).setAttribute("Database User", userName.toUpperCase());
208209
Mockito.verify(spanBuilder, Mockito.times(1)).setAttribute("Original SQL Text", "SELECT 'OK' FROM DUAL");
209210
Mockito.verify(spanBuilder, Mockito.times(1)).setAttribute("Actual SQL Text", "SELECT 'OK' FROM DUAL");
210211
} else {
211-
Mockito.verify(spanBuilder, Mockito.times(0)).setAttribute("Database User", userName);
212+
Mockito.verify(spanBuilder, Mockito.times(0)).setAttribute("Database User", userName.toUpperCase());
212213
Mockito.verify(spanBuilder, Mockito.times(0)).setAttribute("Original SQL Text", "SELECT 'OK' FROM DUAL");
213214
Mockito.verify(spanBuilder, Mockito.times(0)).setAttribute("Actual SQL Text", "SELECT 'OK' FROM DUAL");
214215
}
215-
Mockito.verify(span, atLeast(4)).end();
216+
Mockito.verify(span, atLeast(4)).end(Mockito.any(Instant.class));
216217

217218
}
218219

0 commit comments

Comments
 (0)