Skip to content

Commit fbd592c

Browse files
committed
chore(instrumentation-memcached): update semconv usage to ATTR_ exports
Refs: #2377
1 parent 177691b commit fbd592c

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-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,

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)