Skip to content

Commit

Permalink
fix: conform to semantic conventions
Browse files Browse the repository at this point in the history
also upgrades packages

Signed-off-by: Naseem <naseem@transit.app>
  • Loading branch information
Naseem committed Aug 5, 2020
1 parent ddba883 commit fe24089
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 55 deletions.
23 changes: 12 additions & 11 deletions plugins/node/opentelemetry-plugin-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,31 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/context-async-hooks": "0.10.1",
"@opentelemetry/node": "0.10.1",
"@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.1",
"@types/mocha": "7.0.2",
"@types/node": "12.12.47",
"@types/redis": "2.8.24",
"@opentelemetry/tracing": "0.10.2",
"@types/mocha": "8.0.1",
"@types/node": "14.0.27",
"@types/redis": "2.8.25",
"@types/shimmer": "1.0.1",
"codecov": "3.7.1",
"codecov": "3.7.2",
"cross-env": "7.0.2",
"gts": "2.0.2",
"mocha": "7.2.0",
"mocha": "8.1.1",
"nyc": "15.1.0",
"redis": "3.0.2",
"rimraf": "3.0.2",
"ts-mocha": "7.0.0",
"ts-node": "8.10.2",
"tslint-consistent-codestyle": "1.16.0",
"tslint-microsoft-contrib": "6.2.0",
"typescript": "3.9.6"
"typescript": "3.9.7"
},
"dependencies": {
"@opentelemetry/api": "^0.10.1",
"@opentelemetry/core": "^0.10.1",
"@opentelemetry/api": "^0.10.2",
"@opentelemetry/core": "^0.10.2",
"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
15 changes: 9 additions & 6 deletions plugins/node/opentelemetry-plugin-redis/test/redis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

0 comments on commit fe24089

Please sign in to comment.