Skip to content

Commit f69757f

Browse files
authored
chore(instrumentation-memcached): update semconv usage to ATTR_ exports (#3050)
Refs: #2377
1 parent 2fd905e commit f69757f

File tree

6 files changed

+110
-27
lines changed

6 files changed

+110
-27
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/instrumentation-memcached/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@opentelemetry/contrib-test-utils": "^0.51.0",
5656
"@opentelemetry/sdk-trace-base": "^2.0.0",
5757
"@opentelemetry/sdk-trace-node": "^2.0.0",
58+
"@opentelemetry/semantic-conventions": "^1.27.0",
5859
"@types/mocha": "10.0.10",
5960
"@types/node": "18.18.14",
6061
"cross-env": "7.0.3",
@@ -65,7 +66,6 @@
6566
},
6667
"dependencies": {
6768
"@opentelemetry/instrumentation": "^0.205.0",
68-
"@opentelemetry/semantic-conventions": "^1.27.0",
6969
"@types/memcached": "^2.2.6"
7070
},
7171
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-memcached#readme"

packages/instrumentation-memcached/src/instrumentation.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import {
2222
} from '@opentelemetry/instrumentation';
2323
import type * as Memcached from 'memcached';
2424
import {
25-
DBSYSTEMVALUES_MEMCACHED,
26-
SEMATTRS_DB_OPERATION,
27-
SEMATTRS_DB_STATEMENT,
28-
SEMATTRS_DB_SYSTEM,
29-
} from '@opentelemetry/semantic-conventions';
25+
DB_SYSTEM_VALUE_MEMCACHED,
26+
ATTR_DB_OPERATION,
27+
ATTR_DB_STATEMENT,
28+
ATTR_DB_SYSTEM,
29+
} from './semconv';
3030
import * as utils from './utils';
3131
import { InstrumentationConfig } from './types';
3232
/** @knipignore */
@@ -35,7 +35,7 @@ import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
3535
export class MemcachedInstrumentation extends InstrumentationBase<InstrumentationConfig> {
3636
static readonly COMPONENT = 'memcached';
3737
static readonly COMMON_ATTRIBUTES = {
38-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MEMCACHED,
38+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_MEMCACHED,
3939
};
4040
static readonly DEFAULT_CONFIG: InstrumentationConfig = {
4141
enhancedDatabaseReporting: false,
@@ -137,8 +137,8 @@ export class MemcachedInstrumentation extends InstrumentationBase<Instrumentatio
137137
span.setAttributes({
138138
'db.memcached.key': query.key,
139139
'db.memcached.lifetime': query.lifetime,
140-
[SEMATTRS_DB_OPERATION]: query.type,
141-
[SEMATTRS_DB_STATEMENT]: instrumentation.getConfig()
140+
[ATTR_DB_OPERATION]: query.type,
141+
[ATTR_DB_STATEMENT]: instrumentation.getConfig()
142142
.enhancedDatabaseReporting
143143
? query.command
144144
: undefined,
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 `db.operation.name` instead.
25+
*
26+
* @example findAndModify
27+
* @example HMSET
28+
* @example SELECT
29+
*
30+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
31+
*
32+
* @deprecated Replaced by `db.operation.name`.
33+
*/
34+
export const ATTR_DB_OPERATION = 'db.operation' as const;
35+
36+
/**
37+
* The database statement being executed.
38+
*
39+
* @example SELECT * FROM wuser_table
40+
* @example SET mykey "WuValue"
41+
*
42+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
43+
*
44+
* @deprecated Replaced by `db.query.text`.
45+
*/
46+
export const ATTR_DB_STATEMENT = 'db.statement' as const;
47+
48+
/**
49+
* Deprecated, use `db.system.name` instead.
50+
*
51+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
52+
*
53+
* @deprecated Replaced by `db.system.name`.
54+
*/
55+
export const ATTR_DB_SYSTEM = 'db.system' as const;
56+
57+
/**
58+
* Deprecated, use `server.address` on client spans and `client.address` on server spans.
59+
*
60+
* @example example.com
61+
*
62+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
63+
*
64+
* @deprecated Replaced by `server.address` on client spans and `client.address` on server spans.
65+
*/
66+
export const ATTR_NET_PEER_NAME = 'net.peer.name' as const;
67+
68+
/**
69+
* Deprecated, use `server.port` on client spans and `client.port` on server spans.
70+
*
71+
* @example 8080
72+
*
73+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
74+
*
75+
* @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
76+
*/
77+
export const ATTR_NET_PEER_PORT = 'net.peer.port' as const;
78+
79+
/**
80+
* Enum value "memcached" for attribute {@link ATTR_DB_SYSTEM}.
81+
*
82+
* Memcached
83+
*
84+
* @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
85+
*/
86+
export const DB_SYSTEM_VALUE_MEMCACHED = 'memcached' as const;

packages/instrumentation-memcached/src/utils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616

1717
import type * as Memcached from 'memcached';
18-
import {
19-
SEMATTRS_NET_PEER_NAME,
20-
SEMATTRS_NET_PEER_PORT,
21-
} from '@opentelemetry/semantic-conventions';
18+
import { ATTR_NET_PEER_NAME, ATTR_NET_PEER_PORT } from './semconv';
2219

2320
export const getPeerAttributes = (
2421
client: any /* Memcached, but the type definitions are lacking */,
@@ -52,12 +49,12 @@ export const getPeerAttributes = (
5249
const portNumber = parseInt(port, 10);
5350
if (!isNaN(portNumber)) {
5451
return {
55-
[SEMATTRS_NET_PEER_NAME]: host,
56-
[SEMATTRS_NET_PEER_PORT]: portNumber,
52+
[ATTR_NET_PEER_NAME]: host,
53+
[ATTR_NET_PEER_PORT]: portNumber,
5754
};
5855
}
5956
return {
60-
[SEMATTRS_NET_PEER_NAME]: host,
57+
[ATTR_NET_PEER_NAME]: host,
6158
};
6259
}
6360
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ import {
3030
import type * as Memcached from 'memcached';
3131
import * as assert from 'assert';
3232
import { MemcachedInstrumentation } from '../src';
33+
import { ATTR_EXCEPTION_MESSAGE } from '@opentelemetry/semantic-conventions';
3334
import {
34-
DBSYSTEMVALUES_MEMCACHED,
35-
SEMATTRS_DB_SYSTEM,
36-
SEMATTRS_EXCEPTION_MESSAGE,
37-
SEMATTRS_NET_PEER_NAME,
38-
SEMATTRS_NET_PEER_PORT,
39-
} from '@opentelemetry/semantic-conventions';
35+
DB_SYSTEM_VALUE_MEMCACHED,
36+
ATTR_DB_SYSTEM,
37+
ATTR_NET_PEER_NAME,
38+
ATTR_NET_PEER_PORT,
39+
} from '../src/semconv';
4040
import * as util from 'util';
4141

4242
const instrumentation = new MemcachedInstrumentation();
@@ -50,9 +50,9 @@ const CONFIG = {
5050
};
5151

5252
const DEFAULT_ATTRIBUTES: Attributes = {
53-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MEMCACHED,
54-
[SEMATTRS_NET_PEER_NAME]: CONFIG.host,
55-
[SEMATTRS_NET_PEER_PORT]: CONFIG.port,
53+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_MEMCACHED,
54+
[ATTR_NET_PEER_NAME]: CONFIG.host,
55+
[ATTR_NET_PEER_PORT]: CONFIG.port,
5656
};
5757

5858
interface ExtendedMemcached extends Memcached {
@@ -170,7 +170,7 @@ describe('[email protected]', () => {
170170

171171
assertMatch(
172172
instrumentationSpans?.[0]?.events[0]?.attributes?.[
173-
SEMATTRS_EXCEPTION_MESSAGE
173+
ATTR_EXCEPTION_MESSAGE
174174
] as 'string',
175175
/not stored/
176176
);

0 commit comments

Comments
 (0)