Skip to content

Commit d36fdc7

Browse files
committed
chore: update use of semantic conventions
1 parent 1218d8c commit d36fdc7

File tree

25 files changed

+161
-179
lines changed

25 files changed

+161
-179
lines changed

plugins/node/opentelemetry-instrumentation-aws-lambda/src/aws-lambda.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
TracerProvider,
3434
} from '@opentelemetry/api';
3535
import { CLOUD_RESOURCE } from '@opentelemetry/resources';
36-
import { FaasAttribute } from '@opentelemetry/semantic-conventions';
36+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
3737

3838
import { Callback, Context, Handler } from 'aws-lambda';
3939

@@ -120,8 +120,8 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
120120
const span = plugin.tracer.startSpan(name, {
121121
kind: SpanKind.SERVER,
122122
attributes: {
123-
[FaasAttribute.FAAS_EXECUTION]: context.awsRequestId,
124-
[FaasAttribute.FAAS_ID]: context.invokedFunctionArn,
123+
[SemanticAttributes.FAAS_EXECUTION]: context.awsRequestId,
124+
'faas.id': context.invokedFunctionArn,
125125
[CLOUD_RESOURCE.ACCOUNT_ID]: AwsLambdaInstrumentation._extractAccountId(
126126
context.invokedFunctionArn
127127
),

plugins/node/opentelemetry-instrumentation-aws-lambda/test/integrations/lambda-handler.test.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ import { NodeTracerProvider } from '@opentelemetry/node';
2929
import { Context } from 'aws-lambda';
3030
import * as assert from 'assert';
3131
import { SpanKind, SpanStatusCode } from '@opentelemetry/api';
32-
import {
33-
ExceptionAttribute,
34-
FaasAttribute,
35-
} from '@opentelemetry/semantic-conventions';
32+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
3633

3734
const memoryExporter = new InMemorySpanExporter();
3835
const provider = new NodeTracerProvider();
@@ -43,10 +40,10 @@ const assertSpanSuccess = (span: ReadableSpan) => {
4340
assert.strictEqual(span.kind, SpanKind.SERVER);
4441
assert.strictEqual(span.name, 'my_function');
4542
assert.strictEqual(
46-
span.attributes[FaasAttribute.FAAS_EXECUTION],
43+
span.attributes[SemanticAttributes.FAAS_EXECUTION],
4744
'aws_request_id'
4845
);
49-
assert.strictEqual(span.attributes[FaasAttribute.FAAS_ID], 'my_arn');
46+
assert.strictEqual(span.attributes['faas.id'], 'my_arn');
5047
assert.strictEqual(span.status.code, SpanStatusCode.UNSET);
5148
assert.strictEqual(span.status.message, undefined);
5249
};
@@ -55,15 +52,15 @@ const assertSpanFailure = (span: ReadableSpan) => {
5552
assert.strictEqual(span.kind, SpanKind.SERVER);
5653
assert.strictEqual(span.name, 'my_function');
5754
assert.strictEqual(
58-
span.attributes[FaasAttribute.FAAS_EXECUTION],
55+
span.attributes[SemanticAttributes.FAAS_EXECUTION],
5956
'aws_request_id'
6057
);
61-
assert.strictEqual(span.attributes[FaasAttribute.FAAS_ID], 'my_arn');
58+
assert.strictEqual(span.attributes['faas.id'], 'my_arn');
6259
assert.strictEqual(span.status.code, SpanStatusCode.ERROR);
6360
assert.strictEqual(span.status.message, 'handler error');
6461
assert.strictEqual(span.events.length, 1);
6562
assert.strictEqual(
66-
span.events[0].attributes![ExceptionAttribute.MESSAGE],
63+
span.events[0].attributes![SemanticAttributes.EXCEPTION_MESSAGE],
6764
'handler error'
6865
);
6966
};

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { LookupAddress } from 'dns';
1818
import { diag, Span, SpanKind } from '@opentelemetry/api';
19-
import { GeneralAttribute } from '@opentelemetry/semantic-conventions';
19+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
2020
import {
2121
InstrumentationBase,
2222
InstrumentationNodeModuleDefinition,
@@ -114,7 +114,7 @@ export class DnsInstrumentation extends InstrumentationBase<Dns> {
114114
const span = plugin.tracer.startSpan(name, {
115115
kind: SpanKind.CLIENT,
116116
attributes: {
117-
[GeneralAttribute.NET_PEER_HOSTNAME]: hostname,
117+
[SemanticAttributes.NET_PEER_NAME]: hostname,
118118
},
119119
});
120120

plugins/node/opentelemetry-instrumentation-dns/test/utils/assertSpan.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { SpanKind, SpanStatus, SpanStatusCode } from '@opentelemetry/api';
1818
import { hrTimeToNanoseconds } from '@opentelemetry/core';
1919
import { ReadableSpan } from '@opentelemetry/tracing';
20-
import { GeneralAttribute } from '@opentelemetry/semantic-conventions';
20+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
2121
import * as assert from 'assert';
2222
import type { LookupAddress } from 'dns';
2323
import { AttributeNames } from '../../src/enums/AttributeNames';
@@ -45,7 +45,7 @@ export const assertSpan = (
4545
span.status.message
4646
);
4747
assert.strictEqual(
48-
span.attributes[GeneralAttribute.NET_PEER_HOSTNAME],
48+
span.attributes[SemanticAttributes.NET_PEER_NAME],
4949
validations.hostname
5050
);
5151

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
InstrumentationNodeModuleDefinition,
3535
isWrapped,
3636
} from '@opentelemetry/instrumentation';
37-
import { HttpAttribute } from '@opentelemetry/semantic-conventions';
37+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
3838

3939
/**
4040
* This symbol is used to mark express layer as being already instrumented
@@ -183,7 +183,7 @@ export class ExpressInstrumentation extends InstrumentationBase<
183183
.filter(path => path !== '/' && path !== '/*')
184184
.join('');
185185
const attributes: SpanAttributes = {
186-
[HttpAttribute.HTTP_ROUTE]: route.length > 0 ? route : undefined,
186+
[SemanticAttributes.HTTP_ROUTE]: route.length > 0 ? route : undefined,
187187
};
188188
const metadata = getLayerMetadata(layer, layerPath);
189189
const type = metadata.attributes[

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
import * as assert from 'assert';
2525
import { CustomAttributeNames, ExpressInstrumentationSpan } from '../src/types';
2626
import { ExpressInstrumentation } from '../src';
27-
import { HttpAttribute } from '@opentelemetry/semantic-conventions';
27+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
2828

2929
const instrumentation = new ExpressInstrumentation();
3030
instrumentation.enable();
@@ -164,7 +164,7 @@ describe('ExpressInstrumentation', () => {
164164
.find(span => span.name.includes('request handler'));
165165
assert.notStrictEqual(requestHandlerSpan, undefined);
166166
assert.strictEqual(
167-
requestHandlerSpan?.attributes[HttpAttribute.HTTP_ROUTE],
167+
requestHandlerSpan?.attributes[SemanticAttributes.HTTP_ROUTE],
168168
'/toto/:id'
169169
);
170170
assert.strictEqual(

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { SpanAttributes } from '@opentelemetry/api';
18-
import { HttpAttribute } from '@opentelemetry/semantic-conventions';
18+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
1919
import type * as Hapi from '@hapi/hapi';
2020
import {
2121
AttributeNames,
@@ -76,8 +76,8 @@ export const getRouteMetadata = (
7676
if (pluginName) {
7777
return {
7878
attributes: {
79-
[HttpAttribute.HTTP_ROUTE]: route.path,
80-
[HttpAttribute.HTTP_METHOD]: route.method,
79+
[SemanticAttributes.HTTP_ROUTE]: route.path,
80+
[SemanticAttributes.HTTP_METHOD]: route.method,
8181
[AttributeNames.HAPI_TYPE]: HapiLayerType.PLUGIN,
8282
[AttributeNames.PLUGIN_NAME]: pluginName,
8383
},
@@ -86,8 +86,8 @@ export const getRouteMetadata = (
8686
}
8787
return {
8888
attributes: {
89-
[HttpAttribute.HTTP_ROUTE]: route.path,
90-
[HttpAttribute.HTTP_METHOD]: route.method,
89+
[SemanticAttributes.HTTP_ROUTE]: route.path,
90+
[SemanticAttributes.HTTP_METHOD]: route.method,
9191
[AttributeNames.HAPI_TYPE]: HapiLayerType.ROUTER,
9292
},
9393
name: `route - ${route.path}`,

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

+11-14
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ import {
3030
DbStatementSerializer,
3131
} from './types';
3232
import { IORedisInstrumentation } from './ioredis';
33-
import {
34-
DatabaseAttribute,
35-
GeneralAttribute,
36-
} from '@opentelemetry/semantic-conventions';
33+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
3734
import { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';
3835

3936
const endSpan = (span: Span, err: NodeJS.ErrnoException | null | undefined) => {
@@ -52,16 +49,16 @@ export const traceConnection = (tracer: Tracer, original: Function) => {
5249
const span = tracer.startSpan('connect', {
5350
kind: SpanKind.CLIENT,
5451
attributes: {
55-
[DatabaseAttribute.DB_SYSTEM]: IORedisInstrumentation.DB_SYSTEM,
56-
[DatabaseAttribute.DB_STATEMENT]: 'connect',
52+
[SemanticAttributes.DB_SYSTEM]: IORedisInstrumentation.DB_SYSTEM,
53+
[SemanticAttributes.DB_STATEMENT]: 'connect',
5754
},
5855
});
5956
const { host, port } = this.options;
6057

6158
span.setAttributes({
62-
[GeneralAttribute.NET_PEER_NAME]: host,
63-
[GeneralAttribute.NET_PEER_PORT]: port,
64-
[GeneralAttribute.NET_PEER_ADDRESS]: `redis://${host}:${port}`,
59+
[SemanticAttributes.NET_PEER_NAME]: host,
60+
[SemanticAttributes.NET_PEER_PORT]: port,
61+
[SemanticAttributes.NET_PEER_IP]: `redis://${host}:${port}`,
6562
});
6663
try {
6764
const client = original.apply(this, arguments);
@@ -102,8 +99,8 @@ export const traceSendCommand = (
10299
const span = tracer.startSpan(cmd.name, {
103100
kind: SpanKind.CLIENT,
104101
attributes: {
105-
[DatabaseAttribute.DB_SYSTEM]: IORedisInstrumentation.DB_SYSTEM,
106-
[DatabaseAttribute.DB_STATEMENT]: dbStatementSerializer(
102+
[SemanticAttributes.DB_SYSTEM]: IORedisInstrumentation.DB_SYSTEM,
103+
[SemanticAttributes.DB_STATEMENT]: dbStatementSerializer(
107104
cmd.name,
108105
cmd.args
109106
),
@@ -113,9 +110,9 @@ export const traceSendCommand = (
113110
const { host, port } = this.options;
114111

115112
span.setAttributes({
116-
[GeneralAttribute.NET_PEER_NAME]: host,
117-
[GeneralAttribute.NET_PEER_PORT]: port,
118-
[GeneralAttribute.NET_PEER_ADDRESS]: `redis://${host}:${port}`,
113+
[SemanticAttributes.NET_PEER_NAME]: host,
114+
[SemanticAttributes.NET_PEER_PORT]: port,
115+
[SemanticAttributes.NET_PEER_IP]: `redis://${host}:${port}`,
119116
});
120117

121118
try {

0 commit comments

Comments
 (0)