Skip to content

refactor(instrumentation-express): update semconv usage to ATTR_ exports #2859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
isWrapped,
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
import {
ExpressLayer,
ExpressRouter,
Expand Down Expand Up @@ -195,7 +195,7 @@ export class ExpressInstrumentation extends InstrumentationBase<ExpressInstrumen
.replace(/\/{2,}/g, '/');

const attributes: Attributes = {
[SEMATTRS_HTTP_ROUTE]: route.length > 0 ? route : '/',
[ATTR_HTTP_ROUTE]: route.length > 0 ? route : '/',
};
const metadata = getLayerMetadata(route, layer, layerPath);
const type = metadata.attributes[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
InMemorySpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-base';
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
import * as assert from 'assert';
import { RPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core';
import { ExpressLayerType } from '../src/enums/ExpressLayerType';
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('ExpressInstrumentation', () => {
.find(span => span.name.includes('request handler'));
assert.notStrictEqual(requestHandlerSpan, undefined);
assert.strictEqual(
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
requestHandlerSpan?.attributes[ATTR_HTTP_ROUTE],
'/mw'
);

Expand Down Expand Up @@ -196,7 +196,7 @@ describe('ExpressInstrumentation', () => {
.find(span => span.name.includes('request handler'));
assert.notStrictEqual(requestHandlerSpan, undefined);
assert.strictEqual(
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
requestHandlerSpan?.attributes[ATTR_HTTP_ROUTE],
'/'
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as semver from 'semver';
import { AttributeNames } from '../src/enums/AttributeNames';
import { ExpressInstrumentation } from '../src';
import { createServer, httpRequest, serverWithMiddleware } from './utils';
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
import * as testUtils from '@opentelemetry/contrib-test-utils';

const instrumentation = new ExpressInstrumentation();
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('ExpressInstrumentation', () => {
.find(span => span.name.includes('request handler'));
assert.notStrictEqual(requestHandlerSpan, undefined);
assert.strictEqual(
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
requestHandlerSpan?.attributes[ATTR_HTTP_ROUTE],
'/toto/:id'
);
assert.strictEqual(
Expand Down Expand Up @@ -486,7 +486,7 @@ describe('ExpressInstrumentation', () => {
.getFinishedSpans()
.find(span => span.name.includes('request handler'));
assert.strictEqual(
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
requestHandlerSpan?.attributes[ATTR_HTTP_ROUTE],
'/double-slashes/:id'
);
assert.strictEqual(rpcMetadata?.route, '/double-slashes/:id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import * as sinon from 'sinon';
import { ExpressInstrumentation } from '../src';
import { ExpressRequestInfo, SpanNameHook } from '../src/types';
import { ExpressLayerType } from '../src/enums/ExpressLayerType';
import { SEMATTRS_HTTP_METHOD } from '@opentelemetry/semantic-conventions';
import { ATTR_HTTP_REQUEST_METHOD } from '@opentelemetry/semantic-conventions';

const instrumentation = new ExpressInstrumentation();
instrumentation.enable();
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('ExpressInstrumentation hooks', () => {

it('should call requestHook when set in config', async () => {
const requestHook = sinon.spy((span: Span, info: ExpressRequestInfo) => {
span.setAttribute(SEMATTRS_HTTP_METHOD, info.request.method);
span.setAttribute(ATTR_HTTP_REQUEST_METHOD, info.request.method);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review note: Yes, this is changing from old HTTP semconv http.method to new stable HTTP semconv http.request.method. However, this is not testing that instr-express is generating this. It is just testing that the requestHook is being called. We could satisfy the test by using 'my.http.method' or 'foo' or whatever.


if (info.layerType) {
span.setAttribute('express.layer_type', info.layerType);
Expand All @@ -204,7 +204,7 @@ describe('ExpressInstrumentation hooks', () => {
assert.strictEqual(spans.length, 2);
sinon.assert.calledOnce(requestHook);
assert.strictEqual(
requestHandlerSpan?.attributes['http.method'],
requestHandlerSpan?.attributes['http.request.method'],
'GET'
);
assert.strictEqual(
Expand Down