Skip to content

Commit 6cd67c0

Browse files
chore(instr-express): use exported strings for attributes (#2031)
* chore(instr-express): use exported strings for attributes * use exported strings in tests
1 parent 9df30ea commit 6cd67c0

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
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-express/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ const expressInstrumentation = new ExpressInstrumentation({
144144

145145
## Semantic Conventions
146146

147-
This package uses `@opentelemetry/semantic-conventions` version `1.0+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
147+
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)
148148

149149
Attributes collected:
150150

151-
| Attribute | Short Description | Notes |
152-
| ------------ | ---------------------------------- | ----------------- |
153-
| `http.route` | The matched route (path template). | Key: `HTTP_ROUTE` |
151+
| Attribute | Short Description | Notes |
152+
| ------------ | ---------------------------------- | -------------------------- |
153+
| `http.route` | The matched route (path template). | Key: `SEMATTRS_HTTP_ROUTE` |
154154

155155
## Useful links
156156

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"dependencies": {
6666
"@opentelemetry/core": "^1.8.0",
6767
"@opentelemetry/instrumentation": "^0.49.1",
68-
"@opentelemetry/semantic-conventions": "^1.0.0"
68+
"@opentelemetry/semantic-conventions": "^1.22.0"
6969
},
7070
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express#readme"
7171
}

plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
isWrapped,
4040
safeExecuteInTheMiddle,
4141
} from '@opentelemetry/instrumentation';
42-
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
42+
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
4343
import {
4444
ExpressLayer,
4545
ExpressRouter,
@@ -202,7 +202,7 @@ export class ExpressInstrumentation extends InstrumentationBase<
202202
.replace(/\/{2,}/g, '/');
203203

204204
const attributes: Attributes = {
205-
[SemanticAttributes.HTTP_ROUTE]: route.length > 0 ? route : '/',
205+
[SEMATTRS_HTTP_ROUTE]: route.length > 0 ? route : '/',
206206
};
207207
const metadata = getLayerMetadata(layer, layerPath);
208208
const type = metadata.attributes[

plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
InMemorySpanExporter,
2222
SimpleSpanProcessor,
2323
} from '@opentelemetry/sdk-trace-base';
24-
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
24+
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
2525
import * as assert from 'assert';
2626
import { RPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core';
2727
import { ExpressLayerType } from '../src/enums/ExpressLayerType';
@@ -145,7 +145,7 @@ describe('ExpressInstrumentation', () => {
145145
.find(span => span.name.includes('request handler'));
146146
assert.notStrictEqual(requestHandlerSpan, undefined);
147147
assert.strictEqual(
148-
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
148+
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
149149
'/mw'
150150
);
151151

@@ -196,7 +196,7 @@ describe('ExpressInstrumentation', () => {
196196
.find(span => span.name.includes('request handler'));
197197
assert.notStrictEqual(requestHandlerSpan, undefined);
198198
assert.strictEqual(
199-
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
199+
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
200200
'/'
201201
);
202202

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import * as assert from 'assert';
2525
import { AttributeNames } from '../src/enums/AttributeNames';
2626
import { ExpressInstrumentation } from '../src';
2727
import { createServer, httpRequest, serverWithMiddleware } from './utils';
28-
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
28+
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
2929
import * as testUtils from '@opentelemetry/contrib-test-utils';
3030

3131
const instrumentation = new ExpressInstrumentation();
@@ -114,7 +114,7 @@ describe('ExpressInstrumentation', () => {
114114
.find(span => span.name.includes('request handler'));
115115
assert.notStrictEqual(requestHandlerSpan, undefined);
116116
assert.strictEqual(
117-
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
117+
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
118118
'/toto/:id'
119119
);
120120
assert.strictEqual(
@@ -481,7 +481,7 @@ describe('ExpressInstrumentation', () => {
481481
.getFinishedSpans()
482482
.find(span => span.name.includes('request handler'));
483483
assert.strictEqual(
484-
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
484+
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
485485
'/double-slashes/:id'
486486
);
487487
assert.strictEqual(rpcMetadata?.route, '/double-slashes/:id');

plugins/node/opentelemetry-instrumentation-express/test/hooks.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import * as sinon from 'sinon';
2727
import { ExpressInstrumentation } from '../src';
2828
import { ExpressRequestInfo, SpanNameHook } from '../src/types';
2929
import { ExpressLayerType } from '../src/enums/ExpressLayerType';
30-
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
30+
import { SEMATTRS_HTTP_METHOD } from '@opentelemetry/semantic-conventions';
3131

3232
const instrumentation = new ExpressInstrumentation();
3333
instrumentation.enable();
@@ -178,7 +178,7 @@ describe('ExpressInstrumentation hooks', () => {
178178

179179
it('should call requestHook when set in config', async () => {
180180
const requestHook = sinon.spy((span: Span, info: ExpressRequestInfo) => {
181-
span.setAttribute(SemanticAttributes.HTTP_METHOD, info.request.method);
181+
span.setAttribute(SEMATTRS_HTTP_METHOD, info.request.method);
182182

183183
if (info.layerType) {
184184
span.setAttribute('express.layer_type', info.layerType);

0 commit comments

Comments
 (0)