diff --git a/packages/opentelemetry-exporter-zipkin/README.md b/packages/opentelemetry-exporter-zipkin/README.md index e38ce286c3..f6b78c6a1c 100644 --- a/packages/opentelemetry-exporter-zipkin/README.md +++ b/packages/opentelemetry-exporter-zipkin/README.md @@ -24,8 +24,12 @@ Install the exporter on your application and pass the options. `serviceName` is const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); // Add your zipkin url (`http://localhost:9411/api/v2/spans` is used as -// default) and application name to the Zipkin options +// default) and application name to the Zipkin options. +// You can also define your custom headers which will be added automatically. const options = { + headers: { + 'my-header': 'header-value', + }, url: 'your-zipkin-url', serviceName: 'your-application-name' } diff --git a/packages/opentelemetry-exporter-zipkin/src/types.ts b/packages/opentelemetry-exporter-zipkin/src/types.ts index 812deed5f2..0433351491 100644 --- a/packages/opentelemetry-exporter-zipkin/src/types.ts +++ b/packages/opentelemetry-exporter-zipkin/src/types.ts @@ -20,6 +20,7 @@ import * as api from '@opentelemetry/api'; * Exporter config */ export interface ExporterConfig { + headers?: { [key: string]: string }; logger?: api.Logger; serviceName?: string; url?: string; diff --git a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts index 8d2f72e5f6..dcf5a4b2b0 100644 --- a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts +++ b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts @@ -52,6 +52,7 @@ export class ZipkinExporter implements SpanExporter { headers: { 'Content-Type': 'application/json', [OT_REQUEST_HEADER]: 1, + ...config.headers, }, }, urlOpts diff --git a/packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts b/packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts index 813a0a6185..484e0c02b7 100644 --- a/packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts @@ -97,6 +97,21 @@ describe('ZipkinExporter', () => { assert.ok(typeof exporter.export === 'function'); assert.ok(typeof exporter.shutdown === 'function'); }); + it('should construct an exporter with headers', () => { + const exporter = new ZipkinExporter({ + headers: { + foo: 'bar', + }, + }); + interface ExporterWithHeaders { + _reqOpts: { + headers: { [key: string]: string }; + }; + } + const exporterWithHeaders = (exporter as unknown) as ExporterWithHeaders; + + assert.ok(exporterWithHeaders._reqOpts.headers['foo'] === 'bar'); + }); }); describe('export', () => {