Skip to content

Commit 4c36312

Browse files
committed
- Remove Few Deprecated semantic convention constants.
1 parent f41f62c commit 4c36312

File tree

4 files changed

+109
-39
lines changed

4 files changed

+109
-39
lines changed

plugins/node/opentelemetry-instrumentation-oracledb/src/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ export enum SpanNames {
4848
LOB_MESSAGE = 'oracledb.LobOpMessage',
4949
LOB_GETDATA = 'oracledb.Lob.getData',
5050
}
51+
52+
/*
53+
* The semantic conventions defined DBSYSTEMVALUES_ORACLE as oracle, hence
54+
* defining the new constant to explicitly mention db.
55+
*
56+
*/
57+
export const DB_SYSTEM_VALUE_ORACLE = 'oracledb';
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Copyright (c) 2024, Oracle and/or its affiliates.
17+
* */
18+
19+
/**
20+
* The database management system (DBMS) product as identified
21+
* by the client instrumentation.
22+
*
23+
*/
24+
export const ATTR_DB_SYSTEM = 'db.system.name';
25+
26+
/**
27+
* The name of the database, fully qualified within the server address and port.
28+
*
29+
* @example FREEPDB1
30+
* @example XEPDB1
31+
*
32+
* @note If a database system has multiple namespace components, they **SHOULD** be concatenated (potentially using database system specific conventions) from most general to most specific namespace component, and more specific namespaces **SHOULD NOT** be captured without the more general namespaces, to ensure that "startswith" queries for the more general namespaces will be valid.
33+
* Semantic conventions for individual database systems **SHOULD** document what `db.namespace` means in the context of that system.
34+
* It is **RECOMMENDED** to capture the value as provided by the application without attempting to do any case normalization.
35+
* This attribute has stability level RELEASE CANDIDATE.
36+
*
37+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
38+
*/
39+
export const ATTR_DB_NAMESPACE = 'db.namespace';
40+
41+
/**
42+
* The name of the operation or command being executed.
43+
*
44+
* @example INSERT
45+
* @example COMMIT
46+
* @example SELECT
47+
*
48+
* @note It is **RECOMMENDED** to capture the value as provided by the application without attempting to do any case normalization.
49+
* If the operation name is parsed from the query text, it **SHOULD** be the first operation name found in the query.
50+
* For batch operations, if the individual operations are known to have the same operation name then that operation name **SHOULD** be used prepended by `BATCH `, otherwise `db.operation.name` **SHOULD** be `BATCH` or some other database system specific term if more applicable.
51+
* This attribute has stability level RELEASE CANDIDATE.
52+
*
53+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
54+
*/
55+
export const ATTR_DB_OPERATION_NAME = 'db.operation.name';

plugins/node/opentelemetry-instrumentation-oracledb/src/utils.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,25 @@ import {
2626
diag,
2727
} from '@opentelemetry/api';
2828
import {
29-
SEMATTRS_DB_SYSTEM,
30-
SEMATTRS_DB_NAME,
3129
SEMATTRS_DB_CONNECTION_STRING,
32-
SEMATTRS_NET_PEER_NAME,
33-
SEMATTRS_NET_PEER_PORT,
30+
ATTR_SERVER_PORT,
31+
ATTR_SERVER_ADDRESS,
3432
SEMATTRS_NET_TRANSPORT,
3533
SEMATTRS_DB_USER,
3634
SEMATTRS_DB_STATEMENT,
37-
SEMATTRS_DB_OPERATION,
38-
DBSYSTEMVALUES_ORACLE,
3935
} from '@opentelemetry/semantic-conventions';
36+
import {
37+
ATTR_DB_SYSTEM,
38+
ATTR_DB_NAMESPACE,
39+
ATTR_DB_OPERATION_NAME,
40+
} from './semconv';
4041
import * as oracledbTypes from 'oracledb';
4142

4243
// Local modules.
4344
import { AttributeNames } from './constants';
4445
import { OracleInstrumentationConfig, SpanConnectionConfig } from './types';
4546
import { TraceSpanData, SpanCallLevelConfig } from './internal-types';
46-
import { SpanNames } from './constants';
47+
import { SpanNames, DB_SYSTEM_VALUE_ORACLE } from './constants';
4748

4849
const newmoduleExports: any = oracledbTypes;
4950

@@ -76,18 +77,18 @@ export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
7677
// semantic standards and module custom keys.
7778
private _getConnectionSpanAttributes(config: SpanConnectionConfig) {
7879
return {
79-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_ORACLE,
80+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_ORACLE,
8081
[SEMATTRS_NET_TRANSPORT]: config.protocol,
8182
[SEMATTRS_DB_USER]: config.user,
8283
[AttributeNames.ORACLE_INSTANCE]: config.instanceName,
8384
[AttributeNames.ORACLE_PDBNAME]: config.pdbName,
8485
[AttributeNames.ORACLE_POOL_MIN]: config.poolMin,
8586
[AttributeNames.ORACLE_POOL_MAX]: config.poolMax,
8687
[AttributeNames.ORACLE_POOL_INCR]: config.poolIncrement,
87-
[SEMATTRS_DB_NAME]: config.serviceName,
88+
[ATTR_DB_NAMESPACE]: config.serviceName,
8889
[SEMATTRS_DB_CONNECTION_STRING]: config.connectString,
89-
[SEMATTRS_NET_PEER_NAME]: config.hostName,
90-
[SEMATTRS_NET_PEER_PORT]: config.port,
90+
[ATTR_SERVER_ADDRESS]: config.hostName,
91+
[ATTR_SERVER_PORT]: config.port,
9192
};
9293
}
9394

@@ -133,7 +134,7 @@ export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
133134

134135
if (callConfig.statement) {
135136
span.setAttribute(
136-
SEMATTRS_DB_OPERATION,
137+
ATTR_DB_OPERATION_NAME,
137138
// retrieve just the first word
138139
callConfig.statement.split(' ')[0].toUpperCase()
139140
);

plugins/node/opentelemetry-instrumentation-oracledb/test/oracle.test.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,27 @@ import {
3535
} from '@opentelemetry/sdk-trace-base';
3636
import * as assert from 'assert';
3737
import { OracleInstrumentation } from '../src';
38-
import { AttributeNames, SpanNames } from '../src/constants';
38+
import {
39+
AttributeNames,
40+
SpanNames,
41+
DB_SYSTEM_VALUE_ORACLE,
42+
} from '../src/constants';
43+
3944
import {
4045
SEMATTRS_DB_STATEMENT,
41-
SEMATTRS_DB_SYSTEM,
42-
SEMATTRS_DB_NAME,
43-
SEMATTRS_DB_OPERATION,
44-
SEMATTRS_NET_PEER_NAME,
46+
ATTR_SERVER_ADDRESS,
4547
SEMATTRS_NET_TRANSPORT,
4648
SEMATTRS_DB_CONNECTION_STRING,
47-
SEMATTRS_NET_PEER_PORT,
49+
ATTR_SERVER_PORT,
4850
SEMATTRS_DB_USER,
49-
DBSYSTEMVALUES_ORACLE,
5051
} from '@opentelemetry/semantic-conventions';
5152

53+
import {
54+
ATTR_DB_NAMESPACE,
55+
ATTR_DB_SYSTEM,
56+
ATTR_DB_OPERATION_NAME,
57+
} from '../src/semconv';
58+
5259
const memoryExporter = new InMemorySpanExporter();
5360
let contextManager: AsyncHooksContextManager;
5461
const provider = new BasicTracerProvider();
@@ -103,26 +110,26 @@ let poolConnAttrList: Record<string, string | number>[]; // attributes per span
103110
let spanNamesList: string[]; // span names for rountrips and public API spans.
104111

105112
const DEFAULT_ATTRIBUTES = {
106-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_ORACLE,
107-
[SEMATTRS_DB_NAME]: serviceName,
113+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_ORACLE,
114+
[ATTR_DB_NAMESPACE]: serviceName,
108115
[SEMATTRS_DB_CONNECTION_STRING]: CONFIG.connectString,
109-
[SEMATTRS_NET_PEER_NAME]: hostname,
110-
[SEMATTRS_NET_PEER_PORT]: pno,
116+
[ATTR_SERVER_ADDRESS]: hostname,
117+
[ATTR_SERVER_PORT]: pno,
111118
[SEMATTRS_DB_USER]: CONFIG.user,
112119
[SEMATTRS_NET_TRANSPORT]: 'TCP',
113120
};
114121

115122
// for thick mode, we dont have support for
116123
// hostname, port and protocol.
117124
const DEFAULT_ATTRIBUTES_THICK = {
118-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_ORACLE,
119-
[SEMATTRS_DB_NAME]: serviceName,
125+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_ORACLE,
126+
[ATTR_DB_NAMESPACE]: serviceName,
120127
[SEMATTRS_DB_CONNECTION_STRING]: CONFIG.connectString,
121128
[SEMATTRS_DB_USER]: CONFIG.user,
122129
};
123130

124131
const POOL_ATTRIBUTES = {
125-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_ORACLE,
132+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_ORACLE,
126133
[SEMATTRS_DB_CONNECTION_STRING]: CONFIG.connectString,
127134
[SEMATTRS_DB_USER]: CONFIG.user,
128135
[AttributeNames.ORACLE_POOL_MIN]: POOL_CONFIG.poolMin,
@@ -131,7 +138,7 @@ const POOL_ATTRIBUTES = {
131138
};
132139

133140
const CONN_FAILED_ATTRIBUTES = {
134-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_ORACLE,
141+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_ORACLE,
135142
[SEMATTRS_DB_CONNECTION_STRING]: CONFIG.connectString,
136143
[SEMATTRS_DB_USER]: CONFIG.user,
137144
};
@@ -170,14 +177,14 @@ function updateAttrSpanList(connection: oracledb.Connection) {
170177
let attributes: Record<string, string | number>;
171178
if (oracledb.thin) {
172179
attributes = { ...DEFAULT_ATTRIBUTES };
173-
attributes[SEMATTRS_NET_PEER_NAME] = connAttributes[SEMATTRS_NET_PEER_NAME];
174-
attributes[SEMATTRS_NET_PEER_PORT] = connAttributes[SEMATTRS_NET_PEER_PORT];
180+
attributes[ATTR_SERVER_ADDRESS] = connAttributes[ATTR_SERVER_ADDRESS];
181+
attributes[ATTR_SERVER_PORT] = connAttributes[ATTR_SERVER_PORT];
175182
attributes[SEMATTRS_NET_TRANSPORT] = connAttributes[SEMATTRS_NET_TRANSPORT];
176183
} else {
177184
attributes = { ...DEFAULT_ATTRIBUTES_THICK };
178185
numExecSpans = 1;
179186
}
180-
attributes[SEMATTRS_DB_NAME] = connAttributes[SEMATTRS_DB_NAME];
187+
attributes[ATTR_DB_NAMESPACE] = connAttributes[ATTR_DB_NAMESPACE];
181188

182189
// initialize the span attributes list.
183190
connAttrList = [];
@@ -386,13 +393,13 @@ describe('oracledb', () => {
386393
connAttributes[AttributeNames.ORACLE_INSTANCE] = connection.instanceName;
387394
}
388395
if (connection.serviceName) {
389-
connAttributes[SEMATTRS_DB_NAME] = connection.serviceName;
396+
connAttributes[ATTR_DB_NAMESPACE] = connection.serviceName;
390397
}
391398
if (oracledb.thin && extendedConn.hostName) {
392-
connAttributes[SEMATTRS_NET_PEER_NAME] = extendedConn.hostName;
399+
connAttributes[ATTR_SERVER_ADDRESS] = extendedConn.hostName;
393400
}
394401
if (oracledb.thin && (extendedConn.port as number)) {
395-
connAttributes[SEMATTRS_NET_PEER_PORT] = extendedConn.port;
402+
connAttributes[ATTR_SERVER_PORT] = extendedConn.port;
396403
}
397404
if (oracledb.thin && extendedConn.protocol) {
398405
connAttributes[SEMATTRS_NET_TRANSPORT] = extendedConn.protocol;
@@ -406,24 +413,24 @@ describe('oracledb', () => {
406413

407414
executeAttributes = {
408415
...connAttributes,
409-
[SEMATTRS_DB_OPERATION]: 'SELECT',
416+
[ATTR_DB_OPERATION_NAME]: 'SELECT',
410417
};
411418
if (oracledb.thin) {
412419
// internal roundtrips don't have bind values.
413420
executeAttributesInternalRoundTripBinds = {
414421
...connAttributes,
415-
[SEMATTRS_DB_OPERATION]: 'SELECT',
422+
[ATTR_DB_OPERATION_NAME]: 'SELECT',
416423
[SEMATTRS_DB_STATEMENT]: sqlWithBinds,
417424
};
418425
}
419426
attributesWithSensitiveDataNoBinds = {
420427
...connAttributes,
421-
[SEMATTRS_DB_OPERATION]: 'SELECT',
428+
[ATTR_DB_OPERATION_NAME]: 'SELECT',
422429
[SEMATTRS_DB_STATEMENT]: sql,
423430
};
424431
attributesWithSensitiveDataBinds = {
425432
...connAttributes,
426-
[SEMATTRS_DB_OPERATION]: 'SELECT',
433+
[ATTR_DB_OPERATION_NAME]: 'SELECT',
427434
[SEMATTRS_DB_STATEMENT]: sqlWithBinds,
428435
[AttributeNames.ORACLE_BIND_VALUES]: binds,
429436
};
@@ -1035,7 +1042,7 @@ describe('oracledb', () => {
10351042

10361043
// update sql stmt, operation.
10371044
const attrs = { ...attributesWithSensitiveDataNoBinds };
1038-
attrs[SEMATTRS_DB_OPERATION] = 'BEGIN';
1045+
attrs[ATTR_DB_OPERATION_NAME] = 'BEGIN';
10391046
attrs[SEMATTRS_DB_STATEMENT] = sqlWithOutBinds;
10401047

10411048
try {
@@ -1117,7 +1124,7 @@ describe('oracledb', () => {
11171124
string | number | any[]
11181125
> = {
11191126
...connAttributes,
1120-
[SEMATTRS_DB_OPERATION]: 'SELECT',
1127+
[ATTR_DB_OPERATION_NAME]: 'SELECT',
11211128
[SEMATTRS_DB_STATEMENT]: sql,
11221129
[AttributeNames.ORACLE_BIND_VALUES]: bindsM,
11231130
};

0 commit comments

Comments
 (0)