Skip to content

Commit

Permalink
Fixing Span status when exporting span (#1751)
Browse files Browse the repository at this point in the history
* chore: fixing status code for span to align with latest version

* chore: updating to proto ver. 0.6 for exporter-collector-grpc

* chore: updating to proto ver. 0.6 for exporter-collector-proto

* chore: fixing tests after update

* chore: updating readme and docker container version

* chore: comparing using enums
  • Loading branch information
obecny committed Dec 17, 2020
1 parent c478cc1 commit c5cbc49
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"
services:
# Collector
collector:
image: otel/opentelemetry-collector:0.13.0
image: otel/opentelemetry-collector:0.16.0
# image: otel/opentelemetry-collector:latest
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"]
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ export function ensureExportedSpanIsCorrect(
assert.strictEqual(span.droppedLinksCount, 0, 'droppedLinksCount is wrong');
assert.deepStrictEqual(
span.status,
{ code: 'STATUS_CODE_OK', message: '' },
{
code: 'STATUS_CODE_OK',
deprecatedCode: 'DEPRECATED_STATUS_CODE_OK',
message: '',
},
'status is wrong'
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-collector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![devDependencies][devDependencies-image]][devDependencies-url]
[![Apache License][license-image]][license-image]

This module provides exporter for web and node to be used with [opentelemetry-collector][opentelemetry-collector-url] - last tested with version **0.12.0**.
This module provides exporter for web and node to be used with [opentelemetry-collector][opentelemetry-collector-url] - last tested with version **0.16.0**.

## Installation

Expand Down
37 changes: 36 additions & 1 deletion packages/opentelemetry-exporter-collector/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
Attributes,
Link,
SpanKind,
Status,
StatusCode,
TimedEvent,
TraceState,
} from '@opentelemetry/api';
Expand Down Expand Up @@ -184,12 +186,45 @@ export function toCollectorSpan(
droppedAttributesCount: 0,
events: toCollectorEvents(span.events),
droppedEventsCount: 0,
status: span.status,
status: toCollectorStatus(span.status),
links: toCollectorLinks(span, useHex),
droppedLinksCount: 0,
};
}

/**
* 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
*/
export function toCollectorStatus(
status: Status
): opentelemetryProto.trace.v1.Status {
const spanStatus: opentelemetryProto.trace.v1.Status = {
code: toCollectorCode(status.code),
};
if (typeof status.message !== 'undefined') {
spanStatus.message = status.message;
}
return spanStatus;
}

/**
* Converts resource
* @param resource
Expand Down
28 changes: 26 additions & 2 deletions packages/opentelemetry-exporter-collector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

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

/* eslint-disable @typescript-eslint/no-namespace */
export namespace opentelemetryProto {
Expand Down Expand Up @@ -254,7 +253,32 @@ export namespace opentelemetryProto {
status?: Status;
}

export type Status = api.Status;
export interface Status {
/** The status code of this message. */
code: StatusCode;
/** A developer-facing error message. */
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;
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 @@ -507,7 +507,7 @@ export function ensureSpanIsCorrect(
assert.strictEqual(span.droppedLinksCount, 0, 'droppedLinksCount is wrong');
assert.deepStrictEqual(
span.status,
{ code: api.StatusCode.OK },
{ code: opentelemetryProto.trace.v1.StatusCode.OK },
'status is wrong'
);
}
Expand Down

0 comments on commit c5cbc49

Please sign in to comment.