diff --git a/plugins/node/opentelemetry-instrumentation-express/src/enums/AttributeNames.ts b/plugins/node/opentelemetry-instrumentation-express/src/enums/AttributeNames.ts new file mode 100644 index 0000000000..f6a83e31b0 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-express/src/enums/AttributeNames.ts @@ -0,0 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export enum AttributeNames { + EXPRESS_TYPE = 'express.type', + EXPRESS_NAME = 'express.name', +} diff --git a/plugins/node/opentelemetry-instrumentation-express/src/enums/ExpressLayerType.ts b/plugins/node/opentelemetry-instrumentation-express/src/enums/ExpressLayerType.ts new file mode 100644 index 0000000000..5cfc47c555 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-express/src/enums/ExpressLayerType.ts @@ -0,0 +1,20 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export enum ExpressLayerType { + ROUTER = 'router', + MIDDLEWARE = 'middleware', + REQUEST_HANDLER = 'request_handler', +} diff --git a/plugins/node/opentelemetry-instrumentation-express/src/express.ts b/plugins/node/opentelemetry-instrumentation-express/src/express.ts index acb3780bdf..72b2918e2a 100644 --- a/plugins/node/opentelemetry-instrumentation-express/src/express.ts +++ b/plugins/node/opentelemetry-instrumentation-express/src/express.ts @@ -20,13 +20,13 @@ import * as express from 'express'; import { ExpressLayer, ExpressRouter, - CustomAttributeNames, PatchedRequest, _LAYERS_STORE_PROPERTY, ExpressInstrumentationConfig, - ExpressLayerType, ExpressInstrumentationSpan, } from './types'; +import { ExpressLayerType } from './enums/ExpressLayerType'; +import { AttributeNames } from './enums/AttributeNames'; import { getLayerMetadata, storeLayerPath, isLayerIgnored } from './utils'; import { VERSION } from './version'; import { @@ -187,13 +187,13 @@ export class ExpressInstrumentation extends InstrumentationBase< }; const metadata = getLayerMetadata(layer, layerPath); const type = metadata.attributes[ - CustomAttributeNames.EXPRESS_TYPE + AttributeNames.EXPRESS_TYPE ] as ExpressLayerType; // Rename the root http span in case we haven't done it already // once we reach the request handler if ( - metadata.attributes[CustomAttributeNames.EXPRESS_TYPE] === + metadata.attributes[AttributeNames.EXPRESS_TYPE] === ExpressLayerType.REQUEST_HANDLER ) { const parent = getSpan( @@ -226,7 +226,7 @@ export class ExpressInstrumentation extends InstrumentationBase< // If we found anything that isnt a middleware, there no point of measuring // their time since they dont have callback. if ( - metadata.attributes[CustomAttributeNames.EXPRESS_TYPE] !== + metadata.attributes[AttributeNames.EXPRESS_TYPE] !== ExpressLayerType.MIDDLEWARE ) { span.end(startTime); diff --git a/plugins/node/opentelemetry-instrumentation-express/src/index.ts b/plugins/node/opentelemetry-instrumentation-express/src/index.ts index a7b72ed4dc..b44c9a8f38 100644 --- a/plugins/node/opentelemetry-instrumentation-express/src/index.ts +++ b/plugins/node/opentelemetry-instrumentation-express/src/index.ts @@ -15,4 +15,5 @@ */ export * from './express'; -export { ExpressInstrumentationConfig, ExpressLayerType } from './types'; +export { ExpressLayerType } from './enums/ExpressLayerType'; +export { ExpressInstrumentationConfig } from './types'; diff --git a/plugins/node/opentelemetry-instrumentation-express/src/types.ts b/plugins/node/opentelemetry-instrumentation-express/src/types.ts index 0c44c79dff..e432707903 100644 --- a/plugins/node/opentelemetry-instrumentation-express/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-express/src/types.ts @@ -18,6 +18,7 @@ import { kLayerPatched } from './express'; import { Request } from 'express'; import { SpanAttributes, Span } from '@opentelemetry/api'; import { InstrumentationConfig } from '@opentelemetry/instrumentation'; +import { ExpressLayerType } from './enums/ExpressLayerType'; /** * This const define where on the `request` object the Instrumentation will mount the @@ -67,17 +68,6 @@ export type LayerMetadata = { name: string; }; -export enum CustomAttributeNames { - EXPRESS_TYPE = 'express.type', - EXPRESS_NAME = 'express.name', -} - -export enum ExpressLayerType { - ROUTER = 'router', - MIDDLEWARE = 'middleware', - REQUEST_HANDLER = 'request_handler', -} - export type IgnoreMatcher = string | RegExp | ((name: string) => boolean); /** diff --git a/plugins/node/opentelemetry-instrumentation-express/src/utils.ts b/plugins/node/opentelemetry-instrumentation-express/src/utils.ts index d4cc89caf7..542e36bc2a 100644 --- a/plugins/node/opentelemetry-instrumentation-express/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-express/src/utils.ts @@ -17,13 +17,13 @@ import { SpanAttributes } from '@opentelemetry/api'; import { ExpressLayer, - CustomAttributeNames, PatchedRequest, _LAYERS_STORE_PROPERTY, - ExpressLayerType, IgnoreMatcher, ExpressInstrumentationConfig, } from './types'; +import { ExpressLayerType } from './enums/ExpressLayerType'; +import { AttributeNames } from './enums/AttributeNames'; /** * Store layers path in the request to be able to construct route later @@ -56,24 +56,24 @@ export const getLayerMetadata = ( if (layer.name === 'router') { return { attributes: { - [CustomAttributeNames.EXPRESS_NAME]: layerPath, - [CustomAttributeNames.EXPRESS_TYPE]: ExpressLayerType.ROUTER, + [AttributeNames.EXPRESS_NAME]: layerPath, + [AttributeNames.EXPRESS_TYPE]: ExpressLayerType.ROUTER, }, name: `router - ${layerPath}`, }; } else if (layer.name === 'bound dispatch') { return { attributes: { - [CustomAttributeNames.EXPRESS_NAME]: layerPath ?? 'request handler', - [CustomAttributeNames.EXPRESS_TYPE]: ExpressLayerType.REQUEST_HANDLER, + [AttributeNames.EXPRESS_NAME]: layerPath ?? 'request handler', + [AttributeNames.EXPRESS_TYPE]: ExpressLayerType.REQUEST_HANDLER, }, name: `request handler${layer.path ? ` - ${layerPath}` : ''}`, }; } else { return { attributes: { - [CustomAttributeNames.EXPRESS_NAME]: layer.name, - [CustomAttributeNames.EXPRESS_TYPE]: ExpressLayerType.MIDDLEWARE, + [AttributeNames.EXPRESS_NAME]: layer.name, + [AttributeNames.EXPRESS_TYPE]: ExpressLayerType.MIDDLEWARE, }, name: `middleware - ${layer.name}`, }; diff --git a/plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts b/plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts index 99fd009e83..a02d9f4ddf 100644 --- a/plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts +++ b/plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts @@ -23,11 +23,9 @@ import { } from '@opentelemetry/tracing'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; -import { - CustomAttributeNames, - ExpressInstrumentationSpan, - ExpressLayerType, -} from '../src/types'; +import { ExpressInstrumentationSpan } from '../src/types'; +import { ExpressLayerType } from '../src/enums/ExpressLayerType'; +import { AttributeNames } from '../src/enums/AttributeNames'; import { ExpressInstrumentation } from '../src'; const instrumentation = new ExpressInstrumentation({ @@ -115,7 +113,7 @@ describe('ExpressInstrumentation', () => { .getFinishedSpans() .filter( span => - span.attributes[CustomAttributeNames.EXPRESS_TYPE] === + span.attributes[AttributeNames.EXPRESS_TYPE] === ExpressLayerType.MIDDLEWARE ).length, 0 @@ -164,7 +162,7 @@ describe('ExpressInstrumentation', () => { ); assert.strictEqual( - requestHandlerSpan?.attributes[CustomAttributeNames.EXPRESS_TYPE], + requestHandlerSpan?.attributes[AttributeNames.EXPRESS_TYPE], 'request_handler' ); const exportedRootSpan = spans.find(span => span.name === 'GET /mw'); diff --git a/plugins/node/opentelemetry-instrumentation-express/test/express.test.ts b/plugins/node/opentelemetry-instrumentation-express/test/express.test.ts index a72d2f4452..be11ff2c3c 100644 --- a/plugins/node/opentelemetry-instrumentation-express/test/express.test.ts +++ b/plugins/node/opentelemetry-instrumentation-express/test/express.test.ts @@ -22,7 +22,8 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import * as assert from 'assert'; -import { CustomAttributeNames, ExpressInstrumentationSpan } from '../src/types'; +import { ExpressInstrumentationSpan } from '../src/types'; +import { AttributeNames } from '../src/enums/AttributeNames'; import { ExpressInstrumentation } from '../src'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; @@ -168,7 +169,7 @@ describe('ExpressInstrumentation', () => { '/toto/:id' ); assert.strictEqual( - requestHandlerSpan?.attributes[CustomAttributeNames.EXPRESS_TYPE], + requestHandlerSpan?.attributes[AttributeNames.EXPRESS_TYPE], 'request_handler' ); const exportedRootSpan = memoryExporter diff --git a/plugins/node/opentelemetry-instrumentation-express/test/ignore-all.test.ts b/plugins/node/opentelemetry-instrumentation-express/test/ignore-all.test.ts index f6d7ed82df..77a79c01ba 100644 --- a/plugins/node/opentelemetry-instrumentation-express/test/ignore-all.test.ts +++ b/plugins/node/opentelemetry-instrumentation-express/test/ignore-all.test.ts @@ -22,7 +22,8 @@ import { SimpleSpanProcessor, } from '@opentelemetry/tracing'; import * as assert from 'assert'; -import { CustomAttributeNames, ExpressInstrumentationSpan } from '../src/types'; +import { ExpressInstrumentationSpan } from '../src/types'; +import { AttributeNames } from '../src/enums/AttributeNames'; import { ExpressInstrumentation, ExpressLayerType } from '../src'; const instrumentation = new ExpressInstrumentation({ @@ -120,11 +121,11 @@ describe('ExpressInstrumentation', () => { .getFinishedSpans() .filter( span => - span.attributes[CustomAttributeNames.EXPRESS_TYPE] === + span.attributes[AttributeNames.EXPRESS_TYPE] === ExpressLayerType.MIDDLEWARE || - span.attributes[CustomAttributeNames.EXPRESS_TYPE] === + span.attributes[AttributeNames.EXPRESS_TYPE] === ExpressLayerType.ROUTER || - span.attributes[CustomAttributeNames.EXPRESS_TYPE] === + span.attributes[AttributeNames.EXPRESS_TYPE] === ExpressLayerType.REQUEST_HANDLER ).length, 0 diff --git a/plugins/node/opentelemetry-instrumentation-express/test/utils.test.ts b/plugins/node/opentelemetry-instrumentation-express/test/utils.test.ts index 987028676d..396eea75e3 100644 --- a/plugins/node/opentelemetry-instrumentation-express/test/utils.test.ts +++ b/plugins/node/opentelemetry-instrumentation-express/test/utils.test.ts @@ -16,12 +16,9 @@ import * as utils from '../src/utils'; import * as assert from 'assert'; -import { - ExpressLayerType, - ExpressInstrumentationConfig, - ExpressLayer, - CustomAttributeNames, -} from '../src/types'; +import { ExpressInstrumentationConfig, ExpressLayer } from '../src/types'; +import { ExpressLayerType } from '../src/enums/ExpressLayerType'; +import { AttributeNames } from '../src/enums/AttributeNames'; describe('Utils', () => { describe('isLayerIgnored()', () => { @@ -103,8 +100,8 @@ describe('Utils', () => { ), { attributes: { - [CustomAttributeNames.EXPRESS_NAME]: '/test', - [CustomAttributeNames.EXPRESS_TYPE]: 'router', + [AttributeNames.EXPRESS_NAME]: '/test', + [AttributeNames.EXPRESS_TYPE]: 'router', }, name: 'router - /test', } @@ -121,8 +118,8 @@ describe('Utils', () => { ), { attributes: { - [CustomAttributeNames.EXPRESS_NAME]: '/:id', - [CustomAttributeNames.EXPRESS_TYPE]: 'request_handler', + [AttributeNames.EXPRESS_NAME]: '/:id', + [AttributeNames.EXPRESS_TYPE]: 'request_handler', }, name: 'request handler', } @@ -136,8 +133,8 @@ describe('Utils', () => { } as ExpressLayer), { attributes: { - [CustomAttributeNames.EXPRESS_NAME]: 'bodyParser', - [CustomAttributeNames.EXPRESS_TYPE]: 'middleware', + [AttributeNames.EXPRESS_NAME]: 'bodyParser', + [AttributeNames.EXPRESS_TYPE]: 'middleware', }, name: 'middleware - bodyParser', } diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/enum.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/enum.ts index 20d7e0c914..8be168b96c 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/enum.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/enum.ts @@ -45,17 +45,6 @@ export enum TokenKind { COMMENT = 'Comment', } -export enum SpanAttributes { - COMPONENT = 'graphql', - SOURCE = 'graphql.source', - FIELD_NAME = 'graphql.field.name', - FIELD_PATH = 'graphql.field.path', - FIELD_TYPE = 'graphql.field.type', - OPERATION = 'graphql.operation.name', - VARIABLES = 'graphql.variables.', - ERROR_VALIDATION_NAME = 'graphql.validation.error', -} - export enum SpanNames { EXECUTE = 'graphql.execute', PARSE = 'graphql.parse', diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/enums/AttributeNames.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/enums/AttributeNames.ts new file mode 100644 index 0000000000..b5a1027a41 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/enums/AttributeNames.ts @@ -0,0 +1,25 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export enum AttributeNames { + COMPONENT = 'graphql', + SOURCE = 'graphql.source', + FIELD_NAME = 'graphql.field.name', + FIELD_PATH = 'graphql.field.path', + FIELD_TYPE = 'graphql.field.type', + OPERATION = 'graphql.operation.name', + VARIABLES = 'graphql.variables.', + ERROR_VALIDATION_NAME = 'graphql.validation.error', +} diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/graphql.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/graphql.ts index cfd3e6968d..043e9997c9 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/graphql.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/graphql.ts @@ -25,7 +25,8 @@ import { } from '@opentelemetry/instrumentation'; import type * as graphqlTypes from 'graphql'; import { GraphQLFieldResolver } from 'graphql/type/definition'; -import { SpanAttributes, SpanNames } from './enum'; +import { SpanNames } from './enum'; +import { AttributeNames } from './enums/AttributeNames'; import { OTEL_GRAPHQL_DATA_SYMBOL } from './symbols'; import { @@ -334,7 +335,7 @@ export class GraphQLInstrumentation extends InstrumentationBase { } if (errors && errors.length) { span.recordException({ - name: SpanAttributes.ERROR_VALIDATION_NAME, + name: AttributeNames.ERROR_VALIDATION_NAME, message: JSON.stringify(errors), }); } @@ -355,7 +356,7 @@ export class GraphQLInstrumentation extends InstrumentationBase { const name = (operation as graphqlTypes.OperationDefinitionNode) .operation; if (name) { - span.setAttribute(SpanAttributes.OPERATION, name); + span.setAttribute(AttributeNames.OPERATION, name); } } else { let operationName = ' '; @@ -366,7 +367,7 @@ export class GraphQLInstrumentation extends InstrumentationBase { '$operationName$', operationName ); - span.setAttribute(SpanAttributes.OPERATION, operationName); + span.setAttribute(AttributeNames.OPERATION, operationName); } if (processedArgs.document?.loc) { @@ -375,7 +376,7 @@ export class GraphQLInstrumentation extends InstrumentationBase { if (processedArgs.variableValues && config.allowValues) { Object.entries(processedArgs.variableValues).forEach(([key, value]) => { - span.setAttribute(`${SpanAttributes.VARIABLES}${String(key)}`, value); + span.setAttribute(`${AttributeNames.VARIABLES}${String(key)}`, value); }); } diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts index 6875d22b62..663b5e4c31 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts @@ -17,12 +17,8 @@ import type * as graphqlTypes from 'graphql'; import * as api from '@opentelemetry/api'; import { GraphQLObjectType } from 'graphql/type/definition'; -import { - AllowedOperationTypes, - SpanAttributes, - SpanNames, - TokenKind, -} from './enum'; +import { AllowedOperationTypes, SpanNames, TokenKind } from './enum'; +import { AttributeNames } from './enums/AttributeNames'; import { OTEL_GRAPHQL_DATA_SYMBOL, OTEL_PATCHED_SYMBOL } from './symbols'; import { GraphQLField, @@ -44,7 +40,7 @@ export function addSpanSource( end?: number ): void { const source = getSourceFromLocation(loc, allowValues, start, end); - span.setAttribute(SpanAttributes.SOURCE, source); + span.setAttribute(AttributeNames.SOURCE, source); } function createFieldIfNotExists( @@ -93,9 +89,9 @@ function createResolverSpan( parentSpan?: api.Span ): api.Span { const attributes: api.SpanAttributes = { - [SpanAttributes.FIELD_NAME]: info.fieldName, - [SpanAttributes.FIELD_PATH]: path.join('.'), - [SpanAttributes.FIELD_TYPE]: info.returnType.toString(), + [AttributeNames.FIELD_NAME]: info.fieldName, + [AttributeNames.FIELD_PATH]: path.join('.'), + [AttributeNames.FIELD_TYPE]: info.returnType.toString(), }; const span = tracer.startSpan( diff --git a/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts b/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts index 4016a7fc3f..2fe6851ab9 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts @@ -22,7 +22,8 @@ import { } from '@opentelemetry/tracing'; import * as assert from 'assert'; import { GraphQLInstrumentation } from '../src'; -import { SpanAttributes, SpanNames } from '../src/enum'; +import { SpanNames } from '../src/enum'; +import { AttributeNames } from '../src/enums/AttributeNames'; import { GraphQLInstrumentationConfig } from '../src/types'; import { assertResolveSpan } from './helper'; @@ -118,7 +119,7 @@ describe('graphql', () => { it('should instrument parse', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' books {\n' + @@ -140,7 +141,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' books {\n' + @@ -149,7 +150,7 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'query' ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); @@ -220,7 +221,7 @@ describe('graphql', () => { it('should instrument parse', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' book(id: *) {\n' + @@ -242,7 +243,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' book(id: *) {\n' + @@ -251,7 +252,7 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'query' ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); @@ -306,7 +307,7 @@ describe('graphql', () => { it('should instrument parse', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' query Query1 ($id: Int!) {\n' + ' book(id: $id) {\n' + @@ -328,7 +329,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' query Query1 ($id: Int!) {\n' + ' book(id: $id) {\n' + @@ -337,11 +338,11 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'query' ); assert.deepStrictEqual( - executeSpan.attributes[`${SpanAttributes.VARIABLES}id`], + executeSpan.attributes[`${AttributeNames.VARIABLES}id`], undefined ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); @@ -398,7 +399,7 @@ describe('graphql', () => { it('should instrument parse', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' books {\n' + @@ -420,7 +421,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' books {\n' + @@ -429,7 +430,7 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'query' ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); @@ -462,7 +463,7 @@ describe('graphql', () => { it('should instrument parse', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' books {\n' + @@ -484,7 +485,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' books {\n' + @@ -493,7 +494,7 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'query' ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); @@ -549,7 +550,7 @@ describe('graphql', () => { it('should instrument parse', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' book(id: 0) {\n' + @@ -571,7 +572,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' book(id: 0) {\n' + @@ -580,7 +581,7 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'query' ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); @@ -635,7 +636,7 @@ describe('graphql', () => { it('should instrument parse', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' mutation {\n' + ' addBook(\n' + @@ -660,7 +661,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' mutation {\n' + ' addBook(\n' + @@ -672,7 +673,7 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'mutation' ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); @@ -727,7 +728,7 @@ describe('graphql', () => { it('should instrument parse', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' query Query1 ($id: Int!) {\n' + ' book(id: $id) {\n' + @@ -749,7 +750,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' query Query1 ($id: Int!) {\n' + ' book(id: $id) {\n' + @@ -758,11 +759,11 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'query' ); assert.deepStrictEqual( - executeSpan.attributes[`${SpanAttributes.VARIABLES}id`], + executeSpan.attributes[`${AttributeNames.VARIABLES}id`], 2 ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); @@ -819,7 +820,7 @@ describe('graphql', () => { it('should instrument parse', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' mutation {\n' + ' addBook(\n' + @@ -844,7 +845,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' mutation {\n' + ' addBook(\n' + @@ -856,7 +857,7 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'mutation' ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); @@ -943,7 +944,7 @@ describe('graphql', () => { it('should instrument parse with error', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' book(id: "*") {\n' + @@ -964,7 +965,7 @@ describe('graphql', () => { assert.deepStrictEqual(event.name, 'exception'); assert.deepStrictEqual( event.attributes!['exception.type'], - SpanAttributes.ERROR_VALIDATION_NAME + AttributeNames.ERROR_VALIDATION_NAME ); assert.ok(event.attributes!['exception.message']); }); @@ -996,7 +997,7 @@ describe('graphql', () => { it('should instrument parse with error', () => { const parseSpan = spans[0]; assert.deepStrictEqual( - parseSpan.attributes[SpanAttributes.SOURCE], + parseSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' book(id: *) {\n' + @@ -1021,7 +1022,7 @@ describe('graphql', () => { const executeSpan = spans[2]; assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.SOURCE], + executeSpan.attributes[AttributeNames.SOURCE], '\n' + ' query {\n' + ' book(id: *) {\n' + @@ -1030,7 +1031,7 @@ describe('graphql', () => { ' }\n' ); assert.deepStrictEqual( - executeSpan.attributes[SpanAttributes.OPERATION], + executeSpan.attributes[AttributeNames.OPERATION], 'Operation "foo" not supported' ); assert.deepStrictEqual(executeSpan.name, SpanNames.EXECUTE); diff --git a/plugins/node/opentelemetry-instrumentation-graphql/test/helper.ts b/plugins/node/opentelemetry-instrumentation-graphql/test/helper.ts index f633d6bd82..3bd0f6f734 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/test/helper.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/test/helper.ts @@ -16,7 +16,8 @@ import { ReadableSpan } from '@opentelemetry/tracing'; import * as assert from 'assert'; -import { SpanAttributes, SpanNames } from '../src/enum'; +import { SpanNames } from '../src/enum'; +import { AttributeNames } from '../src/enums/AttributeNames'; export function assertResolveSpan( span: ReadableSpan, @@ -28,10 +29,10 @@ export function assertResolveSpan( ) { const attrs = span.attributes; assert.deepStrictEqual(span.name, SpanNames.RESOLVE); - assert.deepStrictEqual(attrs[SpanAttributes.FIELD_NAME], fieldName); - assert.deepStrictEqual(attrs[SpanAttributes.FIELD_PATH], fieldPath); - assert.deepStrictEqual(attrs[SpanAttributes.FIELD_TYPE], fieldType); - assert.deepStrictEqual(attrs[SpanAttributes.SOURCE], source); + assert.deepStrictEqual(attrs[AttributeNames.FIELD_NAME], fieldName); + assert.deepStrictEqual(attrs[AttributeNames.FIELD_PATH], fieldPath); + assert.deepStrictEqual(attrs[AttributeNames.FIELD_TYPE], fieldType); + assert.deepStrictEqual(attrs[AttributeNames.SOURCE], source); if (parentSpanId) { assert.deepStrictEqual(span.parentSpanId, parentSpanId); } diff --git a/plugins/node/opentelemetry-instrumentation-hapi/src/enums/AttributeNames.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/enums/AttributeNames.ts new file mode 100644 index 0000000000..a387ce0287 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-hapi/src/enums/AttributeNames.ts @@ -0,0 +1,20 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export enum AttributeNames { + HAPI_TYPE = 'hapi.type', + PLUGIN_NAME = 'hapi.plugin.name', + EXT_TYPE = 'server.ext.type', +} diff --git a/plugins/node/opentelemetry-instrumentation-hapi/src/types.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/types.ts index 5383b1382f..782776b5a3 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/src/types.ts @@ -62,12 +62,6 @@ export type ServerExtDirectInput = [ (Hapi.ServerExtOptions | undefined)? ]; -export const AttributeNames = { - HAPI_TYPE: 'hapi.type', - PLUGIN_NAME: 'hapi.plugin.name', - EXT_TYPE: 'server.ext.type', -}; - export const HapiLayerType = { ROUTER: 'router', PLUGIN: 'plugin', diff --git a/plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts index c42378554f..20f9cab058 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts @@ -18,12 +18,12 @@ import { SpanAttributes } from '@opentelemetry/api'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import type * as Hapi from '@hapi/hapi'; import { - AttributeNames, HapiLayerType, HapiLifecycleMethodNames, PatchableExtMethod, ServerExtDirectInput, } from './types'; +import { AttributeNames } from './enums/AttributeNames'; export function getPluginName(plugin: Hapi.Plugin): string { if ((plugin as Hapi.PluginNameVersion).name) { diff --git a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts index f4e51c225a..d3f416ee4a 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-plugin.test.ts @@ -25,7 +25,8 @@ import * as assert from 'assert'; import { getPlugin } from './plugin'; const plugin = getPlugin(); import * as hapi from '@hapi/hapi'; -import { AttributeNames, HapiLayerType } from '../src/types'; +import { HapiLayerType } from '../src/types'; +import { AttributeNames } from '../src/enums/AttributeNames'; describe('Hapi Instrumentation - Hapi.Plugin Tests', () => { const provider = new NodeTracerProvider(); diff --git a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts index 1e7b61ec50..56647b04ff 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi-server-ext.test.ts @@ -26,7 +26,8 @@ import { getPlugin } from './plugin'; const plugin = getPlugin(); import * as hapi from '@hapi/hapi'; -import { AttributeNames, HapiLayerType } from '../src/types'; +import { HapiLayerType } from '../src/types'; +import { AttributeNames } from '../src/enums/AttributeNames'; describe('Hapi Instrumentation - Server.Ext Tests', () => { const provider = new NodeTracerProvider(); diff --git a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts index 5d71d67152..821b01bff9 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts @@ -26,7 +26,8 @@ const plugin = getPlugin(); import * as assert from 'assert'; import * as hapi from '@hapi/hapi'; -import { AttributeNames, HapiLayerType } from '../src/types'; +import { HapiLayerType } from '../src/types'; +import { AttributeNames } from '../src/enums/AttributeNames'; describe('Hapi Instrumentation - Core Tests', () => { const provider = new NodeTracerProvider(); diff --git a/plugins/node/opentelemetry-instrumentation-koa/src/enums/AttributeNames.ts b/plugins/node/opentelemetry-instrumentation-koa/src/enums/AttributeNames.ts new file mode 100644 index 0000000000..f3387b6393 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-koa/src/enums/AttributeNames.ts @@ -0,0 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export enum AttributeNames { + KOA_TYPE = 'koa.type', + KOA_NAME = 'koa.name', +} diff --git a/plugins/node/opentelemetry-instrumentation-koa/src/koa.ts b/plugins/node/opentelemetry-instrumentation-koa/src/koa.ts index 223223aece..509513fae6 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/src/koa.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/src/koa.ts @@ -29,8 +29,8 @@ import { KoaComponentName, kLayerPatched, KoaLayerType, - AttributeNames, } from './types'; +import { AttributeNames } from './enums/AttributeNames'; import { VERSION } from './version'; import { getMiddlewareMetadata } from './utils'; diff --git a/plugins/node/opentelemetry-instrumentation-koa/src/types.ts b/plugins/node/opentelemetry-instrumentation-koa/src/types.ts index 4e3db9307c..6485be8ee8 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/src/types.ts @@ -30,11 +30,6 @@ export type KoaMiddleware = Middleware & { export type KoaContext = ParameterizedContext; -export enum AttributeNames { - KOA_TYPE = 'koa.type', - KOA_NAME = 'koa.name', -} - export enum KoaLayerType { ROUTER = 'router', MIDDLEWARE = 'middleware', diff --git a/plugins/node/opentelemetry-instrumentation-koa/src/utils.ts b/plugins/node/opentelemetry-instrumentation-koa/src/utils.ts index 8e43934dbf..a58dc91fd2 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/src/utils.ts @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { - AttributeNames, - KoaContext, - KoaMiddleware, - KoaLayerType, -} from './types'; +import { KoaContext, KoaMiddleware, KoaLayerType } from './types'; +import { AttributeNames } from './enums/AttributeNames'; import { SpanAttributes } from '@opentelemetry/api'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; diff --git a/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts b/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts index 3aae196cf9..c3f7d1db59 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts @@ -31,7 +31,8 @@ import * as assert from 'assert'; import * as koa from 'koa'; import * as http from 'http'; import { AddressInfo } from 'net'; -import { AttributeNames, KoaLayerType } from '../src/types'; +import { KoaLayerType } from '../src/types'; +import { AttributeNames } from '../src/enums/AttributeNames'; const httpRequest = { get: (options: http.ClientRequestArgs | string) => { diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/enums.ts b/plugins/node/opentelemetry-instrumentation-pg/src/enums.ts index 994de4cb4f..bcd7cadc04 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/enums.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/enums.ts @@ -13,11 +13,3 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -// Postgresql specific attributes not covered by semantic conventions -export enum AttributeNames { - PG_VALUES = 'db.postgresql.values', - PG_PLAN = 'db.postgresql.plan', - IDLE_TIMEOUT_MILLIS = 'db.postgresql.idle.timeout.millis', - MAX_CLIENT = 'db.postgresql.max.client', -} diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/enums/AttributeNames.ts b/plugins/node/opentelemetry-instrumentation-pg/src/enums/AttributeNames.ts new file mode 100644 index 0000000000..6dc453c53d --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-pg/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. + */ +// Postgresql specific attributes not covered by semantic conventions +export enum AttributeNames { + PG_VALUES = 'db.postgresql.values', + PG_PLAN = 'db.postgresql.plan', + IDLE_TIMEOUT_MILLIS = 'db.postgresql.idle.timeout.millis', + MAX_CLIENT = 'db.postgresql.max.client', +} diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/pg.ts b/plugins/node/opentelemetry-instrumentation-pg/src/pg.ts index 67b43c84bf..f8356f2c9f 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/pg.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/pg.ts @@ -38,7 +38,7 @@ import { PgPoolCallback, } from './types'; import * as utils from './utils'; -import { AttributeNames } from './enums'; +import { AttributeNames } from './enums/AttributeNames'; import { SemanticAttributes, DbSystemValues, diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts index 8d70757cab..7ffc045ee8 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts @@ -15,11 +15,11 @@ */ import { Span, SpanStatusCode, Tracer, SpanKind } from '@opentelemetry/api'; +import { AttributeNames } from './enums/AttributeNames'; import { SemanticAttributes, DbSystemValues, } from '@opentelemetry/semantic-conventions'; -import { AttributeNames } from './enums'; import { PgClientExtended, NormalizedQueryConfig, diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts index 7dce86851e..6ce377719a 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts @@ -34,7 +34,7 @@ import { import * as assert from 'assert'; import * as pg from 'pg'; import * as pgPool from 'pg-pool'; -import { AttributeNames } from '../src/enums'; +import { AttributeNames } from '../src/enums/AttributeNames'; import { TimedEvent } from './types'; import { SemanticAttributes, diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts index f1370a0b19..06aa9be7d8 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts @@ -34,7 +34,7 @@ import { import * as assert from 'assert'; import type * as pg from 'pg'; import { PgInstrumentation } from '../src'; -import { AttributeNames } from '../src/enums'; +import { AttributeNames } from '../src/enums/AttributeNames'; import { TimedEvent } from './types'; import { SemanticAttributes, diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts index b5de061fbf..dad020dcb2 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/utils.test.ts @@ -25,7 +25,7 @@ import { import * as assert from 'assert'; import * as pg from 'pg'; import { PgInstrumentationConfig } from '../src'; -import { AttributeNames } from '../src/enums'; +import { AttributeNames } from '../src/enums/AttributeNames'; import { PgClientExtended, NormalizedQueryConfig } from '../src/types'; import * as utils from '../src/utils'; diff --git a/plugins/node/opentelemetry-instrumentation-restify/src/enums/AttributeNames.ts b/plugins/node/opentelemetry-instrumentation-restify/src/enums/AttributeNames.ts new file mode 100644 index 0000000000..c56fcd0dce --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-restify/src/enums/AttributeNames.ts @@ -0,0 +1,21 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export enum AttributeNames { + TYPE = 'restify.type', + NAME = 'restify.name', + METHOD = 'restify.method', + VERSION = 'restify.version', +} diff --git a/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts index d7de0f4c5e..d2f38c9915 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts @@ -18,6 +18,7 @@ import * as api from '@opentelemetry/api'; import * as restify from 'restify'; import { Server } from 'restify'; import * as types from './types'; +import * as AttributeNames from './enums/AttributeNames'; import { VERSION } from './version'; import * as constants from './constants'; import { @@ -183,10 +184,10 @@ export class RestifyInstrumentation extends InstrumentationBase< ? `request handler - ${route}` : `middleware - ${fnName || 'anonymous'}`; const attributes = { - [types.CustomAttributeNames.NAME]: fnName, - [types.CustomAttributeNames.VERSION]: this._moduleVersion || 'n/a', - [types.CustomAttributeNames.TYPE]: metadata.type, - [types.CustomAttributeNames.METHOD]: metadata.methodName, + [AttributeNames.AttributeNames.NAME]: fnName, + [AttributeNames.AttributeNames.VERSION]: this._moduleVersion || 'n/a', + [AttributeNames.AttributeNames.TYPE]: metadata.type, + [AttributeNames.AttributeNames.METHOD]: metadata.methodName, [SemanticAttributes.HTTP_ROUTE]: route, }; const span = this.tracer.startSpan( diff --git a/plugins/node/opentelemetry-instrumentation-restify/src/types.ts b/plugins/node/opentelemetry-instrumentation-restify/src/types.ts index 3af3984cd1..85bd3afe04 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-restify/src/types.ts @@ -17,13 +17,6 @@ import { Span } from '@opentelemetry/api'; import * as restify from 'restify'; import { REQ_SPAN } from './constants'; -export enum CustomAttributeNames { - TYPE = 'restify.type', - NAME = 'restify.name', - METHOD = 'restify.method', - VERSION = 'restify.version', -} - export enum LayerType { MIDDLEWARE = 'middleware', REQUEST_HANDLER = 'request_handler',