From 2afaffa413b78d89f24091e710c9e511a2f65ca5 Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Thu, 18 Jun 2020 23:02:12 +0200 Subject: [PATCH] Adds possibility to set headers to zipkin exporter (#1202) Co-authored-by: Daniel Dyla Co-authored-by: Mayur Kale --- packages/opentelemetry-exporter-zipkin/README.md | 6 +++++- .../opentelemetry-exporter-zipkin/src/types.ts | 1 + .../opentelemetry-exporter-zipkin/src/zipkin.ts | 1 + .../test/zipkin.test.ts | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-exporter-zipkin/README.md b/packages/opentelemetry-exporter-zipkin/README.md index e38ce286c3f..f6b78c6a1cc 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 812deed5f2f..0433351491d 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 8d2f72e5f6b..dcf5a4b2b01 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 813a0a6185b..484e0c02b76 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', () => {