diff --git a/packages/opentelemetry-exporter-zipkin/src/platform/browser/util.ts b/packages/opentelemetry-exporter-zipkin/src/platform/browser/util.ts index 2505c3eec83..2b0ef76b2e7 100644 --- a/packages/opentelemetry-exporter-zipkin/src/platform/browser/util.ts +++ b/packages/opentelemetry-exporter-zipkin/src/platform/browser/util.ts @@ -28,7 +28,7 @@ import * as zipkinTypes from '../../types'; * @param headers - headers * send */ -export function prepareSend(urlStr: string, headers?: Record) { +export function prepareSend(urlStr: string, headers?: Record): zipkinTypes.SendFn { let xhrHeaders: Record; const useBeacon = typeof navigator.sendBeacon === 'function' && !headers; if (headers) { diff --git a/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts b/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts index abcd0789630..1d19b8dd3d5 100644 --- a/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts +++ b/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts @@ -27,7 +27,7 @@ import * as zipkinTypes from '../../types'; * @param headers - headers * send */ -export function prepareSend(urlStr: string, headers?: Record) { +export function prepareSend(urlStr: string, headers?: Record): zipkinTypes.SendFn { const urlOpts = url.parse(urlStr); const reqOpts: http.RequestOptions = Object.assign( diff --git a/packages/opentelemetry-exporter-zipkin/src/transform.ts b/packages/opentelemetry-exporter-zipkin/src/transform.ts index d20be0a14a2..64e4b48bbf6 100644 --- a/packages/opentelemetry-exporter-zipkin/src/transform.ts +++ b/packages/opentelemetry-exporter-zipkin/src/transform.ts @@ -29,8 +29,8 @@ const ZIPKIN_SPAN_KIND_MAPPING = { [api.SpanKind.INTERNAL]: undefined, }; -export const statusCodeTagName = 'ot.status_code'; -export const statusDescriptionTagName = 'ot.status_description'; +export const defaultStatusCodeTagName = 'ot.status_code'; +export const defaultStatusDescriptionTagName = 'ot.status_description'; /** * Translate OpenTelemetry ReadableSpan to ZipkinSpan format diff --git a/packages/opentelemetry-exporter-zipkin/src/types.ts b/packages/opentelemetry-exporter-zipkin/src/types.ts index f419c65f08e..a544f4e9b94 100644 --- a/packages/opentelemetry-exporter-zipkin/src/types.ts +++ b/packages/opentelemetry-exporter-zipkin/src/types.ts @@ -187,3 +187,5 @@ export type SendFunction = ( ) => void; export type GetHeaders = () => Record | undefined; + +export type SendFn = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void; diff --git a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts index 557c0faef3b..ef43cff0f89 100644 --- a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts +++ b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts @@ -21,8 +21,8 @@ import { prepareSend } from './platform/index'; import * as zipkinTypes from './types'; import { toZipkinSpan, - statusCodeTagName, - statusDescriptionTagName, + defaultStatusCodeTagName, + defaultStatusDescriptionTagName, } from './transform'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import { prepareGetHeaders } from './utils'; @@ -45,9 +45,9 @@ export class ZipkinExporter implements SpanExporter { this._urlStr = config.url || getEnv().OTEL_EXPORTER_ZIPKIN_ENDPOINT; this._send = prepareSend(this._urlStr, config.headers); this._serviceName = config.serviceName; - this._statusCodeTagName = config.statusCodeTagName || statusCodeTagName; + this._statusCodeTagName = config.statusCodeTagName || defaultStatusCodeTagName; this._statusDescriptionTagName = - config.statusDescriptionTagName || statusDescriptionTagName; + config.statusDescriptionTagName || defaultStatusDescriptionTagName; this._isShutdown = false; if (typeof config.getExportRequestHeaders === 'function') { this._getHeaders = prepareGetHeaders(config.getExportRequestHeaders); @@ -63,7 +63,7 @@ export class ZipkinExporter implements SpanExporter { export( spans: ReadableSpan[], resultCallback: (result: ExportResult) => void - ) { + ): void { const serviceName = String( this._serviceName || spans[0].resource.attributes[SemanticResourceAttributes.SERVICE_NAME] || diff --git a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts index 673803be0f3..ca8d37aa752 100644 --- a/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/common/transform.test.ts @@ -25,8 +25,8 @@ import { BasicTracerProvider, Span } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import { - statusCodeTagName, - statusDescriptionTagName, + defaultStatusCodeTagName, + defaultStatusDescriptionTagName, toZipkinSpan, _toZipkinAnnotations, _toZipkinTags, @@ -78,8 +78,8 @@ describe('transform', () => { const zipkinSpan = toZipkinSpan( span, 'my-service', - statusCodeTagName, - statusDescriptionTagName + defaultStatusCodeTagName, + defaultStatusDescriptionTagName ); assert.deepStrictEqual(zipkinSpan, { kind: 'SERVER', @@ -101,7 +101,7 @@ describe('transform', () => { tags: { key1: 'value1', key2: 'value2', - [statusCodeTagName]: 'UNSET', + [defaultStatusCodeTagName]: 'UNSET', [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', 'telemetry.sdk.language': language, 'telemetry.sdk.name': 'opentelemetry', @@ -124,8 +124,8 @@ describe('transform', () => { const zipkinSpan = toZipkinSpan( span, 'my-service', - statusCodeTagName, - statusDescriptionTagName + defaultStatusCodeTagName, + defaultStatusDescriptionTagName ); assert.deepStrictEqual(zipkinSpan, { kind: 'SERVER', @@ -140,7 +140,7 @@ describe('transform', () => { name: span.name, parentId: undefined, tags: { - [statusCodeTagName]: 'UNSET', + [defaultStatusCodeTagName]: 'UNSET', [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', 'telemetry.sdk.language': language, 'telemetry.sdk.name': 'opentelemetry', @@ -173,8 +173,8 @@ describe('transform', () => { const zipkinSpan = toZipkinSpan( span, 'my-service', - statusCodeTagName, - statusDescriptionTagName + defaultStatusCodeTagName, + defaultStatusDescriptionTagName ); assert.deepStrictEqual(zipkinSpan, { kind: item.zipkin, @@ -189,7 +189,7 @@ describe('transform', () => { name: span.name, parentId: undefined, tags: { - [statusCodeTagName]: 'UNSET', + [defaultStatusCodeTagName]: 'UNSET', [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', 'telemetry.sdk.language': language, 'telemetry.sdk.name': 'opentelemetry', @@ -219,15 +219,15 @@ describe('transform', () => { const tags: zipkinTypes.Tags = _toZipkinTags( span.attributes, span.status, - statusCodeTagName, - statusDescriptionTagName, + defaultStatusCodeTagName, + defaultStatusDescriptionTagName, DUMMY_RESOURCE ); assert.deepStrictEqual(tags, { key1: 'value1', key2: 'value2', - [statusCodeTagName]: 'UNSET', + [defaultStatusCodeTagName]: 'UNSET', cost: '112.12', service: 'ui', version: '1', @@ -254,8 +254,8 @@ describe('transform', () => { const tags: zipkinTypes.Tags = _toZipkinTags( span.attributes, span.status, - statusCodeTagName, - statusDescriptionTagName, + defaultStatusCodeTagName, + defaultStatusDescriptionTagName, Resource.empty().merge( new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', @@ -266,7 +266,7 @@ describe('transform', () => { assert.deepStrictEqual(tags, { key1: 'value1', key2: 'value2', - [statusCodeTagName]: 'ERROR', + [defaultStatusCodeTagName]: 'ERROR', [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', }); }); @@ -291,8 +291,8 @@ describe('transform', () => { const tags: zipkinTypes.Tags = _toZipkinTags( span.attributes, span.status, - statusCodeTagName, - statusDescriptionTagName, + defaultStatusCodeTagName, + defaultStatusDescriptionTagName, Resource.empty().merge( new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', @@ -303,8 +303,8 @@ describe('transform', () => { assert.deepStrictEqual(tags, { key1: 'value1', key2: 'value2', - [statusCodeTagName]: 'ERROR', - [statusDescriptionTagName]: status.message, + [defaultStatusCodeTagName]: 'ERROR', + [defaultStatusDescriptionTagName]: status.message, [SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test', }); });