Skip to content

Commit 0a0b4dc

Browse files
ZirakJamieDanielsonblumamirpichlermarc
authored
refactor(instrumentation-redis): Use exported semconv strings (#2075)
* refactor(instrumentation-redis): Use exported semconv strings Part of #2025. * chore(instrumentation-redis): Update package-lock --------- Co-authored-by: Jamie Danielson <[email protected]> Co-authored-by: Amir Blum <[email protected]> Co-authored-by: Marc Pichler <[email protected]>
1 parent 4590c8d commit 0a0b4dc

File tree

5 files changed

+40
-21
lines changed

5 files changed

+40
-21
lines changed

package-lock.json

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

plugins/node/opentelemetry-instrumentation-redis/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ const redisInstrumentation = new RedisInstrumentation({
7474
});
7575
```
7676

77+
## Semantic Conventions
78+
79+
This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
80+
81+
Attributes collected:
82+
83+
| Attribute | Short Description | Notes |
84+
|------------------------|--------------------------------------------------------------|--------------------------------------|
85+
| `db.connection_string` | URL to Redis server address, of the form `redis://host:port` | Key: `SEMATTRS_DB_CONNECTION_STRING` |
86+
| `db.statement` | Executed Redis statement | Key: `SEMATTRS_DB_STATEMENT` |
87+
| `db.system` | Database identifier; always `redis` | Key: `SEMATTRS_DB_SYSTEM` |
88+
| `net.peer.name` | Hostname or IP of the connected Redis server | Key: `SEMATTRS_NET_PEER_NAME` |
89+
| `net.peer.port` | Port of the connected Redis server | Key: `SEMATTRS_NET_PORT_NAME` |
90+
7791
## Useful links
7892

7993
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>

plugins/node/opentelemetry-instrumentation-redis/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"dependencies": {
6969
"@opentelemetry/instrumentation": "^0.50.0",
7070
"@opentelemetry/redis-common": "^0.36.1",
71-
"@opentelemetry/semantic-conventions": "^1.0.0"
71+
"@opentelemetry/semantic-conventions": "^1.22.0"
7272
},
7373
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-redis#readme"
7474
}

plugins/node/opentelemetry-instrumentation-redis/src/utils.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ import { RedisCommand, RedisInstrumentationConfig } from './types';
2828
import { EventEmitter } from 'events';
2929
import { RedisInstrumentation } from './';
3030
import {
31-
DbSystemValues,
32-
SemanticAttributes,
31+
DBSYSTEMVALUES_REDIS,
32+
SEMATTRS_DB_CONNECTION_STRING,
33+
SEMATTRS_DB_STATEMENT,
34+
SEMATTRS_DB_SYSTEM,
35+
SEMATTRS_NET_PEER_NAME,
36+
SEMATTRS_NET_PEER_PORT,
3337
} from '@opentelemetry/semantic-conventions';
3438
import { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';
3539
import { RedisPluginClientTypes } from './internal-types';
@@ -100,25 +104,22 @@ export const getTracedInternalSendCommand = (
100104
{
101105
kind: SpanKind.CLIENT,
102106
attributes: {
103-
[SemanticAttributes.DB_SYSTEM]: DbSystemValues.REDIS,
104-
[SemanticAttributes.DB_STATEMENT]: dbStatementSerializer(
105-
cmd.command,
106-
cmd.args
107-
),
107+
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_REDIS,
108+
[SEMATTRS_DB_STATEMENT]: dbStatementSerializer(cmd.command, cmd.args),
108109
},
109110
}
110111
);
111112

112113
// Set attributes for not explicitly typed RedisPluginClientTypes
113114
if (this.options) {
114115
span.setAttributes({
115-
[SemanticAttributes.NET_PEER_NAME]: this.options.host,
116-
[SemanticAttributes.NET_PEER_PORT]: this.options.port,
116+
[SEMATTRS_NET_PEER_NAME]: this.options.host,
117+
[SEMATTRS_NET_PEER_PORT]: this.options.port,
117118
});
118119
}
119120
if (this.address) {
120121
span.setAttribute(
121-
SemanticAttributes.DB_CONNECTION_STRING,
122+
SEMATTRS_DB_CONNECTION_STRING,
122123
`redis://${this.address}`
123124
);
124125
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ import {
3232
import * as assert from 'assert';
3333
import { RedisInstrumentation } from '../src';
3434
import {
35-
DbSystemValues,
36-
SemanticAttributes,
35+
DBSYSTEMVALUES_REDIS,
36+
SEMATTRS_DB_CONNECTION_STRING,
37+
SEMATTRS_DB_STATEMENT,
38+
SEMATTRS_DB_SYSTEM,
39+
SEMATTRS_NET_PEER_NAME,
40+
SEMATTRS_NET_PEER_PORT,
3741
} from '@opentelemetry/semantic-conventions';
3842

3943
const instrumentation = new RedisInstrumentation();
@@ -53,10 +57,10 @@ const CONFIG = {
5357
const URL = `redis://${CONFIG.host}:${CONFIG.port}`;
5458

5559
const DEFAULT_ATTRIBUTES = {
56-
[SemanticAttributes.DB_SYSTEM]: DbSystemValues.REDIS,
57-
[SemanticAttributes.NET_PEER_NAME]: CONFIG.host,
58-
[SemanticAttributes.NET_PEER_PORT]: CONFIG.port,
59-
[SemanticAttributes.DB_CONNECTION_STRING]: URL,
60+
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_REDIS,
61+
[SEMATTRS_NET_PEER_NAME]: CONFIG.host,
62+
[SEMATTRS_NET_PEER_PORT]: CONFIG.port,
63+
[SEMATTRS_DB_CONNECTION_STRING]: URL,
6064
};
6165

6266
const unsetStatus: SpanStatus = {
@@ -192,7 +196,7 @@ describe('[email protected]', () => {
192196
it(`should create a child span for ${operation.description}`, done => {
193197
const attributes = {
194198
...DEFAULT_ATTRIBUTES,
195-
[SemanticAttributes.DB_STATEMENT]: `${operation.command} ${operation.expectedDbStatement}`,
199+
[SEMATTRS_DB_STATEMENT]: `${operation.command} ${operation.expectedDbStatement}`,
196200
};
197201
const span = tracer.startSpan('test span');
198202
context.with(trace.setSpan(context.active(), span), () => {
@@ -281,7 +285,7 @@ describe('[email protected]', () => {
281285
operation.args
282286
);
283287
assert.strictEqual(
284-
endedSpans[0].attributes[SemanticAttributes.DB_STATEMENT],
288+
endedSpans[0].attributes[SEMATTRS_DB_STATEMENT],
285289
expectedStatement
286290
);
287291
done();

0 commit comments

Comments
 (0)