Skip to content

Commit

Permalink
chore(otlp-exporter): add user-agent header/metadata tests
Browse files Browse the repository at this point in the history
  • Loading branch information
llc1123 committed May 18, 2023
1 parent 8cf17c8 commit f87d8d1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
IExportLogsServiceRequest,
IResourceLogs,
} from '@opentelemetry/otlp-transformer';
import { VERSION } from '../src/version';

const logsServiceProtoPath =
'opentelemetry/proto/collector/logs/v1/logs_service.proto';
Expand Down Expand Up @@ -320,6 +321,12 @@ describe('when configuring via environment', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = '';
});
it('should have user-agent header', () => {
const collectorExporter = new OTLPLogsExporter();
assert.deepStrictEqual(collectorExporter.metadata?.get('User-Agent'), [
`OTel-OTLP-Exporter-JavaScript/${VERSION}`,
]);
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPLogsExporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
IExportTraceServiceRequest,
IResourceSpans,
} from '@opentelemetry/otlp-transformer';
import { VERSION } from '../src/version';

const traceServiceProtoPath =
'opentelemetry/proto/collector/trace/v1/trace_service.proto';
Expand Down Expand Up @@ -330,6 +331,12 @@ describe('when configuring via environment', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should have user-agent header', () => {
const collectorExporter = new OTLPTraceExporter();
assert.deepStrictEqual(collectorExporter.metadata?.get('User-Agent'), [
`OTel-OTLP-Exporter-JavaScript/${VERSION}`,
]);
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPTraceExporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
import { nextTick } from 'process';
import { MockedResponse } from './nodeHelpers';
import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';
import { VERSION } from '../../src/version';

let fakeRequest: PassThrough;

Expand Down Expand Up @@ -154,6 +155,13 @@ describe('OTLPTraceExporter - node with json over http', () => {
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should have user-agent header', () => {
const collectorExporter = new OTLPTraceExporter();
assert.deepStrictEqual(
collectorExporter.headers['user-agent'],
`OTel-OTLP-Exporter-JavaScript/${VERSION}`
);
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPTraceExporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
ServiceClientType,
} from '@opentelemetry/otlp-proto-exporter-base';
import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';
import { VERSION } from '../../src/version';

let fakeRequest: PassThrough;

Expand Down Expand Up @@ -129,6 +130,13 @@ describe('OTLPTraceExporter - node with proto over http', () => {
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should have user-agent header', () => {
const collectorExporter = new OTLPTraceExporter();
assert.deepStrictEqual(
collectorExporter.headers['user-agent'],
`OTel-OTLP-Exporter-JavaScript/${VERSION}`
);
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPTraceExporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
IExportMetricsServiceRequest,
IResourceMetrics,
} from '@opentelemetry/otlp-transformer';
import { VERSION } from '../src/version';

const metricsServiceProtoPath =
'opentelemetry/proto/collector/metrics/v1/metrics_service.proto';
Expand Down Expand Up @@ -305,6 +306,13 @@ describe('when configuring via environment', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = '';
});
it('should have user-agent header', () => {
const collectorExporter = new OTLPMetricExporter();
assert.deepStrictEqual(
collectorExporter._otlpExporter.metadata?.get('User-Agent'),
[`OTel-OTLP-Exporter-JavaScript/${VERSION}`]
);
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPMetricExporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
OTLPExporterNodeConfigBase,
} from '@opentelemetry/otlp-exporter-base';
import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';
import { VERSION } from '../../src/version';

let fakeRequest: PassThrough;

Expand Down Expand Up @@ -182,6 +183,13 @@ describe('OTLPMetricExporter - node with json over http', () => {
);
envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = '';
});
it('should have user-agent header', () => {
const collectorExporter = new OTLPMetricExporter();
assert.deepStrictEqual(
collectorExporter._otlpExporter.headers['user-agent'],
`OTel-OTLP-Exporter-JavaScript/${VERSION}`
);
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPMetricExporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { OTLPMetricExporterOptions } from '@opentelemetry/exporter-metrics-otlp-
import { Stream, PassThrough } from 'stream';
import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base';
import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';
import { VERSION } from '../src/version';

let fakeRequest: PassThrough;

Expand Down Expand Up @@ -138,6 +139,13 @@ describe('OTLPMetricExporter - node with proto over http', () => {
);
envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = '';
});
it('should have user-agent header', () => {
const collectorExporter = new OTLPMetricExporter();
assert.deepStrictEqual(
collectorExporter._otlpExporter.headers['user-agent'],
`OTel-OTLP-Exporter-JavaScript/${VERSION}`
);
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPMetricExporter();
Expand Down

0 comments on commit f87d8d1

Please sign in to comment.