Skip to content

Commit

Permalink
chore: fixing status code aligning it with proto (#1860)
Browse files Browse the repository at this point in the history
  • Loading branch information
obecny authored Jan 24, 2021
1 parent 960b868 commit b85acf0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 47 deletions.
10 changes: 5 additions & 5 deletions packages/opentelemetry-api/src/trace/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export interface Status {
*/
export enum StatusCode {
/**
* The operation has been validated by an Application developer or
* Operator to have completed successfully.
* The default status.
*/
OK = 0,
UNSET = 0,
/**
* The default status.
* The operation has been validated by an Application developer or
* Operator to have completed successfully.
*/
UNSET = 1,
OK = 1,
/**
* The operation contains an error.
*/
Expand Down
20 changes: 1 addition & 19 deletions packages/opentelemetry-exporter-collector/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
Link,
SpanKind,
Status,
StatusCode,
TimedEvent,
TraceState,
} from '@opentelemetry/api';
Expand Down Expand Up @@ -192,23 +191,6 @@ export function toCollectorSpan(
};
}

/**
* Converts StatusCode
* @param code
*/
export function toCollectorCode(
code: StatusCode
): opentelemetryProto.trace.v1.StatusCode {
switch (code) {
case StatusCode.OK:
return opentelemetryProto.trace.v1.StatusCode.OK;
case StatusCode.UNSET:
return opentelemetryProto.trace.v1.StatusCode.UNSET;
default:
return opentelemetryProto.trace.v1.StatusCode.ERROR;
}
}

/**
* Converts status
* @param status
Expand All @@ -217,7 +199,7 @@ export function toCollectorStatus(
status: Status
): opentelemetryProto.trace.v1.Status {
const spanStatus: opentelemetryProto.trace.v1.Status = {
code: toCollectorCode(status.code),
code: status.code,
};
if (typeof status.message !== 'undefined') {
spanStatus.message = status.message;
Expand Down
22 changes: 1 addition & 21 deletions packages/opentelemetry-exporter-collector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { SpanKind, Logger, Attributes } from '@opentelemetry/api';
import { Attributes, Logger, SpanKind, StatusCode } from '@opentelemetry/api';

/* eslint-disable @typescript-eslint/no-namespace */
export namespace opentelemetryProto {
Expand Down Expand Up @@ -260,26 +260,6 @@ export namespace opentelemetryProto {
message?: string;
}

/**
* An enumeration of status codes.
* https://github.com/open-telemetry/opentelemetry-proto/blob/master/opentelemetry/proto/trace/v1/trace.proto#L304
*/
export enum StatusCode {
/**
* The default status.
*/
UNSET = 0,
/**
* The operation has been validated by an Application developer or
* Operator to have completed successfully.
*/
OK = 1,
/**
* The operation contains an error.
*/
ERROR = 2,
}

export interface TraceConfig {
constantSampler?: ConstantSampler | null;
probabilitySampler?: ProbabilitySampler | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-collector/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ export function ensureSpanIsCorrect(
assert.strictEqual(span.droppedLinksCount, 0, 'droppedLinksCount is wrong');
assert.deepStrictEqual(
span.status,
{ code: opentelemetryProto.trace.v1.StatusCode.OK },
{ code: StatusCode.OK },
'status is wrong'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('transform', () => {
assert.strictEqual(tag3.vDouble, 3.142);
assert.strictEqual(tag4.key, 'status.code');
assert.strictEqual(tag4.vType, 'DOUBLE');
assert.strictEqual(tag4.vDouble, 0);
assert.strictEqual(tag4.vDouble, api.StatusCode.OK);
assert.strictEqual(tag5.key, 'status.name');
assert.strictEqual(tag5.vType, 'STRING');
assert.strictEqual(tag5.vStr, 'OK');
Expand Down

0 comments on commit b85acf0

Please sign in to comment.