Skip to content

Commit

Permalink
Updated attributes name by using npm OTel convention directly
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewzenkov committed Jul 25, 2022
1 parent 1aeb31e commit fbbe6f4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,13 @@
/**
* https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md
*/
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';

interface AttributesType {
RPC_SYSTEM: string;
GRPC_METHOD: string;
RPC_SERVICE: string;
GRPC_ERROR_NAME: string;
GRPC_ERROR_MESSAGE: string;
}

const RPC_METHOD = SemanticAttributes.RPC_METHOD;
const RPC_SYSTEM = SemanticAttributes.RPC_SYSTEM;
const RPC_SERVICE = SemanticAttributes.RPC_SERVICE;

export const AttributeNames: Readonly<AttributesType> = {
RPC_SYSTEM: RPC_SYSTEM,
GRPC_METHOD: RPC_METHOD,
RPC_SERVICE: RPC_SERVICE,
GRPC_ERROR_NAME: 'grpc.error_name',
GRPC_ERROR_MESSAGE: 'grpc.error_message',
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ import {
getMetadata,
} from './clientUtils';
import { EventEmitter } from 'events';
import { AttributeNames } from '../enums/AttributeNames';
import { _extractMethodAndService } from '../utils';
import {AttributeValues} from '../enums/AttributeValues';
import { AttributeValues } from '../enums/AttributeValues';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';

export class GrpcJsInstrumentation extends InstrumentationBase {
constructor(
Expand Down Expand Up @@ -190,14 +190,14 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
keys: carrier => Object.keys(carrier.getMap()),
}),
() => {
const { service, method } = _extractMethodAndService(name)
const { service, method } = _extractMethodAndService(name);

const span = instrumentation.tracer
.startSpan(spanName, spanOptions)
.setAttributes({
[AttributeNames.RPC_SYSTEM]: AttributeValues.RPC_SYSTEM,
[AttributeNames.GRPC_METHOD]: method,
[AttributeNames.RPC_SERVICE]: service,
[SemanticAttributes.RPC_SYSTEM]: AttributeValues.RPC_SYSTEM,
[SemanticAttributes.RPC_METHOD]: method,
[SemanticAttributes.RPC_SERVICE]: service,
});

context.with(trace.setSpan(context.active(), span), () => {
Expand Down Expand Up @@ -289,15 +289,15 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
original,
args
);
const { service, method } = _extractMethodAndService(original.path)
const { service, method } = _extractMethodAndService(original.path);

const span = instrumentation.tracer
.startSpan(name, { kind: SpanKind.CLIENT })
.setAttributes({
[AttributeNames.RPC_SYSTEM]: 'grpc',
[AttributeNames.GRPC_METHOD]: method,
[AttributeNames.RPC_SERVICE]: service,
})
[SemanticAttributes.RPC_SYSTEM]: 'grpc',
[SemanticAttributes.RPC_METHOD]: method,
[SemanticAttributes.RPC_SERVICE]: service,
});
return context.with(trace.setSpan(context.active(), span), () =>
makeGrpcClientRemoteCall(original, args, metadata, this)(span)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import {
} from './serverUtils';
import { makeGrpcClientRemoteCall, getMetadata } from './clientUtils';
import { _extractMethodAndService, _methodIsIgnored } from '../utils';
import { AttributeNames } from '../enums/AttributeNames';
import {AttributeValues} from "../enums/AttributeValues";
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {AttributeValues} from '../enums/AttributeValues';

/**
* Holding reference to grpc module here to access constant of grpc modules
Expand Down Expand Up @@ -201,9 +201,9 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
const span = instrumentation.tracer
.startSpan(spanName, spanOptions)
.setAttributes({
[AttributeNames.RPC_SYSTEM]: AttributeValues.RPC_SYSTEM,
[AttributeNames.GRPC_METHOD]: method,
[AttributeNames.RPC_SERVICE]: service,
[SemanticAttributes.RPC_SYSTEM]: AttributeValues.RPC_SYSTEM,
[SemanticAttributes.RPC_METHOD]: method,
[SemanticAttributes.RPC_SERVICE]: service,
});

context.with(trace.setSpan(context.active(), span), () => {
Expand Down Expand Up @@ -297,14 +297,14 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
)}`;
const args = Array.prototype.slice.call(arguments);
const metadata = getMetadata(grpcClient, original, args);
const { service, method } = _extractMethodAndService(original.path)
const { service, method } = _extractMethodAndService(original.path);
const span = instrumentation.tracer.startSpan(name, {
kind: SpanKind.CLIENT,
})
.setAttributes({
[AttributeNames.RPC_SYSTEM]: AttributeValues.RPC_SYSTEM,
[AttributeNames.GRPC_METHOD]: method,
[AttributeNames.RPC_SERVICE]: service,
[SemanticAttributes.RPC_SYSTEM]: AttributeValues.RPC_SYSTEM,
[SemanticAttributes.RPC_METHOD]: method,
[SemanticAttributes.RPC_SERVICE]: service,
});
return context.with(trace.setSpan(context.active(), span), () =>
makeGrpcClientRemoteCall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ export const _extractMethodAndService = (name: string): { service: string, metho
return ({
service,
method
})
});
};

0 comments on commit fbbe6f4

Please sign in to comment.