Skip to content

Commit

Permalink
fix(otlp-grpc-exporter): env vars should not override configs from co…
Browse files Browse the repository at this point in the history
…nstructor parameter
  • Loading branch information
llc1123 committed May 22, 2023
1 parent b9abac9 commit 040ac51
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,15 @@ describe('when configuring via environment', () => {
assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['bar']);
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override global headers config with signal headers defined via env', () => {
it('should override global headers config with signal headers defined via env but not config from parameters', () => {
const metadata = new grpc.Metadata();
metadata.set('foo', 'bar');
metadata.set('goo', 'lol');
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=jar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS = 'foo=boo';
metadata.set('foo', 'jar');
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo,goo=loo';
envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS = 'foo=boo,bar=loo';
const collectorExporter = new OTLPLogExporter({ metadata });
assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['boo']);
assert.deepStrictEqual(collectorExporter.metadata?.get('bar'), ['foo']);
assert.deepStrictEqual(collectorExporter.metadata?.get('goo'), ['lol']);
assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['jar']);
assert.deepStrictEqual(collectorExporter.metadata?.get('bar'), ['loo']);
assert.deepStrictEqual(collectorExporter.metadata?.get('goo'), ['loo']);
envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,15 @@ describe('when configuring via environment', () => {
assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['bar']);
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override global headers config with signal headers defined via env', () => {
it('should override global headers config with signal headers defined via env but not config from parameters', () => {
const metadata = new grpc.Metadata();
metadata.set('foo', 'bar');
metadata.set('goo', 'lol');
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=jar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = 'foo=boo';
metadata.set('foo', 'jar');
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo,goo=loo';
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = 'foo=boo,bar=loo';
const collectorExporter = new OTLPTraceExporter({ metadata });
assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['boo']);
assert.deepStrictEqual(collectorExporter.metadata?.get('bar'), ['foo']);
assert.deepStrictEqual(collectorExporter.metadata?.get('goo'), ['lol']);
assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['jar']);
assert.deepStrictEqual(collectorExporter.metadata?.get('bar'), ['loo']);
assert.deepStrictEqual(collectorExporter.metadata?.get('goo'), ['loo']);
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,18 @@ describe('when configuring via environment', () => {
assert.strictEqual(collectorExporter._headers.foo, 'bar');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override global headers config with signal headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = 'foo=boo';
const collectorExporter = new OTLPTraceExporter({ headers: {} });
it('should override global headers config with signal headers defined via env but not config from parameters', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo,goo=loo';
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = 'foo=boo,bar=loo';
const collectorExporter = new OTLPTraceExporter({
headers: { foo: 'jar' },
});
// @ts-expect-error access internal property for testing
assert.strictEqual(collectorExporter._headers.foo, 'jar');
// @ts-expect-error access internal property for testing
assert.strictEqual(collectorExporter._headers.foo, 'boo');
assert.strictEqual(collectorExporter._headers.bar, 'loo');
// @ts-expect-error access internal property for testing
assert.strictEqual(collectorExporter._headers.bar, 'foo');
assert.strictEqual(collectorExporter._headers.goo, 'loo');
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,15 @@ describe('OTLPTraceExporter - node with json over http', () => {
assert.strictEqual(collectorExporter.headers.foo, 'bar');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override global headers config with signal headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = 'foo=boo';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(collectorExporter.headers.foo, 'boo');
assert.strictEqual(collectorExporter.headers.bar, 'foo');
it('should override global headers config with signal headers defined via env but not config from parameters', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo,goo=loo';
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = 'foo=boo,bar=loo';
const collectorExporter = new OTLPTraceExporter({
headers: { foo: 'jar' },
});
assert.strictEqual(collectorExporter.headers.foo, 'jar');
assert.strictEqual(collectorExporter.headers.bar, 'loo');
assert.strictEqual(collectorExporter.headers.goo, 'loo');
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ describe('OTLPTraceExporter - node with proto over http', () => {
assert.strictEqual(collectorExporter.headers.foo, 'bar');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override global headers config with signal headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = 'foo=boo';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(collectorExporter.headers.foo, 'boo');
assert.strictEqual(collectorExporter.headers.bar, 'foo');
it('should override global headers config with signal headers defined via env but not config from parameters', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo,goo=loo';
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = 'foo=boo,bar=loo';
const collectorExporter = new OTLPTraceExporter({
headers: { foo: 'jar' },
});
assert.strictEqual(collectorExporter.headers.foo, 'jar');
assert.strictEqual(collectorExporter.headers.bar, 'loo');
assert.strictEqual(collectorExporter.headers.goo, 'loo');
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,27 +314,26 @@ describe('when configuring via environment', () => {
);
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override global headers config with signal headers defined via env', () => {
it('should override global headers config with signal headers defined via env but not config from parameters', () => {
const metadata = new grpc.Metadata();
metadata.set('foo', 'bar');
metadata.set('goo', 'lol');
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=jar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo';
metadata.set('foo', 'jar');
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo,goo=loo';
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo,bar=loo';
const collectorExporter = new OTLPMetricExporter({
metadata,
temporalityPreference: AggregationTemporality.CUMULATIVE,
});
assert.deepStrictEqual(
collectorExporter._otlpExporter.metadata?.get('foo'),
['boo']
['jar']
);
assert.deepStrictEqual(
collectorExporter._otlpExporter.metadata?.get('bar'),
['foo']
['loo']
);
assert.deepStrictEqual(
collectorExporter._otlpExporter.metadata?.get('goo'),
['lol']
['loo']
);
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,20 +361,24 @@ describe('when configuring via environment', () => {
);
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override global headers config with signal headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo';
it('should override global headers config with signal headers defined via env but not config from parameters', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo,goo=loo';
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo,bar=loo';
const collectorExporter = new OTLPMetricExporter({
headers: {},
headers: { foo: 'jar' },
temporalityPreference: AggregationTemporality.CUMULATIVE,
});
assert.strictEqual(
collectorExporter['_otlpExporter']['_headers'].foo,
'boo'
'jar'
);
assert.strictEqual(
collectorExporter['_otlpExporter']['_headers'].bar,
'foo'
'loo'
);
assert.strictEqual(
collectorExporter['_otlpExporter']['_headers'].goo,
'loo'
);
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,15 @@ describe('OTLPMetricExporter - node with json over http', () => {
assert.strictEqual(collectorExporter._otlpExporter.headers.foo, 'bar');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override global headers config with signal headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo';
const collectorExporter = new OTLPMetricExporter();
assert.strictEqual(collectorExporter._otlpExporter.headers.foo, 'boo');
assert.strictEqual(collectorExporter._otlpExporter.headers.bar, 'foo');
it('should override global headers config with signal headers defined via env but not config from parameters', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo,goo=loo';
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo,bar=loo';
const collectorExporter = new OTLPMetricExporter({
headers: { foo: 'jar' },
});
assert.strictEqual(collectorExporter._otlpExporter.headers.foo, 'jar');
assert.strictEqual(collectorExporter._otlpExporter.headers.bar, 'loo');
assert.strictEqual(collectorExporter._otlpExporter.headers.goo, 'loo');
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,15 @@ describe('OTLPMetricExporter - node with proto over http', () => {
assert.strictEqual(collectorExporter._otlpExporter.headers.foo, 'bar');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override global headers config with signal headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo';
const collectorExporter = new OTLPMetricExporter();
assert.strictEqual(collectorExporter._otlpExporter.headers.foo, 'boo');
assert.strictEqual(collectorExporter._otlpExporter.headers.bar, 'foo');
it('should override global headers config with signal headers defined via env but not config from parameters', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo,goo=loo';
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo,bar=loo';
const collectorExporter = new OTLPMetricExporter({
headers: { foo: 'jar' },
});
assert.strictEqual(collectorExporter._otlpExporter.headers.foo, 'jar');
assert.strictEqual(collectorExporter._otlpExporter.headers.bar, 'loo');
assert.strictEqual(collectorExporter._otlpExporter.headers.goo, 'loo');
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
Expand Down

0 comments on commit 040ac51

Please sign in to comment.