Skip to content

Commit

Permalink
Adds possibility to set headers to zipkin exporter (#1202)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Dyla <[email protected]>
Co-authored-by: Mayur Kale <[email protected]>
  • Loading branch information
3 people authored Jun 18, 2020
1 parent f9f5df5 commit 2afaffa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/opentelemetry-exporter-zipkin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-zipkin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class ZipkinExporter implements SpanExporter {
headers: {
'Content-Type': 'application/json',
[OT_REQUEST_HEADER]: 1,
...config.headers,
},
},
urlOpts
Expand Down
15 changes: 15 additions & 0 deletions packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 2afaffa

Please sign in to comment.