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

feat(trace-otlp-http-exporter): add compression env vars #2796

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export abstract class OTLPExporterNodeBase<
DEFAULT_HEADERS: Record<string, string> = {};
headers: Record<string, string>;
agent: http.Agent | https.Agent | undefined;
compression: CompressionAlgorithm;
compression: CompressionAlgorithm | string;

constructor(config: OTLPExporterNodeConfigBase = {}) {
super(config);
Expand All @@ -53,7 +53,9 @@ export abstract class OTLPExporterNodeBase<
baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS)
);
this.agent = createHttpAgent(config);
this.compression = config.compression || CompressionAlgorithm.NONE;
this.compression =
config.compression || process.env.OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||
process.env.OTEL_EXPORTER_OTLP_COMPRESSION || CompressionAlgorithm.NONE;
}

onInit(_config: OTLPExporterNodeConfigBase): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ describe('OTLPTraceExporter - node with json over http', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_HEADERS = '';
envSource.OTEL_EXPORTER_OTLP_HEADERS = '';
});
it('should use compression defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_COMPRESSION = 'gzip';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(collectorExporter.compression, 'gzip');
envSource.OTEL_EXPORTER_OTLP_COMPRESSION = '';
});
it('should override global compression config with signal compression defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_COMPRESSION = 'foo';
envSource.OTEL_EXPORTER_OTLP_TRACES_COMPRESSION = 'gzip';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(collectorExporter.compression, 'gzip');
envSource.OTEL_EXPORTER_OTLP_COMPRESSION = '';
envSource.OTEL_EXPORTER_OTLP_TRACES_COMPRESSION = '';
});
});

describe('export', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/opentelemetry-core/src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export type ENVIRONMENT = {
OTEL_TRACES_EXPORTER?: string;
OTEL_TRACES_SAMPLER_ARG?: string;
OTEL_TRACES_SAMPLER?: string;
OTEL_EXPORTER_OTLP_COMPRESSION?: string,
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION?: string,
OTEL_EXPORTER_OTLP_METRICS_COMPRESSION?: string
} & ENVIRONMENT_NUMBERS &
ENVIRONMENT_LISTS;

Expand Down Expand Up @@ -135,6 +138,9 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = {
OTEL_TRACES_EXPORTER: 'none',
OTEL_TRACES_SAMPLER: TracesSamplerValues.ParentBasedAlwaysOn,
OTEL_TRACES_SAMPLER_ARG: '',
OTEL_EXPORTER_OTLP_COMPRESSION: '',
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: '',
OTEL_EXPORTER_OTLP_METRICS_COMPRESSION: ''
};

/**
Expand Down