Skip to content

Commit ff6f928

Browse files
authored
chore(instrumentation-mysql): update semconv usage to ATTR_ exports (#3052)
Refs: #2377
1 parent 8af41a9 commit ff6f928

File tree

6 files changed

+143
-38
lines changed

6 files changed

+143
-38
lines changed

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/instrumentation-mysql/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
},
6767
"dependencies": {
6868
"@opentelemetry/instrumentation": "^0.205.0",
69-
"@opentelemetry/semantic-conventions": "^1.27.0",
7069
"@types/mysql": "2.15.27"
7170
},
7271
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-mysql#readme"

packages/instrumentation-mysql/src/instrumentation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import {
2828
isWrapped,
2929
} from '@opentelemetry/instrumentation';
3030
import {
31-
DBSYSTEMVALUES_MYSQL,
32-
SEMATTRS_DB_STATEMENT,
33-
SEMATTRS_DB_SYSTEM,
34-
} from '@opentelemetry/semantic-conventions';
31+
DB_SYSTEM_VALUE_MYSQL,
32+
ATTR_DB_STATEMENT,
33+
ATTR_DB_SYSTEM,
34+
} from './semconv';
3535
import type * as mysqlTypes from 'mysql';
3636
import { AttributeNames } from './AttributeNames';
3737
import { MySQLInstrumentationConfig } from './types';
@@ -53,7 +53,7 @@ type getConnectionCallbackType = (
5353

5454
export class MySQLInstrumentation extends InstrumentationBase<MySQLInstrumentationConfig> {
5555
static readonly COMMON_ATTRIBUTES = {
56-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MYSQL,
56+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_MYSQL,
5757
};
5858
private declare _connectionsUsage: UpDownCounter;
5959

@@ -310,7 +310,7 @@ export class MySQLInstrumentation extends InstrumentationBase<MySQLInstrumentati
310310
},
311311
});
312312

313-
span.setAttribute(SEMATTRS_DB_STATEMENT, getDbStatement(query));
313+
span.setAttribute(ATTR_DB_STATEMENT, getDbStatement(query));
314314

315315
if (thisPlugin.getConfig().enhancedDatabaseReporting) {
316316
let values;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
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+
23+
/**
24+
* Deprecated, use `server.address`, `server.port` attributes instead.
25+
*
26+
* @example "Server=(localdb)\\v11.0;Integrated Security=true;"
27+
*
28+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
29+
*
30+
* @deprecated Replaced by `server.address` and `server.port`.
31+
*/
32+
export const ATTR_DB_CONNECTION_STRING = 'db.connection_string' as const;
33+
34+
/**
35+
* Deprecated, use `db.namespace` instead.
36+
*
37+
* @example customers
38+
* @example main
39+
*
40+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
41+
*
42+
* @deprecated Replaced by `db.namespace`.
43+
*/
44+
export const ATTR_DB_NAME = 'db.name' as const;
45+
46+
/**
47+
* The database statement being executed.
48+
*
49+
* @example SELECT * FROM wuser_table
50+
* @example SET mykey "WuValue"
51+
*
52+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
53+
*
54+
* @deprecated Replaced by `db.query.text`.
55+
*/
56+
export const ATTR_DB_STATEMENT = 'db.statement' as const;
57+
58+
/**
59+
* Deprecated, use `db.system.name` instead.
60+
*
61+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
62+
*
63+
* @deprecated Replaced by `db.system.name`.
64+
*/
65+
export const ATTR_DB_SYSTEM = 'db.system' as const;
66+
67+
/**
68+
* Deprecated, no replacement at this time.
69+
*
70+
* @example readonly_user
71+
* @example reporting_user
72+
*
73+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
74+
*
75+
* @deprecated Removed, no replacement at this time.
76+
*/
77+
export const ATTR_DB_USER = 'db.user' as const;
78+
79+
/**
80+
* Deprecated, use `server.address` on client spans and `client.address` on server spans.
81+
*
82+
* @example example.com
83+
*
84+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
85+
*
86+
* @deprecated Replaced by `server.address` on client spans and `client.address` on server spans.
87+
*/
88+
export const ATTR_NET_PEER_NAME = 'net.peer.name' as const;
89+
90+
/**
91+
* Deprecated, use `server.port` on client spans and `client.port` on server spans.
92+
*
93+
* @example 8080
94+
*
95+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
96+
*
97+
* @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
98+
*/
99+
export const ATTR_NET_PEER_PORT = 'net.peer.port' as const;
100+
101+
/**
102+
* Enum value "mysql" for attribute {@link ATTR_DB_SYSTEM}.
103+
*
104+
* MySQL
105+
*
106+
* @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
107+
*/
108+
export const DB_SYSTEM_VALUE_MYSQL = 'mysql' as const;

packages/instrumentation-mysql/src/utils.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
import { Attributes } from '@opentelemetry/api';
1818
import {
19-
SEMATTRS_DB_CONNECTION_STRING,
20-
SEMATTRS_DB_NAME,
21-
SEMATTRS_DB_USER,
22-
SEMATTRS_NET_PEER_NAME,
23-
SEMATTRS_NET_PEER_PORT,
24-
} from '@opentelemetry/semantic-conventions';
19+
ATTR_DB_CONNECTION_STRING,
20+
ATTR_DB_NAME,
21+
ATTR_DB_USER,
22+
ATTR_NET_PEER_NAME,
23+
ATTR_NET_PEER_PORT,
24+
} from './semconv';
2525
import type {
2626
ConnectionConfig,
2727
PoolActualConfig,
@@ -42,18 +42,18 @@ export function getConnectionAttributes(
4242
const portNumber = parseInt(port, 10);
4343
if (!isNaN(portNumber)) {
4444
return {
45-
[SEMATTRS_NET_PEER_NAME]: host,
46-
[SEMATTRS_NET_PEER_PORT]: portNumber,
47-
[SEMATTRS_DB_CONNECTION_STRING]: getJDBCString(host, port, database),
48-
[SEMATTRS_DB_NAME]: database,
49-
[SEMATTRS_DB_USER]: user,
45+
[ATTR_NET_PEER_NAME]: host,
46+
[ATTR_NET_PEER_PORT]: portNumber,
47+
[ATTR_DB_CONNECTION_STRING]: getJDBCString(host, port, database),
48+
[ATTR_DB_NAME]: database,
49+
[ATTR_DB_USER]: user,
5050
};
5151
}
5252
return {
53-
[SEMATTRS_NET_PEER_NAME]: host,
54-
[SEMATTRS_DB_CONNECTION_STRING]: getJDBCString(host, port, database),
55-
[SEMATTRS_DB_NAME]: database,
56-
[SEMATTRS_DB_USER]: user,
53+
[ATTR_NET_PEER_NAME]: host,
54+
[ATTR_DB_CONNECTION_STRING]: getJDBCString(host, port, database),
55+
[ATTR_DB_NAME]: database,
56+
[ATTR_DB_USER]: user,
5757
};
5858
}
5959

packages/instrumentation-mysql/test/index.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
import { context, Context, trace, SpanStatusCode } from '@opentelemetry/api';
1818
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
1919
import {
20-
DBSYSTEMVALUES_MYSQL,
21-
SEMATTRS_DB_NAME,
22-
SEMATTRS_DB_STATEMENT,
23-
SEMATTRS_DB_SYSTEM,
24-
SEMATTRS_DB_USER,
25-
SEMATTRS_NET_PEER_NAME,
26-
SEMATTRS_NET_PEER_PORT,
27-
} from '@opentelemetry/semantic-conventions';
20+
DB_SYSTEM_VALUE_MYSQL,
21+
ATTR_DB_NAME,
22+
ATTR_DB_STATEMENT,
23+
ATTR_DB_SYSTEM,
24+
ATTR_DB_USER,
25+
ATTR_NET_PEER_NAME,
26+
ATTR_NET_PEER_PORT,
27+
} from '../src/semconv';
2828
import {
2929
BasicTracerProvider,
3030
InMemorySpanExporter,
@@ -860,12 +860,12 @@ function assertSpan(
860860
values?: any,
861861
errorMessage?: string
862862
) {
863-
assert.strictEqual(span.attributes[SEMATTRS_DB_SYSTEM], DBSYSTEMVALUES_MYSQL);
864-
assert.strictEqual(span.attributes[SEMATTRS_DB_NAME], database);
865-
assert.strictEqual(span.attributes[SEMATTRS_NET_PEER_PORT], port);
866-
assert.strictEqual(span.attributes[SEMATTRS_NET_PEER_NAME], host);
867-
assert.strictEqual(span.attributes[SEMATTRS_DB_USER], user);
868-
assert.strictEqual(span.attributes[SEMATTRS_DB_STATEMENT], sql);
863+
assert.strictEqual(span.attributes[ATTR_DB_SYSTEM], DB_SYSTEM_VALUE_MYSQL);
864+
assert.strictEqual(span.attributes[ATTR_DB_NAME], database);
865+
assert.strictEqual(span.attributes[ATTR_NET_PEER_PORT], port);
866+
assert.strictEqual(span.attributes[ATTR_NET_PEER_NAME], host);
867+
assert.strictEqual(span.attributes[ATTR_DB_USER], user);
868+
assert.strictEqual(span.attributes[ATTR_DB_STATEMENT], sql);
869869
if (errorMessage) {
870870
assert.strictEqual(span.status.message, errorMessage);
871871
assert.strictEqual(span.status.code, SpanStatusCode.ERROR);

0 commit comments

Comments
 (0)