diff --git a/packages/opentelemetry-plugin-grpc/package.json b/packages/opentelemetry-plugin-grpc/package.json index 5192ae91ce..564cc4e829 100644 --- a/packages/opentelemetry-plugin-grpc/package.json +++ b/packages/opentelemetry-plugin-grpc/package.json @@ -66,6 +66,7 @@ "dependencies": { "@opentelemetry/api": "^0.8.3", "@opentelemetry/core": "^0.8.3", + "@opentelemetry/semantic-conventions": "^0.8.3", "shimmer": "^1.2.1" } } diff --git a/packages/opentelemetry-plugin-grpc/src/grpc.ts b/packages/opentelemetry-plugin-grpc/src/grpc.ts index bbb04c0269..f0072ea569 100644 --- a/packages/opentelemetry-plugin-grpc/src/grpc.ts +++ b/packages/opentelemetry-plugin-grpc/src/grpc.ts @@ -23,12 +23,15 @@ import { SpanOptions, Status, } from '@opentelemetry/api'; +import { + GeneralAttribute, + RpcAttribute, +} from '@opentelemetry/semantic-conventions'; import { BasePlugin } from '@opentelemetry/core'; import * as events from 'events'; import * as grpcTypes from 'grpc'; import * as path from 'path'; import * as shimmer from 'shimmer'; -import { AttributeNames } from './enums/AttributeNames'; import { grpc, GrpcClientFunc, @@ -173,8 +176,8 @@ export class GrpcPlugin extends BasePlugin { const span = plugin._tracer .startSpan(spanName, spanOptions) .setAttributes({ - [AttributeNames.GRPC_KIND]: spanOptions.kind, - [AttributeNames.COMPONENT]: GrpcPlugin.component, + [RpcAttribute.GRPC_KIND]: spanOptions.kind, + [GeneralAttribute.COMPONENT]: GrpcPlugin.component, }); plugin._tracer.withSpan(span, () => { @@ -235,19 +238,16 @@ export class GrpcPlugin extends BasePlugin { code: _grpcStatusCodeToCanonicalCode(err.code), message: err.message, }); - span.setAttribute( - AttributeNames.GRPC_STATUS_CODE, - err.code.toString() - ); + span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString()); } span.setAttributes({ - [AttributeNames.GRPC_ERROR_NAME]: err.name, - [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, + [RpcAttribute.GRPC_ERROR_NAME]: err.name, + [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, }); } else { span.setStatus({ code: CanonicalCode.OK }); span.setAttribute( - AttributeNames.GRPC_STATUS_CODE, + RpcAttribute.GRPC_STATUS_CODE, plugin._moduleExports.status.OK.toString() ); } @@ -281,7 +281,7 @@ export class GrpcPlugin extends BasePlugin { call.on('finish', () => { span.setStatus(_grpcStatusCodeToSpanStatus(call.status.code)); span.setAttribute( - AttributeNames.GRPC_STATUS_CODE, + RpcAttribute.GRPC_STATUS_CODE, call.status.code.toString() ); @@ -299,8 +299,8 @@ export class GrpcPlugin extends BasePlugin { }); span.addEvent('finished with error'); span.setAttributes({ - [AttributeNames.GRPC_ERROR_NAME]: err.name, - [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, + [RpcAttribute.GRPC_ERROR_NAME]: err.name, + [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, }); endSpan(); }); @@ -357,7 +357,7 @@ export class GrpcPlugin extends BasePlugin { .startSpan(name, { kind: SpanKind.CLIENT, }) - .setAttribute(AttributeNames.COMPONENT, GrpcPlugin.component); + .setAttribute(GeneralAttribute.COMPONENT, GrpcPlugin.component); return plugin._tracer.withSpan(span, () => plugin._makeGrpcClientRemoteCall(original, args, this, plugin)(span) ); @@ -388,18 +388,18 @@ export class GrpcPlugin extends BasePlugin { if (err.code) { span.setStatus(_grpcStatusCodeToSpanStatus(err.code)); span.setAttribute( - AttributeNames.GRPC_STATUS_CODE, + RpcAttribute.GRPC_STATUS_CODE, err.code.toString() ); } span.setAttributes({ - [AttributeNames.GRPC_ERROR_NAME]: err.name, - [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, + [RpcAttribute.GRPC_ERROR_NAME]: err.name, + [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, }); } else { span.setStatus({ code: CanonicalCode.OK }); span.setAttribute( - AttributeNames.GRPC_STATUS_CODE, + RpcAttribute.GRPC_STATUS_CODE, plugin._moduleExports.status.OK.toString() ); } @@ -432,8 +432,8 @@ export class GrpcPlugin extends BasePlugin { span.addEvent('sent'); span.setAttributes({ - [AttributeNames.GRPC_METHOD]: original.path, - [AttributeNames.GRPC_KIND]: SpanKind.CLIENT, + [RpcAttribute.GRPC_METHOD]: original.path, + [RpcAttribute.GRPC_KIND]: SpanKind.CLIENT, }); this._setSpanContext(metadata); @@ -459,8 +459,8 @@ export class GrpcPlugin extends BasePlugin { message: err.message, }); span.setAttributes({ - [AttributeNames.GRPC_ERROR_NAME]: err.name, - [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, + [RpcAttribute.GRPC_ERROR_NAME]: err.name, + [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, }); endSpan(); } @@ -471,7 +471,7 @@ export class GrpcPlugin extends BasePlugin { (status: Status) => { span.setStatus({ code: CanonicalCode.OK }); span.setAttribute( - AttributeNames.GRPC_STATUS_CODE, + RpcAttribute.GRPC_STATUS_CODE, status.code.toString() ); endSpan(); diff --git a/packages/opentelemetry-plugin-grpc/test/utils/assertionUtils.ts b/packages/opentelemetry-plugin-grpc/test/utils/assertionUtils.ts index d6a6a7b3e2..38b0069d1e 100644 --- a/packages/opentelemetry-plugin-grpc/test/utils/assertionUtils.ts +++ b/packages/opentelemetry-plugin-grpc/test/utils/assertionUtils.ts @@ -16,7 +16,6 @@ import { SpanKind } from '@opentelemetry/api'; import * as assert from 'assert'; -import { AttributeNames } from '../../src/enums/AttributeNames'; import { GrpcPlugin } from '../../src/grpc'; import * as grpc from 'grpc'; import { ReadableSpan } from '@opentelemetry/tracing'; @@ -24,6 +23,7 @@ import { hrTimeToMilliseconds, hrTimeToMicroseconds, } from '@opentelemetry/core'; +import { GeneralAttribute } from '@opentelemetry/semantic-conventions'; export const assertSpan = ( span: ReadableSpan, @@ -35,7 +35,7 @@ export const assertSpan = ( assert.strictEqual(span.kind, kind); assert.strictEqual( - span.attributes[AttributeNames.COMPONENT], + span.attributes[GeneralAttribute.COMPONENT], GrpcPlugin.component ); assert.ok(span.endTime); diff --git a/packages/opentelemetry-plugin-http/package.json b/packages/opentelemetry-plugin-http/package.json index f375d22701..ceab9d8a15 100644 --- a/packages/opentelemetry-plugin-http/package.json +++ b/packages/opentelemetry-plugin-http/package.json @@ -72,6 +72,7 @@ "dependencies": { "@opentelemetry/api": "^0.8.3", "@opentelemetry/core": "^0.8.3", + "@opentelemetry/semantic-conventions": "^0.8.3", "semver": "^7.1.3", "shimmer": "^1.2.1" } diff --git a/packages/opentelemetry-plugin-http/src/enums/AttributeNames.ts b/packages/opentelemetry-plugin-http/src/enums/AttributeNames.ts deleted file mode 100644 index 5071f31324..0000000000 --- a/packages/opentelemetry-plugin-http/src/enums/AttributeNames.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export enum AttributeNames { - HTTP_HOST = 'http.host', - COMPONENT = 'component', - HTTP_METHOD = 'http.method', - HTTP_TARGET = 'http.target', - HTTP_ROUTE = 'http.route', - HTTP_URL = 'http.url', - HTTP_STATUS_CODE = 'http.status_code', - HTTP_STATUS_TEXT = 'http.status_text', - HTTP_FLAVOR = 'http.flavor', - NET_PEER_IP = 'net.peer.ip', - NET_PEER_PORT = 'net.peer.port', - NET_PEER_NAME = 'net.peer.name', - NET_HOST_IP = 'net.host.ip', - NET_HOST_PORT = 'net.host.port', - NET_HOST_NAME = 'net.host.name', - NET_TRANSPORT = 'net.transport', - IP_TCP = 'IP.TCP', - IP_UDP = 'IP.UDP', - HTTP_SERVER_NAME = 'http.server_name', - HTTP_CLIENT_IP = 'http.client_ip', - // NOT ON OFFICIAL SPEC - HTTP_ERROR_NAME = 'http.error_name', - HTTP_ERROR_MESSAGE = 'http.error_message', - HTTP_USER_AGENT = 'http.user_agent', -} diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index cc4af12c6d..83b2792e9e 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -29,6 +29,7 @@ import { NoRecordingSpan, getExtractedSpanContext, } from '@opentelemetry/core'; +import { GeneralAttribute } from '@opentelemetry/semantic-conventions'; import { ClientRequest, IncomingMessage, @@ -40,7 +41,6 @@ import { Socket } from 'net'; import * as semver from 'semver'; import * as shimmer from 'shimmer'; import * as url from 'url'; -import { AttributeNames } from './enums/AttributeNames'; import { Err, Func, @@ -463,7 +463,7 @@ export class HttpPlugin extends BasePlugin { } else { span = this._tracer .startSpan(name, options) - .setAttribute(AttributeNames.COMPONENT, this.component); + .setAttribute(GeneralAttribute.COMPONENT, this.component); } this._spanNotEnded.add(span); return span; diff --git a/packages/opentelemetry-plugin-http/src/index.ts b/packages/opentelemetry-plugin-http/src/index.ts index f96c809586..265bc235a7 100644 --- a/packages/opentelemetry-plugin-http/src/index.ts +++ b/packages/opentelemetry-plugin-http/src/index.ts @@ -17,4 +17,3 @@ export * from './http'; export * from './types'; export * from './utils'; -export * from './enums/AttributeNames'; diff --git a/packages/opentelemetry-plugin-http/src/utils.ts b/packages/opentelemetry-plugin-http/src/utils.ts index ef54a59b93..90b4c0fe92 100644 --- a/packages/opentelemetry-plugin-http/src/utils.ts +++ b/packages/opentelemetry-plugin-http/src/utils.ts @@ -14,6 +14,10 @@ * limitations under the License. */ import { Attributes, CanonicalCode, Span, Status } from '@opentelemetry/api'; +import { + HttpAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; import { ClientRequest, IncomingHttpHeaders, @@ -24,7 +28,6 @@ import { } from 'http'; import { Socket } from 'net'; import * as url from 'url'; -import { AttributeNames } from './enums/AttributeNames'; import { Err, IgnoreMatcher, @@ -196,8 +199,8 @@ export const setSpanWithError = ( const message = error.message; span.setAttributes({ - [AttributeNames.HTTP_ERROR_NAME]: error.name, - [AttributeNames.HTTP_ERROR_MESSAGE]: message, + [HttpAttribute.HTTP_ERROR_NAME]: error.name, + [HttpAttribute.HTTP_ERROR_MESSAGE]: message, }); if (!obj) { @@ -334,18 +337,18 @@ export const getOutgoingRequestAttributes = ( const headers = requestOptions.headers || {}; const userAgent = headers['user-agent']; const attributes: Attributes = { - [AttributeNames.HTTP_URL]: getAbsoluteUrl( + [HttpAttribute.HTTP_URL]: getAbsoluteUrl( requestOptions, headers, `${options.component}:` ), - [AttributeNames.HTTP_METHOD]: method, - [AttributeNames.HTTP_TARGET]: requestOptions.path || '/', - [AttributeNames.NET_PEER_NAME]: hostname, + [HttpAttribute.HTTP_METHOD]: method, + [HttpAttribute.HTTP_TARGET]: requestOptions.path || '/', + [GeneralAttribute.NET_PEER_NAME]: hostname, }; if (userAgent !== undefined) { - attributes[AttributeNames.HTTP_USER_AGENT] = userAgent; + attributes[HttpAttribute.HTTP_USER_AGENT] = userAgent; } return attributes; }; @@ -357,11 +360,11 @@ export const getOutgoingRequestAttributes = ( export const getAttributesFromHttpKind = (kind?: string): Attributes => { const attributes: Attributes = {}; if (kind) { - attributes[AttributeNames.HTTP_FLAVOR] = kind; + attributes[HttpAttribute.HTTP_FLAVOR] = kind; if (kind.toUpperCase() !== 'QUIC') { - attributes[AttributeNames.NET_TRANSPORT] = AttributeNames.IP_TCP; + attributes[GeneralAttribute.NET_TRANSPORT] = GeneralAttribute.IP_TCP; } else { - attributes[AttributeNames.NET_TRANSPORT] = AttributeNames.IP_UDP; + attributes[GeneralAttribute.NET_TRANSPORT] = GeneralAttribute.IP_UDP; } } return attributes; @@ -379,14 +382,14 @@ export const getOutgoingRequestAttributesOnResponse = ( const { statusCode, statusMessage, httpVersion, socket } = response; const { remoteAddress, remotePort } = socket; const attributes: Attributes = { - [AttributeNames.NET_PEER_IP]: remoteAddress, - [AttributeNames.NET_PEER_PORT]: remotePort, - [AttributeNames.HTTP_HOST]: `${options.hostname}:${remotePort}`, + [GeneralAttribute.NET_PEER_IP]: remoteAddress, + [GeneralAttribute.NET_PEER_PORT]: remotePort, + [HttpAttribute.HTTP_HOST]: `${options.hostname}:${remotePort}`, }; if (statusCode) { - attributes[AttributeNames.HTTP_STATUS_CODE] = statusCode; - attributes[AttributeNames.HTTP_STATUS_TEXT] = ( + attributes[HttpAttribute.HTTP_STATUS_CODE] = statusCode; + attributes[HttpAttribute.HTTP_STATUS_TEXT] = ( statusMessage || '' ).toUpperCase(); } @@ -417,31 +420,31 @@ export const getIncomingRequestAttributes = ( 'localhost'; const serverName = options.serverName; const attributes: Attributes = { - [AttributeNames.HTTP_URL]: getAbsoluteUrl( + [HttpAttribute.HTTP_URL]: getAbsoluteUrl( requestUrl, headers, `${options.component}:` ), - [AttributeNames.HTTP_HOST]: host, - [AttributeNames.NET_HOST_NAME]: hostname, - [AttributeNames.HTTP_METHOD]: method, + [HttpAttribute.HTTP_HOST]: host, + [GeneralAttribute.NET_HOST_NAME]: hostname, + [HttpAttribute.HTTP_METHOD]: method, }; if (typeof ips === 'string') { - attributes[AttributeNames.HTTP_CLIENT_IP] = ips.split(',')[0]; + attributes[HttpAttribute.HTTP_CLIENT_IP] = ips.split(',')[0]; } if (typeof serverName === 'string') { - attributes[AttributeNames.HTTP_SERVER_NAME] = serverName; + attributes[HttpAttribute.HTTP_SERVER_NAME] = serverName; } if (requestUrl) { - attributes[AttributeNames.HTTP_ROUTE] = requestUrl.pathname || '/'; - attributes[AttributeNames.HTTP_TARGET] = requestUrl.pathname || '/'; + attributes[HttpAttribute.HTTP_ROUTE] = requestUrl.pathname || '/'; + attributes[HttpAttribute.HTTP_TARGET] = requestUrl.pathname || '/'; } if (userAgent !== undefined) { - attributes[AttributeNames.HTTP_USER_AGENT] = userAgent; + attributes[HttpAttribute.HTTP_USER_AGENT] = userAgent; } const httpKindAttributes = getAttributesFromHttpKind(httpVersion); @@ -471,16 +474,16 @@ export const getIncomingRequestAttributesOnResponse = ( : undefined; const attributes: Attributes = { - [AttributeNames.NET_HOST_IP]: localAddress, - [AttributeNames.NET_HOST_PORT]: localPort, - [AttributeNames.NET_PEER_IP]: remoteAddress, - [AttributeNames.NET_PEER_PORT]: remotePort, - [AttributeNames.HTTP_STATUS_CODE]: statusCode, - [AttributeNames.HTTP_STATUS_TEXT]: (statusMessage || '').toUpperCase(), + [GeneralAttribute.NET_HOST_IP]: localAddress, + [GeneralAttribute.NET_HOST_PORT]: localPort, + [GeneralAttribute.NET_PEER_IP]: remoteAddress, + [GeneralAttribute.NET_PEER_PORT]: remotePort, + [HttpAttribute.HTTP_STATUS_CODE]: statusCode, + [HttpAttribute.HTTP_STATUS_TEXT]: (statusMessage || '').toUpperCase(), }; if (route !== undefined) { - attributes[AttributeNames.HTTP_ROUTE] = route; + attributes[HttpAttribute.HTTP_ROUTE] = route; } return attributes; }; diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts index 0597ce7d4f..1cb350bf95 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts @@ -26,11 +26,14 @@ import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/tracing'; +import { + HttpAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as http from 'http'; import * as nock from 'nock'; import * as path from 'path'; -import { AttributeNames } from '../../src/enums/AttributeNames'; import { HttpPlugin, plugin } from '../../src/http'; import { Http, HttpPluginConfig } from '../../src/types'; import { OT_REQUEST_HEADER } from '../../src/utils'; @@ -174,11 +177,11 @@ describe('HttpPlugin', () => { assertSpan(incomingSpan, SpanKind.SERVER, validations); assertSpan(outgoingSpan, SpanKind.CLIENT, validations); assert.strictEqual( - incomingSpan.attributes[AttributeNames.NET_HOST_PORT], + incomingSpan.attributes[GeneralAttribute.NET_HOST_PORT], serverPort ); assert.strictEqual( - outgoingSpan.attributes[AttributeNames.NET_PEER_PORT], + outgoingSpan.attributes[GeneralAttribute.NET_PEER_PORT], serverPort ); }); @@ -276,28 +279,25 @@ describe('HttpPlugin', () => { assert.strictEqual(spans.length, 2); assert.strictEqual( - incomingSpan.attributes[AttributeNames.HTTP_CLIENT_IP], + incomingSpan.attributes[HttpAttribute.HTTP_CLIENT_IP], '' ); assert.strictEqual( - incomingSpan.attributes[AttributeNames.NET_HOST_PORT], + incomingSpan.attributes[GeneralAttribute.NET_HOST_PORT], serverPort ); assert.strictEqual( - outgoingSpan.attributes[AttributeNames.NET_PEER_PORT], + outgoingSpan.attributes[GeneralAttribute.NET_PEER_PORT], serverPort ); [ { span: incomingSpan, kind: SpanKind.SERVER }, { span: outgoingSpan, kind: SpanKind.CLIENT }, ].forEach(({ span, kind }) => { + assert.strictEqual(span.attributes[HttpAttribute.HTTP_FLAVOR], '1.1'); assert.strictEqual( - span.attributes[AttributeNames.HTTP_FLAVOR], - '1.1' - ); - assert.strictEqual( - span.attributes[AttributeNames.NET_TRANSPORT], - AttributeNames.IP_TCP + span.attributes[GeneralAttribute.NET_TRANSPORT], + GeneralAttribute.IP_TCP ); assertSpan(span, kind, validations); }); @@ -708,7 +708,7 @@ describe('HttpPlugin', () => { assert.strictEqual(spans.length, 1); assert.ok(Object.keys(span.attributes).length > 6); assert.strictEqual( - span.attributes[AttributeNames.HTTP_STATUS_CODE], + span.attributes[HttpAttribute.HTTP_STATUS_CODE], 404 ); assert.strictEqual(span.status.code, CanonicalCode.NOT_FOUND); diff --git a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts index c5e8c4c304..2ecc280604 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts @@ -16,13 +16,13 @@ import { CanonicalCode, SpanKind, TraceFlags } from '@opentelemetry/api'; import { NoopLogger } from '@opentelemetry/core'; import { BasicTracerProvider, Span } from '@opentelemetry/tracing'; +import { HttpAttribute } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as http from 'http'; import { IncomingMessage, ServerResponse } from 'http'; import { Socket } from 'net'; import * as sinon from 'sinon'; import * as url from 'url'; -import { AttributeNames } from '../../src'; import { IgnoreMatcher } from '../../src/types'; import * as utils from '../../src/utils'; @@ -264,10 +264,10 @@ describe('Utility', () => { utils.setSpanWithError(span, new Error(errorMessage), obj as any); const attributes = span.attributes; assert.strictEqual( - attributes[AttributeNames.HTTP_ERROR_MESSAGE], + attributes[HttpAttribute.HTTP_ERROR_MESSAGE], errorMessage ); - assert.ok(attributes[AttributeNames.HTTP_ERROR_NAME]); + assert.ok(attributes[HttpAttribute.HTTP_ERROR_NAME]); } }); }); @@ -325,7 +325,7 @@ describe('Utility', () => { const attributes = utils.getIncomingRequestAttributesOnResponse(request, { socket: {}, } as ServerResponse & { socket: Socket }); - assert.deepEqual(attributes[AttributeNames.HTTP_ROUTE], '/test/toto'); + assert.deepEqual(attributes[HttpAttribute.HTTP_ROUTE], '/test/toto'); }); it('should succesfully process without middleware stack', () => { @@ -333,7 +333,7 @@ describe('Utility', () => { const attributes = utils.getIncomingRequestAttributesOnResponse(request, { socket: {}, } as ServerResponse & { socket: Socket }); - assert.deepEqual(attributes[AttributeNames.HTTP_ROUTE], undefined); + assert.deepEqual(attributes[HttpAttribute.HTTP_ROUTE], undefined); }); }); }); diff --git a/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts index beac0ac7f3..9fd14f6ff0 100644 --- a/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts @@ -16,6 +16,10 @@ import { NoopLogger } from '@opentelemetry/core'; import { SpanKind, Span, context } from '@opentelemetry/api'; +import { + HttpAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as http from 'http'; import * as url from 'url'; @@ -30,7 +34,6 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import { HttpPluginConfig } from '../../src/types'; -import { AttributeNames } from '../../src/enums/AttributeNames'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; const protocol = 'http'; const serverPort = 32345; @@ -176,10 +179,10 @@ describe('HttpPlugin Integration tests', () => { assert.strictEqual(spans.length, 1); assert.ok(span.name.indexOf('GET /') >= 0); assert.strictEqual(result.reqHeaders['x-foo'], 'foo'); - assert.strictEqual(span.attributes[AttributeNames.HTTP_FLAVOR], '1.1'); + assert.strictEqual(span.attributes[HttpAttribute.HTTP_FLAVOR], '1.1'); assert.strictEqual( - span.attributes[AttributeNames.NET_TRANSPORT], - AttributeNames.IP_TCP + span.attributes[GeneralAttribute.NET_TRANSPORT], + GeneralAttribute.IP_TCP ); assertSpan(span, SpanKind.CLIENT, validations); }); diff --git a/packages/opentelemetry-plugin-http/test/utils/assertSpan.ts b/packages/opentelemetry-plugin-http/test/utils/assertSpan.ts index c99828ec6f..77fbf04c12 100644 --- a/packages/opentelemetry-plugin-http/test/utils/assertSpan.ts +++ b/packages/opentelemetry-plugin-http/test/utils/assertSpan.ts @@ -16,9 +16,12 @@ import { SpanKind, Status } from '@opentelemetry/api'; import { hrTimeToNanoseconds } from '@opentelemetry/core'; import { ReadableSpan } from '@opentelemetry/tracing'; +import { + GeneralAttribute, + HttpAttribute, +} from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as http from 'http'; -import { AttributeNames } from '../../src/enums/AttributeNames'; import * as utils from '../../src/utils'; import { DummyPropagation } from './DummyPropagation'; @@ -46,23 +49,23 @@ export const assertSpan = ( `${validations.httpMethod} ${validations.pathname}` ); assert.strictEqual( - span.attributes[AttributeNames.COMPONENT], + span.attributes[GeneralAttribute.COMPONENT], validations.component ); assert.strictEqual( - span.attributes[AttributeNames.HTTP_ERROR_MESSAGE], + span.attributes[HttpAttribute.HTTP_ERROR_MESSAGE], span.status.message ); assert.strictEqual( - span.attributes[AttributeNames.HTTP_METHOD], + span.attributes[HttpAttribute.HTTP_METHOD], validations.httpMethod ); assert.strictEqual( - span.attributes[AttributeNames.HTTP_TARGET], + span.attributes[HttpAttribute.HTTP_TARGET], validations.path || validations.pathname ); assert.strictEqual( - span.attributes[AttributeNames.HTTP_STATUS_CODE], + span.attributes[HttpAttribute.HTTP_STATUS_CODE], validations.httpStatusCode ); @@ -82,25 +85,28 @@ export const assertSpan = ( const userAgent = validations.reqHeaders['user-agent']; if (userAgent) { assert.strictEqual( - span.attributes[AttributeNames.HTTP_USER_AGENT], + span.attributes[HttpAttribute.HTTP_USER_AGENT], userAgent ); } } if (span.kind === SpanKind.CLIENT) { assert.strictEqual( - span.attributes[AttributeNames.NET_PEER_NAME], + span.attributes[GeneralAttribute.NET_PEER_NAME], validations.hostname, 'must be consistent (PEER_NAME and hostname)' ); - assert.ok(span.attributes[AttributeNames.NET_PEER_IP], 'must have PEER_IP'); assert.ok( - span.attributes[AttributeNames.NET_PEER_PORT], + span.attributes[GeneralAttribute.NET_PEER_IP], + 'must have PEER_IP' + ); + assert.ok( + span.attributes[GeneralAttribute.NET_PEER_PORT], 'must have PEER_PORT' ); assert.ok( - (span.attributes[AttributeNames.HTTP_URL] as string).indexOf( - span.attributes[AttributeNames.NET_PEER_NAME] as string + (span.attributes[HttpAttribute.HTTP_URL] as string).indexOf( + span.attributes[GeneralAttribute.NET_PEER_NAME] as string ) > -1, 'must be consistent' ); @@ -108,16 +114,16 @@ export const assertSpan = ( if (span.kind === SpanKind.SERVER) { if (validations.serverName) { assert.strictEqual( - span.attributes[AttributeNames.HTTP_SERVER_NAME], + span.attributes[HttpAttribute.HTTP_SERVER_NAME], validations.serverName, ' must have serverName attribute' ); assert.ok( - span.attributes[AttributeNames.NET_HOST_PORT], + span.attributes[GeneralAttribute.NET_HOST_PORT], 'must have HOST_PORT' ); assert.ok( - span.attributes[AttributeNames.NET_HOST_IP], + span.attributes[GeneralAttribute.NET_HOST_IP], 'must have HOST_IP' ); } diff --git a/packages/opentelemetry-plugin-https/package.json b/packages/opentelemetry-plugin-https/package.json index 52309a2511..fcf9aafe08 100644 --- a/packages/opentelemetry-plugin-https/package.json +++ b/packages/opentelemetry-plugin-https/package.json @@ -73,6 +73,7 @@ "@opentelemetry/api": "^0.8.3", "@opentelemetry/core": "^0.8.3", "@opentelemetry/plugin-http": "^0.8.3", + "@opentelemetry/semantic-conventions": "^0.8.3", "semver": "^7.1.3", "shimmer": "^1.2.1" } diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts index 2c3533973a..39aa2e5493 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts @@ -24,7 +24,6 @@ import { import { NoopLogger } from '@opentelemetry/core'; import { NodeTracerProvider } from '@opentelemetry/node'; import { - AttributeNames, Http, HttpPluginConfig, OT_REQUEST_HEADER, @@ -35,6 +34,10 @@ import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/tracing'; +import { + GeneralAttribute, + HttpAttribute, +} from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as fs from 'fs'; import * as http from 'http'; @@ -175,11 +178,11 @@ describe('HttpsPlugin', () => { assertSpan(incomingSpan, SpanKind.SERVER, validations); assertSpan(outgoingSpan, SpanKind.CLIENT, validations); assert.strictEqual( - incomingSpan.attributes[AttributeNames.NET_HOST_PORT], + incomingSpan.attributes[GeneralAttribute.NET_HOST_PORT], serverPort ); assert.strictEqual( - outgoingSpan.attributes[AttributeNames.NET_PEER_PORT], + outgoingSpan.attributes[GeneralAttribute.NET_PEER_PORT], serverPort ); }); @@ -283,15 +286,15 @@ describe('HttpsPlugin', () => { assert.strictEqual(spans.length, 2); assert.strictEqual( - incomingSpan.attributes[AttributeNames.HTTP_CLIENT_IP], + incomingSpan.attributes[HttpAttribute.HTTP_CLIENT_IP], '' ); assert.strictEqual( - incomingSpan.attributes[AttributeNames.NET_HOST_PORT], + incomingSpan.attributes[GeneralAttribute.NET_HOST_PORT], serverPort ); assert.strictEqual( - outgoingSpan.attributes[AttributeNames.NET_PEER_PORT], + outgoingSpan.attributes[GeneralAttribute.NET_PEER_PORT], serverPort ); @@ -299,13 +302,10 @@ describe('HttpsPlugin', () => { { span: incomingSpan, kind: SpanKind.SERVER }, { span: outgoingSpan, kind: SpanKind.CLIENT }, ].forEach(({ span, kind }) => { + assert.strictEqual(span.attributes[HttpAttribute.HTTP_FLAVOR], '1.1'); assert.strictEqual( - span.attributes[AttributeNames.HTTP_FLAVOR], - '1.1' - ); - assert.strictEqual( - span.attributes[AttributeNames.NET_TRANSPORT], - AttributeNames.IP_TCP + span.attributes[GeneralAttribute.NET_TRANSPORT], + GeneralAttribute.IP_TCP ); assertSpan(span, kind, validations); }); @@ -686,7 +686,7 @@ describe('HttpsPlugin', () => { assert.strictEqual(spans.length, 1); assert.ok(Object.keys(span.attributes).length > 6); assert.strictEqual( - span.attributes[AttributeNames.HTTP_STATUS_CODE], + span.attributes[HttpAttribute.HTTP_STATUS_CODE], 404 ); assert.strictEqual(span.status.code, CanonicalCode.NOT_FOUND); diff --git a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts index d36ef1274b..a0a128bb0d 100644 --- a/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/integrations/https-enable.test.ts @@ -15,12 +15,12 @@ */ import { NoopLogger } from '@opentelemetry/core'; -import { - HttpPluginConfig, - Http, - AttributeNames, -} from '@opentelemetry/plugin-http'; +import { HttpPluginConfig, Http } from '@opentelemetry/plugin-http'; import { SpanKind, Span, context } from '@opentelemetry/api'; +import { + HttpAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as http from 'http'; import * as https from 'https'; @@ -184,10 +184,10 @@ describe('HttpsPlugin Integration tests', () => { assert.strictEqual(spans.length, 1); assert.ok(span.name.indexOf('GET /') >= 0); assert.strictEqual(result.reqHeaders['x-foo'], 'foo'); - assert.strictEqual(span.attributes[AttributeNames.HTTP_FLAVOR], '1.1'); + assert.strictEqual(span.attributes[HttpAttribute.HTTP_FLAVOR], '1.1'); assert.strictEqual( - span.attributes[AttributeNames.NET_TRANSPORT], - AttributeNames.IP_TCP + span.attributes[GeneralAttribute.NET_TRANSPORT], + GeneralAttribute.IP_TCP ); assertSpan(span, SpanKind.CLIENT, validations); }); diff --git a/packages/opentelemetry-plugin-https/test/utils/assertSpan.ts b/packages/opentelemetry-plugin-https/test/utils/assertSpan.ts index 1b1860df9f..019ecbd466 100644 --- a/packages/opentelemetry-plugin-https/test/utils/assertSpan.ts +++ b/packages/opentelemetry-plugin-https/test/utils/assertSpan.ts @@ -16,14 +16,15 @@ import { SpanKind } from '@opentelemetry/api'; import { hrTimeToNanoseconds } from '@opentelemetry/core'; +import { + HttpAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as http from 'http'; import { DummyPropagation } from './DummyPropagation'; import { ReadableSpan } from '@opentelemetry/tracing'; -import { - AttributeNames, - parseResponseStatus, -} from '@opentelemetry/plugin-http'; +import { parseResponseStatus } from '@opentelemetry/plugin-http'; export const assertSpan = ( span: ReadableSpan, @@ -48,23 +49,23 @@ export const assertSpan = ( `${validations.httpMethod} ${validations.pathname}` ); assert.strictEqual( - span.attributes[AttributeNames.COMPONENT], + span.attributes[GeneralAttribute.COMPONENT], validations.component ); assert.strictEqual( - span.attributes[AttributeNames.HTTP_ERROR_MESSAGE], + span.attributes[HttpAttribute.HTTP_ERROR_MESSAGE], span.status.message ); assert.strictEqual( - span.attributes[AttributeNames.HTTP_METHOD], + span.attributes[HttpAttribute.HTTP_METHOD], validations.httpMethod ); assert.strictEqual( - span.attributes[AttributeNames.HTTP_TARGET], + span.attributes[HttpAttribute.HTTP_TARGET], validations.path || validations.pathname ); assert.strictEqual( - span.attributes[AttributeNames.HTTP_STATUS_CODE], + span.attributes[HttpAttribute.HTTP_STATUS_CODE], validations.httpStatusCode ); assert.ok(span.endTime); @@ -82,25 +83,28 @@ export const assertSpan = ( const userAgent = validations.reqHeaders['user-agent']; if (userAgent) { assert.strictEqual( - span.attributes[AttributeNames.HTTP_USER_AGENT], + span.attributes[HttpAttribute.HTTP_USER_AGENT], userAgent ); } } if (span.kind === SpanKind.CLIENT) { assert.strictEqual( - span.attributes[AttributeNames.NET_PEER_NAME], + span.attributes[GeneralAttribute.NET_PEER_NAME], validations.hostname, 'must be consistent (PEER_NAME and hostname)' ); - assert.ok(span.attributes[AttributeNames.NET_PEER_IP], 'must have PEER_IP'); assert.ok( - span.attributes[AttributeNames.NET_PEER_PORT], + span.attributes[GeneralAttribute.NET_PEER_IP], + 'must have PEER_IP' + ); + assert.ok( + span.attributes[GeneralAttribute.NET_PEER_PORT], 'must have PEER_PORT' ); assert.ok( - (span.attributes[AttributeNames.HTTP_URL] as string).indexOf( - span.attributes[AttributeNames.NET_PEER_NAME] as string + (span.attributes[HttpAttribute.HTTP_URL] as string).indexOf( + span.attributes[GeneralAttribute.NET_PEER_NAME] as string ) > -1, 'must be consistent' ); @@ -108,16 +112,19 @@ export const assertSpan = ( if (span.kind === SpanKind.SERVER) { if (validations.serverName) { assert.strictEqual( - span.attributes[AttributeNames.HTTP_SERVER_NAME], + span.attributes[HttpAttribute.HTTP_SERVER_NAME], validations.serverName, ' must have serverName attribute' ); } assert.ok( - span.attributes[AttributeNames.NET_HOST_PORT], + span.attributes[GeneralAttribute.NET_HOST_PORT], 'must have HOST_PORT' ); - assert.ok(span.attributes[AttributeNames.NET_HOST_IP], 'must have HOST_IP'); + assert.ok( + span.attributes[GeneralAttribute.NET_HOST_IP], + 'must have HOST_IP' + ); assert.strictEqual(span.parentSpanId, DummyPropagation.SPAN_CONTEXT_KEY); } else if (validations.reqHeaders) { assert.ok(validations.reqHeaders[DummyPropagation.TRACE_CONTEXT_KEY]); diff --git a/packages/opentelemetry-plugin-xml-http-request/package.json b/packages/opentelemetry-plugin-xml-http-request/package.json index f3964d3998..d5f3adc59b 100644 --- a/packages/opentelemetry-plugin-xml-http-request/package.json +++ b/packages/opentelemetry-plugin-xml-http-request/package.json @@ -76,6 +76,7 @@ "dependencies": { "@opentelemetry/api": "^0.8.3", "@opentelemetry/core": "^0.8.3", + "@opentelemetry/semantic-conventions": "^0.8.3", "@opentelemetry/web": "^0.8.3", "shimmer": "^1.2.1" } diff --git a/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts b/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts index 65fbab52bc..ff18cb02f1 100644 --- a/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts +++ b/packages/opentelemetry-plugin-xml-http-request/src/xhr.ts @@ -23,6 +23,10 @@ import { otperformance, urlMatches, } from '@opentelemetry/core'; +import { + HttpAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; import { addSpanNetworkEvent, getResource, @@ -30,7 +34,6 @@ import { PerformanceTimingNames as PTN, } from '@opentelemetry/web'; import * as shimmer from 'shimmer'; -import { AttributeNames } from './enums/AttributeNames'; import { EventNames } from './enums/EventNames'; import { OpenFunction, @@ -151,17 +154,17 @@ export class XMLHttpRequestPlugin extends BasePlugin { if (typeof spanUrl === 'string') { const parsedUrl = parseUrl(spanUrl); - span.setAttribute(AttributeNames.HTTP_STATUS_CODE, xhrMem.status); - span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText); - span.setAttribute(AttributeNames.HTTP_HOST, parsedUrl.host); + span.setAttribute(HttpAttribute.HTTP_STATUS_CODE, xhrMem.status); + span.setAttribute(HttpAttribute.HTTP_STATUS_TEXT, xhrMem.statusText); + span.setAttribute(HttpAttribute.HTTP_HOST, parsedUrl.host); span.setAttribute( - AttributeNames.HTTP_SCHEME, + HttpAttribute.HTTP_SCHEME, parsedUrl.protocol.replace(':', '') ); // @TODO do we want to collect this or it will be collected earlier once only or // maybe when parent span is not available ? - span.setAttribute(AttributeNames.HTTP_USER_AGENT, navigator.userAgent); + span.setAttribute(HttpAttribute.HTTP_USER_AGENT, navigator.userAgent); } } @@ -319,9 +322,9 @@ export class XMLHttpRequestPlugin extends BasePlugin { const currentSpan = this._tracer.startSpan(url, { kind: api.SpanKind.CLIENT, attributes: { - [AttributeNames.COMPONENT]: this.component, - [AttributeNames.HTTP_METHOD]: method, - [AttributeNames.HTTP_URL]: url, + [GeneralAttribute.COMPONENT]: this.component, + [HttpAttribute.HTTP_METHOD]: method, + [HttpAttribute.HTTP_URL]: url, }, }); diff --git a/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts b/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts index 81ab9778fa..1a59f5c092 100644 --- a/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts +++ b/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts @@ -24,13 +24,16 @@ import { } from '@opentelemetry/core'; import { ZoneContextManager } from '@opentelemetry/context-zone'; import * as tracing from '@opentelemetry/tracing'; +import { + HttpAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; import { PerformanceTimingNames as PTN, WebTracerProvider, } from '@opentelemetry/web'; import * as assert from 'assert'; import * as sinon from 'sinon'; -import { AttributeNames } from '../src/enums/AttributeNames'; import { EventNames } from '../src/enums/EventNames'; import { XMLHttpRequestPlugin } from '../src/xhr'; @@ -238,40 +241,40 @@ describe('xhr', () => { assert.ok( attributes[keys[0]] !== '', - `attributes ${AttributeNames.COMPONENT} is not defined` + `attributes ${GeneralAttribute.COMPONENT} is not defined` ); assert.strictEqual( attributes[keys[1]], 'GET', - `attributes ${AttributeNames.HTTP_METHOD} is wrong` + `attributes ${HttpAttribute.HTTP_METHOD} is wrong` ); assert.strictEqual( attributes[keys[2]], url, - `attributes ${AttributeNames.HTTP_URL} is wrong` + `attributes ${HttpAttribute.HTTP_URL} is wrong` ); assert.strictEqual( attributes[keys[3]], 200, - `attributes ${AttributeNames.HTTP_STATUS_CODE} is wrong` + `attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong` ); assert.strictEqual( attributes[keys[4]], 'OK', - `attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong` + `attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong` ); assert.strictEqual( attributes[keys[5]], window.location.host, - `attributes ${AttributeNames.HTTP_HOST} is wrong` + `attributes ${HttpAttribute.HTTP_HOST} is wrong` ); assert.ok( attributes[keys[6]] === 'http' || attributes[keys[6]] === 'https', - `attributes ${AttributeNames.HTTP_SCHEME} is wrong` + `attributes ${HttpAttribute.HTTP_SCHEME} is wrong` ); assert.ok( attributes[keys[7]] !== '', - `attributes ${AttributeNames.HTTP_USER_AGENT} is not defined` + `attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined` ); assert.strictEqual(keys.length, 8, 'number of attributes is wrong'); @@ -508,40 +511,40 @@ describe('xhr', () => { assert.ok( attributes[keys[0]] !== '', - `attributes ${AttributeNames.COMPONENT} is not defined` + `attributes ${GeneralAttribute.COMPONENT} is not defined` ); assert.strictEqual( attributes[keys[1]], 'GET', - `attributes ${AttributeNames.HTTP_METHOD} is wrong` + `attributes ${HttpAttribute.HTTP_METHOD} is wrong` ); assert.strictEqual( attributes[keys[2]], url, - `attributes ${AttributeNames.HTTP_URL} is wrong` + `attributes ${HttpAttribute.HTTP_URL} is wrong` ); assert.strictEqual( attributes[keys[3]], 400, - `attributes ${AttributeNames.HTTP_STATUS_CODE} is wrong` + `attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong` ); assert.strictEqual( attributes[keys[4]], 'Bad Request', - `attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong` + `attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong` ); assert.strictEqual( attributes[keys[5]], 'raw.githubusercontent.com', - `attributes ${AttributeNames.HTTP_HOST} is wrong` + `attributes ${HttpAttribute.HTTP_HOST} is wrong` ); assert.ok( attributes[keys[6]] === 'http' || attributes[keys[6]] === 'https', - `attributes ${AttributeNames.HTTP_SCHEME} is wrong` + `attributes ${HttpAttribute.HTTP_SCHEME} is wrong` ); assert.ok( attributes[keys[7]] !== '', - `attributes ${AttributeNames.HTTP_USER_AGENT} is not defined` + `attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined` ); assert.strictEqual(keys.length, 8, 'number of attributes is wrong'); diff --git a/packages/opentelemetry-semantic-conventions/.eslintignore b/packages/opentelemetry-semantic-conventions/.eslintignore new file mode 100644 index 0000000000..378eac25d3 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/.eslintignore @@ -0,0 +1 @@ +build diff --git a/packages/opentelemetry-semantic-conventions/.eslintrc.js b/packages/opentelemetry-semantic-conventions/.eslintrc.js new file mode 100644 index 0000000000..9dfe62f9b8 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/.eslintrc.js @@ -0,0 +1,9 @@ +module.exports = { + "env": { + "mocha": true, + "commonjs": true, + "node": true, + "browser": true + }, + ...require('../../eslint.config.js') +} diff --git a/packages/opentelemetry-semantic-conventions/.npmignore b/packages/opentelemetry-semantic-conventions/.npmignore new file mode 100644 index 0000000000..9505ba9450 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/.npmignore @@ -0,0 +1,4 @@ +/bin +/coverage +/doc +/test diff --git a/packages/opentelemetry-semantic-conventions/LICENSE b/packages/opentelemetry-semantic-conventions/LICENSE new file mode 100644 index 0000000000..b0e74c7d15 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [2020] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/opentelemetry-semantic-conventions/README.md b/packages/opentelemetry-semantic-conventions/README.md new file mode 100644 index 0000000000..eca85da6fc --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/README.md @@ -0,0 +1,49 @@ +# OpenTelemetry Semantic Conventions + +[![Gitter chat][gitter-image]][gitter-url] +[![NPM Published Version][npm-img]][npm-url] +[![dependencies][dependencies-image]][dependencies-url] +[![devDependencies][devDependencies-image]][devDependencies-url] +[![Apache License][license-image]][license-image] + +Semantic Convention constants for use with the OpenTelemetry SDK/APIs. [This document][trace-semantic_conventions] defines standard attributes for traces. + +## Installation + +```bash +npm install --save @opentelemetry/semantic-conventions +``` + +## Usage + +```ts +import { GeneralAttribute } from '@opentelemetry/semantic-conventions'; + +const span = tracer.startSpan().startSpan(spanName, spanOptions) + .setAttributes({ + [GeneralAttribute.NET_PEER_HOSTNAME]: 'localhost', + }); +``` + +## Useful links + +- For more information on OpenTelemetry, visit: +- For more about OpenTelemetry JavaScript: +- For help or feedback on this project, join us on [gitter][gitter-url] + +## License + +Apache 2.0 - See [LICENSE][license-url] for more information. + +[gitter-image]: https://badges.gitter.im/open-telemetry/opentelemetry-js.svg +[gitter-url]: https://gitter.im/open-telemetry/opentelemetry-node?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge +[license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/master/LICENSE +[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat +[dependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/status.svg?path=packages/opentelemetry-semantic-conventions +[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-semantic-conventions +[devDependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/dev-status.svg?path=packages/opentelemetry-semantic-conventions +[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-semantic-conventions&type=dev +[npm-url]: https://www.npmjs.com/package/@opentelemetry/semantic-conventions +[npm-img]: https://badge.fury.io/js/%40opentelemetry%semantic-conventions.svg + +[trace-semantic_conventions]: https://github.com/open-telemetry/opentelemetry-specification/tree/master/specification/trace/semantic_conventions diff --git a/packages/opentelemetry-semantic-conventions/package.json b/packages/opentelemetry-semantic-conventions/package.json new file mode 100644 index 0000000000..f033eb908b --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/package.json @@ -0,0 +1,57 @@ +{ + "name": "@opentelemetry/semantic-conventions", + "version": "0.8.3", + "description": "OpenTelemetry semantic conventions", + "main": "build/src/index.js", + "types": "build/src/index.d.ts", + "repository": "open-telemetry/opentelemetry-js", + "scripts": { + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", + "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", + "tdd": "npm run test -- --watch-extensions ts --watch", + "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", + "clean": "rimraf build/*", + "precompile": "tsc --version", + "version:update": "node ../../scripts/version-update.js", + "compile": "npm run version:update && tsc -p .", + "prepare": "npm run compile" + }, + "keywords": [ + "opentelemetry", + "nodejs", + "tracing", + "attributes", + "semantic conventions" + ], + "author": "OpenTelemetry Authors", + "license": "Apache-2.0", + "engines": { + "node": ">=8.0.0" + }, + "files": [ + "build/src/**/*.js", + "build/src/**/*.d.ts", + "doc", + "LICENSE", + "README.md" + ], + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@types/mocha": "7.0.2", + "@types/node": "14.0.13", + "@types/sinon": "9.0.4", + "codecov": "3.7.0", + "gts": "2.0.2", + "mocha": "7.2.0", + "nock": "12.0.3", + "nyc": "15.1.0", + "rimraf": "3.0.2", + "sinon": "9.0.2", + "ts-mocha": "7.0.0", + "ts-node": "8.10.2", + "typescript": "3.9.5" + } +} diff --git a/packages/opentelemetry-plugin-grpc/src/enums/AttributeNames.ts b/packages/opentelemetry-semantic-conventions/src/index.ts similarity index 69% rename from packages/opentelemetry-plugin-grpc/src/enums/AttributeNames.ts rename to packages/opentelemetry-semantic-conventions/src/index.ts index 3fdea85bc7..ae2998a38c 100644 --- a/packages/opentelemetry-plugin-grpc/src/enums/AttributeNames.ts +++ b/packages/opentelemetry-semantic-conventions/src/index.ts @@ -14,11 +14,4 @@ * limitations under the License. */ -export enum AttributeNames { - COMPONENT = 'component', - GRPC_KIND = 'grpc.kind', // SERVER or CLIENT - GRPC_METHOD = 'grpc.method', - GRPC_STATUS_CODE = 'grpc.status_code', - GRPC_ERROR_NAME = 'grpc.error_name', - GRPC_ERROR_MESSAGE = 'grpc.error_message', -} +export * from './trace'; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/database.ts b/packages/opentelemetry-semantic-conventions/src/trace/database.ts new file mode 100644 index 0000000000..86705c746e --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/src/trace/database.ts @@ -0,0 +1,30 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Database attribute names defined by the Opetelemetry Semantic Conventions specification + * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/database.md + */ +export const DatabaseAttribute = { + // db (required) + DB_TYPE: 'db.type', + DB_INSTANCE: 'db.instance', + DB_STATEMENT: 'db.statement', + DB_URL: 'db.url', + + // db (optional) + DB_USER: 'db.user', +}; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/general.ts b/packages/opentelemetry-semantic-conventions/src/trace/general.ts new file mode 100644 index 0000000000..d52f4ff449 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/src/trace/general.ts @@ -0,0 +1,37 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const GeneralAttribute = { + // Not in spec + COMPONENT: 'component', + + NET_PEER_IP: 'net.peer.ip', + NET_PEER_ADDRESS: 'net.peer.address', + NET_PEER_HOSTNAME: 'net.peer.host', + NET_PEER_PORT: 'net.peer.port', + NET_PEER_NAME: 'net.peer.name', + NET_PEER_IPV4: 'net.peer.ipv4', + NET_PEER_IPV6: 'net.peer.ipv6', + NET_PEER_SERVICE: 'net.peer.service', + NET_HOST_IP: 'net.host.ip', + NET_HOST_PORT: 'net.host.port', + NET_HOST_NAME: 'net.host.name', + NET_TRANSPORT: 'net.transport', + + // These are used as potential values to NET_TRANSPORT + IP_TCP: 'IP.TCP', + IP_UDP: 'IP.UDP', + INPROC: 'inproc', +}; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/http.ts b/packages/opentelemetry-semantic-conventions/src/trace/http.ts new file mode 100644 index 0000000000..d194db6a41 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/src/trace/http.ts @@ -0,0 +1,33 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const HttpAttribute = { + HTTP_HOST: 'http.host', + HTTP_METHOD: 'http.method', + HTTP_TARGET: 'http.target', + HTTP_ROUTE: 'http.route', + HTTP_URL: 'http.url', + HTTP_STATUS_CODE: 'http.status_code', + HTTP_STATUS_TEXT: 'http.status_text', + HTTP_FLAVOR: 'http.flavor', + HTTP_SERVER_NAME: 'http.server_name', + HTTP_CLIENT_IP: 'http.client_ip', + HTTP_SCHEME: 'http.scheme', + + // NOT ON OFFICIAL SPEC + HTTP_ERROR_NAME: 'http.error_name', + HTTP_ERROR_MESSAGE: 'http.error_message', + HTTP_USER_AGENT: 'http.user_agent', +}; diff --git a/packages/opentelemetry-plugin-xml-http-request/src/enums/AttributeNames.ts b/packages/opentelemetry-semantic-conventions/src/trace/index.ts similarity index 63% rename from packages/opentelemetry-plugin-xml-http-request/src/enums/AttributeNames.ts rename to packages/opentelemetry-semantic-conventions/src/trace/index.ts index 29adbdff16..a923ac0a36 100644 --- a/packages/opentelemetry-plugin-xml-http-request/src/enums/AttributeNames.ts +++ b/packages/opentelemetry-semantic-conventions/src/trace/index.ts @@ -13,15 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export enum AttributeNames { - COMPONENT = 'component', - HTTP_HOST = 'http.host', - HTTP_FLAVOR = 'http.flavor', - HTTP_METHOD = 'http.method', - HTTP_SCHEME = 'http.scheme', - HTTP_STATUS_CODE = 'http.status_code', - HTTP_STATUS_TEXT = 'http.status_text', - HTTP_URL = 'http.url', - // NOT ON OFFICIAL SPEC - HTTP_USER_AGENT = 'http.user_agent', -} + +export * from './general'; +export * from './rpc'; +export * from './http'; +export * from './database'; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/rpc.ts b/packages/opentelemetry-semantic-conventions/src/trace/rpc.ts new file mode 100644 index 0000000000..c2681b3d98 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/src/trace/rpc.ts @@ -0,0 +1,25 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const RpcAttribute = { + RPC_SERVICE: 'rpc.service', + + // GRPC (no spec) + GRPC_KIND: 'grpc.kind', // SERVER or CLIENT + GRPC_METHOD: 'grpc.method', + GRPC_STATUS_CODE: 'grpc.status_code', + GRPC_ERROR_NAME: 'grpc.error_name', + GRPC_ERROR_MESSAGE: 'grpc.error_message', +}; diff --git a/packages/opentelemetry-semantic-conventions/src/version.ts b/packages/opentelemetry-semantic-conventions/src/version.ts new file mode 100644 index 0000000000..9e616149a4 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/src/version.ts @@ -0,0 +1,18 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// this is autogenerated file, see scripts/version-update.js +export const VERSION = '0.8.3'; diff --git a/packages/opentelemetry-semantic-conventions/tsconfig.json b/packages/opentelemetry-semantic-conventions/tsconfig.json new file mode 100644 index 0000000000..e4b3b29e6a --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.base", + "compilerOptions": { + "rootDir": ".", + "outDir": "build" + }, + "include": ["src/**/*.ts", "test/**/*.ts"] +}