Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: programmatic url and headers take precedence in metric exporters… #4334

Merged
merged 9 commits into from
Dec 6, 2023
4 changes: 4 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to experimental packages in this project will be documented

### :boom: Breaking Change

* fix(exporter-metrics-otlp-grpc): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati
Vunovati marked this conversation as resolved.
Show resolved Hide resolved
* fix(exporter-metrics-otlp-http): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati
* fix(exporter-metrics-otlp-proto): programatic headers take precedence over environment variables [#2370](https://github.com/open-telemetry/opentelemetry-js/pull/4334) @Vunovati

### :rocket: (Enhancement)

* feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase<
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
),
...config?.headers,
};

this.metadata ||= new Metadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ describe('when configuring via environment', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = '';
});
it('should use override url defined in env with url defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics';
const constructorDefinedEndpoint = 'http://constructor/v1/metrics';
const collectorExporter = new OTLPMetricExporter({
url: constructorDefinedEndpoint,
});
assert.strictEqual(collectorExporter._otlpExporter.url, 'constructor');
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPMetricExporter();
Expand Down Expand Up @@ -363,6 +372,23 @@ describe('when configuring via environment', () => {
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override headers defined via env with headers defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
const collectorExporter = new OTLPMetricExporter({
headers: {
foo: 'constructor',
},
});
assert.deepStrictEqual(
collectorExporter._otlpExporter.metadata?.get('foo'),
['constructor']
);
assert.deepStrictEqual(
collectorExporter._otlpExporter.metadata?.get('bar'),
['foo']
);
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
});

testOTLPMetricExporter({ useTLS: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class OTLPExporterNodeProxy extends OTLPExporterNodeBase<
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
),
...config?.headers,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ describe('OTLPMetricExporter - node with json over http', () => {
);
envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = '';
});
it('should use override url defined in env with url defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics';
const constructorDefinedEndpoint = 'http://constructor/v1/metrics';
const collectorExporter = new OTLPMetricExporter({
url: constructorDefinedEndpoint,
});
assert.strictEqual(
collectorExporter._otlpExporter.url,
constructorDefinedEndpoint
);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPMetricExporter();
Expand All @@ -318,6 +330,20 @@ describe('OTLPMetricExporter - node with json over http', () => {
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override headers defined via env with headers defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
const collectorExporter = new OTLPMetricExporter({
headers: {
foo: 'constructor',
},
});
assert.strictEqual(
collectorExporter._otlpExporter.headers.foo,
'constructor'
);
assert.strictEqual(collectorExporter._otlpExporter.headers.bar, 'foo');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should use delta temporality defined via env', () => {
for (const envValue of ['delta', 'DELTA', 'DeLTa', 'delta ']) {
envSource.OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE = envValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase<
...baggageUtils.parseKeyPairsIntoRecord(
getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS
),
...config?.headers,
Vunovati marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ describe('OTLPMetricExporter - node with proto over http', () => {
);
envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = '';
});
it('should use override url defined in env with url defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics';
const constructorDefinedEndpoint = 'http://constructor/v1/metrics';
const collectorExporter = new OTLPMetricExporter({
url: constructorDefinedEndpoint,
});
assert.strictEqual(
collectorExporter._otlpExporter.url,
constructorDefinedEndpoint
);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPMetricExporter();
Expand All @@ -163,6 +175,20 @@ describe('OTLPMetricExporter - node with proto over http', () => {
envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should override headers defined via env with headers defined in constructor', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo';
const collectorExporter = new OTLPMetricExporter({
headers: {
foo: 'constructor',
},
});
assert.strictEqual(
collectorExporter._otlpExporter.headers.foo,
'constructor'
);
assert.strictEqual(collectorExporter._otlpExporter.headers.bar, 'foo');
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
});

describe('export', () => {
Expand Down