Skip to content

Commit b2e599f

Browse files
authored
Merge branch 'main' into trentm-semconv-up-instr-aws-sdk
2 parents 3d36e4f + fe3dc37 commit b2e599f

File tree

12 files changed

+314
-148
lines changed

12 files changed

+314
-148
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
);
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
* The database statement being executed.
36+
*
37+
* @example SELECT * FROM wuser_table
38+
* @example SET mykey "WuValue"
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.query.text`.
43+
*/
44+
export const ATTR_DB_STATEMENT = 'db.statement' as const;
45+
46+
/**
47+
* Deprecated, use `db.system.name` instead.
48+
*
49+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
50+
*
51+
* @deprecated Replaced by `db.system.name`.
52+
*/
53+
export const ATTR_DB_SYSTEM = 'db.system' as const;
54+
55+
/**
56+
* Deprecated, use `server.address` on client spans and `client.address` on server spans.
57+
*
58+
* @example example.com
59+
*
60+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
61+
*
62+
* @deprecated Replaced by `server.address` on client spans and `client.address` on server spans.
63+
*/
64+
export const ATTR_NET_PEER_NAME = 'net.peer.name' as const;
65+
66+
/**
67+
* Deprecated, use `server.port` on client spans and `client.port` on server spans.
68+
*
69+
* @example 8080
70+
*
71+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
72+
*
73+
* @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
74+
*/
75+
export const ATTR_NET_PEER_PORT = 'net.peer.port' as const;
76+
77+
/**
78+
* Enum value "redis" for attribute {@link ATTR_DB_SYSTEM_NAME}.
79+
*
80+
* [Redis](https://redis.io/)
81+
*
82+
* @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
83+
*/
84+
export const DB_SYSTEM_NAME_VALUE_REDIS = 'redis' as const;
85+
86+
/**
87+
* Enum value "redis" for attribute {@link ATTR_DB_SYSTEM}.
88+
*
89+
* Redis
90+
*
91+
* @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
92+
*/
93+
export const DB_SYSTEM_VALUE_REDIS = 'redis' as const;

packages/instrumentation-redis/src/v2-v3/instrumentation.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,21 @@ import { PACKAGE_NAME, PACKAGE_VERSION } from '../version';
3333
import type { RedisCommand, RedisPluginClientTypes } from './internal-types';
3434
import { Attributes, SpanKind, context, trace } from '@opentelemetry/api';
3535
import {
36-
DBSYSTEMVALUES_REDIS,
37-
SEMATTRS_DB_CONNECTION_STRING,
38-
SEMATTRS_DB_STATEMENT,
39-
SEMATTRS_DB_SYSTEM,
40-
SEMATTRS_NET_PEER_NAME,
41-
SEMATTRS_NET_PEER_PORT,
4236
ATTR_DB_SYSTEM_NAME,
4337
ATTR_DB_QUERY_TEXT,
4438
ATTR_DB_OPERATION_NAME,
4539
ATTR_SERVER_ADDRESS,
4640
ATTR_SERVER_PORT,
4741
} from '@opentelemetry/semantic-conventions';
42+
import {
43+
ATTR_DB_CONNECTION_STRING,
44+
ATTR_DB_STATEMENT,
45+
ATTR_DB_SYSTEM,
46+
ATTR_NET_PEER_NAME,
47+
ATTR_NET_PEER_PORT,
48+
DB_SYSTEM_NAME_VALUE_REDIS,
49+
DB_SYSTEM_VALUE_REDIS,
50+
} from '../semconv';
4851
import { defaultDbStatementSerializer } from '@opentelemetry/redis-common';
4952

5053
export class RedisInstrumentationV2_V3 extends InstrumentationBase<RedisInstrumentationConfig> {
@@ -156,17 +159,14 @@ export class RedisInstrumentationV2_V3 extends InstrumentationBase<RedisInstrume
156159

157160
if (instrumentation._semconvStability & SemconvStability.OLD) {
158161
Object.assign(attributes, {
159-
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_REDIS,
160-
[SEMATTRS_DB_STATEMENT]: dbStatementSerializer(
161-
cmd.command,
162-
cmd.args
163-
),
162+
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_REDIS,
163+
[ATTR_DB_STATEMENT]: dbStatementSerializer(cmd.command, cmd.args),
164164
});
165165
}
166166

167167
if (instrumentation._semconvStability & SemconvStability.STABLE) {
168168
Object.assign(attributes, {
169-
[ATTR_DB_SYSTEM_NAME]: 'redis',
169+
[ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
170170
[ATTR_DB_OPERATION_NAME]: cmd.command,
171171
[ATTR_DB_QUERY_TEXT]: dbStatementSerializer(cmd.command, cmd.args),
172172
});
@@ -186,8 +186,8 @@ export class RedisInstrumentationV2_V3 extends InstrumentationBase<RedisInstrume
186186

187187
if (instrumentation._semconvStability & SemconvStability.OLD) {
188188
Object.assign(connectionAttributes, {
189-
[SEMATTRS_NET_PEER_NAME]: this.connection_options.host,
190-
[SEMATTRS_NET_PEER_PORT]: this.connection_options.port,
189+
[ATTR_NET_PEER_NAME]: this.connection_options.host,
190+
[ATTR_NET_PEER_PORT]: this.connection_options.port,
191191
});
192192
}
193193

@@ -206,7 +206,7 @@ export class RedisInstrumentationV2_V3 extends InstrumentationBase<RedisInstrume
206206
instrumentation._semconvStability & SemconvStability.OLD
207207
) {
208208
span.setAttribute(
209-
SEMATTRS_DB_CONNECTION_STRING,
209+
ATTR_DB_CONNECTION_STRING,
210210
`redis://${this.address}`
211211
);
212212
}

0 commit comments

Comments
 (0)