From 1b24b8b636dd501cd235f24d03c886aa1843b54f Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 2 Nov 2020 03:07:45 +0530 Subject: [PATCH 1/5] fix: change status codes from grpc status codes closes #1634 --- packages/opentelemetry-api/README.md | 2 +- packages/opentelemetry-api/src/trace/span.ts | 2 +- .../opentelemetry-api/src/trace/status.ts | 138 ++---------------- .../noop-implementations/noop-span.test.ts | 4 +- .../test/helper.ts | 4 +- .../test/helper.ts | 4 +- .../test/helper.ts | 12 +- .../src/transform.ts | 6 +- .../test/jaeger.test.ts | 2 +- .../test/transform.test.ts | 8 +- .../src/transform.ts | 2 +- .../test/common/transform.test.ts | 4 +- .../test/helper.ts | 4 +- .../test/node/zipkin.test.ts | 14 +- .../src/client/utils.ts | 10 +- .../src/server/clientStreamAndUnary.ts | 10 +- .../src/server/serverStreamAndBidi.ts | 16 +- .../opentelemetry-plugin-grpc-js/src/utils.ts | 14 +- .../opentelemetry-plugin-grpc/src/grpc.ts | 16 +- .../opentelemetry-plugin-grpc/src/utils.ts | 14 +- .../opentelemetry-plugin-http/src/http.ts | 4 +- .../opentelemetry-plugin-http/src/types.ts | 4 - .../opentelemetry-plugin-http/src/utils.ts | 58 ++------ .../test/functionals/http-enable.test.ts | 8 +- .../test/functionals/utils.test.ts | 17 +-- .../test/functionals/https-enable.test.ts | 8 +- .../src/shim.ts | 2 +- packages/opentelemetry-tracing/src/Span.ts | 2 +- .../opentelemetry-tracing/test/Span.test.ts | 14 +- 29 files changed, 117 insertions(+), 286 deletions(-) diff --git a/packages/opentelemetry-api/README.md b/packages/opentelemetry-api/README.md index e85eac8c255..180ab4c7e2c 100644 --- a/packages/opentelemetry-api/README.md +++ b/packages/opentelemetry-api/README.md @@ -168,7 +168,7 @@ async function doSomething() { } catch (err) { span.setStatus({ // use an appropriate status code here - code: api.CanonicalCode.INTERNAL, + code: api.StatusCode.ERROR, message: err.message, }); span.end(); diff --git a/packages/opentelemetry-api/src/trace/span.ts b/packages/opentelemetry-api/src/trace/span.ts index 59cafea2df2..5142c6161a9 100644 --- a/packages/opentelemetry-api/src/trace/span.ts +++ b/packages/opentelemetry-api/src/trace/span.ts @@ -75,7 +75,7 @@ export interface Span { /** * Sets a status to the span. If used, this will override the default Span - * status. Default is {@link CanonicalCode.OK}. SetStatus overrides the value + * status. Default is {@link StatusCode.UNSET}. SetStatus overrides the value * of previous calls to SetStatus on the Span. * * @param status the Status to set. diff --git a/packages/opentelemetry-api/src/trace/status.ts b/packages/opentelemetry-api/src/trace/status.ts index 12504992f75..1fbae609c99 100644 --- a/packages/opentelemetry-api/src/trace/status.ts +++ b/packages/opentelemetry-api/src/trace/status.ts @@ -14,145 +14,27 @@ * limitations under the License. */ export interface Status { - /** The canonical code of this message. */ - code: CanonicalCode; + /** The status code of this message. */ + code: StatusCode; /** A developer-facing error message. */ message?: string; } /** - * An enumeration of canonical status codes. + * An enumeration of status codes. */ -export enum CanonicalCode { +export enum StatusCode { /** - * Not an error; returned on success + * The operation has been validated by an Application developer or + * Operator to have completed successfully. */ OK = 0, /** - * The operation was cancelled (typically by the caller). + * The default status. */ - CANCELLED = 1, + UNSET = 1, /** - * Unknown error. An example of where this error may be returned is - * if a status value received from another address space belongs to - * an error-space that is not known in this address space. Also - * errors raised by APIs that do not return enough error information - * may be converted to this error. + * The operation contains an error. */ - UNKNOWN = 2, - /** - * Client specified an invalid argument. Note that this differs - * from FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments - * that are problematic regardless of the state of the system - * (e.g., a malformed file name). - */ - INVALID_ARGUMENT = 3, - /** - * Deadline expired before operation could complete. For operations - * that change the state of the system, this error may be returned - * even if the operation has completed successfully. For example, a - * successful response from a server could have been delayed long - * enough for the deadline to expire. - */ - DEADLINE_EXCEEDED = 4, - /** - * Some requested entity (e.g., file or directory) was not found. - */ - NOT_FOUND = 5, - /** - * Some entity that we attempted to create (e.g., file or directory) - * already exists. - */ - ALREADY_EXISTS = 6, - /** - * The caller does not have permission to execute the specified - * operation. PERMISSION_DENIED must not be used for rejections - * caused by exhausting some resource (use RESOURCE_EXHAUSTED - * instead for those errors). PERMISSION_DENIED must not be - * used if the caller can not be identified (use UNAUTHENTICATED - * instead for those errors). - */ - PERMISSION_DENIED = 7, - /** - * Some resource has been exhausted, perhaps a per-user quota, or - * perhaps the entire file system is out of space. - */ - RESOURCE_EXHAUSTED = 8, - /** - * Operation was rejected because the system is not in a state - * required for the operation's execution. For example, directory - * to be deleted may be non-empty, an rmdir operation is applied to - * a non-directory, etc. - * - * A litmus test that may help a service implementor in deciding - * between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: - * - * - Use UNAVAILABLE if the client can retry just the failing call. - * - Use ABORTED if the client should retry at a higher-level - * (e.g., restarting a read-modify-write sequence). - * - Use FAILED_PRECONDITION if the client should not retry until - * the system state has been explicitly fixed. E.g., if an "rmdir" - * fails because the directory is non-empty, FAILED_PRECONDITION - * should be returned since the client should not retry unless - * they have first fixed up the directory by deleting files from it. - * - Use FAILED_PRECONDITION if the client performs conditional - * REST Get/Update/Delete on a resource and the resource on the - * server does not match the condition. E.g., conflicting - * read-modify-write on the same resource. - */ - FAILED_PRECONDITION = 9, - /** - * The operation was aborted, typically due to a concurrency issue - * like sequencer check failures, transaction aborts, etc. - * - * See litmus test above for deciding between FAILED_PRECONDITION, - * ABORTED, and UNAVAILABLE. - */ - ABORTED = 10, - /** - * Operation was attempted past the valid range. E.g., seeking or - * reading past end of file. - * - * Unlike INVALID_ARGUMENT, this error indicates a problem that may - * be fixed if the system state changes. For example, a 32-bit file - * system will generate INVALID_ARGUMENT if asked to read at an - * offset that is not in the range [0,2^32-1], but it will generate - * OUT_OF_RANGE if asked to read from an offset past the current - * file size. - * - * There is a fair bit of overlap between FAILED_PRECONDITION and - * OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific - * error) when it applies so that callers who are iterating through - * a space can easily look for an OUT_OF_RANGE error to detect when - * they are done. - */ - OUT_OF_RANGE = 11, - /** - * Operation is not implemented or not supported/enabled in this service. - */ - UNIMPLEMENTED = 12, - /** - * Internal errors. Means some invariants expected by underlying - * system has been broken. If you see one of these errors, - * something is very broken. - */ - INTERNAL = 13, - /** - * The service is currently unavailable. This is a most likely a - * transient condition and may be corrected by retrying with - * a backoff. - * - * See litmus test above for deciding between FAILED_PRECONDITION, - * ABORTED, and UNAVAILABLE. - */ - UNAVAILABLE = 14, - /** - * Unrecoverable data loss or corruption. - */ - DATA_LOSS = 15, - /** - * The request does not have valid authentication credentials for the - * operation. - */ - UNAUTHENTICATED = 16, + ERROR = 2, } diff --git a/packages/opentelemetry-api/test/noop-implementations/noop-span.test.ts b/packages/opentelemetry-api/test/noop-implementations/noop-span.test.ts index 8d224123a45..feb9247fe94 100644 --- a/packages/opentelemetry-api/test/noop-implementations/noop-span.test.ts +++ b/packages/opentelemetry-api/test/noop-implementations/noop-span.test.ts @@ -16,7 +16,7 @@ import * as assert from 'assert'; import { - CanonicalCode, + StatusCode, INVALID_SPANID, INVALID_TRACEID, NoopSpan, @@ -39,7 +39,7 @@ describe('NoopSpan', () => { span.addEvent('sent'); span.addEvent('sent', { id: '42', key: 'value' }); - span.setStatus({ code: CanonicalCode.CANCELLED }); + span.setStatus({ code: StatusCode.ERROR }); span.updateName('my-span'); diff --git a/packages/opentelemetry-exporter-collector-grpc/test/helper.ts b/packages/opentelemetry-exporter-collector-grpc/test/helper.ts index 0607571c9c1..659c3e87cb8 100644 --- a/packages/opentelemetry-exporter-collector-grpc/test/helper.ts +++ b/packages/opentelemetry-exporter-collector-grpc/test/helper.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { TraceFlags, ValueType } from '@opentelemetry/api'; +import { TraceFlags, ValueType, StatusCode } from '@opentelemetry/api'; import { ReadableSpan } from '@opentelemetry/tracing'; import { Resource } from '@opentelemetry/resources'; import { collectorTypes } from '@opentelemetry/exporter-collector'; @@ -123,7 +123,7 @@ export const mockedReadableSpan: ReadableSpan = { startTime: [1574120165, 429803070], endTime: [1574120165, 438688070], ended: true, - status: { code: 0 }, + status: { code: StatusCode.OK }, attributes: { component: 'document-load' }, links: [ { diff --git a/packages/opentelemetry-exporter-collector-proto/test/helper.ts b/packages/opentelemetry-exporter-collector-proto/test/helper.ts index 0034e3f3ba1..51d970226dc 100644 --- a/packages/opentelemetry-exporter-collector-proto/test/helper.ts +++ b/packages/opentelemetry-exporter-collector-proto/test/helper.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { TraceFlags, ValueType } from '@opentelemetry/api'; +import { TraceFlags, ValueType, StatusCode } from '@opentelemetry/api'; import { hexToBase64 } from '@opentelemetry/core'; import { ReadableSpan } from '@opentelemetry/tracing'; import { Resource } from '@opentelemetry/resources'; @@ -106,7 +106,7 @@ export const mockedReadableSpan: ReadableSpan = { startTime: [1574120165, 429803070], endTime: [1574120165, 438688070], ended: true, - status: { code: 0 }, + status: { code: StatusCode.OK }, attributes: { component: 'document-load' }, links: [ { diff --git a/packages/opentelemetry-exporter-collector/test/helper.ts b/packages/opentelemetry-exporter-collector/test/helper.ts index f9f482d29f3..c94c5ce6639 100644 --- a/packages/opentelemetry-exporter-collector/test/helper.ts +++ b/packages/opentelemetry-exporter-collector/test/helper.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { TraceFlags, ValueType } from '@opentelemetry/api'; +import { TraceFlags, ValueType, StatusCode } from '@opentelemetry/api'; import { ReadableSpan } from '@opentelemetry/tracing'; import { Resource } from '@opentelemetry/resources'; import { MetricRecord, MeterProvider } from '@opentelemetry/metrics'; @@ -115,7 +115,7 @@ export const mockedReadableSpan: ReadableSpan = { startTime: [1574120165, 429803070], endTime: [1574120165, 438688070], ended: true, - status: { code: 0 }, + status: { code: StatusCode.OK }, attributes: { component: 'document-load' }, links: [ { @@ -186,7 +186,7 @@ export const basicTrace: ReadableSpan[] = [ startTime: [1574120165, 429803070], endTime: [1574120165, 438688070], ended: true, - status: { code: 0 }, + status: { code: StatusCode.OK }, attributes: {}, links: [], events: [], @@ -206,7 +206,7 @@ export const basicTrace: ReadableSpan[] = [ startTime: [1575120165, 439803070], endTime: [1575120165, 448688070], ended: true, - status: { code: 0 }, + status: { code: StatusCode.OK }, attributes: {}, links: [], events: [], @@ -226,7 +226,7 @@ export const basicTrace: ReadableSpan[] = [ startTime: [1575120165, 439803070], endTime: [1575120165, 448688070], ended: true, - status: { code: 0 }, + status: { code: StatusCode.OK }, attributes: {}, links: [], events: [], @@ -462,7 +462,7 @@ export function ensureSpanIsCorrect( ); assert.strictEqual(span.droppedEventsCount, 0, 'droppedEventsCount is wrong'); assert.strictEqual(span.droppedLinksCount, 0, 'droppedLinksCount is wrong'); - assert.deepStrictEqual(span.status, { code: 0 }, 'status is wrong'); + assert.deepStrictEqual(span.status, { code: StatusCode.OK }, 'status is wrong'); } export function ensureWebResourceIsCorrect( diff --git a/packages/opentelemetry-exporter-jaeger/src/transform.ts b/packages/opentelemetry-exporter-jaeger/src/transform.ts index 17c1cbfbbf8..457e5fe7cf4 100644 --- a/packages/opentelemetry-exporter-jaeger/src/transform.ts +++ b/packages/opentelemetry-exporter-jaeger/src/transform.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Link, CanonicalCode, SpanKind } from '@opentelemetry/api'; +import { Link, StatusCode, SpanKind } from '@opentelemetry/api'; import { ReadableSpan } from '@opentelemetry/tracing'; import { hrTimeToMilliseconds, @@ -51,13 +51,13 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan { (name): Tag => ({ key: name, value: toTagValue(span.attributes[name]) }) ); tags.push({ key: 'status.code', value: span.status.code }); - tags.push({ key: 'status.name', value: CanonicalCode[span.status.code] }); + tags.push({ key: 'status.name', value: StatusCode[span.status.code] }); if (span.status.message) { tags.push({ key: 'status.message', value: span.status.message }); } // Ensure that if Status.Code is not OK, that we set the "error" tag on the // Jaeger span. - if (span.status.code !== CanonicalCode.OK) { + if (span.status.code !== StatusCode.OK) { tags.push({ key: 'error', value: true }); } diff --git a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts index b74b1cd2d4b..c5781b47cc6 100644 --- a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts @@ -124,7 +124,7 @@ describe('JaegerExporter', () => { endTime: [1566156731, 709], ended: true, status: { - code: api.CanonicalCode.DATA_LOSS, + code: api.StatusCode.ERROR, }, attributes: {}, links: [], diff --git a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts index 332b540cdc1..2e02297afd1 100644 --- a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts @@ -40,7 +40,7 @@ describe('transform', () => { endTime: [1566156731, 709], ended: true, status: { - code: api.CanonicalCode.OK, + code: api.StatusCode.OK, }, attributes: { testBool: true, @@ -165,7 +165,7 @@ describe('transform', () => { endTime: [1566156731, 709], ended: true, status: { - code: api.CanonicalCode.DATA_LOSS, + code: api.StatusCode.ERROR, message: 'data loss', }, attributes: {}, @@ -227,7 +227,7 @@ describe('transform', () => { endTime: [1566156731, 709], ended: true, status: { - code: api.CanonicalCode.OK, + code: api.StatusCode.OK, }, attributes: {}, parentSpanId: '3e0c63257de34c92', @@ -277,7 +277,7 @@ describe('transform', () => { endTime: [1566156731, 709], ended: true, status: { - code: api.CanonicalCode.DATA_LOSS, + code: api.StatusCode.ERROR, message: 'data loss', }, attributes: {}, diff --git a/packages/opentelemetry-exporter-zipkin/src/transform.ts b/packages/opentelemetry-exporter-zipkin/src/transform.ts index c515eb7fd6f..6b983a1e843 100644 --- a/packages/opentelemetry-exporter-zipkin/src/transform.ts +++ b/packages/opentelemetry-exporter-zipkin/src/transform.ts @@ -78,7 +78,7 @@ export function _toZipkinTags( for (const key of Object.keys(attributes)) { tags[key] = String(attributes[key]); } - tags[statusCodeTagName] = String(api.CanonicalCode[status.code]); + tags[statusCodeTagName] = String(api.StatusCode[status.code]); if (status.message) { tags[statusDescriptionTagName] = status.message; } diff --git a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts index 4b97df3a858..4027b73e966 100644 --- a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts @@ -235,7 +235,7 @@ describe('transform', () => { parentId ); const status: api.Status = { - code: api.CanonicalCode.ABORTED, + code: api.StatusCode.ERROR, }; span.setStatus(status); span.setAttributes({ @@ -266,7 +266,7 @@ describe('transform', () => { parentId ); const status: api.Status = { - code: api.CanonicalCode.ABORTED, + code: api.StatusCode.ERROR, message: 'my-message', }; span.setStatus(status); diff --git a/packages/opentelemetry-exporter-zipkin/test/helper.ts b/packages/opentelemetry-exporter-zipkin/test/helper.ts index d58532d0ee5..9614474bd2c 100644 --- a/packages/opentelemetry-exporter-zipkin/test/helper.ts +++ b/packages/opentelemetry-exporter-zipkin/test/helper.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { TraceFlags } from '@opentelemetry/api'; +import { TraceFlags, StatusCode } from '@opentelemetry/api'; import { ReadableSpan } from '@opentelemetry/tracing'; import { Resource } from '@opentelemetry/resources'; import * as assert from 'assert'; @@ -32,7 +32,7 @@ export const mockedReadableSpan: ReadableSpan = { startTime: [1574120165, 429803070], endTime: [1574120165, 438688070], ended: true, - status: { code: 0 }, + status: { code: StatusCode.OK }, attributes: { component: 'foo' }, links: [], events: [], diff --git a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts index 298cd04f262..424f8f588bd 100644 --- a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts @@ -50,7 +50,7 @@ function getReadableSpan() { ended: true, duration: [duration, 0], status: { - code: api.CanonicalCode.OK, + code: api.StatusCode.OK, }, attributes: {}, links: [], @@ -149,7 +149,7 @@ describe('Zipkin Exporter - node', () => { ended: true, duration: [duration, 0], status: { - code: api.CanonicalCode.OK, + code: api.StatusCode.OK, }, attributes: { key1: 'value1', @@ -179,7 +179,7 @@ describe('Zipkin Exporter - node', () => { ended: true, duration: [duration, 0], status: { - code: api.CanonicalCode.OK, + code: api.StatusCode.OK, }, attributes: {}, links: [], @@ -341,7 +341,7 @@ describe('Zipkin Exporter - node', () => { ended: true, duration: [duration, 0], status: { - code: api.CanonicalCode.OK, + code: api.StatusCode.OK, }, attributes: { key1: 'value1', @@ -371,7 +371,7 @@ describe('Zipkin Exporter - node', () => { ended: true, duration: [duration, 0], status: { - code: api.CanonicalCode.OK, + code: api.StatusCode.OK, }, attributes: {}, links: [], @@ -413,7 +413,7 @@ describe('Zipkin Exporter - node', () => { ended: true, duration: [duration, 0], status: { - code: api.CanonicalCode.OK, + code: api.StatusCode.OK, }, attributes: { key1: 'value1', @@ -445,7 +445,7 @@ describe('Zipkin Exporter - node', () => { ended: true, duration: [duration, 0], status: { - code: api.CanonicalCode.OK, + code: api.StatusCode.OK, }, attributes: {}, links: [], diff --git a/packages/opentelemetry-plugin-grpc-js/src/client/utils.ts b/packages/opentelemetry-plugin-grpc-js/src/client/utils.ts index 33fdc8659de..90fab8b8b2f 100644 --- a/packages/opentelemetry-plugin-grpc-js/src/client/utils.ts +++ b/packages/opentelemetry-plugin-grpc-js/src/client/utils.ts @@ -19,7 +19,7 @@ import type { GrpcClientFunc, SendUnaryDataCallback } from '../types'; import { SpanKind, Span, - CanonicalCode, + StatusCode, Status, propagation, } from '@opentelemetry/api'; @@ -27,7 +27,7 @@ import { RpcAttribute } from '@opentelemetry/semantic-conventions'; import type * as grpcJs from '@grpc/grpc-js'; import { grpcStatusCodeToSpanStatus, - grpcStatusCodeToCanonicalCode, + grpcStatusCodeToOpenTelemetryStatusCode, CALL_SPAN_ENDED, methodIsIgnored, } from '../utils'; @@ -119,10 +119,10 @@ export function makeGrpcClientRemoteCall( [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, }); } else { - span.setStatus({ code: CanonicalCode.OK }); + span.setStatus({ code: StatusCode.OK }); span.setAttribute( RpcAttribute.GRPC_STATUS_CODE, - CanonicalCode.OK.toString() + StatusCode.OK.toString() ); } @@ -173,7 +173,7 @@ export function makeGrpcClientRemoteCall( call[CALL_SPAN_ENDED] = true; span.setStatus({ - code: grpcStatusCodeToCanonicalCode(err.code), + code: grpcStatusCodeToOpenTelemetryStatusCode(err.code), message: err.message, }); span.setAttributes({ diff --git a/packages/opentelemetry-plugin-grpc-js/src/server/clientStreamAndUnary.ts b/packages/opentelemetry-plugin-grpc-js/src/server/clientStreamAndUnary.ts index d8398134273..2e92334cb09 100644 --- a/packages/opentelemetry-plugin-grpc-js/src/server/clientStreamAndUnary.ts +++ b/packages/opentelemetry-plugin-grpc-js/src/server/clientStreamAndUnary.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { Span, CanonicalCode } from '@opentelemetry/api'; +import { Span, StatusCode } from '@opentelemetry/api'; import type { ServerCallWithMeta, SendUnaryDataCallback } from '../types'; -import { grpcStatusCodeToCanonicalCode } from '../utils'; +import { grpcStatusCodeToOpenTelemetryStatusCode } from '../utils'; import { RpcAttribute } from '@opentelemetry/semantic-conventions'; import type { GrpcJsPlugin } from '../grpcJs'; import type * as grpcJs from '@grpc/grpc-js'; @@ -40,7 +40,7 @@ export function clientStreamAndUnaryHandler( if (err) { if (err.code) { span.setStatus({ - code: grpcStatusCodeToCanonicalCode(err.code), + code: grpcStatusCodeToOpenTelemetryStatusCode(err.code), message: err.message, }); span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString()); @@ -50,10 +50,10 @@ export function clientStreamAndUnaryHandler( [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, }); } else { - span.setStatus({ code: CanonicalCode.OK }); + span.setStatus({ code: StatusCode.OK }); span.setAttribute( RpcAttribute.GRPC_STATUS_CODE, - CanonicalCode.OK.toString() + StatusCode.OK.toString() ); } diff --git a/packages/opentelemetry-plugin-grpc-js/src/server/serverStreamAndBidi.ts b/packages/opentelemetry-plugin-grpc-js/src/server/serverStreamAndBidi.ts index 1fe8a14a44e..138d98e9c9b 100644 --- a/packages/opentelemetry-plugin-grpc-js/src/server/serverStreamAndBidi.ts +++ b/packages/opentelemetry-plugin-grpc-js/src/server/serverStreamAndBidi.ts @@ -14,12 +14,15 @@ * limitations under the License. */ -import { Span, CanonicalCode } from '@opentelemetry/api'; +import { Span, StatusCode } from '@opentelemetry/api'; import { RpcAttribute } from '@opentelemetry/semantic-conventions'; import type * as grpcJs from '@grpc/grpc-js'; import type { GrpcJsPlugin } from '../grpcJs'; import { GrpcEmitter } from '../types'; -import { CALL_SPAN_ENDED, grpcStatusCodeToCanonicalCode } from '../utils'; +import { + CALL_SPAN_ENDED, + grpcStatusCodeToOpenTelemetryStatusCode, +} from '../utils'; /** * Handle patching for serverStream and Bidi type server handlers @@ -52,12 +55,9 @@ export function serverStreamAndBidiHandler( call[CALL_SPAN_ENDED] = true; span.setStatus({ - code: CanonicalCode.OK, + code: StatusCode.OK, }); - span.setAttribute( - RpcAttribute.GRPC_STATUS_CODE, - CanonicalCode.OK.toString() - ); + span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, StatusCode.OK.toString()); endSpan(); }); @@ -71,7 +71,7 @@ export function serverStreamAndBidiHandler( call[CALL_SPAN_ENDED] = true; span.setStatus({ - code: grpcStatusCodeToCanonicalCode(err.code), + code: grpcStatusCodeToOpenTelemetryStatusCode(err.code), message: err.message, }); span.setAttributes({ diff --git a/packages/opentelemetry-plugin-grpc-js/src/utils.ts b/packages/opentelemetry-plugin-grpc-js/src/utils.ts index ada72b0938b..990ceca9e4d 100644 --- a/packages/opentelemetry-plugin-grpc-js/src/utils.ts +++ b/packages/opentelemetry-plugin-grpc-js/src/utils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CanonicalCode, Status } from '@opentelemetry/api'; +import { StatusCode, Status } from '@opentelemetry/api'; import type * as grpcTypes from '@grpc/grpc-js'; // For types only import { IgnoreMatcher } from './types'; @@ -26,16 +26,16 @@ import { IgnoreMatcher } from './types'; export const CALL_SPAN_ENDED = Symbol('opentelemetry call span ended'); /** - * Convert a grpc status code to an opentelemetry Canonical code. For now, the enums are exactly the same + * Convert a grpc status code to an opentelemetry Status code. * @param status */ -export const grpcStatusCodeToCanonicalCode = ( +export const grpcStatusCodeToOpenTelemetryStatusCode = ( status?: grpcTypes.status -): CanonicalCode => { - if (status !== 0 && !status) { - return CanonicalCode.UNKNOWN; +): StatusCode => { + if (status !== undefined && status === 0) { + return StatusCode.OK; } - return status as number; + return StatusCode.ERROR; }; /** diff --git a/packages/opentelemetry-plugin-grpc/src/grpc.ts b/packages/opentelemetry-plugin-grpc/src/grpc.ts index bc185dc777d..c27361014f7 100644 --- a/packages/opentelemetry-plugin-grpc/src/grpc.ts +++ b/packages/opentelemetry-plugin-grpc/src/grpc.ts @@ -15,7 +15,7 @@ */ import { - CanonicalCode, + StatusCode, context, propagation, Span, @@ -40,7 +40,7 @@ import { } from './types'; import { findIndex, - _grpcStatusCodeToCanonicalCode, + _grpcStatusCodeToOpenTelemetryStatusCode, _grpcStatusCodeToSpanStatus, _methodIsIgnored, } from './utils'; @@ -262,7 +262,7 @@ export class GrpcPlugin extends BasePlugin { if (err) { if (err.code) { span.setStatus({ - code: _grpcStatusCodeToCanonicalCode(err.code), + code: _grpcStatusCodeToOpenTelemetryStatusCode(err.code), message: err.message, }); span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString()); @@ -272,7 +272,7 @@ export class GrpcPlugin extends BasePlugin { [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, }); } else { - span.setStatus({ code: CanonicalCode.OK }); + span.setStatus({ code: StatusCode.OK }); span.setAttribute( RpcAttribute.GRPC_STATUS_CODE, plugin._moduleExports.status.OK.toString() @@ -321,7 +321,7 @@ export class GrpcPlugin extends BasePlugin { call.on('error', (err: grpcTypes.ServiceError) => { span.setStatus({ - code: _grpcStatusCodeToCanonicalCode(err.code), + code: _grpcStatusCodeToOpenTelemetryStatusCode(err.code), message: err.message, }); span.addEvent('finished with error'); @@ -437,7 +437,7 @@ export class GrpcPlugin extends BasePlugin { [RpcAttribute.GRPC_ERROR_MESSAGE]: err.message, }); } else { - span.setStatus({ code: CanonicalCode.OK }); + span.setStatus({ code: StatusCode.OK }); span.setAttribute( RpcAttribute.GRPC_STATUS_CODE, plugin._moduleExports.status.OK.toString() @@ -494,7 +494,7 @@ export class GrpcPlugin extends BasePlugin { 'error', (err: grpcTypes.ServiceError) => { span.setStatus({ - code: _grpcStatusCodeToCanonicalCode(err.code), + code: _grpcStatusCodeToOpenTelemetryStatusCode(err.code), message: err.message, }); span.setAttributes({ @@ -508,7 +508,7 @@ export class GrpcPlugin extends BasePlugin { ((call as unknown) as events.EventEmitter).on( 'status', (status: Status) => { - span.setStatus({ code: CanonicalCode.OK }); + span.setStatus({ code: StatusCode.OK }); span.setAttribute( RpcAttribute.GRPC_STATUS_CODE, status.code.toString() diff --git a/packages/opentelemetry-plugin-grpc/src/utils.ts b/packages/opentelemetry-plugin-grpc/src/utils.ts index a7a8c692bea..a89b6568014 100644 --- a/packages/opentelemetry-plugin-grpc/src/utils.ts +++ b/packages/opentelemetry-plugin-grpc/src/utils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CanonicalCode, Status } from '@opentelemetry/api'; +import { StatusCode, Status } from '@opentelemetry/api'; import * as grpcTypes from 'grpc'; // For types only import { IgnoreMatcher } from './types'; @@ -34,16 +34,16 @@ export const findIndex: (args: T[], fn: (arg: T) => boolean) => number = ( }; /** - * Convert a grpc status code to an opentelemetry Canonical code. For now, the enums are exactly the same + * Convert a grpc status code to an opentelemetry Status code. * @param status */ -export const _grpcStatusCodeToCanonicalCode = ( +export const _grpcStatusCodeToOpenTelemetryStatusCode = ( status?: grpcTypes.status -): CanonicalCode => { - if (status !== 0 && !status) { - return CanonicalCode.UNKNOWN; +): StatusCode => { + if (status !== undefined && status === 0) { + return StatusCode.OK; } - return status as number; + return StatusCode.ERROR; }; export const _grpcStatusCodeToSpanStatus = (status: number): Status => { diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index 2f18916ea49..c45871fe0a6 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { - CanonicalCode, + StatusCode, context, propagation, Span, @@ -220,7 +220,7 @@ export class HttpPlugin extends BasePlugin { let status: Status; if (response.aborted && !response.complete) { - status = { code: CanonicalCode.ABORTED }; + status = { code: StatusCode.ERROR }; } else { status = utils.parseResponseStatus(response.statusCode!); } diff --git a/packages/opentelemetry-plugin-http/src/types.ts b/packages/opentelemetry-plugin-http/src/types.ts index 82f19cf7679..cc417817548 100644 --- a/packages/opentelemetry-plugin-http/src/types.ts +++ b/packages/opentelemetry-plugin-http/src/types.ts @@ -93,7 +93,3 @@ export interface Err extends Error { syscall?: string; stack?: string; } - -export interface SpecialHttpStatusCodeMapping { - [custom: number]: number; -} diff --git a/packages/opentelemetry-plugin-http/src/utils.ts b/packages/opentelemetry-plugin-http/src/utils.ts index cfe8d9515e3..0cba43d95c5 100644 --- a/packages/opentelemetry-plugin-http/src/utils.ts +++ b/packages/opentelemetry-plugin-http/src/utils.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Attributes, CanonicalCode, Span, Status } from '@opentelemetry/api'; +import { Attributes, StatusCode, Span, Status } from '@opentelemetry/api'; import { HttpAttribute, GeneralAttribute, @@ -28,25 +28,7 @@ import { } from 'http'; import { Socket } from 'net'; import * as url from 'url'; -import { - Err, - IgnoreMatcher, - ParsedRequestOptions, - SpecialHttpStatusCodeMapping, -} from './types'; - -export const HTTP_STATUS_SPECIAL_CASES: SpecialHttpStatusCodeMapping = { - 401: CanonicalCode.UNAUTHENTICATED, - 403: CanonicalCode.PERMISSION_DENIED, - 404: CanonicalCode.NOT_FOUND, - 429: CanonicalCode.RESOURCE_EXHAUSTED, - 499: CanonicalCode.CANCELLED, - 501: CanonicalCode.UNIMPLEMENTED, - 503: CanonicalCode.UNAVAILABLE, - 504: CanonicalCode.DEADLINE_EXCEEDED, - 598: CanonicalCode.INTERNAL, - 599: CanonicalCode.INTERNAL, -}; +import { Err, IgnoreMatcher, ParsedRequestOptions } from './types'; /** * Get an absolute url @@ -82,35 +64,13 @@ export const getAbsoluteUrl = ( export const parseResponseStatus = ( statusCode: number ): Omit => { - // search for special case - const code: number | undefined = HTTP_STATUS_SPECIAL_CASES[statusCode]; - - if (code !== undefined) { - return { code }; - } - - // 0xx are unknown - if (statusCode < 100) { - return { code: CanonicalCode.UNKNOWN }; - } - // 1xx, 2xx, 3xx are OK - if (statusCode < 400) { - return { code: CanonicalCode.OK }; - } - - // 4xx are client errors - if (statusCode < 500) { - return { code: CanonicalCode.INVALID_ARGUMENT }; - } - - // 5xx are internal errors - if (statusCode < 512) { - return { code: CanonicalCode.INTERNAL }; + if (statusCode >= 100 && statusCode < 400) { + return { code: StatusCode.OK }; } - // All other codes are unknown - return { code: CanonicalCode.UNKNOWN }; + // All other codes are error + return { code: StatusCode.ERROR }; }; /** @@ -199,7 +159,7 @@ export const setSpanWithError = ( }); if (!obj) { - span.setStatus({ code: CanonicalCode.UNKNOWN, message }); + span.setStatus({ code: StatusCode.ERROR, message }); return; } @@ -207,9 +167,9 @@ export const setSpanWithError = ( if ((obj as IncomingMessage).statusCode) { status = parseResponseStatus((obj as IncomingMessage).statusCode!); } else if ((obj as ClientRequest).aborted) { - status = { code: CanonicalCode.ABORTED }; + status = { code: StatusCode.ERROR }; } else { - status = { code: CanonicalCode.UNKNOWN }; + status = { code: StatusCode.ERROR }; } status.message = message; diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts index b08f868e8ee..c453bbf3160 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { - CanonicalCode, + StatusCode, context, propagation, Span as ISpan, @@ -598,7 +598,7 @@ describe('HttpPlugin', () => { const spans = memoryExporter.getFinishedSpans(); const [span] = spans; assert.strictEqual(spans.length, 1); - assert.strictEqual(span.status.code, CanonicalCode.ABORTED); + assert.strictEqual(span.status.code, StatusCode.ERROR); assert.ok(Object.keys(span.attributes).length >= 6); } }); @@ -636,7 +636,7 @@ describe('HttpPlugin', () => { const spans = memoryExporter.getFinishedSpans(); const [span] = spans; assert.strictEqual(spans.length, 1); - assert.strictEqual(span.status.code, CanonicalCode.ABORTED); + assert.strictEqual(span.status.code, StatusCode.ERROR); assert.ok(Object.keys(span.attributes).length > 7); } }); @@ -670,7 +670,7 @@ describe('HttpPlugin', () => { span.attributes[HttpAttribute.HTTP_STATUS_CODE], 404 ); - assert.strictEqual(span.status.code, CanonicalCode.NOT_FOUND); + assert.strictEqual(span.status.code, StatusCode.ERROR); done(); }); }); diff --git a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts index dbb21c25028..1a43c057bb2 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/utils.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { - CanonicalCode, + StatusCode, ROOT_CONTEXT, SpanKind, TraceFlags, @@ -33,31 +33,24 @@ import * as utils from '../../src/utils'; describe('Utility', () => { describe('parseResponseStatus()', () => { - it('should return UNKNOWN code by default', () => { + it('should return ERROR code by default', () => { const status = utils.parseResponseStatus( (undefined as unknown) as number ); - assert.deepStrictEqual(status, { code: CanonicalCode.UNKNOWN }); + assert.deepStrictEqual(status, { code: StatusCode.ERROR }); }); it('should return OK for Success HTTP status code', () => { for (let index = 100; index < 400; index++) { const status = utils.parseResponseStatus(index); - assert.deepStrictEqual(status, { code: CanonicalCode.OK }); + assert.deepStrictEqual(status, { code: StatusCode.OK }); } }); it('should not return OK for Bad HTTP status code', () => { for (let index = 400; index <= 600; index++) { const status = utils.parseResponseStatus(index); - assert.notStrictEqual(status.code, CanonicalCode.OK); - } - }); - it('should handle special HTTP status codes', () => { - for (const key in utils.HTTP_STATUS_SPECIAL_CASES) { - const status = utils.parseResponseStatus(key as any); - const canonicalCode = utils.HTTP_STATUS_SPECIAL_CASES[key]; - assert.deepStrictEqual(status.code, canonicalCode); + assert.notStrictEqual(status.code, StatusCode.OK); } }); }); diff --git a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts index 06febe96b6b..10cc3aeb534 100644 --- a/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts +++ b/packages/opentelemetry-plugin-https/test/functionals/https-enable.test.ts @@ -15,7 +15,7 @@ */ import { - CanonicalCode, + StatusCode, context, propagation, Span as ISpan, @@ -595,7 +595,7 @@ describe('HttpsPlugin', () => { const spans = memoryExporter.getFinishedSpans(); const [span] = spans; assert.strictEqual(spans.length, 1); - assert.strictEqual(span.status.code, CanonicalCode.ABORTED); + assert.strictEqual(span.status.code, StatusCode.ERROR); assert.ok(Object.keys(span.attributes).length >= 6); } }); @@ -633,7 +633,7 @@ describe('HttpsPlugin', () => { const spans = memoryExporter.getFinishedSpans(); const [span] = spans; assert.strictEqual(spans.length, 1); - assert.strictEqual(span.status.code, CanonicalCode.ABORTED); + assert.strictEqual(span.status.code, StatusCode.ERROR); assert.ok(Object.keys(span.attributes).length > 7); } }); @@ -653,7 +653,7 @@ describe('HttpsPlugin', () => { span.attributes[HttpAttribute.HTTP_STATUS_CODE], 404 ); - assert.strictEqual(span.status.code, CanonicalCode.NOT_FOUND); + assert.strictEqual(span.status.code, StatusCode.ERROR); done(); }); }); diff --git a/packages/opentelemetry-shim-opentracing/src/shim.ts b/packages/opentelemetry-shim-opentracing/src/shim.ts index 5b1364308a8..91934c3c478 100644 --- a/packages/opentelemetry-shim-opentracing/src/shim.ts +++ b/packages/opentelemetry-shim-opentracing/src/shim.ts @@ -319,7 +319,7 @@ export class SpanShim extends opentracing.Span { key === opentracing.Tags.ERROR && (value === true || value === 'true') ) { - this._span.setStatus({ code: api.CanonicalCode.UNKNOWN }); + this._span.setStatus({ code: api.StatusCode.ERROR }); return this; } diff --git a/packages/opentelemetry-tracing/src/Span.ts b/packages/opentelemetry-tracing/src/Span.ts index 61d0869b6a8..7755393acc2 100644 --- a/packages/opentelemetry-tracing/src/Span.ts +++ b/packages/opentelemetry-tracing/src/Span.ts @@ -51,7 +51,7 @@ export class Span implements api.Span, ReadableSpan { readonly instrumentationLibrary: InstrumentationLibrary; name: string; status: api.Status = { - code: api.CanonicalCode.OK, + code: api.StatusCode.UNSET, }; endTime: api.HrTime = [0, 0]; private _ended = false; diff --git a/packages/opentelemetry-tracing/test/Span.test.ts b/packages/opentelemetry-tracing/test/Span.test.ts index 91d67d86707..2a9527b9652 100644 --- a/packages/opentelemetry-tracing/test/Span.test.ts +++ b/packages/opentelemetry-tracing/test/Span.test.ts @@ -15,7 +15,7 @@ */ import { - CanonicalCode, + StatusCode, Exception, LinkContext, ROOT_CONTEXT, @@ -344,7 +344,7 @@ describe('Span', () => { SpanKind.CLIENT ); span.setStatus({ - code: CanonicalCode.PERMISSION_DENIED, + code: StatusCode.ERROR, message: 'This is an error', }); span.end(); @@ -366,7 +366,7 @@ describe('Span', () => { assert.strictEqual(span.parentSpanId, parentId); assert.strictEqual(span.spanContext.traceId, spanContext.traceId); assert.deepStrictEqual(span.status, { - code: CanonicalCode.OK, + code: StatusCode.UNSET, }); assert.deepStrictEqual(span.attributes, {}); assert.deepStrictEqual(span.links, []); @@ -478,19 +478,19 @@ describe('Span', () => { SpanKind.CLIENT ); span.setStatus({ - code: CanonicalCode.PERMISSION_DENIED, + code: StatusCode.ERROR, message: 'This is an error', }); - assert.strictEqual(span.status.code, CanonicalCode.PERMISSION_DENIED); + assert.strictEqual(span.status.code, StatusCode.ERROR); assert.strictEqual(span.status.message, 'This is an error'); span.end(); // shouldn't update status span.setStatus({ - code: CanonicalCode.OK, + code: StatusCode.OK, message: 'OK', }); - assert.strictEqual(span.status.code, CanonicalCode.PERMISSION_DENIED); + assert.strictEqual(span.status.code, StatusCode.ERROR); }); it('should only end a span once', () => { From 836556ad996a8bb0e4696cea16995233905f4b9f Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 2 Nov 2020 03:29:26 +0530 Subject: [PATCH 2/5] fix: lint issue --- packages/opentelemetry-exporter-collector/test/helper.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-exporter-collector/test/helper.ts b/packages/opentelemetry-exporter-collector/test/helper.ts index c94c5ce6639..f430b441bc2 100644 --- a/packages/opentelemetry-exporter-collector/test/helper.ts +++ b/packages/opentelemetry-exporter-collector/test/helper.ts @@ -462,7 +462,11 @@ export function ensureSpanIsCorrect( ); assert.strictEqual(span.droppedEventsCount, 0, 'droppedEventsCount is wrong'); assert.strictEqual(span.droppedLinksCount, 0, 'droppedLinksCount is wrong'); - assert.deepStrictEqual(span.status, { code: StatusCode.OK }, 'status is wrong'); + assert.deepStrictEqual( + span.status, + { code: StatusCode.OK }, + 'status is wrong' + ); } export function ensureWebResourceIsCorrect( From 0f1acce544dc25ee963e35014f68c3580c25c62b Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 2 Nov 2020 04:56:26 +0530 Subject: [PATCH 3/5] fix: tests zipkin and jaeger --- .../test/transform.test.ts | 4 ++-- .../test/common/transform.test.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts index 2e02297afd1..df3b65785b0 100644 --- a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts @@ -202,10 +202,10 @@ describe('transform', () => { const [tag1, tag2, tag3, tag4, tag5] = thriftSpan.tags; assert.strictEqual(tag1.key, 'status.code'); assert.strictEqual(tag1.vType, 'DOUBLE'); - assert.strictEqual(tag1.vDouble, 15); + assert.strictEqual(tag1.vDouble, 2); assert.strictEqual(tag2.key, 'status.name'); assert.strictEqual(tag2.vType, 'STRING'); - assert.strictEqual(tag2.vStr, 'DATA_LOSS'); + assert.strictEqual(tag2.vStr, 'ERROR'); assert.strictEqual(tag3.key, 'status.message'); assert.strictEqual(tag3.vType, 'STRING'); assert.strictEqual(tag3.vStr, 'data loss'); diff --git a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts index 4027b73e966..0c6773d227c 100644 --- a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts @@ -96,7 +96,7 @@ describe('transform', () => { tags: { key1: 'value1', key2: 'value2', - [statusCodeTagName]: 'OK', + [statusCodeTagName]: 'UNSET', 'telemetry.sdk.language': language, 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': VERSION, @@ -134,7 +134,7 @@ describe('transform', () => { name: span.name, parentId: undefined, tags: { - [statusCodeTagName]: 'OK', + [statusCodeTagName]: 'UNSET', 'telemetry.sdk.language': language, 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': VERSION, @@ -182,7 +182,7 @@ describe('transform', () => { name: span.name, parentId: undefined, tags: { - [statusCodeTagName]: 'OK', + [statusCodeTagName]: 'UNSET', 'telemetry.sdk.language': language, 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': VERSION, @@ -219,7 +219,7 @@ describe('transform', () => { assert.deepStrictEqual(tags, { key1: 'value1', key2: 'value2', - [statusCodeTagName]: 'OK', + [statusCodeTagName]: 'UNSET', cost: '112.12', service: 'ui', version: '1', @@ -253,7 +253,7 @@ describe('transform', () => { assert.deepStrictEqual(tags, { key1: 'value1', key2: 'value2', - [statusCodeTagName]: 'ABORTED', + [statusCodeTagName]: 'ERROR', }); }); it('should map OpenTelemetry Status.message to a Zipkin tag', () => { @@ -285,7 +285,7 @@ describe('transform', () => { assert.deepStrictEqual(tags, { key1: 'value1', key2: 'value2', - [statusCodeTagName]: 'ABORTED', + [statusCodeTagName]: 'ERROR', [statusDescriptionTagName]: status.message, }); }); From e4ac03982764cb58839d4d3fe47460d6c903c6ed Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 2 Nov 2020 19:46:41 +0530 Subject: [PATCH 4/5] fix: grpc tests --- .../test/utils/assertionUtils.ts | 14 ++++++++++++-- packages/opentelemetry-plugin-grpc-js/src/utils.ts | 2 +- packages/opentelemetry-plugin-grpc/src/utils.ts | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/opentelemetry-grpc-utils/test/utils/assertionUtils.ts b/packages/opentelemetry-grpc-utils/test/utils/assertionUtils.ts index 746f930f58e..35b727f317c 100644 --- a/packages/opentelemetry-grpc-utils/test/utils/assertionUtils.ts +++ b/packages/opentelemetry-grpc-utils/test/utils/assertionUtils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { SpanKind } from '@opentelemetry/api'; +import { SpanKind, StatusCode } from '@opentelemetry/api'; import * as assert from 'assert'; import type * as grpc from 'grpc'; import type * as grpcJs from '@grpc/grpc-js'; @@ -24,6 +24,16 @@ import { hrTimeToMicroseconds, } from '@opentelemetry/core'; + +export const grpcStatusCodeToOpenTelemetryStatusCode = ( + status: grpc.status | grpcJs.status +): StatusCode => { + if (status !== undefined && status === 0) { + return StatusCode.OK; + } + return StatusCode.ERROR; +}; + export const assertSpan = ( component: string, span: ReadableSpan, @@ -48,7 +58,7 @@ export const assertSpan = ( // validations assert.strictEqual(span.name, validations.name); - assert.strictEqual(span.status.code, validations.status); + assert.strictEqual(span.status.code, grpcStatusCodeToOpenTelemetryStatusCode(validations.status)); }; // Check if sourceSpan was propagated to targetSpan diff --git a/packages/opentelemetry-plugin-grpc-js/src/utils.ts b/packages/opentelemetry-plugin-grpc-js/src/utils.ts index 990ceca9e4d..c60bbf0e7d2 100644 --- a/packages/opentelemetry-plugin-grpc-js/src/utils.ts +++ b/packages/opentelemetry-plugin-grpc-js/src/utils.ts @@ -43,7 +43,7 @@ export const grpcStatusCodeToOpenTelemetryStatusCode = ( * @param status */ export const grpcStatusCodeToSpanStatus = (status: number): Status => { - return { code: status }; + return { code: grpcStatusCodeToOpenTelemetryStatusCode(status) }; }; /** diff --git a/packages/opentelemetry-plugin-grpc/src/utils.ts b/packages/opentelemetry-plugin-grpc/src/utils.ts index a89b6568014..03a34378899 100644 --- a/packages/opentelemetry-plugin-grpc/src/utils.ts +++ b/packages/opentelemetry-plugin-grpc/src/utils.ts @@ -47,7 +47,7 @@ export const _grpcStatusCodeToOpenTelemetryStatusCode = ( }; export const _grpcStatusCodeToSpanStatus = (status: number): Status => { - return { code: status }; + return { code: _grpcStatusCodeToOpenTelemetryStatusCode(status) }; }; /** From 5b0f479fe15c2c7cca5b2de492a887aa08c8f98e Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 2 Nov 2020 19:59:18 +0530 Subject: [PATCH 5/5] fix: lint issue --- .../opentelemetry-grpc-utils/test/utils/assertionUtils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry-grpc-utils/test/utils/assertionUtils.ts b/packages/opentelemetry-grpc-utils/test/utils/assertionUtils.ts index 35b727f317c..cc2ccc3c980 100644 --- a/packages/opentelemetry-grpc-utils/test/utils/assertionUtils.ts +++ b/packages/opentelemetry-grpc-utils/test/utils/assertionUtils.ts @@ -24,7 +24,6 @@ import { hrTimeToMicroseconds, } from '@opentelemetry/core'; - export const grpcStatusCodeToOpenTelemetryStatusCode = ( status: grpc.status | grpcJs.status ): StatusCode => { @@ -58,7 +57,10 @@ export const assertSpan = ( // validations assert.strictEqual(span.name, validations.name); - assert.strictEqual(span.status.code, grpcStatusCodeToOpenTelemetryStatusCode(validations.status)); + assert.strictEqual( + span.status.code, + grpcStatusCodeToOpenTelemetryStatusCode(validations.status) + ); }; // Check if sourceSpan was propagated to targetSpan