Skip to content

Commit 2f0d9dc

Browse files
authored
feat(opentelemetry): Support db.system.name attribute for database spans (#18902)
Supports the now stable `db.system.name` semantic convention attribute alongside the deprecated `db.system` attribute when identifying database spans. Closes #18903 (added automatically)
1 parent 9115e19 commit 2f0d9dc

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

packages/opentelemetry/src/utils/parseSpanDescription.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Attributes, AttributeValue } from '@opentelemetry/api';
22
import { SpanKind } from '@opentelemetry/api';
33
import {
4+
ATTR_DB_SYSTEM_NAME,
45
ATTR_HTTP_REQUEST_METHOD,
56
ATTR_HTTP_ROUTE,
67
ATTR_URL_FULL,
@@ -47,7 +48,7 @@ export function inferSpanData(spanName: string, attributes: SpanAttributes, kind
4748
}
4849

4950
// eslint-disable-next-line deprecation/deprecation
50-
const dbSystem = attributes[SEMATTRS_DB_SYSTEM];
51+
const dbSystem = attributes[ATTR_DB_SYSTEM_NAME] || attributes[SEMATTRS_DB_SYSTEM];
5152
const opIsCache =
5253
typeof attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] === 'string' &&
5354
attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP].startsWith('cache.');

packages/opentelemetry/test/utils/parseSpanDescription.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { Span } from '@opentelemetry/api';
33
import { SpanKind } from '@opentelemetry/api';
44
import {
5+
ATTR_DB_SYSTEM_NAME,
56
ATTR_HTTP_ROUTE,
67
SEMATTRS_DB_STATEMENT,
78
SEMATTRS_DB_SYSTEM,
@@ -147,6 +148,48 @@ describe('parseSpanDescription', () => {
147148
source: 'task',
148149
},
149150
],
151+
[
152+
'works with db.system.name (stable attribute)',
153+
{
154+
[ATTR_DB_SYSTEM_NAME]: 'postgresql',
155+
[SEMATTRS_DB_STATEMENT]: 'SELECT * from users',
156+
},
157+
'test name',
158+
SpanKind.CLIENT,
159+
{
160+
description: 'SELECT * from users',
161+
op: 'db',
162+
source: 'task',
163+
},
164+
],
165+
[
166+
'works with db.system.name without statement',
167+
{
168+
[ATTR_DB_SYSTEM_NAME]: 'postgresql',
169+
},
170+
'test name',
171+
SpanKind.CLIENT,
172+
{
173+
description: 'test name',
174+
op: 'db',
175+
source: 'task',
176+
},
177+
],
178+
[
179+
'prefers db.system.name over deprecated db.system',
180+
{
181+
[ATTR_DB_SYSTEM_NAME]: 'postgresql',
182+
[SEMATTRS_DB_SYSTEM]: 'mysql',
183+
[SEMATTRS_DB_STATEMENT]: 'SELECT * from users',
184+
},
185+
'test name',
186+
SpanKind.CLIENT,
187+
{
188+
description: 'SELECT * from users',
189+
op: 'db',
190+
source: 'task',
191+
},
192+
],
150193
[
151194
'works with rpc service',
152195
{

0 commit comments

Comments
 (0)