diff --git a/packages/opentelemetry-instrumentation-fetch/src/enums/AttributeNames.ts b/packages/opentelemetry-instrumentation-fetch/src/enums/AttributeNames.ts index 7b9c935694b..c3ce12fad7f 100644 --- a/packages/opentelemetry-instrumentation-fetch/src/enums/AttributeNames.ts +++ b/packages/opentelemetry-instrumentation-fetch/src/enums/AttributeNames.ts @@ -19,4 +19,6 @@ */ export enum AttributeNames { COMPONENT = 'component', + HTTP_ERROR_NAME = 'http.error_name', + HTTP_STATUS_TEXT = 'http.status_text', } diff --git a/packages/opentelemetry-instrumentation-fetch/src/fetch.ts b/packages/opentelemetry-instrumentation-fetch/src/fetch.ts index 5a87d4b6c0e..93259c80029 100644 --- a/packages/opentelemetry-instrumentation-fetch/src/fetch.ts +++ b/packages/opentelemetry-instrumentation-fetch/src/fetch.ts @@ -23,7 +23,7 @@ import { import * as core from '@opentelemetry/core'; import * as web from '@opentelemetry/web'; import { AttributeNames } from './enums/AttributeNames'; -import { HttpAttribute } from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { FetchError, FetchResponse, SpanData } from './types'; import { VERSION } from './version'; @@ -121,16 +121,16 @@ export class FetchInstrumentation extends InstrumentationBase< response: FetchResponse ): void { const parsedUrl = web.parseUrl(response.url); - span.setAttribute(HttpAttribute.HTTP_STATUS_CODE, response.status); + span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, response.status); if (response.statusText != null) { - span.setAttribute(HttpAttribute.HTTP_STATUS_TEXT, response.statusText); + span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, response.statusText); } - span.setAttribute(HttpAttribute.HTTP_HOST, parsedUrl.host); + span.setAttribute(SemanticAttributes.HTTP_HOST, parsedUrl.host); span.setAttribute( - HttpAttribute.HTTP_SCHEME, + SemanticAttributes.HTTP_SCHEME, parsedUrl.protocol.replace(':', '') ); - span.setAttribute(HttpAttribute.HTTP_USER_AGENT, navigator.userAgent); + span.setAttribute(SemanticAttributes.HTTP_USER_AGENT, navigator.userAgent); } /** @@ -196,8 +196,8 @@ export class FetchInstrumentation extends InstrumentationBase< kind: api.SpanKind.CLIENT, attributes: { [AttributeNames.COMPONENT]: this.moduleName, - [HttpAttribute.HTTP_METHOD]: method, - [HttpAttribute.HTTP_URL]: url, + [SemanticAttributes.HTTP_METHOD]: method, + [SemanticAttributes.HTTP_URL]: url, }, }); } diff --git a/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts b/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts index b6cff23c49a..f0f2065ef4c 100644 --- a/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts +++ b/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts @@ -37,7 +37,7 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { FetchInstrumentation, FetchInstrumentationConfig } from '../src'; import { AttributeNames } from '../src/enums/AttributeNames'; -import { HttpAttribute } from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; class DummySpanExporter implements tracing.SpanExporter { export(spans: any) {} @@ -335,37 +335,37 @@ describe('fetch', () => { assert.strictEqual( attributes[keys[1]], 'GET', - `attributes ${HttpAttribute.HTTP_METHOD} is wrong` + `attributes ${SemanticAttributes.HTTP_METHOD} is wrong` ); assert.strictEqual( attributes[keys[2]], url, - `attributes ${HttpAttribute.HTTP_URL} is wrong` + `attributes ${SemanticAttributes.HTTP_URL} is wrong` ); assert.strictEqual( attributes[keys[3]], 200, - `attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong` + `attributes ${SemanticAttributes.HTTP_STATUS_CODE} is wrong` ); assert.ok( attributes[keys[4]] === 'OK' || attributes[keys[4]] === '', - `attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong` + `attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong` ); assert.ok( (attributes[keys[5]] as string).indexOf('localhost') === 0, - `attributes ${HttpAttribute.HTTP_HOST} is wrong` + `attributes ${SemanticAttributes.HTTP_HOST} is wrong` ); assert.ok( attributes[keys[6]] === 'http' || attributes[keys[6]] === 'https', - `attributes ${HttpAttribute.HTTP_SCHEME} is wrong` + `attributes ${SemanticAttributes.HTTP_SCHEME} is wrong` ); assert.ok( attributes[keys[7]] !== '', - `attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined` + `attributes ${SemanticAttributes.HTTP_USER_AGENT} is not defined` ); assert.ok( (attributes[keys[8]] as number) > 0, - `attributes ${HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH} is <= 0` + `attributes ${SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH} is <= 0` ); assert.strictEqual(keys.length, 9, 'number of attributes is wrong'); @@ -764,7 +764,7 @@ describe('fetch', () => { assert.strictEqual( attributes[keys[3]], 200, - `Missing basic attribute ${HttpAttribute.HTTP_STATUS_CODE}` + `Missing basic attribute ${SemanticAttributes.HTTP_STATUS_CODE}` ); }); }); diff --git a/packages/opentelemetry-instrumentation-grpc/src/enums.ts b/packages/opentelemetry-instrumentation-grpc/src/enums.ts new file mode 100644 index 00000000000..9dfd3e0923e --- /dev/null +++ b/packages/opentelemetry-instrumentation-grpc/src/enums.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. + */ + +/** + * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md + */ +export enum AttributeNames { + GRPC_KIND = 'grpc.kind', // SERVER or CLIENT + GRPC_METHOD = 'grpc.method', + GRPC_ERROR_NAME = 'grpc.error_name', + GRPC_ERROR_MESSAGE = 'grpc.error_message', +} diff --git a/packages/opentelemetry-instrumentation-grpc/src/grpc-js/clientUtils.ts b/packages/opentelemetry-instrumentation-grpc/src/grpc-js/clientUtils.ts index 645149c051b..a53daa3ee07 100644 --- a/packages/opentelemetry-instrumentation-grpc/src/grpc-js/clientUtils.ts +++ b/packages/opentelemetry-instrumentation-grpc/src/grpc-js/clientUtils.ts @@ -24,7 +24,6 @@ import { propagation, context, } from '@opentelemetry/api'; -import { RpcAttribute } from '@opentelemetry/semantic-conventions'; import type * as grpcJs from '@grpc/grpc-js'; import { _grpcStatusCodeToSpanStatus, @@ -33,6 +32,8 @@ import { } from '../utils'; import { CALL_SPAN_ENDED } from './serverUtils'; import { EventEmitter } from 'events'; +import { AttributeNames } from '../enums'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; /** * Parse a package method list and return a list of methods to patch @@ -89,16 +90,19 @@ export function makeGrpcClientRemoteCall( if (err) { if (err.code) { span.setStatus(_grpcStatusCodeToSpanStatus(err.code)); - span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString()); + span.setAttribute( + SemanticAttributes.RPC_GRPC_STATUS_CODE, + err.code.toString() + ); } span.setAttributes({ - [RpcAttribute.GRPC_ERROR_NAME]: err.name, - [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, }); } else { span.setStatus({ code: SpanStatusCode.UNSET }); span.setAttribute( - RpcAttribute.GRPC_STATUS_CODE, + SemanticAttributes.RPC_GRPC_STATUS_CODE, SpanStatusCode.UNSET.toString() ); } @@ -124,8 +128,8 @@ export function makeGrpcClientRemoteCall( } span.setAttributes({ - [RpcAttribute.GRPC_METHOD]: original.path, - [RpcAttribute.GRPC_KIND]: SpanKind.CLIENT, + [AttributeNames.GRPC_METHOD]: original.path, + [AttributeNames.GRPC_KIND]: SpanKind.CLIENT, }); setSpanContext(metadata); @@ -154,8 +158,8 @@ export function makeGrpcClientRemoteCall( message: err.message, }); span.setAttributes({ - [RpcAttribute.GRPC_ERROR_NAME]: err.name, - [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, }); endSpan(); diff --git a/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts b/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts index cfb83288bb0..bec965b22eb 100644 --- a/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts +++ b/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts @@ -42,7 +42,6 @@ import { setSpan, diag, } from '@opentelemetry/api'; -import { RpcAttribute } from '@opentelemetry/semantic-conventions'; import { shouldNotTraceServerCall, handleServerFunction, @@ -54,6 +53,7 @@ import { getMetadata, } from './clientUtils'; import { EventEmitter } from 'events'; +import { AttributeNames } from '../enums'; export class GrpcJsInstrumentation extends InstrumentationBase { constructor( @@ -197,7 +197,7 @@ export class GrpcJsInstrumentation extends InstrumentationBase { const span = instrumentation.tracer .startSpan(spanName, spanOptions) .setAttributes({ - [RpcAttribute.GRPC_KIND]: spanOptions.kind, + [AttributeNames.GRPC_KIND]: spanOptions.kind, }); context.with(setSpan(context.active(), span), () => { diff --git a/packages/opentelemetry-instrumentation-grpc/src/grpc-js/serverUtils.ts b/packages/opentelemetry-instrumentation-grpc/src/grpc-js/serverUtils.ts index eac6238350d..ab953af8c6e 100644 --- a/packages/opentelemetry-instrumentation-grpc/src/grpc-js/serverUtils.ts +++ b/packages/opentelemetry-instrumentation-grpc/src/grpc-js/serverUtils.ts @@ -21,7 +21,6 @@ */ import { context, Span, SpanStatusCode } from '@opentelemetry/api'; -import { RpcAttribute } from '@opentelemetry/semantic-conventions'; import type * as grpcJs from '@grpc/grpc-js'; import type { ServerCallWithMeta, @@ -34,6 +33,8 @@ import { _methodIsIgnored, } from '../utils'; import { IgnoreMatcher } from '../types'; +import { AttributeNames } from '../enums'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; export const CALL_SPAN_ENDED = Symbol('opentelemetry call span ended'); @@ -70,7 +71,7 @@ function serverStreamAndBidiHandler( code: SpanStatusCode.UNSET, }); span.setAttribute( - RpcAttribute.GRPC_STATUS_CODE, + SemanticAttributes.RPC_GRPC_STATUS_CODE, SpanStatusCode.OK.toString() ); @@ -90,8 +91,8 @@ function serverStreamAndBidiHandler( message: err.message, }); span.setAttributes({ - [RpcAttribute.GRPC_ERROR_NAME]: err.name, - [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, }); endSpan(); }); @@ -121,16 +122,19 @@ function clientStreamAndUnaryHandler( code: _grpcStatusCodeToOpenTelemetryStatusCode(err.code), message: err.message, }); - span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString()); + span.setAttribute( + SemanticAttributes.RPC_GRPC_STATUS_CODE, + err.code.toString() + ); } span.setAttributes({ - [RpcAttribute.GRPC_ERROR_NAME]: err.name, - [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, }); } else { span.setStatus({ code: SpanStatusCode.UNSET }); span.setAttribute( - RpcAttribute.GRPC_STATUS_CODE, + SemanticAttributes.RPC_GRPC_STATUS_CODE, SpanStatusCode.OK.toString() ); } diff --git a/packages/opentelemetry-instrumentation-grpc/src/grpc/clientUtils.ts b/packages/opentelemetry-instrumentation-grpc/src/grpc/clientUtils.ts index fda7b4c7ed6..503ab2c1362 100644 --- a/packages/opentelemetry-instrumentation-grpc/src/grpc/clientUtils.ts +++ b/packages/opentelemetry-instrumentation-grpc/src/grpc/clientUtils.ts @@ -17,7 +17,7 @@ import type * as grpcTypes from 'grpc'; import type * as events from 'events'; import { SendUnaryDataCallback, GrpcClientFunc } from './types'; -import { RpcAttribute } from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { context, Span, @@ -31,6 +31,7 @@ import { _grpcStatusCodeToOpenTelemetryStatusCode, findIndex, } from '../utils'; +import { AttributeNames } from '../enums'; /** * This method handles the client remote call @@ -55,16 +56,19 @@ export const makeGrpcClientRemoteCall = function ( if (err) { if (err.code) { span.setStatus(_grpcStatusCodeToSpanStatus(err.code)); - span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString()); + span.setAttribute( + SemanticAttributes.RPC_GRPC_STATUS_CODE, + err.code.toString() + ); } span.setAttributes({ - [RpcAttribute.GRPC_ERROR_NAME]: err.name, - [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, }); } else { span.setStatus({ code: SpanStatusCode.UNSET }); span.setAttribute( - RpcAttribute.GRPC_STATUS_CODE, + SemanticAttributes.RPC_GRPC_STATUS_CODE, grpcClient.status.OK.toString() ); } @@ -96,8 +100,8 @@ export const makeGrpcClientRemoteCall = function ( span.addEvent('sent'); span.setAttributes({ - [RpcAttribute.GRPC_METHOD]: original.path, - [RpcAttribute.GRPC_KIND]: SpanKind.CLIENT, + [AttributeNames.GRPC_METHOD]: original.path, + [AttributeNames.GRPC_KIND]: SpanKind.CLIENT, }); setSpanContext(metadata); @@ -123,8 +127,8 @@ export const makeGrpcClientRemoteCall = function ( message: err.message, }); span.setAttributes({ - [RpcAttribute.GRPC_ERROR_NAME]: err.name, - [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, }); endSpan(); } @@ -135,7 +139,7 @@ export const makeGrpcClientRemoteCall = function ( (status: SpanStatus) => { span.setStatus({ code: SpanStatusCode.UNSET }); span.setAttribute( - RpcAttribute.GRPC_STATUS_CODE, + SemanticAttributes.RPC_GRPC_STATUS_CODE, status.code.toString() ); endSpan(); diff --git a/packages/opentelemetry-instrumentation-grpc/src/grpc/index.ts b/packages/opentelemetry-instrumentation-grpc/src/grpc/index.ts index 0fe0d30bab9..25bf00bb2c1 100644 --- a/packages/opentelemetry-instrumentation-grpc/src/grpc/index.ts +++ b/packages/opentelemetry-instrumentation-grpc/src/grpc/index.ts @@ -29,7 +29,6 @@ import { GrpcClientFunc, } from './types'; import { GrpcInstrumentationConfig } from '../types'; -import { RpcAttribute } from '@opentelemetry/semantic-conventions'; import { context, propagation, @@ -45,6 +44,7 @@ import { } from './serverUtils'; import { makeGrpcClientRemoteCall, getMetadata } from './clientUtils'; import { _methodIsIgnored } from '../utils'; +import { AttributeNames } from '../enums'; /** * Holding reference to grpc module here to access constant of grpc modules @@ -205,7 +205,7 @@ export class GrpcNativeInstrumentation extends InstrumentationBase< const span = instrumentation.tracer .startSpan(spanName, spanOptions) .setAttributes({ - [RpcAttribute.GRPC_KIND]: spanOptions.kind, + [AttributeNames.GRPC_KIND]: spanOptions.kind, }); context.with(setSpan(context.active(), span), () => { diff --git a/packages/opentelemetry-instrumentation-grpc/src/grpc/serverUtils.ts b/packages/opentelemetry-instrumentation-grpc/src/grpc/serverUtils.ts index cd928a4665f..9d6673c09fd 100644 --- a/packages/opentelemetry-instrumentation-grpc/src/grpc/serverUtils.ts +++ b/packages/opentelemetry-instrumentation-grpc/src/grpc/serverUtils.ts @@ -17,13 +17,14 @@ import type * as grpcTypes from 'grpc'; import { SendUnaryDataCallback, ServerCallWithMeta } from './types'; import { GrpcNativeInstrumentation } from './'; -import { RpcAttribute } from '@opentelemetry/semantic-conventions'; import { context, Span, SpanStatusCode } from '@opentelemetry/api'; import { _grpcStatusCodeToOpenTelemetryStatusCode, _grpcStatusCodeToSpanStatus, _methodIsIgnored, } from '../utils'; +import { AttributeNames } from '../enums'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; export const clientStreamAndUnaryHandler = function ( grpcClient: typeof grpcTypes, @@ -47,16 +48,19 @@ export const clientStreamAndUnaryHandler = function ( code: _grpcStatusCodeToOpenTelemetryStatusCode(err.code), message: err.message, }); - span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString()); + span.setAttribute( + SemanticAttributes.RPC_GRPC_STATUS_CODE, + err.code.toString() + ); } span.setAttributes({ - [RpcAttribute.GRPC_ERROR_NAME]: err.name, - [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, }); } else { span.setStatus({ code: SpanStatusCode.UNSET }); span.setAttribute( - RpcAttribute.GRPC_STATUS_CODE, + SemanticAttributes.RPC_GRPC_STATUS_CODE, grpcClient.status.OK.toString() ); } @@ -89,7 +93,7 @@ export const serverStreamAndBidiHandler = function ( call.on('finish', () => { span.setStatus(_grpcStatusCodeToSpanStatus(call.status.code)); span.setAttribute( - RpcAttribute.GRPC_STATUS_CODE, + SemanticAttributes.RPC_GRPC_STATUS_CODE, call.status.code.toString() ); @@ -107,8 +111,8 @@ export const serverStreamAndBidiHandler = function ( }); span.addEvent('finished with error'); span.setAttributes({ - [RpcAttribute.GRPC_ERROR_NAME]: err.name, - [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, + [AttributeNames.GRPC_ERROR_NAME]: err.name, + [AttributeNames.GRPC_ERROR_MESSAGE]: err.message, }); endSpan(); }); diff --git a/packages/opentelemetry-instrumentation-http/src/enums.ts b/packages/opentelemetry-instrumentation-http/src/enums.ts new file mode 100644 index 00000000000..f9b8be3c8ea --- /dev/null +++ b/packages/opentelemetry-instrumentation-http/src/enums.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + +/** + * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md + */ +export enum AttributeNames { + HTTP_ERROR_NAME = 'http.error_name', + HTTP_ERROR_MESSAGE = 'http.error_message', + HTTP_STATUS_TEXT = 'http.status_text', +} diff --git a/packages/opentelemetry-instrumentation-http/src/utils.ts b/packages/opentelemetry-instrumentation-http/src/utils.ts index d0ac02cabab..4802ecca218 100644 --- a/packages/opentelemetry-instrumentation-http/src/utils.ts +++ b/packages/opentelemetry-instrumentation-http/src/utils.ts @@ -20,8 +20,8 @@ import { SpanStatus, } from '@opentelemetry/api'; import { - HttpAttribute, - GeneralAttribute, + NetTransportValues, + SemanticAttributes, } from '@opentelemetry/semantic-conventions'; import { ClientRequest, @@ -33,6 +33,7 @@ import { } from 'http'; import { Socket } from 'net'; import * as url from 'url'; +import { AttributeNames } from './enums'; import { Err, IgnoreMatcher, ParsedRequestOptions } from './types'; /** @@ -158,8 +159,8 @@ export const setSpanWithError = ( const message = error.message; span.setAttributes({ - [HttpAttribute.HTTP_ERROR_NAME]: error.name, - [HttpAttribute.HTTP_ERROR_MESSAGE]: message, + [AttributeNames.HTTP_ERROR_NAME]: error.name, + [AttributeNames.HTTP_ERROR_MESSAGE]: message, }); if (!obj) { @@ -194,9 +195,11 @@ export const setRequestContentLengthAttribute = ( if (length === null) return; if (isCompressed(request.headers)) { - attributes[HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH] = length; + attributes[SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH] = length; } else { - attributes[HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED] = length; + attributes[ + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED + ] = length; } }; @@ -213,10 +216,10 @@ export const setResponseContentLengthAttribute = ( if (length === null) return; if (isCompressed(response.headers)) { - attributes[HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH] = length; + attributes[SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH] = length; } else { attributes[ - HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED ] = length; } }; @@ -341,18 +344,18 @@ export const getOutgoingRequestAttributes = ( const headers = requestOptions.headers || {}; const userAgent = headers['user-agent']; const attributes: SpanAttributes = { - [HttpAttribute.HTTP_URL]: getAbsoluteUrl( + [SemanticAttributes.HTTP_URL]: getAbsoluteUrl( requestOptions, headers, `${options.component}:` ), - [HttpAttribute.HTTP_METHOD]: method, - [HttpAttribute.HTTP_TARGET]: requestOptions.path || '/', - [GeneralAttribute.NET_PEER_NAME]: hostname, + [SemanticAttributes.HTTP_METHOD]: method, + [SemanticAttributes.HTTP_TARGET]: requestOptions.path || '/', + [SemanticAttributes.NET_PEER_NAME]: hostname, }; if (userAgent !== undefined) { - attributes[HttpAttribute.HTTP_USER_AGENT] = userAgent; + attributes[SemanticAttributes.HTTP_USER_AGENT] = userAgent; } return attributes; }; @@ -364,11 +367,11 @@ export const getOutgoingRequestAttributes = ( export const getAttributesFromHttpKind = (kind?: string): SpanAttributes => { const attributes: SpanAttributes = {}; if (kind) { - attributes[HttpAttribute.HTTP_FLAVOR] = kind; + attributes[SemanticAttributes.HTTP_FLAVOR] = kind; if (kind.toUpperCase() !== 'QUIC') { - attributes[GeneralAttribute.NET_TRANSPORT] = GeneralAttribute.IP_TCP; + attributes[SemanticAttributes.NET_TRANSPORT] = NetTransportValues.IP_TCP; } else { - attributes[GeneralAttribute.NET_TRANSPORT] = GeneralAttribute.IP_UDP; + attributes[SemanticAttributes.NET_TRANSPORT] = NetTransportValues.IP_UDP; } } return attributes; @@ -386,15 +389,15 @@ export const getOutgoingRequestAttributesOnResponse = ( const { statusCode, statusMessage, httpVersion, socket } = response; const { remoteAddress, remotePort } = socket; const attributes: SpanAttributes = { - [GeneralAttribute.NET_PEER_IP]: remoteAddress, - [GeneralAttribute.NET_PEER_PORT]: remotePort, - [HttpAttribute.HTTP_HOST]: `${options.hostname}:${remotePort}`, + [SemanticAttributes.NET_PEER_IP]: remoteAddress, + [SemanticAttributes.NET_PEER_PORT]: remotePort, + [SemanticAttributes.HTTP_HOST]: `${options.hostname}:${remotePort}`, }; setResponseContentLengthAttribute(response, attributes); if (statusCode) { - attributes[HttpAttribute.HTTP_STATUS_CODE] = statusCode; - attributes[HttpAttribute.HTTP_STATUS_TEXT] = ( + attributes[SemanticAttributes.HTTP_STATUS_CODE] = statusCode; + attributes[AttributeNames.HTTP_STATUS_TEXT] = ( statusMessage || '' ).toUpperCase(); } @@ -425,31 +428,31 @@ export const getIncomingRequestAttributes = ( 'localhost'; const serverName = options.serverName; const attributes: SpanAttributes = { - [HttpAttribute.HTTP_URL]: getAbsoluteUrl( + [SemanticAttributes.HTTP_URL]: getAbsoluteUrl( requestUrl, headers, `${options.component}:` ), - [HttpAttribute.HTTP_HOST]: host, - [GeneralAttribute.NET_HOST_NAME]: hostname, - [HttpAttribute.HTTP_METHOD]: method, + [SemanticAttributes.HTTP_HOST]: host, + [SemanticAttributes.NET_HOST_NAME]: hostname, + [SemanticAttributes.HTTP_METHOD]: method, }; if (typeof ips === 'string') { - attributes[HttpAttribute.HTTP_CLIENT_IP] = ips.split(',')[0]; + attributes[SemanticAttributes.HTTP_CLIENT_IP] = ips.split(',')[0]; } if (typeof serverName === 'string') { - attributes[HttpAttribute.HTTP_SERVER_NAME] = serverName; + attributes[SemanticAttributes.HTTP_SERVER_NAME] = serverName; } if (requestUrl) { - attributes[HttpAttribute.HTTP_ROUTE] = requestUrl.pathname || '/'; - attributes[HttpAttribute.HTTP_TARGET] = requestUrl.pathname || '/'; + attributes[SemanticAttributes.HTTP_ROUTE] = requestUrl.pathname || '/'; + attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.pathname || '/'; } if (userAgent !== undefined) { - attributes[HttpAttribute.HTTP_USER_AGENT] = userAgent; + attributes[SemanticAttributes.HTTP_USER_AGENT] = userAgent; } setRequestContentLengthAttribute(request, attributes); @@ -483,16 +486,16 @@ export const getIncomingRequestAttributesOnResponse = ( : undefined; const attributes: SpanAttributes = { - [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(), + [SemanticAttributes.NET_HOST_IP]: localAddress, + [SemanticAttributes.NET_HOST_PORT]: localPort, + [SemanticAttributes.NET_PEER_IP]: remoteAddress, + [SemanticAttributes.NET_PEER_PORT]: remotePort, + [SemanticAttributes.HTTP_STATUS_CODE]: statusCode, + [AttributeNames.HTTP_STATUS_TEXT]: (statusMessage || '').toUpperCase(), }; if (route !== undefined) { - attributes[HttpAttribute.HTTP_ROUTE] = route; + attributes[SemanticAttributes.HTTP_ROUTE] = route; } return attributes; }; diff --git a/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts index 736daa62331..2361b26756c 100644 --- a/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts @@ -28,8 +28,8 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import { - HttpAttribute, - GeneralAttribute, + NetTransportValues, + SemanticAttributes, } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as nock from 'nock'; @@ -172,11 +172,11 @@ describe('HttpInstrumentation', () => { assertSpan(incomingSpan, SpanKind.SERVER, validations); assertSpan(outgoingSpan, SpanKind.CLIENT, validations); assert.strictEqual( - incomingSpan.attributes[GeneralAttribute.NET_HOST_PORT], + incomingSpan.attributes[SemanticAttributes.NET_HOST_PORT], serverPort ); assert.strictEqual( - outgoingSpan.attributes[GeneralAttribute.NET_PEER_PORT], + outgoingSpan.attributes[SemanticAttributes.NET_PEER_PORT], serverPort ); }); @@ -249,25 +249,28 @@ describe('HttpInstrumentation', () => { assert.strictEqual(spans.length, 2); assert.strictEqual( - incomingSpan.attributes[HttpAttribute.HTTP_CLIENT_IP], + incomingSpan.attributes[SemanticAttributes.HTTP_CLIENT_IP], '' ); assert.strictEqual( - incomingSpan.attributes[GeneralAttribute.NET_HOST_PORT], + incomingSpan.attributes[SemanticAttributes.NET_HOST_PORT], serverPort ); assert.strictEqual( - outgoingSpan.attributes[GeneralAttribute.NET_PEER_PORT], + outgoingSpan.attributes[SemanticAttributes.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[GeneralAttribute.NET_TRANSPORT], - GeneralAttribute.IP_TCP + span.attributes[SemanticAttributes.HTTP_FLAVOR], + '1.1' + ); + assert.strictEqual( + span.attributes[SemanticAttributes.NET_TRANSPORT], + NetTransportValues.IP_TCP ); assertSpan(span, kind, validations); }); @@ -658,7 +661,7 @@ describe('HttpInstrumentation', () => { assert.strictEqual(spans.length, 1); assert.ok(Object.keys(span.attributes).length > 6); assert.strictEqual( - span.attributes[HttpAttribute.HTTP_STATUS_CODE], + span.attributes[SemanticAttributes.HTTP_STATUS_CODE], 404 ); assert.strictEqual(span.status.code, SpanStatusCode.ERROR); diff --git a/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts b/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts index 86de0fbefa9..fe473f408f8 100644 --- a/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts +++ b/packages/opentelemetry-instrumentation-http/test/functionals/https-enable.test.ts @@ -30,8 +30,8 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import { - GeneralAttribute, - HttpAttribute, + NetTransportValues, + SemanticAttributes, } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as fs from 'fs'; @@ -160,11 +160,11 @@ describe('HttpsInstrumentation', () => { assertSpan(incomingSpan, SpanKind.SERVER, validations); assertSpan(outgoingSpan, SpanKind.CLIENT, validations); assert.strictEqual( - incomingSpan.attributes[GeneralAttribute.NET_HOST_PORT], + incomingSpan.attributes[SemanticAttributes.NET_HOST_PORT], serverPort ); assert.strictEqual( - outgoingSpan.attributes[GeneralAttribute.NET_PEER_PORT], + outgoingSpan.attributes[SemanticAttributes.NET_PEER_PORT], serverPort ); }); @@ -240,15 +240,15 @@ describe('HttpsInstrumentation', () => { assert.strictEqual(spans.length, 2); assert.strictEqual( - incomingSpan.attributes[HttpAttribute.HTTP_CLIENT_IP], + incomingSpan.attributes[SemanticAttributes.HTTP_CLIENT_IP], '' ); assert.strictEqual( - incomingSpan.attributes[GeneralAttribute.NET_HOST_PORT], + incomingSpan.attributes[SemanticAttributes.NET_HOST_PORT], serverPort ); assert.strictEqual( - outgoingSpan.attributes[GeneralAttribute.NET_PEER_PORT], + outgoingSpan.attributes[SemanticAttributes.NET_PEER_PORT], serverPort ); @@ -256,10 +256,13 @@ describe('HttpsInstrumentation', () => { { 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[GeneralAttribute.NET_TRANSPORT], - GeneralAttribute.IP_TCP + span.attributes[SemanticAttributes.HTTP_FLAVOR], + '1.1' + ); + assert.strictEqual( + span.attributes[SemanticAttributes.NET_TRANSPORT], + NetTransportValues.IP_TCP ); assertSpan(span, kind, validations); }); @@ -658,7 +661,7 @@ describe('HttpsInstrumentation', () => { assert.strictEqual(spans.length, 1); assert.ok(Object.keys(span.attributes).length > 6); assert.strictEqual( - span.attributes[HttpAttribute.HTTP_STATUS_CODE], + span.attributes[SemanticAttributes.HTTP_STATUS_CODE], 404 ); assert.strictEqual(span.status.code, SpanStatusCode.ERROR); diff --git a/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts b/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts index 26bef9061ce..2e5fdcce13e 100644 --- a/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts +++ b/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts @@ -21,7 +21,7 @@ import { TraceFlags, } from '@opentelemetry/api'; import { BasicTracerProvider, Span } from '@opentelemetry/tracing'; -import { HttpAttribute } from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as http from 'http'; import { IncomingMessage, ServerResponse } from 'http'; @@ -30,6 +30,7 @@ import * as sinon from 'sinon'; import * as url from 'url'; import { IgnoreMatcher } from '../../src/types'; import * as utils from '../../src/utils'; +import { AttributeNames } from '../../src/enums'; describe('Utility', () => { describe('parseResponseStatus()', () => { @@ -258,10 +259,10 @@ describe('Utility', () => { utils.setSpanWithError(span, new Error(errorMessage), obj as any); const attributes = span.attributes; assert.strictEqual( - attributes[HttpAttribute.HTTP_ERROR_MESSAGE], + attributes[AttributeNames.HTTP_ERROR_MESSAGE], errorMessage ); - assert.ok(attributes[HttpAttribute.HTTP_ERROR_NAME]); + assert.ok(attributes[AttributeNames.HTTP_ERROR_NAME]); } }); }); @@ -293,7 +294,7 @@ describe('Utility', () => { const attributes = utils.getIncomingRequestAttributesOnResponse(request, { socket: {}, } as ServerResponse & { socket: Socket }); - assert.deepEqual(attributes[HttpAttribute.HTTP_ROUTE], '/test/toto'); + assert.deepEqual(attributes[SemanticAttributes.HTTP_ROUTE], '/test/toto'); }); it('should succesfully process without middleware stack', () => { @@ -303,7 +304,7 @@ describe('Utility', () => { const attributes = utils.getIncomingRequestAttributesOnResponse(request, { socket: {}, } as ServerResponse & { socket: Socket }); - assert.deepEqual(attributes[HttpAttribute.HTTP_ROUTE], undefined); + assert.deepEqual(attributes[SemanticAttributes.HTTP_ROUTE], undefined); }); }); // Verify the key in the given attributes is set to the given value, @@ -313,14 +314,14 @@ describe('Utility', () => { key: string | undefined, value: number ) { - const httpAttributes = [ - HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, - HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH, - HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED, - HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH, + const SemanticAttributess = [ + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED, + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, ]; - for (const attr of httpAttributes) { + for (const attr of SemanticAttributess) { if (attr === key) { assert.strictEqual(attributes[attr], value); } else { @@ -341,7 +342,7 @@ describe('Utility', () => { verifyValueInAttributes( attributes, - HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED, + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED, 1200 ); }); @@ -357,7 +358,7 @@ describe('Utility', () => { verifyValueInAttributes( attributes, - HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED, + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED, 1200 ); }); @@ -373,7 +374,7 @@ describe('Utility', () => { verifyValueInAttributes( attributes, - HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH, + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 1200 ); }); @@ -392,7 +393,7 @@ describe('Utility', () => { verifyValueInAttributes( attributes, - HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, 1200 ); }); @@ -411,7 +412,7 @@ describe('Utility', () => { verifyValueInAttributes( attributes, - HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, 1200 ); }); @@ -430,7 +431,7 @@ describe('Utility', () => { verifyValueInAttributes( attributes, - HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH, + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 1200 ); }); diff --git a/packages/opentelemetry-instrumentation-http/test/integrations/http-enable.test.ts b/packages/opentelemetry-instrumentation-http/test/integrations/http-enable.test.ts index 9995cd985c9..75d21dd7318 100644 --- a/packages/opentelemetry-instrumentation-http/test/integrations/http-enable.test.ts +++ b/packages/opentelemetry-instrumentation-http/test/integrations/http-enable.test.ts @@ -16,8 +16,9 @@ import { SpanKind, Span, context, propagation } from '@opentelemetry/api'; import { - HttpAttribute, - GeneralAttribute, + HttpFlavorValues, + NetTransportValues, + SemanticAttributes, } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as url from 'url'; @@ -229,10 +230,13 @@ describe('HttpInstrumentation Integration tests', () => { assert.strictEqual(spans.length, 2); assert.strictEqual(span.name, 'HTTP GET'); assert.strictEqual(result.reqHeaders['x-foo'], 'foo'); - assert.strictEqual(span.attributes[HttpAttribute.HTTP_FLAVOR], '1.1'); assert.strictEqual( - span.attributes[GeneralAttribute.NET_TRANSPORT], - GeneralAttribute.IP_TCP + span.attributes[SemanticAttributes.HTTP_FLAVOR], + HttpFlavorValues.HTTP_1_1 + ); + assert.strictEqual( + span.attributes[SemanticAttributes.NET_TRANSPORT], + NetTransportValues.IP_TCP ); assertSpan(span, SpanKind.CLIENT, validations); }); diff --git a/packages/opentelemetry-instrumentation-http/test/integrations/https-enable.test.ts b/packages/opentelemetry-instrumentation-http/test/integrations/https-enable.test.ts index 7df9f3e771b..729aa1fe912 100644 --- a/packages/opentelemetry-instrumentation-http/test/integrations/https-enable.test.ts +++ b/packages/opentelemetry-instrumentation-http/test/integrations/https-enable.test.ts @@ -16,8 +16,9 @@ import { SpanKind, Span, context, propagation } from '@opentelemetry/api'; import { - HttpAttribute, - GeneralAttribute, + HttpFlavorValues, + NetTransportValues, + SemanticAttributes, } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as http from 'http'; @@ -238,10 +239,13 @@ describe('HttpsInstrumentation Integration tests', () => { assert.strictEqual(spans.length, 2); assert.strictEqual(span.name, 'HTTPS GET'); assert.strictEqual(result.reqHeaders['x-foo'], 'foo'); - assert.strictEqual(span.attributes[HttpAttribute.HTTP_FLAVOR], '1.1'); assert.strictEqual( - span.attributes[GeneralAttribute.NET_TRANSPORT], - GeneralAttribute.IP_TCP + span.attributes[SemanticAttributes.HTTP_FLAVOR], + HttpFlavorValues.HTTP_1_1 + ); + assert.strictEqual( + span.attributes[SemanticAttributes.NET_TRANSPORT], + NetTransportValues.IP_TCP ); assertSpan(span, SpanKind.CLIENT, validations); }); diff --git a/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts b/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts index 97e67f7557a..ff0229c1356 100644 --- a/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts +++ b/packages/opentelemetry-instrumentation-http/test/utils/assertSpan.ts @@ -16,14 +16,12 @@ import { SpanKind, SpanStatus } from '@opentelemetry/api'; import { hrTimeToNanoseconds } from '@opentelemetry/core'; import { ReadableSpan } from '@opentelemetry/tracing'; -import { - GeneralAttribute, - HttpAttribute, -} from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as http from 'http'; import * as utils from '../../src/utils'; import { DummyPropagation } from './DummyPropagation'; +import { AttributeNames } from '../../src/enums'; export const assertSpan = ( span: ReadableSpan, @@ -49,19 +47,19 @@ export const assertSpan = ( `${validations.component.toUpperCase()} ${validations.httpMethod}` ); assert.strictEqual( - span.attributes[HttpAttribute.HTTP_ERROR_MESSAGE], + span.attributes[AttributeNames.HTTP_ERROR_MESSAGE], span.status.message ); assert.strictEqual( - span.attributes[HttpAttribute.HTTP_METHOD], + span.attributes[SemanticAttributes.HTTP_METHOD], validations.httpMethod ); assert.strictEqual( - span.attributes[HttpAttribute.HTTP_TARGET], + span.attributes[SemanticAttributes.HTTP_TARGET], validations.path || validations.pathname ); assert.strictEqual( - span.attributes[HttpAttribute.HTTP_STATUS_CODE], + span.attributes[SemanticAttributes.HTTP_STATUS_CODE], validations.httpStatusCode ); @@ -81,7 +79,7 @@ export const assertSpan = ( const userAgent = validations.reqHeaders['user-agent']; if (userAgent) { assert.strictEqual( - span.attributes[HttpAttribute.HTTP_USER_AGENT], + span.attributes[SemanticAttributes.HTTP_USER_AGENT], userAgent ); } @@ -95,34 +93,34 @@ export const assertSpan = ( validations.resHeaders['content-encoding'] !== 'identity' ) { assert.strictEqual( - span.attributes[HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH], + span.attributes[SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH], contentLength ); } else { assert.strictEqual( span.attributes[ - HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED ], contentLength ); } } assert.strictEqual( - span.attributes[GeneralAttribute.NET_PEER_NAME], + span.attributes[SemanticAttributes.NET_PEER_NAME], validations.hostname, 'must be consistent (PEER_NAME and hostname)' ); assert.ok( - span.attributes[GeneralAttribute.NET_PEER_IP], + span.attributes[SemanticAttributes.NET_PEER_IP], 'must have PEER_IP' ); assert.ok( - span.attributes[GeneralAttribute.NET_PEER_PORT], + span.attributes[SemanticAttributes.NET_PEER_PORT], 'must have PEER_PORT' ); assert.ok( - (span.attributes[HttpAttribute.HTTP_URL] as string).indexOf( - span.attributes[GeneralAttribute.NET_PEER_NAME] as string + (span.attributes[SemanticAttributes.HTTP_URL] as string).indexOf( + span.attributes[SemanticAttributes.NET_PEER_NAME] as string ) > -1, 'must be consistent' ); @@ -136,13 +134,13 @@ export const assertSpan = ( validations.reqHeaders['content-encoding'] !== 'identity' ) { assert.strictEqual( - span.attributes[HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH], + span.attributes[SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH], contentLength ); } else { assert.strictEqual( span.attributes[ - HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED ], contentLength ); @@ -150,16 +148,16 @@ export const assertSpan = ( } if (validations.serverName) { assert.strictEqual( - span.attributes[HttpAttribute.HTTP_SERVER_NAME], + span.attributes[SemanticAttributes.HTTP_SERVER_NAME], validations.serverName, ' must have serverName attribute' ); assert.ok( - span.attributes[GeneralAttribute.NET_HOST_PORT], + span.attributes[SemanticAttributes.NET_HOST_PORT], 'must have HOST_PORT' ); assert.ok( - span.attributes[GeneralAttribute.NET_HOST_IP], + span.attributes[SemanticAttributes.NET_HOST_IP], 'must have HOST_IP' ); } diff --git a/packages/opentelemetry-instrumentation-xml-http-request/src/enums/AttributeNames.ts b/packages/opentelemetry-instrumentation-xml-http-request/src/enums/AttributeNames.ts new file mode 100644 index 00000000000..dd1fce77bed --- /dev/null +++ b/packages/opentelemetry-instrumentation-xml-http-request/src/enums/AttributeNames.ts @@ -0,0 +1,22 @@ +/* + * 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. + */ + +/** + * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md + */ +export enum AttributeNames { + HTTP_STATUS_TEXT = 'http.status_text', +} diff --git a/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts b/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts index b65afdc6949..ab9f4f4fa93 100644 --- a/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts +++ b/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts @@ -21,7 +21,7 @@ import { InstrumentationConfig, } from '@opentelemetry/instrumentation'; import { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core'; -import { HttpAttribute } from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { addSpanNetworkEvents, getResource, @@ -37,6 +37,7 @@ import { XhrMem, } from './types'; import { VERSION } from './version'; +import { AttributeNames } from './enums/AttributeNames'; // how long to wait for observer to collect information about resources // this is needed as event "load" is called before observer @@ -150,20 +151,23 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase { // content length comes from the PerformanceTiming resource; this ensures that our // matching logic found the right one assert.ok( - (span.attributes[HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH] as any) > - 0 + (span.attributes[ + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH + ] as any) > 0 ); done(); }, 500); diff --git a/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts b/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts index 8537fe8c3ad..d9818bb9c0d 100644 --- a/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts +++ b/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts @@ -25,7 +25,7 @@ import { } from '@opentelemetry/propagator-b3'; import { ZoneContextManager } from '@opentelemetry/context-zone'; import * as tracing from '@opentelemetry/tracing'; -import { HttpAttribute } from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { PerformanceTimingNames as PTN, WebTracerProvider, @@ -35,6 +35,7 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { EventNames } from '../src/enums/EventNames'; import { XMLHttpRequestInstrumentation } from '../src/xhr'; +import { AttributeNames } from '../src/enums/AttributeNames'; class DummySpanExporter implements tracing.SpanExporter { export(spans: any) {} @@ -289,39 +290,39 @@ describe('xhr', () => { assert.strictEqual( attributes[keys[0]], 'GET', - `attributes ${HttpAttribute.HTTP_METHOD} is wrong` + `attributes ${SemanticAttributes.HTTP_METHOD} is wrong` ); assert.strictEqual( attributes[keys[1]], url, - `attributes ${HttpAttribute.HTTP_URL} is wrong` + `attributes ${SemanticAttributes.HTTP_URL} is wrong` ); assert.ok( (attributes[keys[2]] as number) > 0, - 'attributes ${HttpAttributes.HTTP_RESPONSE_CONTENT_SIZE} <= 0' + 'attributes ${SemanticAttributess.HTTP_RESPONSE_CONTENT_SIZE} <= 0' ); assert.strictEqual( attributes[keys[3]], 200, - `attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong` + `attributes ${SemanticAttributes.HTTP_STATUS_CODE} is wrong` ); assert.strictEqual( attributes[keys[4]], 'OK', - `attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong` + `attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong` ); assert.strictEqual( attributes[keys[5]], parseUrl(url).host, - `attributes ${HttpAttribute.HTTP_HOST} is wrong` + `attributes ${SemanticAttributes.HTTP_HOST} is wrong` ); assert.ok( attributes[keys[6]] === 'http' || attributes[keys[6]] === 'https', - `attributes ${HttpAttribute.HTTP_SCHEME} is wrong` + `attributes ${SemanticAttributes.HTTP_SCHEME} is wrong` ); assert.ok( attributes[keys[7]] !== '', - `attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined` + `attributes ${SemanticAttributes.HTTP_USER_AGENT} is not defined` ); assert.strictEqual(keys.length, 8, 'number of attributes is wrong'); @@ -693,7 +694,7 @@ describe('xhr', () => { assert.strictEqual( attributes[keys[1]], secondUrl, - `attribute ${HttpAttribute.HTTP_URL} is wrong` + `attribute ${SemanticAttributes.HTTP_URL} is wrong` ); }); }); @@ -789,40 +790,40 @@ describe('xhr', () => { assert.strictEqual( attributes[keys[0]], 'GET', - `attributes ${HttpAttribute.HTTP_METHOD} is wrong` + `attributes ${SemanticAttributes.HTTP_METHOD} is wrong` ); assert.strictEqual( attributes[keys[1]], url, - `attributes ${HttpAttribute.HTTP_URL} is wrong` + `attributes ${SemanticAttributes.HTTP_URL} is wrong` ); assert.strictEqual( attributes[keys[2]], 0, - `attributes ${HttpAttribute.HTTP_REQUEST_CONTENT_LENGTH} is wrong` + `attributes ${SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH} is wrong` ); assert.strictEqual( attributes[keys[3]], 400, - `attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong` + `attributes ${SemanticAttributes.HTTP_STATUS_CODE} is wrong` ); assert.strictEqual( attributes[keys[4]], 'Bad Request', - `attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong` + `attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong` ); assert.strictEqual( attributes[keys[5]], 'raw.githubusercontent.com', - `attributes ${HttpAttribute.HTTP_HOST} is wrong` + `attributes ${SemanticAttributes.HTTP_HOST} is wrong` ); assert.ok( attributes[keys[6]] === 'http' || attributes[keys[6]] === 'https', - `attributes ${HttpAttribute.HTTP_SCHEME} is wrong` + `attributes ${SemanticAttributes.HTTP_SCHEME} is wrong` ); assert.ok( attributes[keys[7]] !== '', - `attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined` + `attributes ${SemanticAttributes.HTTP_USER_AGENT} is not defined` ); assert.strictEqual(keys.length, 8, 'number of attributes is wrong'); @@ -924,35 +925,35 @@ describe('xhr', () => { assert.strictEqual( attributes[keys[0]], 'GET', - `attributes ${HttpAttribute.HTTP_METHOD} is wrong` + `attributes ${SemanticAttributes.HTTP_METHOD} is wrong` ); assert.strictEqual( attributes[keys[1]], url, - `attributes ${HttpAttribute.HTTP_URL} is wrong` + `attributes ${SemanticAttributes.HTTP_URL} is wrong` ); assert.strictEqual( attributes[keys[2]], 0, - `attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong` + `attributes ${SemanticAttributes.HTTP_STATUS_CODE} is wrong` ); assert.strictEqual( attributes[keys[3]], '', - `attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong` + `attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong` ); assert.strictEqual( attributes[keys[4]], 'raw.githubusercontent.com', - `attributes ${HttpAttribute.HTTP_HOST} is wrong` + `attributes ${SemanticAttributes.HTTP_HOST} is wrong` ); assert.ok( attributes[keys[5]] === 'http' || attributes[keys[5]] === 'https', - `attributes ${HttpAttribute.HTTP_SCHEME} is wrong` + `attributes ${SemanticAttributes.HTTP_SCHEME} is wrong` ); assert.ok( attributes[keys[6]] !== '', - `attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined` + `attributes ${SemanticAttributes.HTTP_USER_AGENT} is not defined` ); assert.strictEqual(keys.length, 7, 'number of attributes is wrong'); @@ -1016,35 +1017,35 @@ describe('xhr', () => { assert.strictEqual( attributes[keys[0]], 'GET', - `attributes ${HttpAttribute.HTTP_METHOD} is wrong` + `attributes ${SemanticAttributes.HTTP_METHOD} is wrong` ); assert.strictEqual( attributes[keys[1]], url, - `attributes ${HttpAttribute.HTTP_URL} is wrong` + `attributes ${SemanticAttributes.HTTP_URL} is wrong` ); assert.strictEqual( attributes[keys[2]], 0, - `attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong` + `attributes ${SemanticAttributes.HTTP_STATUS_CODE} is wrong` ); assert.strictEqual( attributes[keys[3]], '', - `attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong` + `attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong` ); assert.strictEqual( attributes[keys[4]], 'raw.githubusercontent.com', - `attributes ${HttpAttribute.HTTP_HOST} is wrong` + `attributes ${SemanticAttributes.HTTP_HOST} is wrong` ); assert.ok( attributes[keys[5]] === 'http' || attributes[keys[5]] === 'https', - `attributes ${HttpAttribute.HTTP_SCHEME} is wrong` + `attributes ${SemanticAttributes.HTTP_SCHEME} is wrong` ); assert.ok( attributes[keys[6]] !== '', - `attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined` + `attributes ${SemanticAttributes.HTTP_USER_AGENT} is not defined` ); assert.strictEqual(keys.length, 7, 'number of attributes is wrong'); @@ -1110,35 +1111,35 @@ describe('xhr', () => { assert.strictEqual( attributes[keys[0]], 'GET', - `attributes ${HttpAttribute.HTTP_METHOD} is wrong` + `attributes ${SemanticAttributes.HTTP_METHOD} is wrong` ); assert.strictEqual( attributes[keys[1]], url, - `attributes ${HttpAttribute.HTTP_URL} is wrong` + `attributes ${SemanticAttributes.HTTP_URL} is wrong` ); assert.strictEqual( attributes[keys[2]], 0, - `attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong` + `attributes ${SemanticAttributes.HTTP_STATUS_CODE} is wrong` ); assert.strictEqual( attributes[keys[3]], '', - `attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong` + `attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong` ); assert.strictEqual( attributes[keys[4]], 'raw.githubusercontent.com', - `attributes ${HttpAttribute.HTTP_HOST} is wrong` + `attributes ${SemanticAttributes.HTTP_HOST} is wrong` ); assert.ok( attributes[keys[5]] === 'http' || attributes[keys[5]] === 'https', - `attributes ${HttpAttribute.HTTP_SCHEME} is wrong` + `attributes ${SemanticAttributes.HTTP_SCHEME} is wrong` ); assert.ok( attributes[keys[6]] !== '', - `attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined` + `attributes ${SemanticAttributes.HTTP_USER_AGENT} is not defined` ); assert.strictEqual(keys.length, 7, 'number of attributes is wrong'); diff --git a/packages/opentelemetry-semantic-conventions/src/index.ts b/packages/opentelemetry-semantic-conventions/src/index.ts index ae2998a38ce..6f9f387e23c 100644 --- a/packages/opentelemetry-semantic-conventions/src/index.ts +++ b/packages/opentelemetry-semantic-conventions/src/index.ts @@ -15,3 +15,4 @@ */ export * from './trace'; +export * from './resource'; diff --git a/packages/opentelemetry-semantic-conventions/src/resource/ResourceAttributes.ts b/packages/opentelemetry-semantic-conventions/src/resource/ResourceAttributes.ts new file mode 100644 index 00000000000..5c719f07c50 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/src/resource/ResourceAttributes.ts @@ -0,0 +1,514 @@ +/* + * 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. + */ + +// DO NOT EDIT, this is an Auto-generated file from scripts/semconv/templates//templates/SemanticAttributes.ts.j2 +export const ResourceAttributes = { + /** + * Name of the cloud provider. + */ + CLOUD_PROVIDER: 'cloud.provider', + + /** + * The cloud account ID the resource is assigned to. + */ + CLOUD_ACCOUNT_ID: 'cloud.account.id', + + /** + * The geographical region the resource is running. Refer to your provider's docs to see the available regions, for example [AWS regions](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/), [Azure regions](https://azure.microsoft.com/en-us/global-infrastructure/geographies/), or [Google Cloud regions](https://cloud.google.com/about/locations). + */ + CLOUD_REGION: 'cloud.region', + + /** + * Cloud regions often have multiple, isolated locations known as zones to increase availability. Availability zone represents the zone where the resource is running. + * + * Note: Availability zones are called "zones" on Google Cloud. + */ + CLOUD_AVAILABILITY_ZONE: 'cloud.availability_zone', + + /** + * The cloud infrastructure resource in use. + * + * Note: The prefix of the service SHOULD match the one specified in `cloud.provider`. + */ + CLOUD_INFRASTRUCTURE_SERVICE: 'cloud.infrastructure_service', + + /** + * The Amazon Resource Name (ARN) of an [ECS container instance](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_instances.html). + */ + AWS_ECS_CONTAINER_ARN: 'aws.ecs.container.arn', + + /** + * The ARN of an [ECS cluster](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/clusters.html). + */ + AWS_ECS_CLUSTER_ARN: 'aws.ecs.cluster.arn', + + /** + * The [launch type](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_types.html) for an ECS task. + */ + AWS_ECS_LAUNCHTYPE: 'aws.ecs.launchtype', + + /** + * The ARN of an [ECS task definition](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definitions.html). + */ + AWS_ECS_TASK_ARN: 'aws.ecs.task.arn', + + /** + * The task definition family this task definition is a member of. + */ + AWS_ECS_TASK_FAMILY: 'aws.ecs.task.family', + + /** + * The ARN of an EKS cluster. + */ + AWS_EKS_CLUSTER_ARN: 'aws.eks.cluster.arn', + + /** + * The name(s) of the AWS log group(s) an application is writing to. + * + * Note: Multiple log groups must be supported for cases like multi-container applications, where a single application has sidecar containers, and each write to their own log group. + */ + AWS_LOG_GROUP_NAMES: 'aws.log.group.names', + + /** + * The Amazon Resource Name(s) (ARN) of the AWS log group(s). + * + * Note: See the [log group ARN format documentation](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/iam-access-control-overview-cwl.html#CWL_ARN_Format). + */ + AWS_LOG_GROUP_ARNS: 'aws.log.group.arns', + + /** + * The name(s) of the AWS log stream(s) an application is writing to. + */ + AWS_LOG_STREAM_NAMES: 'aws.log.stream.names', + + /** + * The ARN(s) of the AWS log stream(s). + * + * Note: See the [log stream ARN format documentation](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/iam-access-control-overview-cwl.html#CWL_ARN_Format). One log group can contain several log streams, so these ARNs necessarily identify both a log group and a log stream. + */ + AWS_LOG_STREAM_ARNS: 'aws.log.stream.arns', + + /** + * Container name. + */ + CONTAINER_NAME: 'container.name', + + /** + * Container ID. Usually a UUID, as for example used to [identify Docker containers](https://docs.docker.com/engine/reference/run/#container-identification). The UUID might be abbreviated. + */ + CONTAINER_ID: 'container.id', + + /** + * The container runtime managing this container. + */ + CONTAINER_RUNTIME: 'container.runtime', + + /** + * Name of the image the container was built on. + */ + CONTAINER_IMAGE_NAME: 'container.image.name', + + /** + * Container image tag. + */ + CONTAINER_IMAGE_TAG: 'container.image.tag', + + /** + * Name of the [deployment environment](https://en.wikipedia.org/wiki/Deployment_environment) (aka deployment tier). + */ + DEPLOYMENT_ENVIRONMENT: 'deployment.environment', + + /** + * The name of the function being executed. + */ + FAAS_NAME: 'faas.name', + + /** + * The unique ID of the function being executed. + * + * Note: For example, in AWS Lambda this field corresponds to the [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) value, in GCP to the URI of the resource, and in Azure to the [FunctionDirectory](https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function) field. + */ + FAAS_ID: 'faas.id', + + /** + * The version string of the function being executed as defined in [Version Attributes](../../resource/semantic_conventions/README.md#version-attributes). + */ + FAAS_VERSION: 'faas.version', + + /** + * The execution environment ID as a string. + */ + FAAS_INSTANCE: 'faas.instance', + + /** + * The amount of memory available to the serverless function in MiB. + * + * Note: It's recommended to set this attribute since e.g. too little memory can easily stop a Java AWS Lambda function from working correctly. On AWS Lambda, the environment variable `AWS_LAMBDA_FUNCTION_MEMORY_SIZE` provides this information. + */ + FAAS_MAX_MEMORY: 'faas.max_memory', + + /** + * Unique host ID. For Cloud, this must be the instance_id assigned by the cloud provider. + */ + HOST_ID: 'host.id', + + /** + * Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully qualified hostname, or another name specified by the user. + */ + HOST_NAME: 'host.name', + + /** + * Type of host. For Cloud, this must be the machine type. + */ + HOST_TYPE: 'host.type', + + /** + * The CPU architecture the host system is running on. + */ + HOST_ARCH: 'host.arch', + + /** + * Name of the VM image or OS install the host was instantiated from. + */ + HOST_IMAGE_NAME: 'host.image.name', + + /** + * VM image ID. For Cloud, this value is from the provider. + */ + HOST_IMAGE_ID: 'host.image.id', + + /** + * The version string of the VM image as defined in [Version Attributes](README.md#version-attributes). + */ + HOST_IMAGE_VERSION: 'host.image.version', + + /** + * The name of the cluster. + */ + K8S_CLUSTER_NAME: 'k8s.cluster.name', + + /** + * The name of the Node. + */ + K8S_NODE_NAME: 'k8s.node.name', + + /** + * The UID of the Node. + */ + K8S_NODE_UID: 'k8s.node.uid', + + /** + * The name of the namespace that the pod is running in. + */ + K8S_NAMESPACE_NAME: 'k8s.namespace.name', + + /** + * The UID of the Pod. + */ + K8S_POD_UID: 'k8s.pod.uid', + + /** + * The name of the Pod. + */ + K8S_POD_NAME: 'k8s.pod.name', + + /** + * The name of the Container in a Pod template. + */ + K8S_CONTAINER_NAME: 'k8s.container.name', + + /** + * The UID of the ReplicaSet. + */ + K8S_REPLICASET_UID: 'k8s.replicaset.uid', + + /** + * The name of the ReplicaSet. + */ + K8S_REPLICASET_NAME: 'k8s.replicaset.name', + + /** + * The UID of the Deployment. + */ + K8S_DEPLOYMENT_UID: 'k8s.deployment.uid', + + /** + * The name of the Deployment. + */ + K8S_DEPLOYMENT_NAME: 'k8s.deployment.name', + + /** + * The UID of the StatefulSet. + */ + K8S_STATEFULSET_UID: 'k8s.statefulset.uid', + + /** + * The name of the StatefulSet. + */ + K8S_STATEFULSET_NAME: 'k8s.statefulset.name', + + /** + * The UID of the DaemonSet. + */ + K8S_DAEMONSET_UID: 'k8s.daemonset.uid', + + /** + * The name of the DaemonSet. + */ + K8S_DAEMONSET_NAME: 'k8s.daemonset.name', + + /** + * The UID of the Job. + */ + K8S_JOB_UID: 'k8s.job.uid', + + /** + * The name of the Job. + */ + K8S_JOB_NAME: 'k8s.job.name', + + /** + * The UID of the CronJob. + */ + K8S_CRONJOB_UID: 'k8s.cronjob.uid', + + /** + * The name of the CronJob. + */ + K8S_CRONJOB_NAME: 'k8s.cronjob.name', + + /** + * The operating system type. + */ + OS_TYPE: 'os.type', + + /** + * Human readable (not intended to be parsed) OS version information, like e.g. reported by `ver` or `lsb_release -a` commands. + */ + OS_DESCRIPTION: 'os.description', + + /** + * Process identifier (PID). + */ + PROCESS_PID: 'process.pid', + + /** + * The name of the process executable. On Linux based systems, can be set to the `Name` in `proc/[pid]/status`. On Windows, can be set to the base name of `GetProcessImageFileNameW`. + */ + PROCESS_EXECUTABLE_NAME: 'process.executable.name', + + /** + * The full path to the process executable. On Linux based systems, can be set to the target of `proc/[pid]/exe`. On Windows, can be set to the result of `GetProcessImageFileNameW`. + */ + PROCESS_EXECUTABLE_PATH: 'process.executable.path', + + /** + * The command used to launch the process (i.e. the command name). On Linux based systems, can be set to the zeroth string in `proc/[pid]/cmdline`. On Windows, can be set to the first parameter extracted from `GetCommandLineW`. + */ + PROCESS_COMMAND: 'process.command', + + /** + * The full command used to launch the process as a single string representing the full command. On Windows, can be set to the result of `GetCommandLineW`. Do not set this if you have to assemble it just for monitoring; use `process.command_args` instead. + */ + PROCESS_COMMAND_LINE: 'process.command_line', + + /** + * All the command arguments (including the command/executable itself) as received by the process. On Linux-based systems (and some other Unixoid systems supporting procfs), can be set according to the list of null-delimited strings extracted from `proc/[pid]/cmdline`. For libc-based executables, this would be the full argv vector passed to `main`. + */ + PROCESS_COMMAND_ARGS: 'process.command_args', + + /** + * The username of the user that owns the process. + */ + PROCESS_OWNER: 'process.owner', + + /** + * The name of the runtime of this process. For compiled native binaries, this SHOULD be the name of the compiler. + */ + PROCESS_RUNTIME_NAME: 'process.runtime.name', + + /** + * The version of the runtime of this process, as returned by the runtime without modification. + */ + PROCESS_RUNTIME_VERSION: 'process.runtime.version', + + /** + * An additional description about the runtime of the process, for example a specific vendor customization of the runtime environment. + */ + PROCESS_RUNTIME_DESCRIPTION: 'process.runtime.description', + + /** + * Logical name of the service. + * + * Note: MUST be the same for all instances of horizontally scaled services. If the value was not specified, SDKs MUST fallback to `unknown_service:` concatenated with [`process.executable.name`](process.md#process), e.g. `unknown_service:bash`. If `process.executable.name` is not available, the value MUST be set to `unknown_service`. + */ + SERVICE_NAME: 'service.name', + + /** + * A namespace for `service.name`. + * + * Note: A string value having a meaning that helps to distinguish a group of services, for example the team name that owns a group of services. `service.name` is expected to be unique within the same namespace. If `service.namespace` is not specified in the Resource then `service.name` is expected to be unique for all services that have no explicit namespace defined (so the empty/unspecified namespace is simply one more valid namespace). Zero-length namespace string is assumed equal to unspecified namespace. + */ + SERVICE_NAMESPACE: 'service.namespace', + + /** + * The string ID of the service instance. + * + * Note: MUST be unique for each instance of the same `service.namespace,service.name` pair (in other words `service.namespace,service.name,service.instance.id` triplet MUST be globally unique). The ID helps to distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled service). It is preferable for the ID to be persistent and stay the same for the lifetime of the service instance, however it is acceptable that the ID is ephemeral and changes during important lifetime events for the service (e.g. service restarts). If the service has no inherent unique ID that can be used as the value of this attribute it is recommended to generate a random Version 1 or Version 4 RFC 4122 UUID (services aiming for reproducible UUIDs may also use Version 5, see RFC 4122 for more recommendations). + */ + SERVICE_INSTANCE_ID: 'service.instance.id', + + /** + * The version string of the service API or implementation. + */ + SERVICE_VERSION: 'service.version', + + /** + * The name of the telemetry SDK as defined above. + */ + TELEMETRY_SDK_NAME: 'telemetry.sdk.name', + + /** + * The language of the telemetry SDK. + */ + TELEMETRY_SDK_LANGUAGE: 'telemetry.sdk.language', + + /** + * The version string of the telemetry SDK. + */ + TELEMETRY_SDK_VERSION: 'telemetry.sdk.version', + + /** + * The version string of the auto instrumentation agent, if used. + */ + TELEMETRY_AUTO_VERSION: 'telemetry.auto.version', +}; + +// Enum definitions + +export enum CloudProviderValues { + /** Amazon Web Services. */ + AWS = 'aws', + /** Microsoft Azure. */ + AZURE = 'azure', + /** Google Cloud Platform. */ + GCP = 'gcp', +} + +export enum CloudInfrastructureServiceValues { + /** AWS Elastic Compute Cloud. */ + AWS_EC2 = 'aws_ec2', + /** AWS Elastic Container Service. */ + AWS_ECS = 'aws_ecs', + /** AWS Elastic Kubernetes Service. */ + AWS_EKS = 'aws_eks', + /** AWS Lambda. */ + AWS_LAMBDA = 'aws_lambda', + /** AWS Elastic Beanstalk. */ + AWS_ELASTICBEANSTALK = 'aws_elastic_beanstalk', + /** Azure Virtual Machines. */ + AZURE_VM = 'azure_vm', + /** Azure Container Instances. */ + AZURE_CONTAINERINSTANCES = 'azure_container_instances', + /** Azure Kubernetes Service. */ + AZURE_AKS = 'azure_aks', + /** Azure Functions. */ + AZURE_FUNCTIONS = 'azure_functions', + /** Azure App Service. */ + AZURE_APPSERVICE = 'azure_app_service', + /** Google Cloud Compute Engine (GCE). */ + GCP_COMPUTEENGINE = 'gcp_compute_engine', + /** Google Cloud Run. */ + GCP_CLOUDRUN = 'gcp_cloud_run', + /** Google Cloud Kubernetes Engine (GKE). */ + GCP_KUBERNETESENGINE = 'gcp_kubernetes_engine', + /** Google Cloud Functions (GCF). */ + GCP_CLOUDFUNCTIONS = 'gcp_cloud_functions', + /** Google Cloud App Engine (GAE). */ + GCP_APPENGINE = 'gcp_app_engine', +} + +export enum AwsEcsLaunchtypeValues { + /** ec2. */ + EC2 = 'ec2', + /** fargate. */ + FARGATE = 'fargate', +} + +export enum HostArchValues { + /** AMD64. */ + AMD64 = 'amd64', + /** ARM32. */ + ARM32 = 'arm32', + /** ARM64. */ + ARM64 = 'arm64', + /** Itanium. */ + IA64 = 'ia64', + /** 32-bit PowerPC. */ + PPC32 = 'ppc32', + /** 64-bit PowerPC. */ + PPC64 = 'ppc64', + /** 32-bit x86. */ + X86 = 'x86', +} + +export enum OsTypeValues { + /** Microsoft Windows. */ + WINDOWS = 'WINDOWS', + /** Linux. */ + LINUX = 'LINUX', + /** Apple Darwin. */ + DARWIN = 'DARWIN', + /** FreeBSD. */ + FREEBSD = 'FREEBSD', + /** NetBSD. */ + NETBSD = 'NETBSD', + /** OpenBSD. */ + OPENBSD = 'OPENBSD', + /** DragonFly BSD. */ + DRAGONFLYBSD = 'DRAGONFLYBSD', + /** HP-UX (Hewlett Packard Unix). */ + HPUX = 'HPUX', + /** AIX (Advanced Interactive eXecutive). */ + AIX = 'AIX', + /** Oracle Solaris. */ + SOLARIS = 'SOLARIS', + /** IBM z/OS. */ + ZOS = 'ZOS', +} + +export enum TelemetrySdkLanguageValues { + /** cpp. */ + CPP = 'cpp', + /** dotnet. */ + DOTNET = 'dotnet', + /** erlang. */ + ERLANG = 'erlang', + /** go. */ + GO = 'go', + /** java. */ + JAVA = 'java', + /** nodejs. */ + NODEJS = 'nodejs', + /** php. */ + PHP = 'php', + /** python. */ + PYTHON = 'python', + /** ruby. */ + RUBY = 'ruby', + /** webjs. */ + WEBJS = 'webjs', +} diff --git a/packages/opentelemetry-semantic-conventions/src/resource/index.ts b/packages/opentelemetry-semantic-conventions/src/resource/index.ts new file mode 100644 index 00000000000..e3810b5eeb5 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/src/resource/index.ts @@ -0,0 +1,16 @@ +/* + * 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 * from './ResourceAttributes'; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts b/packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts new file mode 100644 index 00000000000..9f756902fd1 --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts @@ -0,0 +1,748 @@ +/* + * 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. + */ + +// DO NOT EDIT, this is an Auto-generated file from scripts/semconv/templates//templates/SemanticAttributes.ts.j2 +export const SemanticAttributes = { + /** + * An identifier for the database management system (DBMS) product being used. See below for a list of well-known identifiers. + */ + DB_SYSTEM: 'db.system', + + /** + * The connection string used to connect to the database. It is recommended to remove embedded credentials. + */ + DB_CONNECTION_STRING: 'db.connection_string', + + /** + * Username for accessing the database. + */ + DB_USER: 'db.user', + + /** + * The fully-qualified class name of the [Java Database Connectivity (JDBC)](https://docs.oracle.com/javase/8/docs/technotes/guides/jdbc/) driver used to connect. + */ + DB_JDBC_DRIVER_CLASSNAME: 'db.jdbc.driver_classname', + + /** + * If no [tech-specific attribute](#call-level-attributes-for-specific-technologies) is defined, this attribute is used to report the name of the database being accessed. For commands that switch the database, this should be set to the target database (even if the command fails). + * + * Note: In some SQL databases, the database name to be used is called "schema name". + */ + DB_NAME: 'db.name', + + /** + * The database statement being executed. + * + * Note: The value may be sanitized to exclude sensitive information. + */ + DB_STATEMENT: 'db.statement', + + /** + * The name of the operation being executed, e.g. the [MongoDB command name](https://docs.mongodb.com/manual/reference/command/#database-operations) such as `findAndModify`, or the SQL keyword. + * + * Note: When setting this to an SQL keyword, it is not recommended to attempt any client-side parsing of `db.statement` just to get this property, but it should be set if the operation name is provided by the library being instrumented. If the SQL statement has an ambiguous operation, or performs more than one operation, this value may be omitted. + */ + DB_OPERATION: 'db.operation', + + /** + * The Microsoft SQL Server [instance name](https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=sql-server-ver15) connecting to. This name is used to determine the port of a named instance. + * + * Note: If setting a `db.mssql.instance_name`, `net.peer.port` is no longer required (but still recommended if non-standard). + */ + DB_MSSQL_INSTANCE_NAME: 'db.mssql.instance_name', + + /** + * The name of the keyspace being accessed. To be used instead of the generic `db.name` attribute. + */ + DB_CASSANDRA_KEYSPACE: 'db.cassandra.keyspace', + + /** + * The fetch size used for paging, i.e. how many rows will be returned at once. + */ + DB_CASSANDRA_PAGE_SIZE: 'db.cassandra.page_size', + + /** + * The consistency level of the query. Based on consistency values from [CQL](https://docs.datastax.com/en/cassandra-oss/3.0/cassandra/dml/dmlConfigConsistency.html). + */ + DB_CASSANDRA_CONSISTENCY_LEVEL: 'db.cassandra.consistency_level', + + /** + * The name of the primary table that the operation is acting upon, including the schema name (if applicable). + * + * Note: This mirrors the db.sql.table attribute but references cassandra rather than sql. It is not recommended to attempt any client-side parsing of `db.statement` just to get this property, but it should be set if it is provided by the library being instrumented. If the operation is acting upon an anonymous table, or more than one table, this value MUST NOT be set. + */ + DB_CASSANDRA_TABLE: 'db.cassandra.table', + + /** + * Whether or not the query is idempotent. + */ + DB_CASSANDRA_IDEMPOTENCE: 'db.cassandra.idempotence', + + /** + * The number of times a query was speculatively executed. Not set or `0` if the query was not executed speculatively. + */ + DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT: + 'db.cassandra.speculative_execution_count', + + /** + * The ID of the coordinating node for a query. + */ + DB_CASSANDRA_COORDINATOR_ID: 'db.cassandra.coordinator.id', + + /** + * The data center of the coordinating node for a query. + */ + DB_CASSANDRA_COORDINATOR_DC: 'db.cassandra.coordinator.dc', + + /** + * The [HBase namespace](https://hbase.apache.org/book.html#_namespace) being accessed. To be used instead of the generic `db.name` attribute. + */ + DB_HBASE_NAMESPACE: 'db.hbase.namespace', + + /** + * The index of the database being accessed as used in the [`SELECT` command](https://redis.io/commands/select), provided as an integer. To be used instead of the generic `db.name` attribute. + */ + DB_REDIS_DATABASE_INDEX: 'db.redis.database_index', + + /** + * The collection being accessed within the database stated in `db.name`. + */ + DB_MONGODB_COLLECTION: 'db.mongodb.collection', + + /** + * The name of the primary table that the operation is acting upon, including the schema name (if applicable). + * + * Note: It is not recommended to attempt any client-side parsing of `db.statement` just to get this property, but it should be set if it is provided by the library being instrumented. If the operation is acting upon an anonymous table, or more than one table, this value MUST NOT be set. + */ + DB_SQL_TABLE: 'db.sql.table', + + /** + * The type of the exception (its fully-qualified class name, if applicable). The dynamic type of the exception should be preferred over the static type in languages that support it. + */ + EXCEPTION_TYPE: 'exception.type', + + /** + * The exception message. + */ + EXCEPTION_MESSAGE: 'exception.message', + + /** + * A stacktrace as a string in the natural representation for the language runtime. The representation is to be determined and documented by each language SIG. + */ + EXCEPTION_STACKTRACE: 'exception.stacktrace', + + /** + * SHOULD be set to true if the exception event is recorded at a point where it is known that the exception is escaping the scope of the span. + * + * Note: An exception is considered to have escaped (or left) the scope of a span, +if that span is ended while the exception is still logically "in flight". +This may be actually "in flight" in some languages (e.g. if the exception +is passed to a Context manager's `__exit__` method in Python) but will +usually be caught at the point of recording the exception in most languages. + +It is usually not possible to determine at the point where an exception is thrown +whether it will escape the scope of a span. +However, it is trivial to know that an exception +will escape, if one checks for an active exception just before ending the span, +as done in the [example above](#exception-end-example). + +It follows that an exception may still escape the scope of the span +even if the `exception.escaped` attribute was not set or set to false, +since the event might have been recorded at a time where it was not +clear whether the exception will escape. + */ + EXCEPTION_ESCAPED: 'exception.escaped', + + /** + * Type of the trigger on which the function is executed. + */ + FAAS_TRIGGER: 'faas.trigger', + + /** + * The execution ID of the current function execution. + */ + FAAS_EXECUTION: 'faas.execution', + + /** + * The name of the source on which the triggering operation was performed. For example, in Cloud Storage or S3 corresponds to the bucket name, and in Cosmos DB to the database name. + */ + FAAS_DOCUMENT_COLLECTION: 'faas.document.collection', + + /** + * Describes the type of the operation that was performed on the data. + */ + FAAS_DOCUMENT_OPERATION: 'faas.document.operation', + + /** + * A string containing the time when the data was accessed in the [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format expressed in [UTC](https://www.w3.org/TR/NOTE-datetime). + */ + FAAS_DOCUMENT_TIME: 'faas.document.time', + + /** + * The document name/table subjected to the operation. For example, in Cloud Storage or S3 is the name of the file, and in Cosmos DB the table name. + */ + FAAS_DOCUMENT_NAME: 'faas.document.name', + + /** + * A string containing the function invocation time in the [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format expressed in [UTC](https://www.w3.org/TR/NOTE-datetime). + */ + FAAS_TIME: 'faas.time', + + /** + * A string containing the schedule period as [Cron Expression](https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm). + */ + FAAS_CRON: 'faas.cron', + + /** + * A boolean that is true if the serverless function is executed for the first time (aka cold-start). + */ + FAAS_COLDSTART: 'faas.coldstart', + + /** + * The name of the invoked function. + * + * Note: SHOULD be equal to the `faas.name` resource attribute of the invoked function. + */ + FAAS_INVOKED_NAME: 'faas.invoked_name', + + /** + * The cloud provider of the invoked function. + * + * Note: SHOULD be equal to the `cloud.provider` resource attribute of the invoked function. + */ + FAAS_INVOKED_PROVIDER: 'faas.invoked_provider', + + /** + * The cloud region of the invoked function. + * + * Note: SHOULD be equal to the `cloud.region` resource attribute of the invoked function. + */ + FAAS_INVOKED_REGION: 'faas.invoked_region', + + /** + * Transport protocol used. See note below. + */ + NET_TRANSPORT: 'net.transport', + + /** + * Remote address of the peer (dotted decimal for IPv4 or [RFC5952](https://tools.ietf.org/html/rfc5952) for IPv6). + */ + NET_PEER_IP: 'net.peer.ip', + + /** + * Remote port number. + */ + NET_PEER_PORT: 'net.peer.port', + + /** + * Remote hostname or similar, see note below. + */ + NET_PEER_NAME: 'net.peer.name', + + /** + * Like `net.peer.ip` but for the host IP. Useful in case of a multi-IP host. + */ + NET_HOST_IP: 'net.host.ip', + + /** + * Like `net.peer.port` but for the host port. + */ + NET_HOST_PORT: 'net.host.port', + + /** + * Local hostname or similar, see note below. + */ + NET_HOST_NAME: 'net.host.name', + + /** + * The [`service.name`](../../resource/semantic_conventions/README.md#service) of the remote service. SHOULD be equal to the actual `service.name` resource attribute of the remote service if any. + */ + PEER_SERVICE: 'peer.service', + + /** + * Username or client_id extracted from the access token or [Authorization](https://tools.ietf.org/html/rfc7235#section-4.2) header in the inbound request from outside the system. + */ + ENDUSER_ID: 'enduser.id', + + /** + * Actual/assumed role the client is making the request under extracted from token or application security context. + */ + ENDUSER_ROLE: 'enduser.role', + + /** + * Scopes or granted authorities the client currently possesses extracted from token or application security context. The value would come from the scope associated with an [OAuth 2.0 Access Token](https://tools.ietf.org/html/rfc6749#section-3.3) or an attribute value in a [SAML 2.0 Assertion](http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0.html). + */ + ENDUSER_SCOPE: 'enduser.scope', + + /** + * Current "managed" thread ID (as opposed to OS thread ID). + */ + THREAD_ID: 'thread.id', + + /** + * Current thread name. + */ + THREAD_NAME: 'thread.name', + + /** + * The method or function name, or equivalent (usually rightmost part of the code unit's name). + */ + CODE_FUNCTION: 'code.function', + + /** + * The "namespace" within which `code.function` is defined. Usually the qualified class or module name, such that `code.namespace` + some separator + `code.function` form a unique identifier for the code unit. + */ + CODE_NAMESPACE: 'code.namespace', + + /** + * The source code file name that identifies the code unit as uniquely as possible (preferably an absolute file path). + */ + CODE_FILEPATH: 'code.filepath', + + /** + * The line number in `code.filepath` best representing the operation. It SHOULD point within the code unit named in `code.function`. + */ + CODE_LINENO: 'code.lineno', + + /** + * HTTP request method. + */ + HTTP_METHOD: 'http.method', + + /** + * Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]`. Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless. + * + * Note: `http.url` MUST NOT contain credentials passed via URL in form of `https://username:password@www.example.com/`. In such case the attribute's value should be `https://www.example.com/`. + */ + HTTP_URL: 'http.url', + + /** + * The full request target as passed in a HTTP request line or equivalent. + */ + HTTP_TARGET: 'http.target', + + /** + * The value of the [HTTP host header](https://tools.ietf.org/html/rfc7230#section-5.4). When the header is empty or not present, this attribute should be the same. + */ + HTTP_HOST: 'http.host', + + /** + * The URI scheme identifying the used protocol. + */ + HTTP_SCHEME: 'http.scheme', + + /** + * [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6). + */ + HTTP_STATUS_CODE: 'http.status_code', + + /** + * Kind of HTTP protocol used. + * + * Note: If `net.transport` is not specified, it can be assumed to be `IP.TCP` except if `http.flavor` is `QUIC`, in which case `IP.UDP` is assumed. + */ + HTTP_FLAVOR: 'http.flavor', + + /** + * Value of the [HTTP User-Agent](https://tools.ietf.org/html/rfc7231#section-5.5.3) header sent by the client. + */ + HTTP_USER_AGENT: 'http.user_agent', + + /** + * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://tools.ietf.org/html/rfc7230#section-3.3.2) header. For requests using transport encoding, this should be the compressed size. + */ + HTTP_REQUEST_CONTENT_LENGTH: 'http.request_content_length', + + /** + * The size of the uncompressed request payload body after transport decoding. Not set if transport encoding not used. + */ + HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED: + 'http.request_content_length_uncompressed', + + /** + * The size of the response payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://tools.ietf.org/html/rfc7230#section-3.3.2) header. For requests using transport encoding, this should be the compressed size. + */ + HTTP_RESPONSE_CONTENT_LENGTH: 'http.response_content_length', + + /** + * The size of the uncompressed response payload body after transport decoding. Not set if transport encoding not used. + */ + HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED: + 'http.response_content_length_uncompressed', + + /** + * The primary server name of the matched virtual host. This should be obtained via configuration. If no such configuration can be obtained, this attribute MUST NOT be set ( `net.host.name` should be used instead). + * + * Note: `http.url` is usually not readily available on the server side but would have to be assembled in a cumbersome and sometimes lossy process from other information (see e.g. open-telemetry/opentelemetry-python/pull/148). It is thus preferred to supply the raw data that is available. + */ + HTTP_SERVER_NAME: 'http.server_name', + + /** + * The matched route (path template). + */ + HTTP_ROUTE: 'http.route', + + /** + * The IP address of the original client behind all proxies, if known (e.g. from [X-Forwarded-For](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For)). + * + * Note: This is not necessarily the same as `net.peer.ip`, which would identify the network-level peer, which may be a proxy. + */ + HTTP_CLIENT_IP: 'http.client_ip', + + /** + * A string identifying the messaging system. + */ + MESSAGING_SYSTEM: 'messaging.system', + + /** + * The message destination name. This might be equal to the span name but is required nevertheless. + */ + MESSAGING_DESTINATION: 'messaging.destination', + + /** + * The kind of message destination. + */ + MESSAGING_DESTINATION_KIND: 'messaging.destination_kind', + + /** + * A boolean that is true if the message destination is temporary. + */ + MESSAGING_TEMP_DESTINATION: 'messaging.temp_destination', + + /** + * The name of the transport protocol. + */ + MESSAGING_PROTOCOL: 'messaging.protocol', + + /** + * The version of the transport protocol. + */ + MESSAGING_PROTOCOL_VERSION: 'messaging.protocol_version', + + /** + * Connection string. + */ + MESSAGING_URL: 'messaging.url', + + /** + * A value used by the messaging system as an identifier for the message, represented as a string. + */ + MESSAGING_MESSAGE_ID: 'messaging.message_id', + + /** + * The [conversation ID](#conversations) identifying the conversation to which the message belongs, represented as a string. Sometimes called "Correlation ID". + */ + MESSAGING_CONVERSATION_ID: 'messaging.conversation_id', + + /** + * The (uncompressed) size of the message payload in bytes. Also use this attribute if it is unknown whether the compressed or uncompressed payload size is reported. + */ + MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES: 'messaging.message_payload_size_bytes', + + /** + * The compressed size of the message payload in bytes. + */ + MESSAGING_MESSAGE_PAYLOAD_COMPRESSED_SIZE_BYTES: + 'messaging.message_payload_compressed_size_bytes', + + /** + * A string identifying the kind of message consumption as defined in the [Operation names](#operation-names) section above. If the operation is "send", this attribute MUST NOT be set, since the operation can be inferred from the span kind in that case. + */ + MESSAGING_OPERATION: 'messaging.operation', + + /** + * Message keys in Kafka are used for grouping alike messages to ensure they're processed on the same partition. They differ from `messaging.message_id` in that they're not unique. If the key is `null`, the attribute MUST NOT be set. + * + * Note: If the key type is not string, it's string representation has to be supplied for the attribute. If the key has no unambiguous, canonical string form, don't include its value. + */ + MESSAGING_KAFKA_MESSAGE_KEY: 'messaging.kafka.message_key', + + /** + * Name of the Kafka Consumer Group that is handling the message. Only applies to consumers, not producers. + */ + MESSAGING_KAFKA_CONSUMER_GROUP: 'messaging.kafka.consumer_group', + + /** + * Client Id for the Consumer or Producer that is handling the message. + */ + MESSAGING_KAFKA_CLIENT_ID: 'messaging.kafka.client_id', + + /** + * Partition the message is sent to. + */ + MESSAGING_KAFKA_PARTITION: 'messaging.kafka.partition', + + /** + * A boolean that is true if the message is a tombstone. + */ + MESSAGING_KAFKA_TOMBSTONE: 'messaging.kafka.tombstone', + + /** + * A string identifying the remoting system. + */ + RPC_SYSTEM: 'rpc.system', + + /** + * The full name of the service being called, including its package name, if applicable. + */ + RPC_SERVICE: 'rpc.service', + + /** + * The name of the method being called, must be equal to the $method part in the span name. + */ + RPC_METHOD: 'rpc.method', + + /** + * The [numeric status code](https://github.com/grpc/grpc/blob/v1.33.2/doc/statuscodes.md) of the gRPC request. + */ + RPC_GRPC_STATUS_CODE: 'rpc.grpc.status_code', +}; + +// Enum definitions + +export enum DbSystemValues { + /** Some other SQL database. Fallback only. See notes. */ + OTHER_SQL = 'other_sql', + /** Microsoft SQL Server. */ + MSSQL = 'mssql', + /** MySQL. */ + MYSQL = 'mysql', + /** Oracle Database. */ + ORACLE = 'oracle', + /** IBM Db2. */ + DB2 = 'db2', + /** PostgreSQL. */ + POSTGRESQL = 'postgresql', + /** Amazon Redshift. */ + REDSHIFT = 'redshift', + /** Apache Hive. */ + HIVE = 'hive', + /** Cloudscape. */ + CLOUDSCAPE = 'cloudscape', + /** HyperSQL DataBase. */ + HSQLDB = 'hsqldb', + /** Progress Database. */ + PROGRESS = 'progress', + /** SAP MaxDB. */ + MAXDB = 'maxdb', + /** SAP HANA. */ + HANADB = 'hanadb', + /** Ingres. */ + INGRES = 'ingres', + /** FirstSQL. */ + FIRSTSQL = 'firstsql', + /** EnterpriseDB. */ + EDB = 'edb', + /** InterSystems Caché. */ + CACHE = 'cache', + /** Adabas (Adaptable Database System). */ + ADABAS = 'adabas', + /** Firebird. */ + FIREBIRD = 'firebird', + /** Apache Derby. */ + DERBY = 'derby', + /** FileMaker. */ + FILEMAKER = 'filemaker', + /** Informix. */ + INFORMIX = 'informix', + /** InstantDB. */ + INSTANTDB = 'instantdb', + /** InterBase. */ + INTERBASE = 'interbase', + /** MariaDB. */ + MARIADB = 'mariadb', + /** Netezza. */ + NETEZZA = 'netezza', + /** Pervasive PSQL. */ + PERVASIVE = 'pervasive', + /** PointBase. */ + POINTBASE = 'pointbase', + /** SQLite. */ + SQLITE = 'sqlite', + /** Sybase. */ + SYBASE = 'sybase', + /** Teradata. */ + TERADATA = 'teradata', + /** Vertica. */ + VERTICA = 'vertica', + /** H2. */ + H2 = 'h2', + /** ColdFusion IMQ. */ + COLDFUSION = 'coldfusion', + /** Apache Cassandra. */ + CASSANDRA = 'cassandra', + /** Apache HBase. */ + HBASE = 'hbase', + /** MongoDB. */ + MONGODB = 'mongodb', + /** Redis. */ + REDIS = 'redis', + /** Couchbase. */ + COUCHBASE = 'couchbase', + /** CouchDB. */ + COUCHDB = 'couchdb', + /** Microsoft Azure Cosmos DB. */ + COSMOSDB = 'cosmosdb', + /** Amazon DynamoDB. */ + DYNAMODB = 'dynamodb', + /** Neo4j. */ + NEO4J = 'neo4j', + /** Apache Geode. */ + GEODE = 'geode', + /** Elasticsearch. */ + ELASTICSEARCH = 'elasticsearch', +} + +export enum NetTransportValues {} + +export enum DbCassandraConsistencyLevelValues { + /** ALL. */ + ALL = 'ALL', + /** EACH_QUORUM. */ + EACH_QUORUM = 'EACH_QUORUM', + /** QUORUM. */ + QUORUM = 'QUORUM', + /** LOCAL_QUORUM. */ + LOCAL_QUORUM = 'LOCAL_QUORUM', + /** ONE. */ + ONE = 'ONE', + /** TWO. */ + TWO = 'TWO', + /** THREE. */ + THREE = 'THREE', + /** LOCAL_ONE. */ + LOCAL_ONE = 'LOCAL_ONE', + /** ANY. */ + ANY = 'ANY', + /** SERIAL. */ + SERIAL = 'SERIAL', + /** LOCAL_SERIAL. */ + LOCAL_SERIAL = 'LOCAL_SERIAL', +} + +export enum FaasTriggerValues { + /** A response to some data source operation such as a database or filesystem read/write. */ + DATASOURCE = 'datasource', + /** To provide an answer to an inbound HTTP request. */ + HTTP = 'http', + /** A function is set to be executed when messages are sent to a messaging system. */ + PUBSUB = 'pubsub', + /** A function is scheduled to be executed regularly. */ + TIMER = 'timer', + /** If none of the others apply. */ + OTHER = 'other', +} + +export enum FaasDocumentOperationValues { + /** When a new object is created. */ + INSERT = 'insert', + /** When an object is modified. */ + EDIT = 'edit', + /** When an object is deleted. */ + DELETE = 'delete', +} + +export enum FaasInvokedProviderValues { + /** Amazon Web Services. */ + AWS = 'aws', + /** Amazon Web Services. */ + AZURE = 'azure', + /** Google Cloud Platform. */ + GCP = 'gcp', +} + +export enum NetTransportValues { + /** IP.TCP. */ + IP_TCP = 'IP.TCP', + /** IP.UDP. */ + IP_UDP = 'IP.UDP', + /** Another IP-based protocol. */ + IP = 'IP', + /** Unix Domain socket. See below. */ + UNIX = 'Unix', + /** Named or anonymous pipe. See note below. */ + PIPE = 'pipe', + /** In-process communication. */ + INPROC = 'inproc', + /** Something else (non IP-based). */ + OTHER = 'other', +} + +export enum HttpFlavorValues { + /** HTTP 1.0. */ + HTTP_1_0 = '1.0', + /** HTTP 1.1. */ + HTTP_1_1 = '1.1', + /** HTTP 2. */ + HTTP_2_0 = '2.0', + /** SPDY protocol. */ + SPDY = 'SPDY', + /** QUIC protocol. */ + QUIC = 'QUIC', +} + +export enum MessagingDestinationKindValues { + /** A message sent to a queue. */ + QUEUE = 'queue', + /** A message sent to a topic. */ + TOPIC = 'topic', +} + +export enum MessagingOperationValues { + /** receive. */ + RECEIVE = 'receive', + /** process. */ + PROCESS = 'process', +} + +export enum NetTransportValues {} + +export enum RpcGrpcStatusCodeValues { + /** OK. */ + OK = 0, + /** CANCELLED. */ + CANCELLED = 1, + /** UNKNOWN. */ + UNKNOWN = 2, + /** INVALID_ARGUMENT. */ + INVALID_ARGUMENT = 3, + /** DEADLINE_EXCEEDED. */ + DEADLINE_EXCEEDED = 4, + /** NOT_FOUND. */ + NOT_FOUND = 5, + /** ALREADY_EXISTS. */ + ALREADY_EXISTS = 6, + /** PERMISSION_DENIED. */ + PERMISSION_DENIED = 7, + /** RESOURCE_EXHAUSTED. */ + RESOURCE_EXHAUSTED = 8, + /** FAILED_PRECONDITION. */ + FAILED_PRECONDITION = 9, + /** ABORTED. */ + ABORTED = 10, + /** OUT_OF_RANGE. */ + OUT_OF_RANGE = 11, + /** UNIMPLEMENTED. */ + UNIMPLEMENTED = 12, + /** INTERNAL. */ + INTERNAL = 13, + /** UNAVAILABLE. */ + UNAVAILABLE = 14, + /** DATA_LOSS. */ + DATA_LOSS = 15, + /** UNAUTHENTICATED. */ + UNAUTHENTICATED = 16, +} diff --git a/packages/opentelemetry-semantic-conventions/src/trace/database.ts b/packages/opentelemetry-semantic-conventions/src/trace/database.ts deleted file mode 100644 index b8e4bfa6de3..00000000000 --- a/packages/opentelemetry-semantic-conventions/src/trace/database.ts +++ /dev/null @@ -1,156 +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. - */ - -/** - * 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 = { - // Connection-level attributes - - /** - * An identifier for the database management system (DBMS) product being used. - * - * @remarks - * Required. - */ - DB_SYSTEM: 'db.system', - - /** - * The connection string used to connect to the database. - * It is recommended to remove embedded credentials. - * - * @remarks - * Optional. - */ - DB_CONNECTION_STRING: 'db.connection_string', - - /** - * Username for accessing the database, e.g., "readonly_user" or "reporting_user". - * - * @remarks - * Optional. - */ - DB_USER: 'db.user', - - // Please see ./general.ts for NET_PEER_NAME, NET_PEER_IP, NET_PEER_PORT, NET_TRANSPORT - - // Call-level attributes - - /** - * If no [tech-specific attribute](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/database.md#call-level-attributes-for-specific-technologies) - * is defined in the list below, - * this attribute is used to report the name of the database being accessed. - * For commands that switch the database,this should be set to the - * target database (even if the command fails). - * - * @remarks - * Required if applicable and no more specific attribute is defined. - */ - DB_NAME: 'db.name', - - /** - * The database statement being executed. - * Note that the value may be sanitized to exclude sensitive information. - * E.g., for db.system="other_sql", "SELECT * FROM wuser_table"; - * for db.system="redis", "SET mykey 'WuValue'". - * - * @remarks - * Required if applicable. - */ - DB_STATEMENT: 'db.statement', - - /** - * The name of the operation being executed, - * e.g. the MongoDB command name such as findAndModify. - * While it would semantically make sense to set this, - * e.g., to an SQL keyword like SELECT or INSERT, - * it is not recommended to attempt any client-side parsing of - * db.statement just to get this property (the back end can do that if required). - * - * @remarks - * Required if db.statement is not applicable. - */ - DB_OPERATION: 'db.operation', - - // Connection-level attributes for specific technologies - - /** - * The instance name connecting to. - * This name is used to determine the port of a named instance. - * - * @remarks - * If setting a `db.mssql.instance_name`, - * `net.peer.port` is no longer required (but still recommended if non-standard) - */ - DB_MSSSQL_INSTANCE_NAME: 'db.mssql.instance_name', - - /** - * The fully-qualified class name of the Java Database Connectivity (JDBC) driver used to connect, - * e.g., "org.postgresql.Driver" or "com.microsoft.sqlserver.jdbc.SQLServerDriver". - * - * @remarks - * Optional. - */ - DB_JDBC_DRIVER_CLASSNAME: 'db.jdbc.driver_classname', - - // Call-level attributes for specific technologies - - /** - * The name of the keyspace being accessed. To be used instead of the generic db.name attribute. - * - * @remarks - * Required. - */ - DB_CASSANDRA_KEYSPACE: 'db.cassandra.keyspace', - - /** - * The [HBase namespace](https://hbase.apache.org/book.html#_namespace) being accessed. - * To be used instead of the generic db.name attribute. - * - * @remarks - * Required. - */ - DB_HBASE_NAMESPACE: 'db.hbase.namespace', - - /** - * The index of the database being accessed as used in the [SELECT command](https://redis.io/commands/select), - * provided as an integer. To be used instead of the generic db.name attribute. - * - * @remarks - * Required if other than the default database (0). - */ - DB_REDIS_DATABASE_INDEX: 'db.redis.database_index', - - /** - * The collection being accessed within the database stated in db.name. - * - * @remarks - * Required. - */ - DB_MONGODB_COLLECTION: 'db.mongodb.collection', - - // Not in spec. - - /** Deprecated. Not in spec. */ - DB_TYPE: 'db.type', - - /** Deprecated. Not in spec. */ - DB_INSTANCE: 'db.instance', - - /** Deprecated. Not in spec. */ - DB_URL: 'db.url', -}; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/faas.ts b/packages/opentelemetry-semantic-conventions/src/trace/faas.ts deleted file mode 100644 index aff39d78c91..00000000000 --- a/packages/opentelemetry-semantic-conventions/src/trace/faas.ts +++ /dev/null @@ -1,170 +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. - */ - -/** - * FaaS (Function as a Service) attribute names defined by the Opetelemetry Semantic Conventions specification - * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/faas.md - */ -export const FaasAttribute = { - // General attributes - - /** - * The name of the function being executed. - * - * @remarks - * Required. - */ - FAAS_NAME: 'faas.name', - - /** - * The unique ID of the function being executed. - * For example, in AWS Lambda this field corresponds to the ARN value, in GCP to the URI of the resource, and in Azure to the FunctionDirectory field. - * - * @remarks - * Required. - */ - FAAS_ID: 'faas.id', - - /** - * The version string of the function being executed. - * - * @remarks - * Optional. - */ - FAAS_VERSION: 'faas.version', - - /** - * The execution environment ID as a string. - * - * @remarks - * Optional. - */ - FAAS_INSTANCE: 'faas.instance', - - /** - * Type of the trigger on which the function is executed. - * Possible values: datasource, http, pubsub, timer, other - * - * @remarks - * Required if applicable. - */ - FAAS_TRIGGER: 'faas.trigger', - - /** - * The execution ID of the current function execution. - * - * @remarks - * Optional. - */ - FAAS_EXECUTION: 'faas.execution', - - // Incoming Invocations - - /** - * A boolean that is true if the serverless function is executed for the first time (aka cold-start). - * - * @remarks - * Optional. - */ - FAAS_COLD_START: 'faas.coldstart', - - // Outgoing Invocations - // This section describes outgoing FaaS invocations as they are reported by a client calling a FaaS instance. - - /** - * The name of the invoked function. - * SHOULD be equal to the faas.name resource attribute of the invoked function. - * - * @remarks - * Optional. - */ - FAAS_INVOKED_NAME: 'faas.invoked_name', - - /** - * The cloud provider of the invoked function. - * SHOULD be equal to the cloud.provider resource attribute of the invoked function. - * - * @remarks - * Optional. - */ - FAAS_INVOKED_PROVIDER: 'faas.invoked_provider', - - /** - * The cloud region of the invoked function. - * SHOULD be equal to the cloud.region resource attribute of the invoked function. - * - * @remarks - * Optional. - */ - FAAS_INVOKED_REGION: 'faas.invoked_region', - - // Datesource Trigger - - /** - * The name of the source on which the triggering operation was performed. - * For example, in Cloud Storage or S3 corresponds to the bucket name, and in Cosmos DB to the database name. - * - * @remarks - * Required if applicable. - */ - FAAS_DOC_COLLECTION: 'faas.document.collection', - - /** - * Describes the type of the operation that was performed on the data. - * MUST be one of the following or, if none of the listed values apply, a custom value: insert, edit, delete - * - * @remarks - * Required if applicable. - */ - FAAS_DOC_OPERATION: 'faas.document.operation', - - /** - * A string containing the time when the data was accessed in the ISO 8601 format expressed in UTC. - * - * @remarks - * Required if applicable. - */ - FAAS_DOC_TIME: 'faas.document.time', - - /** - * The document name/table subjected to the operation. - * For example, in Cloud Storage or S3 is the name of the file, and in Cosmos DB the table name. - * - * @remarks - * Optional. - */ - FAAS_DOC_NAME: 'faas.document.name', - - // Timer Trigger - - /** - * A string containing the function invocation time in the ISO 8601 format expressed in UTC. - * Example: "2020-01-23T13:47:06Z" - * - * @remarks - * Required if applicable. - */ - FAAS_TIME: 'faas.time', - - /** - * A string containing the schedule period as Cron Expression. - * Example: "0/5 * * * ? *" - * - * @remarks - * Optional. - */ - FAAS_CRON: 'faas.cron', -}; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/general.ts b/packages/opentelemetry-semantic-conventions/src/trace/general.ts deleted file mode 100644 index 6fa64be3aaf..00000000000 --- a/packages/opentelemetry-semantic-conventions/src/trace/general.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. - */ - -/** - * General purpose networking attributes defined by the OpenTelemetry Semantic Conventions Specification - * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/span-general.md - */ -export const GeneralAttribute = { - 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', - PIPE: 'pipe', - UNIX: 'Unix', -}; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/http.ts b/packages/opentelemetry-semantic-conventions/src/trace/http.ts deleted file mode 100644 index 04618c5fd91..00000000000 --- a/packages/opentelemetry-semantic-conventions/src/trace/http.ts +++ /dev/null @@ -1,39 +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 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', - HTTP_RESPONSE_CONTENT_LENGTH: 'http.response_content_length', - HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED: - 'http.response_content_length_uncompressed', - HTTP_REQUEST_CONTENT_LENGTH: 'http.request_content_length', - HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED: - 'http.request_content_length_uncompressed', - - // 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-semantic-conventions/src/trace/index.ts b/packages/opentelemetry-semantic-conventions/src/trace/index.ts index 20b5ebd5d57..aa5c1024276 100644 --- a/packages/opentelemetry-semantic-conventions/src/trace/index.ts +++ b/packages/opentelemetry-semantic-conventions/src/trace/index.ts @@ -13,12 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -export * from './database'; -export * from './exception'; -export * from './general'; -export * from './http'; -export * from './os'; -export * from './rpc'; -export * from './faas'; -export * from './messaging'; +export * from './SemanticAttributes'; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/messaging.ts b/packages/opentelemetry-semantic-conventions/src/trace/messaging.ts deleted file mode 100644 index c5266a60a2d..00000000000 --- a/packages/opentelemetry-semantic-conventions/src/trace/messaging.ts +++ /dev/null @@ -1,151 +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. - */ - -/** - * messaging attribute names defined by the Opetelemetry Semantic Conventions specification - * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md - */ -export const MessagingAttribute = { - /** - * A string identifying the messaging system. - * example: kafka, rabbitmq, sqs, sns - * - * @remarks - * Required. - */ - MESSAGING_SYSTEM: 'messaging.system', - - /** - * The message destination name. This might be equal to the span name but is required nevertheless. - * example: MyQueue, MyTopic - * - * @remarks - * Required. - */ - MESSAGING_DESTINATION: 'messaging.destination', - - /** - * The kind of message destination - * allowed values: queue, topic, - * - * @remarks - * Required only if the message destination is either a queue or topic. - */ - MESSAGING_DESTINATION_KIND: 'messaging.destination_kind', - - /** - * A boolean that is true if the message destination is temporary - * - * @remarks - * Conditional If missing, it is assumed to be false. - */ - MESSAGING_TEMP_DESTINATION: 'messaging.temp_destination', - - /** - * The kind of message destination - * allowed values: queue, topic, - * - * @remarks - * Required only if the message destination is either a queue or topic. - */ - MESSAGING_PROTOCOL: 'messaging.protocol', - - /** - * The version of the transport protocol. - * - * @remarks - * Optional. - */ - MESSAGING_PROTOCOL_VERSION: 'messaging.protocol_version', - - /** - * Connection string. - * example: https://queue.amazonaws.com/80398EXAMPLE/MyQueue - * - * @remarks - * Optional. - */ - MESSAGING_URL: 'messaging.url', - - /** - * A value used by the messaging system as an identifier for the message, represented as a string. - * - * @remarks - * Optional. - */ - MESSAGING_MESSAGE_ID: 'messaging.message_id', - - /** - * The conversation ID identifying the conversation to which the message belongs, represented as a string. Sometimes called "Correlation ID". - * - * @remarks - * Optional. - */ - MESSAGING_CONVERSATION_ID: 'messaging.conversation_id', - - /** - * The (uncompressed) size of the message payload in bytes. Also use this attribute if it is unknown whether the compressed or uncompressed payload size is reported. - * Should be number. - * - * @remarks - * Optional. - */ - MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES: 'messaging.message_payload_size_bytes', - - /** - * The compressed size of the message payload in bytes. - * Should be number. - * - * @remarks - * Optional. - */ - MESSAGING_MESSAGE_PAYLOAD_COMPRESSED_SIZE_BYTES: - 'messaging.message_payload_compressed_size_bytes', - - /** - * For message consumers only. - * allowed values: receive, process, - * - * @remarks - * Optional. - */ - MESSAGING_OPERATION: 'messaging.operation', - - // System specific attributes - MESSAGING_RABBITMQ_ROUTING_KEY: 'messaging.rabbitmq.routing_key', - MESSAGING_KAFKA_MESSAGE_KEY: 'messaging.kafka.message_key', - MESSAGING_KAFKA_CONSUMER_GROUP: 'messaging.kafka.consumer_group', - MESSAGING_KAFKA_CLIENT_ID: 'messaging.kafka.client_id', - MESSAGING_KAFKA_PARTITION: 'messaging.kafka.partition', - MESSAGING_KAFKA_TOMBSTONE: 'messaging.kafka.tombstone', -}; - -export const MessagingOperationName = { - /** - * A message is sent to a destination by a message producer/client. - */ - SEND: 'send', - - /** - * A message is received from a destination by a message consumer/server. - */ - RECEIVE: 'receive', - - /** - * A message that was previously received from a destination is processed by a message consumer/server. - */ - PROCESS: 'process', -}; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/os.ts b/packages/opentelemetry-semantic-conventions/src/trace/os.ts deleted file mode 100644 index 1ffa94ff560..00000000000 --- a/packages/opentelemetry-semantic-conventions/src/trace/os.ts +++ /dev/null @@ -1,63 +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. - */ - -/** - * The operating system (OS) on which the process represented by this resource is running. - * - * In case of virtualized environments, this is the operating system as it - * is observed by the process, i.e., the virtualized guest rather than the - * underlying host. - * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/resource/semantic_conventions/os.md - */ -export const OperatingSystem = { - /** - * The operating system type. - * This should be set to one of {@link OperatingSystemValues} - * E.g., "WINDOWS" - * - * @remarks - * Required. - */ - TYPE: 'os.type', - /** - * Human readable (not intended to be parsed) OS version information. - * E.g., "Microsoft Windows [Version 10.0.18363.778]" - * - * @remarks - * Required if applicable. - */ - DESCRIPTION: 'os.description', -}; - -/** - * {@link OperatingSystem.TYPE} SHOULD be set to one of the values - * listed below. - * If none of the listed values apply, a custom value best describing - * the family the operating system belongs to CAN be used. - */ -export const OperatingSystemValues = { - WINDOWS: 'WINDOWS', - LINUX: 'LINUX', - DARWIN: 'DARWIN', - FREEBSD: 'FREEBSD', - NETBSD: 'NETBSD', - OPENBSD: 'OPENBSD', - DRAGONFLYBSD: 'DRAGONFLYBSD', - HPUX: 'HPUX', - AIX: 'AIX', - SOLARIS: 'SOLARIS', - ZOS: 'ZOS', -}; diff --git a/packages/opentelemetry-semantic-conventions/src/trace/rpc.ts b/packages/opentelemetry-semantic-conventions/src/trace/rpc.ts deleted file mode 100644 index ec23d93bf37..00000000000 --- a/packages/opentelemetry-semantic-conventions/src/trace/rpc.ts +++ /dev/null @@ -1,47 +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 const RpcAttribute = { - /** - * A string identifying the remoting system. - * - * @remarks - * Required - */ - RPC_SYSTEM: 'rpc.system', - - /** - * The full name of the service being called, including its package name, if applicable. - * - * @remarks - * Not required, but recommended - */ - RPC_SERVICE: 'rpc.service', - - /** - * The name of the method being called, must be equal to the $method part in the span name. - * - * @remarks - * Not required, but recommended - */ - RPC_METHOD: 'rpc.method', - - // 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-tracing/src/Span.ts b/packages/opentelemetry-tracing/src/Span.ts index a24c1a77418..bfaf77b20b9 100644 --- a/packages/opentelemetry-tracing/src/Span.ts +++ b/packages/opentelemetry-tracing/src/Span.ts @@ -24,15 +24,13 @@ import { timeInputToHrTime, } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { - ExceptionAttribute, - ExceptionEventName, -} from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { ReadableSpan } from './export/ReadableSpan'; import { Tracer } from './Tracer'; import { SpanProcessor } from './SpanProcessor'; import { TraceParams } from './types'; import { SpanAttributeValue, Context } from '@opentelemetry/api'; +import { ExceptionEventName } from './enums'; /** * This class represents a span. @@ -190,25 +188,27 @@ export class Span implements api.Span, ReadableSpan { recordException(exception: api.Exception, time: api.TimeInput = hrTime()) { const attributes: api.SpanAttributes = {}; if (typeof exception === 'string') { - attributes[ExceptionAttribute.MESSAGE] = exception; + attributes[SemanticAttributes.EXCEPTION_MESSAGE] = exception; } else if (exception) { if (exception.code) { - attributes[ExceptionAttribute.TYPE] = exception.code.toString(); + attributes[ + SemanticAttributes.EXCEPTION_TYPE + ] = exception.code.toString(); } else if (exception.name) { - attributes[ExceptionAttribute.TYPE] = exception.name; + attributes[SemanticAttributes.EXCEPTION_TYPE] = exception.name; } if (exception.message) { - attributes[ExceptionAttribute.MESSAGE] = exception.message; + attributes[SemanticAttributes.EXCEPTION_MESSAGE] = exception.message; } if (exception.stack) { - attributes[ExceptionAttribute.STACKTRACE] = exception.stack; + attributes[SemanticAttributes.EXCEPTION_STACKTRACE] = exception.stack; } } // these are minimum requirements from spec if ( - attributes[ExceptionAttribute.TYPE] || - attributes[ExceptionAttribute.MESSAGE] + attributes[SemanticAttributes.EXCEPTION_TYPE] || + attributes[SemanticAttributes.EXCEPTION_MESSAGE] ) { this.addEvent(ExceptionEventName, attributes as api.SpanAttributes, time); } else { diff --git a/packages/opentelemetry-semantic-conventions/src/trace/exception.ts b/packages/opentelemetry-tracing/src/enums.ts similarity index 82% rename from packages/opentelemetry-semantic-conventions/src/trace/exception.ts rename to packages/opentelemetry-tracing/src/enums.ts index cf7dc596bef..af2909dc68e 100644 --- a/packages/opentelemetry-semantic-conventions/src/trace/exception.ts +++ b/packages/opentelemetry-tracing/src/enums.ts @@ -14,10 +14,5 @@ * limitations under the License. */ -export const ExceptionAttribute = { - MESSAGE: 'exception.message', - STACKTRACE: 'exception.stacktrace', - TYPE: 'exception.type', -}; - +// Event name definitions export const ExceptionEventName = 'exception'; diff --git a/packages/opentelemetry-tracing/test/Span.test.ts b/packages/opentelemetry-tracing/test/Span.test.ts index 46d4a3f17bb..23dcacd639c 100644 --- a/packages/opentelemetry-tracing/test/Span.test.ts +++ b/packages/opentelemetry-tracing/test/Span.test.ts @@ -29,7 +29,7 @@ import { hrTimeToMilliseconds, hrTimeToNanoseconds, } from '@opentelemetry/core'; -import { ExceptionAttribute } from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import { BasicTracerProvider, Span, SpanProcessor } from '../src'; @@ -692,10 +692,11 @@ describe('Span', () => { assert.ok(event.attributes); - const type = event.attributes[ExceptionAttribute.TYPE]; - const message = event.attributes[ExceptionAttribute.MESSAGE]; + const type = event.attributes[SemanticAttributes.EXCEPTION_TYPE]; + const message = + event.attributes[SemanticAttributes.EXCEPTION_MESSAGE]; const stacktrace = String( - event.attributes[ExceptionAttribute.STACKTRACE] + event.attributes[SemanticAttributes.EXCEPTION_STACKTRACE] ); assert.strictEqual(type, 'Error'); assert.strictEqual(message, 'boom'); @@ -733,7 +734,7 @@ describe('Span', () => { span.recordException({ code: 12 }); const event = span.events[0]; assert.deepStrictEqual(event.attributes, { - [ExceptionAttribute.TYPE]: '12', + [SemanticAttributes.EXCEPTION_TYPE]: '12', }); }); }); diff --git a/packages/opentelemetry-web/src/utils.ts b/packages/opentelemetry-web/src/utils.ts index 8c6a1a0e866..af9d15c9d38 100644 --- a/packages/opentelemetry-web/src/utils.ts +++ b/packages/opentelemetry-web/src/utils.ts @@ -26,7 +26,7 @@ import { timeInputToHrTime, urlMatches, } from '@opentelemetry/core'; -import { HttpAttribute } from '@opentelemetry/semantic-conventions'; +import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; // Used to normalize relative URLs let a: HTMLAnchorElement | undefined; @@ -90,7 +90,7 @@ export function addSpanNetworkEvents( const contentLength = resource[PTN.ENCODED_BODY_SIZE]; if (contentLength !== undefined) { span.setAttribute( - HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH, + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, contentLength ); } diff --git a/scripts/semconv/.gitignore b/scripts/semconv/.gitignore new file mode 100644 index 00000000000..a93b221beb5 --- /dev/null +++ b/scripts/semconv/.gitignore @@ -0,0 +1 @@ +opentelemetry-specification/ diff --git a/scripts/semconv/generate.sh b/scripts/semconv/generate.sh new file mode 100755 index 00000000000..589537c2699 --- /dev/null +++ b/scripts/semconv/generate.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ROOT_DIR="${SCRIPT_DIR}/../../" + +# freeze the spec version to make SpanAttributess generation reproducible +SPEC_VERSION=v1.1.0 +GENERATOR_VERSION=0.2.1 + +cd ${SCRIPT_DIR} + +rm -rf opentelemetry-specification || true +mkdir opentelemetry-specification +cd opentelemetry-specification + +git init +git remote add origin https://github.com/open-telemetry/opentelemetry-specification.git +git fetch origin "$SPEC_VERSION" --depth=1 +git reset --hard FETCH_HEAD +cd ${SCRIPT_DIR} + +docker run --rm \ + -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/trace:/source \ + -v ${SCRIPT_DIR}/templates:/templates \ + -v ${ROOT_DIR}/packages/opentelemetry-semantic-conventions/src/trace/:/output \ + otel/semconvgen:${GENERATOR_VERSION} \ + -f /source \ + code \ + --template /templates/SemanticAttributes.ts.j2 \ + --output /output/SemanticAttributes.ts \ + -Dclass=SemanticAttributes + +docker run --rm \ + -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/resource:/source \ + -v ${SCRIPT_DIR}/templates:/templates \ + -v ${ROOT_DIR}/packages/opentelemetry-semantic-conventions/src/resource/:/output \ + otel/semconvgen:${GENERATOR_VERSION} \ + -f /source \ + code \ + --template /templates/SemanticAttributes.ts.j2 \ + --output /output/ResourceAttributes.ts \ + -Dclass=ResourceAttributes + +# Run the automatic linting fixing task to ensure it will pass eslint +cd "$ROOT_DIR/packages/opentelemetry-semantic-conventions" + +npm run lint:fix + +cd "$ROOT_DIR" diff --git a/scripts/semconv/templates/SemanticAttributes.ts.j2 b/scripts/semconv/templates/SemanticAttributes.ts.j2 new file mode 100644 index 00000000000..f2ee675302c --- /dev/null +++ b/scripts/semconv/templates/SemanticAttributes.ts.j2 @@ -0,0 +1,60 @@ +/* + * 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. + */ + + +{%- macro print_value(type, value) -%} + {{ "\"" if type == "string"}}{{value}}{{ "\"" if type == "string"}} +{%- endmacro %} +{%- macro upFirst(text) -%} + {{ text[0]|upper}}{{text[1:] }} +{%- endmacro %} +{%- macro lowerFirst(text) -%} + {{ text[0]|lower}}{{text[1:] }} +{%- endmacro %} + +// DO NOT EDIT, this is an Auto-generated file from scripts/semconv/templates/{{template}} +export const {{class}} = { + {%- for attribute in attributes if attribute.is_local and not attribute.ref %} + + /** + * {% filter escape %}{{attribute.brief | to_doc_brief}}.{% endfilter %} + {%- if attribute.note %} + * + * Note: {% filter escape %}{{attribute.note | to_doc_brief}}.{% endfilter %} + {%- endif %} + {%- if attribute.deprecated %} + * + * @deprecated {{attribute.deprecated | to_doc_brief}}. + {%- endif %} + */ + {{attribute.fqn | to_const_name}}: '{{attribute.fqn}}', + {%- endfor %} +} + +// Enum definitions +{%- for attribute in attributes if attribute.is_local %} +{%- if attribute.is_enum %} +{%- set class_name = attribute.fqn | to_camelcase(True) ~ "Values" %} +{%- set type = attribute.attr_type.enum_type %} + +export enum {{class_name}} { + {%- for member in attribute.attr_type.members if attribute.is_local and not attribute.ref %} + /** {% filter escape %}{{member.brief | to_doc_brief}}.{% endfilter %} */ + {{ member.member_id | to_const_name }} = {{ print_value(type, member.value) }}, + {%- endfor %} +} +{% endif %} +{%- endfor %}