Skip to content

Commit b85acf0

Browse files
authored
chore: fixing status code aligning it with proto (#1860)
1 parent 960b868 commit b85acf0

File tree

5 files changed

+9
-47
lines changed

5 files changed

+9
-47
lines changed

packages/opentelemetry-api/src/trace/status.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ export interface Status {
2525
*/
2626
export enum StatusCode {
2727
/**
28-
* The operation has been validated by an Application developer or
29-
* Operator to have completed successfully.
28+
* The default status.
3029
*/
31-
OK = 0,
30+
UNSET = 0,
3231
/**
33-
* The default status.
32+
* The operation has been validated by an Application developer or
33+
* Operator to have completed successfully.
3434
*/
35-
UNSET = 1,
35+
OK = 1,
3636
/**
3737
* The operation contains an error.
3838
*/

packages/opentelemetry-exporter-collector/src/transform.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
Link,
2020
SpanKind,
2121
Status,
22-
StatusCode,
2322
TimedEvent,
2423
TraceState,
2524
} from '@opentelemetry/api';
@@ -192,23 +191,6 @@ export function toCollectorSpan(
192191
};
193192
}
194193

195-
/**
196-
* Converts StatusCode
197-
* @param code
198-
*/
199-
export function toCollectorCode(
200-
code: StatusCode
201-
): opentelemetryProto.trace.v1.StatusCode {
202-
switch (code) {
203-
case StatusCode.OK:
204-
return opentelemetryProto.trace.v1.StatusCode.OK;
205-
case StatusCode.UNSET:
206-
return opentelemetryProto.trace.v1.StatusCode.UNSET;
207-
default:
208-
return opentelemetryProto.trace.v1.StatusCode.ERROR;
209-
}
210-
}
211-
212194
/**
213195
* Converts status
214196
* @param status
@@ -217,7 +199,7 @@ export function toCollectorStatus(
217199
status: Status
218200
): opentelemetryProto.trace.v1.Status {
219201
const spanStatus: opentelemetryProto.trace.v1.Status = {
220-
code: toCollectorCode(status.code),
202+
code: status.code,
221203
};
222204
if (typeof status.message !== 'undefined') {
223205
spanStatus.message = status.message;

packages/opentelemetry-exporter-collector/src/types.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { SpanKind, Logger, Attributes } from '@opentelemetry/api';
17+
import { Attributes, Logger, SpanKind, StatusCode } from '@opentelemetry/api';
1818

1919
/* eslint-disable @typescript-eslint/no-namespace */
2020
export namespace opentelemetryProto {
@@ -260,26 +260,6 @@ export namespace opentelemetryProto {
260260
message?: string;
261261
}
262262

263-
/**
264-
* An enumeration of status codes.
265-
* https://github.com/open-telemetry/opentelemetry-proto/blob/master/opentelemetry/proto/trace/v1/trace.proto#L304
266-
*/
267-
export enum StatusCode {
268-
/**
269-
* The default status.
270-
*/
271-
UNSET = 0,
272-
/**
273-
* The operation has been validated by an Application developer or
274-
* Operator to have completed successfully.
275-
*/
276-
OK = 1,
277-
/**
278-
* The operation contains an error.
279-
*/
280-
ERROR = 2,
281-
}
282-
283263
export interface TraceConfig {
284264
constantSampler?: ConstantSampler | null;
285265
probabilitySampler?: ProbabilitySampler | null;

packages/opentelemetry-exporter-collector/test/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ export function ensureSpanIsCorrect(
515515
assert.strictEqual(span.droppedLinksCount, 0, 'droppedLinksCount is wrong');
516516
assert.deepStrictEqual(
517517
span.status,
518-
{ code: opentelemetryProto.trace.v1.StatusCode.OK },
518+
{ code: StatusCode.OK },
519519
'status is wrong'
520520
);
521521
}

packages/opentelemetry-exporter-jaeger/test/transform.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('transform', () => {
126126
assert.strictEqual(tag3.vDouble, 3.142);
127127
assert.strictEqual(tag4.key, 'status.code');
128128
assert.strictEqual(tag4.vType, 'DOUBLE');
129-
assert.strictEqual(tag4.vDouble, 0);
129+
assert.strictEqual(tag4.vDouble, api.StatusCode.OK);
130130
assert.strictEqual(tag5.key, 'status.name');
131131
assert.strictEqual(tag5.vType, 'STRING');
132132
assert.strictEqual(tag5.vStr, 'OK');

0 commit comments

Comments
 (0)