Skip to content

Commit 293b3dd

Browse files
committed
move imports of stable semconv vars to be from the semantic-conventions package
1 parent 9cf4d66 commit 293b3dd

File tree

4 files changed

+76
-75
lines changed

4 files changed

+76
-75
lines changed

plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ import {
5959
ATTR_ERROR_TYPE,
6060
ATTR_SERVER_PORT,
6161
ATTR_SERVER_ADDRESS,
62+
ATTR_DB_NAMESPACE,
63+
ATTR_DB_OPERATION_NAME,
6264
ATTR_DB_SYSTEM_NAME,
65+
METRIC_DB_CLIENT_OPERATION_DURATION,
6366
} from '@opentelemetry/semantic-conventions';
6467
import {
6568
METRIC_DB_CLIENT_CONNECTION_COUNT,
6669
METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS,
67-
METRIC_DB_CLIENT_OPERATION_DURATION,
68-
ATTR_DB_NAMESPACE,
69-
ATTR_DB_OPERATION_NAME,
7070
ATTR_DB_SYSTEM,
7171
DB_SYSTEM_VALUE_POSTGRESQL,
7272
} from './semconv';
@@ -283,7 +283,7 @@ export class PgInstrumentation extends InstrumentationBase<PgInstrumentationConf
283283

284284
private recordOperationDuration(attributes: Attributes, startTime: HrTime) {
285285
const metricsAttributes: Attributes = {};
286-
const keysToCopy = [
286+
const keysToCopy: string[] = [
287287
ATTR_DB_NAMESPACE,
288288
ATTR_ERROR_TYPE,
289289
ATTR_SERVER_PORT,

plugins/node/opentelemetry-instrumentation-pg/src/semconv.ts

Lines changed: 67 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17+
/*
18+
* This file contains a copy of unstable semantic convention definitions
19+
* used by this package.
20+
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
21+
*/
22+
1723
/**
1824
* The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation **SHOULD** use a combination of parameters that would make the name unique, for example, combining attributes `server.address`, `server.port`, and `db.namespace`, formatted as `server.address:server.port/db.namespace`. Instrumentations that generate connection pool name following different patterns **SHOULD** document it.
1925
*
@@ -22,7 +28,7 @@
2228
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
2329
*/
2430
export const ATTR_DB_CLIENT_CONNECTION_POOL_NAME =
25-
'db.client.connection.pool.name';
31+
'db.client.connection.pool.name' as const;
2632

2733
/**
2834
* The state of a connection in the pool
@@ -31,121 +37,114 @@ export const ATTR_DB_CLIENT_CONNECTION_POOL_NAME =
3137
*
3238
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
3339
*/
34-
export const ATTR_DB_CLIENT_CONNECTION_STATE = 'db.client.connection.state';
40+
export const ATTR_DB_CLIENT_CONNECTION_STATE =
41+
'db.client.connection.state' as const;
3542

3643
/**
37-
* The name of the database, fully qualified within the server address and port.
44+
* Deprecated, use `server.address`, `server.port` attributes instead.
3845
*
39-
* @example customers
40-
* @example test.users
41-
*
42-
* @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.
43-
* Semantic conventions for individual database systems **SHOULD** document what `db.namespace` means in the context of that system.
44-
* It is **RECOMMENDED** to capture the value as provided by the application without attempting to do any case normalization.
45-
* This attribute has stability level RELEASE CANDIDATE.
46+
* @example "Server=(localdb)\\v11.0;Integrated Security=true;"
4647
*
4748
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
49+
*
50+
* @deprecated Replaced by `server.address` and `server.port`.
4851
*/
49-
export const ATTR_DB_NAMESPACE = 'db.namespace';
52+
export const ATTR_DB_CONNECTION_STRING = 'db.connection_string' as const;
5053

5154
/**
52-
* The name of the operation or command being executed.
53-
*
54-
* @example findAndModify
55-
* @example HMSET
56-
* @example SELECT
55+
* Deprecated, use `db.namespace` instead.
5756
*
58-
* @note It is **RECOMMENDED** to capture the value as provided by the application without attempting to do any case normalization.
59-
* If the operation name is parsed from the query text, it **SHOULD** be the first operation name found in the query.
60-
* 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.
61-
* This attribute has stability level RELEASE CANDIDATE.
57+
* @example customers
58+
* @example main
6259
*
6360
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
64-
*/
65-
export const ATTR_DB_OPERATION_NAME = 'db.operation.name';
66-
67-
/**
68-
* Enum value "used" for attribute {@link ATTR_DB_CLIENT_CONNECTION_STATE}.
69-
*/
70-
export const DB_CLIENT_CONNECTION_STATE_VALUE_USED = 'used';
71-
72-
/**
73-
* Enum value "idle" for attribute {@link ATTR_DB_CLIENT_CONNECTION_STATE}.
74-
*/
75-
export const DB_CLIENT_CONNECTION_STATE_VALUE_IDLE = 'idle';
76-
77-
/**
78-
* The number of connections that are currently in state described by the `state` attribute
7961
*
80-
* @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
62+
* @deprecated Replaced by `db.namespace`.
8163
*/
82-
export const METRIC_DB_CLIENT_CONNECTION_COUNT = 'db.client.connection.count';
64+
export const ATTR_DB_NAME = 'db.name' as const;
8365

8466
/**
85-
* The number of current pending requests for an open connection
67+
* The database statement being executed.
8668
*
87-
* @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
69+
* @example SELECT * FROM wuser_table
70+
* @example SET mykey "WuValue"
71+
*
72+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
73+
*
74+
* @deprecated Replaced by `db.query.text`.
8875
*/
89-
export const METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS =
90-
'db.client.connection.pending_requests';
76+
export const ATTR_DB_STATEMENT = 'db.statement' as const;
9177

9278
/**
93-
* Duration of database client operations.
79+
* Deprecated, use `db.system.name` instead.
9480
*
95-
* @note Batch operations **SHOULD** be recorded as a single operation.
81+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
9682
*
97-
* @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
83+
* @deprecated Replaced by `db.system.name`.
9884
*/
99-
export const METRIC_DB_CLIENT_OPERATION_DURATION =
100-
'db.client.operation.duration';
85+
export const ATTR_DB_SYSTEM = 'db.system' as const;
10186

10287
/**
103-
* An identifier for the database management system (DBMS) product being used.
88+
* Deprecated, no replacement at this time.
89+
*
90+
* @example readonly_user
91+
* @example reporting_user
92+
*
93+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
10494
*
95+
* @deprecated Removed, no replacement at this time.
10596
*/
106-
export const ATTR_DB_SYSTEM = 'db.system';
97+
export const ATTR_DB_USER = 'db.user' as const;
10798

10899
/**
109-
* An identifier for the database management system (DBMS) product being used. See below for a list of well-known identifiers.
100+
* Deprecated, use `server.address` on client spans and `client.address` on server spans.
110101
*
102+
* @example example.com
103+
*
104+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
105+
*
106+
* @deprecated Replaced by `server.address` on client spans and `client.address` on server spans.
111107
*/
112-
export const DB_SYSTEM_VALUE_POSTGRESQL = 'postgresql';
108+
export const ATTR_NET_PEER_NAME = 'net.peer.name' as const;
113109

114110
/**
115-
* If no [tech-specific attribute](#call-level-attributes-for-specific-technologies) is defined, this attribute is used to report the name of the database being accessed. For commands that switch the database, this should be set to the target database (even if the command fails).
111+
* Deprecated, use `server.port` on client spans and `client.port` on server spans.
116112
*
117-
* Note: In some SQL databases, the database name to be used is called &#34;schema name&#34;.
113+
* @example 8080
118114
*
115+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
116+
*
117+
* @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
119118
*/
120-
export const ATTR_DB_NAME = 'db.name';
119+
export const ATTR_NET_PEER_PORT = 'net.peer.port' as const;
121120

122121
/**
123-
* The connection string used to connect to the database. It is recommended to remove embedded credentials.
124-
*
122+
* Enum value "idle" for attribute {@link ATTR_DB_CLIENT_CONNECTION_STATE}.
125123
*/
126-
export const ATTR_DB_CONNECTION_STRING = 'db.connection_string';
124+
export const DB_CLIENT_CONNECTION_STATE_VALUE_IDLE = 'idle' as const;
127125

128126
/**
129-
* Username for accessing the database.
130-
*
127+
* Enum value "used" for attribute {@link ATTR_DB_CLIENT_CONNECTION_STATE}.
131128
*/
132-
export const ATTR_DB_USER = 'db.user';
129+
export const DB_CLIENT_CONNECTION_STATE_VALUE_USED = 'used' as const;
133130

134131
/**
135-
* Remote port number.
136-
*
132+
* Enum value "postgresql" for attribute {@link ATTR_DB_SYSTEM}.
137133
*/
138-
export const ATTR_NET_PEER_PORT = 'net.peer.port';
134+
export const DB_SYSTEM_VALUE_POSTGRESQL = 'postgresql' as const;
135+
139136
/**
140-
* Remote hostname or similar.
137+
* The number of connections that are currently in state described by the `state` attribute
141138
*
139+
* @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
142140
*/
143-
export const ATTR_NET_PEER_NAME = 'net.peer.name';
141+
export const METRIC_DB_CLIENT_CONNECTION_COUNT =
142+
'db.client.connection.count' as const;
144143

145144
/**
146-
* The database statement being executed.
147-
*
148-
* Note: The value may be sanitized to exclude sensitive information.
145+
* The number of current pending requests for an open connection
149146
*
147+
* @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
150148
*/
151-
export const ATTR_DB_STATEMENT = 'db.statement';
149+
export const METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS =
150+
'db.client.connection.pending_requests' as const;

plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ import * as pg from 'pg';
4040
import * as pgPool from 'pg-pool';
4141
import { AttributeNames } from '../src/enums/AttributeNames';
4242
import { TimedEvent } from './types';
43+
import { METRIC_DB_CLIENT_OPERATION_DURATION } from '@opentelemetry/semantic-conventions';
4344
import {
4445
ATTR_DB_CLIENT_CONNECTION_STATE,
4546
METRIC_DB_CLIENT_CONNECTION_COUNT,
4647
METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS,
47-
METRIC_DB_CLIENT_OPERATION_DURATION,
4848
ATTR_DB_SYSTEM,
4949
ATTR_DB_NAME,
5050
ATTR_DB_USER,

plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ import {
4242
} from '../src';
4343
import { AttributeNames } from '../src/enums/AttributeNames';
4444
import { TimedEvent } from './types';
45-
import { ATTR_ERROR_TYPE } from '@opentelemetry/semantic-conventions';
4645
import {
47-
METRIC_DB_CLIENT_OPERATION_DURATION,
4846
ATTR_DB_OPERATION_NAME,
47+
ATTR_ERROR_TYPE,
48+
METRIC_DB_CLIENT_OPERATION_DURATION,
49+
} from '@opentelemetry/semantic-conventions';
50+
import {
4951
ATTR_DB_SYSTEM,
5052
ATTR_DB_NAME,
5153
ATTR_DB_USER,

0 commit comments

Comments
 (0)