Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exporter-zipkin): correct status tags names #2519

Merged
merged 3 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions packages/opentelemetry-exporter-zipkin/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const ZIPKIN_SPAN_KIND_MAPPING = {
[api.SpanKind.INTERNAL]: undefined,
};

export const defaultStatusCodeTagName = 'ot.status_code';
export const defaultStatusDescriptionTagName = 'ot.status_description';
export const defaultStatusCodeTagName = 'otel.status_code';
export const defaultStatusErrorTagName = 'error';

/**
* Translate OpenTelemetry ReadableSpan to ZipkinSpan format
Expand All @@ -40,7 +40,7 @@ export function toZipkinSpan(
span: ReadableSpan,
serviceName: string,
statusCodeTagName: string,
statusDescriptionTagName: string
statusErrorTagName: string
): zipkinTypes.Span {
const zipkinSpan: zipkinTypes.Span = {
traceId: span.spanContext().traceId,
Expand All @@ -55,7 +55,7 @@ export function toZipkinSpan(
span.attributes,
span.status,
statusCodeTagName,
statusDescriptionTagName,
statusErrorTagName,
span.resource
),
annotations: span.events.length
Expand All @@ -71,16 +71,18 @@ export function _toZipkinTags(
attributes: api.SpanAttributes,
status: api.SpanStatus,
statusCodeTagName: string,
statusDescriptionTagName: string,
statusErrorTagName: string,
resource: Resource
): zipkinTypes.Tags {
const tags: { [key: string]: string } = {};
for (const key of Object.keys(attributes)) {
tags[key] = String(attributes[key]);
}
tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);
if (status.message) {
tags[statusDescriptionTagName] = status.message;
if (status.code !== api.SpanStatusCode.UNSET) {
tags[statusCodeTagName] = String(api.SpanStatusCode[status.code]);
}
if (status.code === api.SpanStatusCode.ERROR && status.message) {
tags[statusErrorTagName] = status.message;
}

Object.keys(resource.attributes).forEach(
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as zipkinTypes from './types';
import {
toZipkinSpan,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
defaultStatusErrorTagName,
} from './transform';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { prepareGetHeaders } from './utils';
Expand All @@ -47,7 +47,7 @@ export class ZipkinExporter implements SpanExporter {
this._serviceName = config.serviceName;
this._statusCodeTagName = config.statusCodeTagName || defaultStatusCodeTagName;
this._statusDescriptionTagName =
config.statusDescriptionTagName || defaultStatusDescriptionTagName;
config.statusDescriptionTagName || defaultStatusErrorTagName;
this._isShutdown = false;
if (typeof config.getExportRequestHeaders === 'function') {
this._getHeaders = prepareGetHeaders(config.getExportRequestHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as assert from 'assert';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import {
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
defaultStatusErrorTagName,
toZipkinSpan,
_toZipkinAnnotations,
_toZipkinTags,
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('transform', () => {
span,
'my-service',
defaultStatusCodeTagName,
defaultStatusDescriptionTagName
defaultStatusErrorTagName
);
assert.deepStrictEqual(zipkinSpan, {
kind: 'SERVER',
Expand All @@ -101,7 +101,6 @@ describe('transform', () => {
tags: {
key1: 'value1',
key2: 'value2',
[defaultStatusCodeTagName]: 'UNSET',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
'telemetry.sdk.language': language,
'telemetry.sdk.name': 'opentelemetry',
Expand All @@ -125,7 +124,7 @@ describe('transform', () => {
span,
'my-service',
defaultStatusCodeTagName,
defaultStatusDescriptionTagName
defaultStatusErrorTagName
);
assert.deepStrictEqual(zipkinSpan, {
kind: 'SERVER',
Expand All @@ -140,7 +139,6 @@ describe('transform', () => {
name: span.name,
parentId: undefined,
tags: {
[defaultStatusCodeTagName]: 'UNSET',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
'telemetry.sdk.language': language,
'telemetry.sdk.name': 'opentelemetry',
Expand Down Expand Up @@ -174,7 +172,7 @@ describe('transform', () => {
span,
'my-service',
defaultStatusCodeTagName,
defaultStatusDescriptionTagName
defaultStatusErrorTagName
);
assert.deepStrictEqual(zipkinSpan, {
kind: item.zipkin,
Expand All @@ -189,7 +187,6 @@ describe('transform', () => {
name: span.name,
parentId: undefined,
tags: {
[defaultStatusCodeTagName]: 'UNSET',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
'telemetry.sdk.language': language,
'telemetry.sdk.name': 'opentelemetry',
Expand Down Expand Up @@ -220,14 +217,13 @@ describe('transform', () => {
span.attributes,
span.status,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
defaultStatusErrorTagName,
DUMMY_RESOURCE
);

assert.deepStrictEqual(tags, {
key1: 'value1',
key2: 'value2',
[defaultStatusCodeTagName]: 'UNSET',
cost: '112.12',
service: 'ui',
version: '1',
Expand Down Expand Up @@ -255,7 +251,7 @@ describe('transform', () => {
span.attributes,
span.status,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
defaultStatusErrorTagName,
Resource.empty().merge(
new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
Expand Down Expand Up @@ -292,7 +288,7 @@ describe('transform', () => {
span.attributes,
span.status,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
defaultStatusErrorTagName,
Resource.empty().merge(
new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
Expand All @@ -304,7 +300,7 @@ describe('transform', () => {
key1: 'value1',
key2: 'value2',
[defaultStatusCodeTagName]: 'ERROR',
[defaultStatusDescriptionTagName]: status.message,
[defaultStatusErrorTagName]: status.message,
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-zipkin/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function ensureSpanIsCorrect(span: Span) {
localEndpoint: { serviceName: 'OpenTelemetry Service' },
tags: {
component: 'foo',
'ot.status_code': 'OK',
'otel.status_code': 'OK',
service: 'ui',
version: '1',
cost: '112.12',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('Zipkin Exporter - node', () => {
tags: {
key1: 'value1',
key2: 'value2',
'ot.status_code': 'OK',
'otel.status_code': 'OK',
},
timestamp: startTime * MICROS_PER_SECS,
traceId: span1.spanContext().traceId,
Expand All @@ -230,7 +230,7 @@ describe('Zipkin Exporter - node', () => {
},
name: span2.name,
tags: {
'ot.status_code': 'OK',
'otel.status_code': 'OK',
},
timestamp: hrTimeToMicroseconds([startTime, 0]),
traceId: span2.spanContext().traceId,
Expand Down