Skip to content

Commit

Permalink
Merge branch 'main' into doc-breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored Mar 2, 2022
2 parents bdf26e7 + df0cee9 commit 6d6cc8d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 5 deletions.
2 changes: 1 addition & 1 deletion karma.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
target: 'web',
output: { filename: 'bundle.js' },
resolve: { extensions: ['.ts', '.js'] },
devtool: 'inline-source-map',
devtool: 'eval-source-map',
module: {
rules: [
{ test: /\.ts$/, use: 'ts-loader' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { OTLPExporterBase } from '../../OTLPExporterBase';
import { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
import * as otlpTypes from '../../types';
import { parseHeaders } from '../../util';
import { createHttpAgent, sendWithHttp } from './util';
import { createHttpAgent, sendWithHttp, configureCompression } from './util';
import { diag } from '@opentelemetry/api';
import { getEnv, baggageUtils } from '@opentelemetry/core';

Expand Down Expand Up @@ -53,7 +53,7 @@ export abstract class OTLPExporterNodeBase<
baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS)
);
this.agent = createHttpAgent(config);
this.compression = config.compression || CompressionAlgorithm.NONE;
this.compression = configureCompression(config.compression);
}

onInit(_config: OTLPExporterNodeConfigBase): void {}
Expand Down
10 changes: 10 additions & 0 deletions packages/exporter-trace-otlp-http/src/platform/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
import { OTLPExporterNodeConfigBase } from '.';
import { diag } from '@opentelemetry/api';
import { CompressionAlgorithm } from './types';
import { getEnv } from '@opentelemetry/core';

let gzip: zlib.Gzip | undefined;

Expand Down Expand Up @@ -131,3 +132,12 @@ export function createHttpAgent(
return undefined;
}
}

export function configureCompression(compression: CompressionAlgorithm | undefined): CompressionAlgorithm {
if (compression) {
return compression;
} else {
const definedCompression = getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION || getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;
return definedCompression === CompressionAlgorithm.GZIP ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE;
}
}
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
40 changes: 40 additions & 0 deletions packages/exporter-trace-otlp-http/test/node/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as assert from 'assert';
import { CompressionAlgorithm} from '../../src/platform/node/types';
import { configureCompression} from '../../src/platform/node/util';

describe('configureCompression', () => {
const envSource = process.env;
it('should return none for compression', () => {
const compression = CompressionAlgorithm.NONE;
assert.strictEqual(configureCompression(compression), CompressionAlgorithm.NONE);
});
it('should return gzip compression defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_COMPRESSION = 'gzip';
assert.strictEqual(configureCompression(undefined),CompressionAlgorithm.GZIP);
delete envSource.OTEL_EXPORTER_OTLP_TRACES_COMPRESSION;
});
it('should return none for compression defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_COMPRESSION = 'none';
assert.strictEqual(configureCompression(undefined),CompressionAlgorithm.NONE);
delete envSource.OTEL_EXPORTER_OTLP_TRACES_COMPRESSION;
});
it('should return none for compression when no compression is set', () => {
assert.strictEqual(configureCompression(undefined),CompressionAlgorithm.NONE);
});
});
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
14 changes: 12 additions & 2 deletions packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,32 @@ import {
SpanContext,
SpanKind,
TraceFlags,
HrTime,
} from '@opentelemetry/api';
import {
DEFAULT_ATTRIBUTE_COUNT_LIMIT,
DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT,
hrTime,
hrTimeDuration,
hrTimeToMilliseconds,
hrTimeToNanoseconds,
otperformance as performance,
} from '@opentelemetry/core';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import * as assert from 'assert';
import * as sinon from 'sinon';
import { BasicTracerProvider, Span, SpanProcessor } from '../../src';

const performanceTimeOrigin = hrTime();
const performanceTimeOrigin: HrTime = [1, 1];

describe('Span', () => {
beforeEach(() => {
sinon.stub(performance, 'timeOrigin')
.value(hrTimeToMilliseconds(performanceTimeOrigin));
});
afterEach(() => {
sinon.restore();
});

const tracer = new BasicTracerProvider({
spanLimits: {
attributeValueLengthLimit: 100,
Expand Down

0 comments on commit 6d6cc8d

Please sign in to comment.