Skip to content

Commit

Permalink
chore: use SpanStatusCode/SpanStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed Feb 10, 2021
1 parent c3220c5 commit 61cce95
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import type { GrpcClientFunc, SendUnaryDataCallback } from './types';
import {
SpanKind,
Span,
StatusCode,
Status,
SpanStatusCode,
SpanStatus,
propagation,
context,
} from '@opentelemetry/api';
Expand Down Expand Up @@ -96,10 +96,10 @@ export function makeGrpcClientRemoteCall(
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: StatusCode.UNSET });
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
StatusCode.UNSET.toString()
SpanStatusCode.UNSET.toString()
);
}

Expand Down Expand Up @@ -161,7 +161,7 @@ export function makeGrpcClientRemoteCall(
endSpan();
});

call.on('status', (status: Status) => {
call.on('status', (status: SpanStatus) => {
if (call[CALL_SPAN_ENDED]) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* error event should be processed.
*/

import { context, Span, StatusCode } from '@opentelemetry/api';
import { context, Span, SpanStatusCode } from '@opentelemetry/api';
import { RpcAttribute } from '@opentelemetry/semantic-conventions';
import type * as grpcJs from '@grpc/grpc-js';
import type {
Expand Down Expand Up @@ -67,9 +67,12 @@ function serverStreamAndBidiHandler<RequestType, ResponseType>(
call[CALL_SPAN_ENDED] = true;

span.setStatus({
code: StatusCode.UNSET,
code: SpanStatusCode.UNSET,
});
span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, StatusCode.OK.toString());
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
SpanStatusCode.OK.toString()
);

endSpan();
});
Expand Down Expand Up @@ -125,10 +128,10 @@ function clientStreamAndUnaryHandler<RequestType, ResponseType>(
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: StatusCode.UNSET });
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
StatusCode.OK.toString()
SpanStatusCode.OK.toString()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { RpcAttribute } from '@opentelemetry/semantic-conventions';
import {
context,
Span,
StatusCode,
SpanStatusCode,
SpanKind,
Status,
SpanStatus,
propagation,
} from '@opentelemetry/api';
import {
Expand Down Expand Up @@ -62,7 +62,7 @@ export const makeGrpcClientRemoteCall = function (
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: StatusCode.UNSET });
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
grpcClient.status.OK.toString()
Expand Down Expand Up @@ -132,8 +132,8 @@ export const makeGrpcClientRemoteCall = function (

((call as unknown) as events.EventEmitter).on(
'status',
(status: Status) => {
span.setStatus({ code: StatusCode.UNSET });
(status: SpanStatus) => {
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
status.code.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type * as grpcTypes from 'grpc';
import { SendUnaryDataCallback, ServerCallWithMeta } from './types';
import { GrpcNativeInstrumentation } from './';
import { RpcAttribute } from '@opentelemetry/semantic-conventions';
import { context, Span, StatusCode } from '@opentelemetry/api';
import { context, Span, SpanStatusCode } from '@opentelemetry/api';
import {
_grpcStatusCodeToOpenTelemetryStatusCode,
_grpcStatusCodeToSpanStatus,
Expand Down Expand Up @@ -54,7 +54,7 @@ export const clientStreamAndUnaryHandler = function <RequestType, ResponseType>(
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: StatusCode.UNSET });
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
grpcClient.status.OK.toString()
Expand Down

0 comments on commit 61cce95

Please sign in to comment.