Skip to content

Commit

Permalink
fix: conform to semantic conventions
Browse files Browse the repository at this point in the history
Signed-off-by: Naseem <naseem@transit.app>
  • Loading branch information
Naseem committed Aug 10, 2020
1 parent 32a87c6 commit 1c68ea4
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 127 deletions.
19 changes: 10 additions & 9 deletions plugins/node/opentelemetry-plugin-ioredis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/context-async-hooks": "0.10.2",
"@opentelemetry/node": "0.10.2",
"@opentelemetry/context-async-hooks": "0.10.1",
"@opentelemetry/node": "0.10.1",
"@opentelemetry/semantic-conventions": "^0.10.2",
"@opentelemetry/test-utils": "^0.9.0",
"@opentelemetry/tracing": "0.10.2",
"@types/ioredis": "4.17.3",
"@opentelemetry/tracing": "0.10.1",
"@types/ioredis": "4.17.2",
"@types/mocha": "7.0.2",
"@types/node": "14.0.27",
"@types/node": "13.13.14",
"@types/shimmer": "1.0.1",
"codecov": "3.7.2",
"codecov": "3.7.1",
"cross-env": "7.0.2",
"gts": "2.0.2",
"ioredis": "4.17.3",
Expand All @@ -63,11 +64,11 @@
"ts-node": "8.10.2",
"tslint-consistent-codestyle": "1.16.0",
"tslint-microsoft-contrib": "6.2.0",
"typescript": "3.9.7"
"typescript": "3.9.6"
},
"dependencies": {
"@opentelemetry/api": "^0.10.2",
"@opentelemetry/core": "^0.10.2",
"@opentelemetry/api": "^0.10.1",
"@opentelemetry/core": "^0.10.1",
"shimmer": "^1.2.1"
}
}
32 changes: 0 additions & 32 deletions plugins/node/opentelemetry-plugin-ioredis/src/enums.ts

This file was deleted.

5 changes: 2 additions & 3 deletions plugins/node/opentelemetry-plugin-ioredis/src/ioredis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { traceConnection, traceSendCommand } from './utils';
import { VERSION } from './version';

export class IORedisPlugin extends BasePlugin<typeof ioredisTypes> {
static readonly COMPONENT = 'ioredis';
static readonly DB_TYPE = 'redis';
static readonly DB_SYSTEM = 'redis';
readonly supportedVersions = ['>1 <5'];
protected _config!: IoredisPluginConfig;

Expand Down Expand Up @@ -74,4 +73,4 @@ export class IORedisPlugin extends BasePlugin<typeof ioredisTypes> {
}
}

export const plugin = new IORedisPlugin(IORedisPlugin.COMPONENT);
export const plugin = new IORedisPlugin('ioredis');
27 changes: 14 additions & 13 deletions plugins/node/opentelemetry-plugin-ioredis/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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
),
Expand All @@ -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 {
Expand Down
42 changes: 22 additions & 20 deletions plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 = {
Expand Down Expand Up @@ -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()', () => {
Expand All @@ -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();
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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, () => {
Expand Down Expand Up @@ -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],
Expand All @@ -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',
};

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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
),
Expand Down
13 changes: 7 additions & 6 deletions plugins/node/opentelemetry-plugin-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/context-async-hooks": "0.10.2",
"@opentelemetry/node": "0.10.2",
"@opentelemetry/context-async-hooks": "0.10.1",
"@opentelemetry/node": "0.10.1",
"@opentelemetry/semantic-conventions": "^0.10.2",
"@opentelemetry/test-utils": "^0.9.0",
"@opentelemetry/tracing": "0.10.2",
"@types/mocha": "7.0.2",
"@types/node": "14.0.27",
"@types/redis": "2.8.25",
"@types/shimmer": "1.0.1",
"codecov": "3.7.2",
"codecov": "3.7.1",
"cross-env": "7.0.2",
"gts": "2.0.2",
"mocha": "7.2.0",
Expand All @@ -62,11 +63,11 @@
"ts-node": "8.10.2",
"tslint-consistent-codestyle": "1.16.0",
"tslint-microsoft-contrib": "6.2.0",
"typescript": "3.9.7"
"typescript": "3.9.6"
},
"dependencies": {
"@opentelemetry/api": "^0.10.2",
"@opentelemetry/core": "^0.10.2",
"@opentelemetry/api": "^0.10.1",
"@opentelemetry/core": "^0.10.1",
"shimmer": "^1.2.1"
}
}
32 changes: 0 additions & 32 deletions plugins/node/opentelemetry-plugin-redis/src/enums.ts

This file was deleted.

15 changes: 9 additions & 6 deletions plugins/node/opentelemetry-plugin-redis/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}`
);
}
Expand Down
Loading

0 comments on commit 1c68ea4

Please sign in to comment.