Skip to content

Commit e761302

Browse files
committed
Use db.system.name as span name fallback per stable semconv
Per the stable database semantic conventions, when neither operation nor target are available, the span name should be db.system.name. Updated the test to expect 'other_sql' (the db.system.name value) for stable semconv, while keeping 'DB Query' for old semconv to maintain backward compatibility.
1 parent 11e7b49 commit e761302

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CI-PLAN.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ Note: All jobs with parameters in parentheses (e.g., Java version, VM, indy sett
3333
- Fix: Same as above
3434

3535
## Notes
36-
The failures are all related to the db.query.summary implementation. The span name is being set to "localhost" instead of "DB Query". This is happening in test cases that involve getClientInfo exceptions.
36+
The failures were all related to the db.query.summary implementation. The span name was being set to "localhost" instead of "DB Query" when SQL could not be parsed.
3737

38-
The issue appears to be that when there's no actual SQL statement (e.g., during getClientInfo operations that fail), the query summary logic is returning the server name ("localhost") as the span name instead of falling back to "DB Query".
38+
**Root cause**: When SQL statement cannot be parsed (e.g., "testing 123" which is not valid SQL), the sanitizer returns null for operation, collection, and querySummary. The span name logic was incorrectly falling back to server.address as the span name.
3939

40-
Root cause: The implementation needs to handle cases where there is no SQL statement and fall back to an appropriate default span name.
40+
**Solution**: According to OpenTelemetry semantic conventions for database spans, `server.address` should only be used as part of the `{target}` when combined with an operation (e.g., "SELECT localhost"). When there is no operation, the fallback should be `db.system.name` or the default "DB Query" span name.
41+
42+
**Fix applied**: Updated `DbClientSpanNameExtractor.computeSpanNameStable()` to only use server.address when an operation is available. When no operation exists, it now properly falls back to db.system.name or "DB Query".
43+
44+
**Commit**: 11e7b49ed1

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientSpanNameExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ protected String computeSpanNameStable(
129129
return target;
130130
}
131131

132-
// Final fallback to db.system.name
132+
// Final fallback to db.system.name (required attribute per spec)
133133
String dbSystem = getter.getDbSystem(request);
134134
if (dbSystem != null) {
135135
return dbSystem;
136136
}
137137

138+
// Ultimate fallback if db.system.name is somehow not available
138139
return DEFAULT_SPAN_NAME;
139140
}
140141

instrumentation/jdbc/testing/src/main/java/io/opentelemetry/instrumentation/jdbc/testing/AbstractJdbcInstrumentationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ void testGetClientInfoException(String query) throws SQLException {
12201220
trace.hasSpansSatisfyingExactly(
12211221
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
12221222
span ->
1223-
span.hasName("DB Query")
1223+
span.hasName(emitStableDatabaseSemconv() ? "other_sql" : "DB Query")
12241224
.hasKind(SpanKind.CLIENT)
12251225
.hasParent(trace.getSpan(0))
12261226
.hasAttributesSatisfyingExactly(

0 commit comments

Comments
 (0)