Skip to content

Commit 2afaffa

Browse files
obecnydyladanmayurkale22
authored
Adds possibility to set headers to zipkin exporter (#1202)
Co-authored-by: Daniel Dyla <[email protected]> Co-authored-by: Mayur Kale <[email protected]>
1 parent f9f5df5 commit 2afaffa

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

packages/opentelemetry-exporter-zipkin/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ Install the exporter on your application and pass the options. `serviceName` is
2424
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
2525

2626
// Add your zipkin url (`http://localhost:9411/api/v2/spans` is used as
27-
// default) and application name to the Zipkin options
27+
// default) and application name to the Zipkin options.
28+
// You can also define your custom headers which will be added automatically.
2829
const options = {
30+
headers: {
31+
'my-header': 'header-value',
32+
},
2933
url: 'your-zipkin-url',
3034
serviceName: 'your-application-name'
3135
}

packages/opentelemetry-exporter-zipkin/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as api from '@opentelemetry/api';
2020
* Exporter config
2121
*/
2222
export interface ExporterConfig {
23+
headers?: { [key: string]: string };
2324
logger?: api.Logger;
2425
serviceName?: string;
2526
url?: string;

packages/opentelemetry-exporter-zipkin/src/zipkin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class ZipkinExporter implements SpanExporter {
5252
headers: {
5353
'Content-Type': 'application/json',
5454
[OT_REQUEST_HEADER]: 1,
55+
...config.headers,
5556
},
5657
},
5758
urlOpts

packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ describe('ZipkinExporter', () => {
9797
assert.ok(typeof exporter.export === 'function');
9898
assert.ok(typeof exporter.shutdown === 'function');
9999
});
100+
it('should construct an exporter with headers', () => {
101+
const exporter = new ZipkinExporter({
102+
headers: {
103+
foo: 'bar',
104+
},
105+
});
106+
interface ExporterWithHeaders {
107+
_reqOpts: {
108+
headers: { [key: string]: string };
109+
};
110+
}
111+
const exporterWithHeaders = (exporter as unknown) as ExporterWithHeaders;
112+
113+
assert.ok(exporterWithHeaders._reqOpts.headers['foo'] === 'bar');
114+
});
100115
});
101116

102117
describe('export', () => {

0 commit comments

Comments
 (0)