Skip to content

Commit

Permalink
refactor(attributes): move enums to @opentelemetry/semantic-conventio…
Browse files Browse the repository at this point in the history
…ns (#1160)
  • Loading branch information
markwolff authored Jun 15, 2020
1 parent 9d58227 commit 0596054
Show file tree
Hide file tree
Showing 33 changed files with 668 additions and 223 deletions.
1 change: 1 addition & 0 deletions packages/opentelemetry-plugin-grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"dependencies": {
"@opentelemetry/api": "^0.8.3",
"@opentelemetry/core": "^0.8.3",
"@opentelemetry/semantic-conventions": "^0.8.3",
"shimmer": "^1.2.1"
}
}
46 changes: 23 additions & 23 deletions packages/opentelemetry-plugin-grpc/src/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import {
SpanOptions,
Status,
} from '@opentelemetry/api';
import {
GeneralAttribute,
RpcAttribute,
} from '@opentelemetry/semantic-conventions';
import { BasePlugin } from '@opentelemetry/core';
import * as events from 'events';
import * as grpcTypes from 'grpc';
import * as path from 'path';
import * as shimmer from 'shimmer';
import { AttributeNames } from './enums/AttributeNames';
import {
grpc,
GrpcClientFunc,
Expand Down Expand Up @@ -173,8 +176,8 @@ export class GrpcPlugin extends BasePlugin<grpc> {
const span = plugin._tracer
.startSpan(spanName, spanOptions)
.setAttributes({
[AttributeNames.GRPC_KIND]: spanOptions.kind,
[AttributeNames.COMPONENT]: GrpcPlugin.component,
[RpcAttribute.GRPC_KIND]: spanOptions.kind,
[GeneralAttribute.COMPONENT]: GrpcPlugin.component,
});

plugin._tracer.withSpan(span, () => {
Expand Down Expand Up @@ -235,19 +238,16 @@ export class GrpcPlugin extends BasePlugin<grpc> {
code: _grpcStatusCodeToCanonicalCode(err.code),
message: err.message,
});
span.setAttribute(
AttributeNames.GRPC_STATUS_CODE,
err.code.toString()
);
span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString());
}
span.setAttributes({
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: CanonicalCode.OK });
span.setAttribute(
AttributeNames.GRPC_STATUS_CODE,
RpcAttribute.GRPC_STATUS_CODE,
plugin._moduleExports.status.OK.toString()
);
}
Expand Down Expand Up @@ -281,7 +281,7 @@ export class GrpcPlugin extends BasePlugin<grpc> {
call.on('finish', () => {
span.setStatus(_grpcStatusCodeToSpanStatus(call.status.code));
span.setAttribute(
AttributeNames.GRPC_STATUS_CODE,
RpcAttribute.GRPC_STATUS_CODE,
call.status.code.toString()
);

Expand All @@ -299,8 +299,8 @@ export class GrpcPlugin extends BasePlugin<grpc> {
});
span.addEvent('finished with error');
span.setAttributes({
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
});
endSpan();
});
Expand Down Expand Up @@ -357,7 +357,7 @@ export class GrpcPlugin extends BasePlugin<grpc> {
.startSpan(name, {
kind: SpanKind.CLIENT,
})
.setAttribute(AttributeNames.COMPONENT, GrpcPlugin.component);
.setAttribute(GeneralAttribute.COMPONENT, GrpcPlugin.component);
return plugin._tracer.withSpan(span, () =>
plugin._makeGrpcClientRemoteCall(original, args, this, plugin)(span)
);
Expand Down Expand Up @@ -388,18 +388,18 @@ export class GrpcPlugin extends BasePlugin<grpc> {
if (err.code) {
span.setStatus(_grpcStatusCodeToSpanStatus(err.code));
span.setAttribute(
AttributeNames.GRPC_STATUS_CODE,
RpcAttribute.GRPC_STATUS_CODE,
err.code.toString()
);
}
span.setAttributes({
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: CanonicalCode.OK });
span.setAttribute(
AttributeNames.GRPC_STATUS_CODE,
RpcAttribute.GRPC_STATUS_CODE,
plugin._moduleExports.status.OK.toString()
);
}
Expand Down Expand Up @@ -432,8 +432,8 @@ export class GrpcPlugin extends BasePlugin<grpc> {

span.addEvent('sent');
span.setAttributes({
[AttributeNames.GRPC_METHOD]: original.path,
[AttributeNames.GRPC_KIND]: SpanKind.CLIENT,
[RpcAttribute.GRPC_METHOD]: original.path,
[RpcAttribute.GRPC_KIND]: SpanKind.CLIENT,
});

this._setSpanContext(metadata);
Expand All @@ -459,8 +459,8 @@ export class GrpcPlugin extends BasePlugin<grpc> {
message: err.message,
});
span.setAttributes({
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
});
endSpan();
}
Expand All @@ -471,7 +471,7 @@ export class GrpcPlugin extends BasePlugin<grpc> {
(status: Status) => {
span.setStatus({ code: CanonicalCode.OK });
span.setAttribute(
AttributeNames.GRPC_STATUS_CODE,
RpcAttribute.GRPC_STATUS_CODE,
status.code.toString()
);
endSpan();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

import { SpanKind } from '@opentelemetry/api';
import * as assert from 'assert';
import { AttributeNames } from '../../src/enums/AttributeNames';
import { GrpcPlugin } from '../../src/grpc';
import * as grpc from 'grpc';
import { ReadableSpan } from '@opentelemetry/tracing';
import {
hrTimeToMilliseconds,
hrTimeToMicroseconds,
} from '@opentelemetry/core';
import { GeneralAttribute } from '@opentelemetry/semantic-conventions';

export const assertSpan = (
span: ReadableSpan,
Expand All @@ -35,7 +35,7 @@ export const assertSpan = (
assert.strictEqual(span.kind, kind);

assert.strictEqual(
span.attributes[AttributeNames.COMPONENT],
span.attributes[GeneralAttribute.COMPONENT],
GrpcPlugin.component
);
assert.ok(span.endTime);
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-plugin-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"dependencies": {
"@opentelemetry/api": "^0.8.3",
"@opentelemetry/core": "^0.8.3",
"@opentelemetry/semantic-conventions": "^0.8.3",
"semver": "^7.1.3",
"shimmer": "^1.2.1"
}
Expand Down
41 changes: 0 additions & 41 deletions packages/opentelemetry-plugin-http/src/enums/AttributeNames.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/opentelemetry-plugin-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
NoRecordingSpan,
getExtractedSpanContext,
} from '@opentelemetry/core';
import { GeneralAttribute } from '@opentelemetry/semantic-conventions';
import {
ClientRequest,
IncomingMessage,
Expand All @@ -40,7 +41,6 @@ import { Socket } from 'net';
import * as semver from 'semver';
import * as shimmer from 'shimmer';
import * as url from 'url';
import { AttributeNames } from './enums/AttributeNames';
import {
Err,
Func,
Expand Down Expand Up @@ -463,7 +463,7 @@ export class HttpPlugin extends BasePlugin<Http> {
} else {
span = this._tracer
.startSpan(name, options)
.setAttribute(AttributeNames.COMPONENT, this.component);
.setAttribute(GeneralAttribute.COMPONENT, this.component);
}
this._spanNotEnded.add(span);
return span;
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-plugin-http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@
export * from './http';
export * from './types';
export * from './utils';
export * from './enums/AttributeNames';
Loading

0 comments on commit 0596054

Please sign in to comment.