diff --git a/packages/opentelemetry-test-utils/package.json b/packages/opentelemetry-test-utils/package.json index d9f931883a..04237fd106 100644 --- a/packages/opentelemetry-test-utils/package.json +++ b/packages/opentelemetry-test-utils/package.json @@ -23,6 +23,7 @@ }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "devDependencies": { + "@types/node": "^14.0.27", "gts": "2.0.2", "ts-node": "8.10.2", "tslint-consistent-codestyle": "1.16.0", diff --git a/plugins/node/opentelemetry-plugin-ioredis/package.json b/plugins/node/opentelemetry-plugin-ioredis/package.json index 774abaea7c..759a143402 100644 --- a/plugins/node/opentelemetry-plugin-ioredis/package.json +++ b/plugins/node/opentelemetry-plugin-ioredis/package.json @@ -46,6 +46,7 @@ "devDependencies": { "@opentelemetry/context-async-hooks": "0.10.2", "@opentelemetry/node": "0.10.2", + "@opentelemetry/semantic-conventions": "^0.10.2", "@opentelemetry/test-utils": "^0.9.0", "@opentelemetry/tracing": "0.10.2", "@types/ioredis": "4.17.3", diff --git a/plugins/node/opentelemetry-plugin-ioredis/src/enums.ts b/plugins/node/opentelemetry-plugin-ioredis/src/enums.ts deleted file mode 100644 index f229cf64e5..0000000000 --- a/plugins/node/opentelemetry-plugin-ioredis/src/enums.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export enum AttributeNames { - // required by https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-database.md - COMPONENT = 'component', - DB_TYPE = 'db.type', - DB_INSTANCE = 'db.instance', - DB_STATEMENT = 'db.statement', - PEER_ADDRESS = 'peer.address', - PEER_HOSTNAME = 'peer.host', - - // optional - DB_USER = 'db.user', - PEER_PORT = 'peer.port', - PEER_IPV4 = 'peer.ipv4', - PEER_IPV6 = 'peer.ipv6', - PEER_SERVICE = 'peer.service', -} diff --git a/plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts b/plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts index 48340921f3..92f6cef781 100644 --- a/plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts +++ b/plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts @@ -22,8 +22,7 @@ import { traceConnection, traceSendCommand } from './utils'; import { VERSION } from './version'; export class IORedisPlugin extends BasePlugin { - static readonly COMPONENT = 'ioredis'; - static readonly DB_TYPE = 'redis'; + static readonly DB_SYSTEM = 'redis'; readonly supportedVersions = ['>1 <5']; protected _config!: IoredisPluginConfig; @@ -74,4 +73,4 @@ export class IORedisPlugin extends BasePlugin { } } -export const plugin = new IORedisPlugin(IORedisPlugin.COMPONENT); +export const plugin = new IORedisPlugin('ioredis'); diff --git a/plugins/node/opentelemetry-plugin-ioredis/src/utils.ts b/plugins/node/opentelemetry-plugin-ioredis/src/utils.ts index c53ccc6fbe..c452123568 100644 --- a/plugins/node/opentelemetry-plugin-ioredis/src/utils.ts +++ b/plugins/node/opentelemetry-plugin-ioredis/src/utils.ts @@ -23,7 +23,10 @@ import { DbStatementSerializer, } from './types'; import { IORedisPlugin } from './ioredis'; -import { AttributeNames } from './enums'; +import { + DatabaseAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; const endSpan = (span: Span, err: NodeJS.ErrnoException | null | undefined) => { if (err) { @@ -42,17 +45,16 @@ export const traceConnection = (tracer: Tracer, original: Function) => { const span = tracer.startSpan('connect', { kind: SpanKind.CLIENT, attributes: { - [AttributeNames.COMPONENT]: IORedisPlugin.COMPONENT, - [AttributeNames.DB_TYPE]: IORedisPlugin.DB_TYPE, - [AttributeNames.DB_STATEMENT]: 'connect', + [DatabaseAttribute.DB_SYSTEM]: IORedisPlugin.DB_SYSTEM, + [DatabaseAttribute.DB_STATEMENT]: 'connect', }, }); const { host, port } = this.options; span.setAttributes({ - [AttributeNames.PEER_HOSTNAME]: host, - [AttributeNames.PEER_PORT]: port, - [AttributeNames.PEER_ADDRESS]: `redis://${host}:${port}`, + [GeneralAttribute.NET_PEER_HOSTNAME]: host, + [GeneralAttribute.NET_PEER_PORT]: port, + [GeneralAttribute.NET_PEER_ADDRESS]: `redis://${host}:${port}`, }); try { const client = original.apply(this, arguments); @@ -95,9 +97,8 @@ export const traceSendCommand = ( const span = tracer.startSpan(cmd.name, { kind: SpanKind.CLIENT, attributes: { - [AttributeNames.COMPONENT]: IORedisPlugin.COMPONENT, - [AttributeNames.DB_TYPE]: IORedisPlugin.DB_TYPE, - [AttributeNames.DB_STATEMENT]: dbStatementSerializer( + [DatabaseAttribute.DB_SYSTEM]: IORedisPlugin.DB_SYSTEM, + [DatabaseAttribute.DB_STATEMENT]: dbStatementSerializer( cmd.name, cmd.args ), @@ -107,9 +108,9 @@ export const traceSendCommand = ( const { host, port } = this.options; span.setAttributes({ - [AttributeNames.PEER_HOSTNAME]: host, - [AttributeNames.PEER_PORT]: port, - [AttributeNames.PEER_ADDRESS]: `redis://${host}:${port}`, + [GeneralAttribute.NET_PEER_HOSTNAME]: host, + [GeneralAttribute.NET_PEER_PORT]: port, + [GeneralAttribute.NET_PEER_ADDRESS]: `redis://${host}:${port}`, }); try { diff --git a/plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts b/plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts index 95afd4383f..44494ed6cf 100644 --- a/plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts +++ b/plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts @@ -26,8 +26,11 @@ import { import * as assert from 'assert'; import * as ioredisTypes from 'ioredis'; import { IORedisPlugin, plugin } from '../src'; -import { AttributeNames } from '../src/enums'; import { IoredisPluginConfig, DbStatementSerializer } from '../src/types'; +import { + DatabaseAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; const memoryExporter = new InMemorySpanExporter(); @@ -39,11 +42,10 @@ const CONFIG = { const URL = `redis://${CONFIG.host}:${CONFIG.port}`; const DEFAULT_ATTRIBUTES = { - [AttributeNames.COMPONENT]: IORedisPlugin.COMPONENT, - [AttributeNames.DB_TYPE]: IORedisPlugin.DB_TYPE, - [AttributeNames.PEER_HOSTNAME]: CONFIG.host, - [AttributeNames.PEER_PORT]: CONFIG.port, - [AttributeNames.PEER_ADDRESS]: URL, + [DatabaseAttribute.DB_SYSTEM]: IORedisPlugin.DB_SYSTEM, + [GeneralAttribute.NET_PEER_HOSTNAME]: CONFIG.host, + [GeneralAttribute.NET_PEER_PORT]: CONFIG.port, + [GeneralAttribute.NET_PEER_ADDRESS]: URL, }; const okStatus: Status = { @@ -91,7 +93,7 @@ describe('ioredis', () => { }); it('should have correct module name', () => { - assert.strictEqual(plugin.moduleName, IORedisPlugin.COMPONENT); + assert.strictEqual(plugin.moduleName, 'ioredis'); }); describe('#createClient()', () => { @@ -100,7 +102,7 @@ describe('ioredis', () => { let client: ioredisTypes.Redis; const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'connect', + [DatabaseAttribute.DB_STATEMENT]: 'connect', }; const readyHandler = () => { const endedSpans = memoryExporter.getFinishedSpans(); @@ -194,9 +196,9 @@ describe('ioredis', () => { it(`should create a child span for cb style ${command.description}`, done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: `${command.name} ${command.args.join( - ' ' - )}`, + [DatabaseAttribute.DB_STATEMENT]: `${ + command.name + } ${command.args.join(' ')}`, }; const span = provider .getTracer('ioredis-test') @@ -226,7 +228,7 @@ describe('ioredis', () => { it('should create a child span for hset promise', async () => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'hset hash random random', + [DatabaseAttribute.DB_STATEMENT]: 'hset hash random random', }; const span = provider.getTracer('ioredis-test').startSpan('test span'); await provider.getTracer('ioredis-test').withSpan(span, async () => { @@ -254,7 +256,7 @@ describe('ioredis', () => { it('should create a child span for streamify scanning', done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'scan 0', + [DatabaseAttribute.DB_STATEMENT]: 'scan 0', }; const span = provider.getTracer('ioredis-test').startSpan('test span'); provider.getTracer('ioredis-test').withSpan(span, () => { @@ -329,7 +331,7 @@ describe('ioredis', () => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'subscribe news music', + [DatabaseAttribute.DB_STATEMENT]: 'subscribe news music', }; testUtils.assertSpan( endedSpans[5], @@ -348,7 +350,7 @@ describe('ioredis', () => { it('should create a child span for lua', done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: + [DatabaseAttribute.DB_STATEMENT]: 'evalsha bfbf458525d6a0b19200bfd6db3af481156b367b 1 test', }; @@ -387,7 +389,7 @@ describe('ioredis', () => { it('should create a child span for multi/transaction', done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'multi', + [DatabaseAttribute.DB_STATEMENT]: 'multi', }; const span = provider.getTracer('ioredis-test').startSpan('test span'); @@ -423,7 +425,7 @@ describe('ioredis', () => { it('should create a child span for pipeline', done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'set foo bar', + [DatabaseAttribute.DB_STATEMENT]: 'set foo bar', }; const span = provider.getTracer('ioredis-test').startSpan('test span'); @@ -457,7 +459,7 @@ describe('ioredis', () => { it('should create a child span for get promise', async () => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'get test', + [DatabaseAttribute.DB_STATEMENT]: 'get test', }; const span = provider.getTracer('ioredis-test').startSpan('test span'); await provider.getTracer('ioredis-test').withSpan(span, async () => { @@ -486,7 +488,7 @@ describe('ioredis', () => { it('should create a child span for del', async () => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'del test', + [DatabaseAttribute.DB_STATEMENT]: 'del test', }; const span = provider.getTracer('ioredis-test').startSpan('test span'); await provider.getTracer('ioredis-test').withSpan(span, async () => { @@ -541,7 +543,7 @@ describe('ioredis', () => { it(`should tag the span with a custom db.statement for cb style ${command.description}`, done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: dbStatementSerializer( + [DatabaseAttribute.DB_STATEMENT]: dbStatementSerializer( command.name, command.args ), diff --git a/plugins/node/opentelemetry-plugin-redis/package.json b/plugins/node/opentelemetry-plugin-redis/package.json index 389bff65bc..2b7bf831f4 100644 --- a/plugins/node/opentelemetry-plugin-redis/package.json +++ b/plugins/node/opentelemetry-plugin-redis/package.json @@ -45,6 +45,7 @@ "devDependencies": { "@opentelemetry/context-async-hooks": "0.10.2", "@opentelemetry/node": "0.10.2", + "@opentelemetry/semantic-conventions": "^0.10.2", "@opentelemetry/test-utils": "^0.9.0", "@opentelemetry/tracing": "0.10.2", "@types/mocha": "7.0.2", diff --git a/plugins/node/opentelemetry-plugin-redis/src/enums.ts b/plugins/node/opentelemetry-plugin-redis/src/enums.ts deleted file mode 100644 index f229cf64e5..0000000000 --- a/plugins/node/opentelemetry-plugin-redis/src/enums.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export enum AttributeNames { - // required by https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-database.md - COMPONENT = 'component', - DB_TYPE = 'db.type', - DB_INSTANCE = 'db.instance', - DB_STATEMENT = 'db.statement', - PEER_ADDRESS = 'peer.address', - PEER_HOSTNAME = 'peer.host', - - // optional - DB_USER = 'db.user', - PEER_PORT = 'peer.port', - PEER_IPV4 = 'peer.ipv4', - PEER_IPV6 = 'peer.ipv6', - PEER_SERVICE = 'peer.service', -} diff --git a/plugins/node/opentelemetry-plugin-redis/src/utils.ts b/plugins/node/opentelemetry-plugin-redis/src/utils.ts index 0b9f14e8b6..6d486d5324 100644 --- a/plugins/node/opentelemetry-plugin-redis/src/utils.ts +++ b/plugins/node/opentelemetry-plugin-redis/src/utils.ts @@ -23,7 +23,10 @@ import { } from './types'; import { EventEmitter } from 'events'; import { RedisPlugin } from './redis'; -import { AttributeNames } from './enums'; +import { + DatabaseAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; const endSpan = (span: Span, err?: Error | null) => { if (err) { @@ -78,21 +81,21 @@ export const getTracedInternalSendCommand = ( const span = tracer.startSpan(`${RedisPlugin.COMPONENT}-${cmd.command}`, { kind: SpanKind.CLIENT, attributes: { - [AttributeNames.COMPONENT]: RedisPlugin.COMPONENT, - [AttributeNames.DB_STATEMENT]: cmd.command, + [DatabaseAttribute.DB_SYSTEM]: RedisPlugin.COMPONENT, + [DatabaseAttribute.DB_STATEMENT]: cmd.command, }, }); // Set attributes for not explicitly typed RedisPluginClientTypes if (this.options) { span.setAttributes({ - [AttributeNames.PEER_HOSTNAME]: this.options.host, - [AttributeNames.PEER_PORT]: this.options.port, + [GeneralAttribute.NET_PEER_HOSTNAME]: this.options.host, + [GeneralAttribute.NET_PEER_PORT]: this.options.port, }); } if (this.address) { span.setAttribute( - AttributeNames.PEER_ADDRESS, + GeneralAttribute.NET_PEER_ADDRESS, `redis://${this.address}` ); } diff --git a/plugins/node/opentelemetry-plugin-redis/test/redis.test.ts b/plugins/node/opentelemetry-plugin-redis/test/redis.test.ts index 09dc0ad596..ecc62248f0 100644 --- a/plugins/node/opentelemetry-plugin-redis/test/redis.test.ts +++ b/plugins/node/opentelemetry-plugin-redis/test/redis.test.ts @@ -26,7 +26,10 @@ import { import * as assert from 'assert'; import * as redisTypes from 'redis'; import { plugin, RedisPlugin } from '../src'; -import { AttributeNames } from '../src/enums'; +import { + DatabaseAttribute, + GeneralAttribute, +} from '@opentelemetry/semantic-conventions'; const memoryExporter = new InMemorySpanExporter(); @@ -38,10 +41,10 @@ const CONFIG = { const URL = `redis://${CONFIG.host}:${CONFIG.port}`; const DEFAULT_ATTRIBUTES = { - [AttributeNames.COMPONENT]: RedisPlugin.COMPONENT, - [AttributeNames.PEER_HOSTNAME]: CONFIG.host, - [AttributeNames.PEER_PORT]: CONFIG.port, - [AttributeNames.PEER_ADDRESS]: URL, + [DatabaseAttribute.DB_SYSTEM]: RedisPlugin.COMPONENT, + [GeneralAttribute.NET_PEER_HOSTNAME]: CONFIG.host, + [GeneralAttribute.NET_PEER_PORT]: CONFIG.port, + [GeneralAttribute.NET_PEER_ADDRESS]: URL, }; const okStatus: Status = { @@ -172,7 +175,7 @@ describe('redis@2.x', () => { it(`should create a child span for ${operation.description}`, done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: operation.command, + [DatabaseAttribute.DB_STATEMENT]: operation.command, }; const span = tracer.startSpan('test span'); tracer.withSpan(span, () => {