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(otlp-exporter): add timeout env var #2738

Merged
merged 82 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
4e81f83
feat(otlp-exporter): add timeout env var
svetlanabrennan Jan 24, 2022
11ea770
feat(otlp-exporter): add timeout env var test
svetlanabrennan Jan 25, 2022
a9a526f
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Jan 26, 2022
4f659fb
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Jan 26, 2022
2bc61e4
feat(otlp-exporter): add trace_timeout env var
svetlanabrennan Jan 26, 2022
48a25d7
Merge branch 'add-exporter-timeout' of github.com:svetlanabrennan/ope…
svetlanabrennan Jan 26, 2022
da3211f
feat(otlp-exporter): add how timeout is selected
svetlanabrennan Jan 26, 2022
0c1011d
feat(otlp-exporter): add negative value check to env vars
svetlanabrennan Jan 27, 2022
ed4079f
feat(otlp-exporter): add negative value check to env vars
svetlanabrennan Jan 27, 2022
fc486a1
feat(otlp-exporter): add timeout config information to readme
svetlanabrennan Jan 28, 2022
7292244
feat(otlp-exporter): add const var for default timeout value
svetlanabrennan Jan 28, 2022
ca98326
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Jan 31, 2022
5e7d2f5
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Jan 31, 2022
e8dc21b
feat(otlp-exporter): refactor code based on feedback
svetlanabrennan Feb 1, 2022
6c3a42d
Merge branch 'add-exporter-timeout' of github.com:svetlanabrennan/ope…
svetlanabrennan Feb 1, 2022
111cb83
feat(otlp-exporter): move configuring timeout to utils and tests
svetlanabrennan Feb 3, 2022
bbb75cb
feat(otlp-exporter): add timeout to http and xhr request
svetlanabrennan Feb 8, 2022
8866035
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Feb 8, 2022
b8543c0
Fix typo in environment.ts
svetlanabrennan Feb 8, 2022
3873a85
feat(otlp-exporter): update timeout to general timers
svetlanabrennan Feb 14, 2022
1fe1847
feat(otlp-exporter): update node http timeout tests
svetlanabrennan Feb 15, 2022
a207d50
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Feb 15, 2022
991beeb
feat(otlp-exporter): fix dependency version for http exporter
svetlanabrennan Feb 15, 2022
4e5af76
feat(otlp-exporter): add grpc deadline test
svetlanabrennan Feb 15, 2022
b27ca5f
feat(otlp-exporter): fix typos
svetlanabrennan Feb 15, 2022
a428d9d
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Feb 17, 2022
21f596e
feat(otlp-exporter): add browser timeout test
svetlanabrennan Feb 18, 2022
3043e10
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Feb 18, 2022
d66cb4a
feat(otlp-exporter): fix lint errors
svetlanabrennan Feb 18, 2022
fd4406b
Merge branch 'add-exporter-timeout' of github.com:svetlanabrennan/ope…
svetlanabrennan Feb 18, 2022
d42991e
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Feb 23, 2022
c7fe6cc
Merge branch 'main' into add-exporter-timeout
Flarna Feb 24, 2022
10880be
feat(otlp-exporter): fix tests after main merge
svetlanabrennan Feb 25, 2022
3e8360d
feat(otlp-exporter): fix one test and lint on readme
svetlanabrennan Feb 26, 2022
481795d
feat(otlp-exporter): fix tests that call export method
svetlanabrennan Mar 1, 2022
e8db3dc
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Mar 1, 2022
4f9a556
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Mar 2, 2022
d9a665f
feat(otlp-exporter): update various items based on feedback
svetlanabrennan Mar 2, 2022
4222cc6
feat(otlp-exporter): add additional tests
svetlanabrennan Mar 2, 2022
0d9de49
feat(otlp-exporter): add two more tests
svetlanabrennan Mar 2, 2022
80c1b0a
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Mar 10, 2022
eff3298
feat(otlp-exporter): add 1 more test
svetlanabrennan Mar 11, 2022
84aa2ec
Merge branch 'add-exporter-timeout' of github.com:svetlanabrennan/ope…
svetlanabrennan Mar 11, 2022
70ca58d
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Mar 15, 2022
b00c3e6
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Mar 16, 2022
83092e6
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Mar 17, 2022
44eeb56
feat(otlp-exporter): add logic around request aborted after response …
svetlanabrennan Mar 24, 2022
cfeb182
feat(otlp-exporter): update grpc deadline calculation
svetlanabrennan Mar 24, 2022
8b6a005
feat(otlp-exporter): add real http request test to proto exporter
svetlanabrennan Mar 24, 2022
d955eac
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Mar 24, 2022
5547628
feat(otlp-exporter): fix timeout test
svetlanabrennan Mar 24, 2022
bc6bb16
feat(otlp-exporter): fix grpc readme
svetlanabrennan Mar 24, 2022
f5309fd
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Mar 28, 2022
8c0eda7
Update packages/exporter-trace-otlp-http/src/platform/node/util.ts
svetlanabrennan Mar 28, 2022
5f24eb9
Merge branch 'add-exporter-timeout' of github.com:svetlanabrennan/ope…
svetlanabrennan Mar 28, 2022
7f103cb
feat(otlp-exporter): remove comment from sendWithHttp
svetlanabrennan Mar 31, 2022
1a3b0bf
Merge branch 'main' into add-exporter-timeout
rauno56 Apr 13, 2022
a9f6a9a
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Apr 19, 2022
f0055a0
feat(otlp-exporter): fix metric tests and add changelong
svetlanabrennan Apr 19, 2022
c79c521
feat(otlp-exporter): fix lint
svetlanabrennan Apr 19, 2022
d887480
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Apr 20, 2022
d18c587
feat(otlp-exporter): fix metric tests
svetlanabrennan Apr 20, 2022
d1ccc95
Merge branch 'add-exporter-timeout' of github.com:svetlanabrennan/ope…
svetlanabrennan Apr 20, 2022
b97a418
feat(otlp-exporter): fix proto tests
svetlanabrennan Apr 20, 2022
0b8f7da
feat(otlp-exporter): fix lint
svetlanabrennan Apr 20, 2022
f053d09
feat(otlp-exporter): Merge branch 'main' into add-exporter-timeout
svetlanabrennan Apr 21, 2022
78d4e93
feat(otlp-exporter): fix tests after main merge
svetlanabrennan Apr 22, 2022
f32b965
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Apr 25, 2022
0b4c617
Merge branch 'main' into add-exporter-timeout
Flarna Apr 26, 2022
e81f9dd
feat(otlp-exporter): fix lint
svetlanabrennan Apr 26, 2022
ae49cd3
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Apr 27, 2022
828993e
Merge branch 'main' into add-exporter-timeout
vmarchaud Apr 30, 2022
dc647fd
Merge branch 'main' into add-exporter-timeout
svetlanabrennan May 5, 2022
fbaa457
feat(otlp-exporter): fix accidentally removed code after main merge
svetlanabrennan May 5, 2022
14ba7d3
feat(otlp-exporter): replace nextTick with queueMicroTask for browser…
svetlanabrennan May 9, 2022
1ebc461
feat(otlp-exporter): add more details to changelog item
svetlanabrennan May 9, 2022
27b2b86
Merge branch 'main' into add-exporter-timeout
svetlanabrennan May 9, 2022
b186cbf
Merge branch 'main' into add-exporter-timeout
svetlanabrennan May 10, 2022
511999a
feat(otlp-exporter): fix server timing issue in real http request tes…
svetlanabrennan May 10, 2022
b553759
feat(otlp-exporter): fix real http request tests
svetlanabrennan May 10, 2022
5da6ce2
feat(otlp-exporter): add comment to two ways of destroying request
svetlanabrennan May 11, 2022
6ee89b0
Merge branch 'main' into add-exporter-timeout
dyladan May 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ All notable changes to experimental packages in this project will be documented
* feat(proto): add @opentelemetry/otlp-transformer package with hand-rolled transformation #2746 @dyladan
* feat(sdk-metrics-base): shutdown and forceflush on MeterProvider #2890 @legendecas
* feat(sdk-metrics-base): return the same meter for identical input to getMeter #2901 @legendecas
* feat(otlp-exporter): add timeout env var #2738 @svetlanabrennan
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved

### :bug: (Bug Fix)

Expand Down
41 changes: 31 additions & 10 deletions experimental/packages/exporter-trace-otlp-grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ provider.register();

Note, that this will only work if TLS is also configured on the server.

## Exporter Timeout Configuration

The OTLPTraceExporter has a timeout configuration option which is the maximum time, in milliseconds, the OTLP exporter will wait for each batch export. The default value is 10000ms.

+ To override the default timeout duration, provide `timeoutMillis` to OTLPTraceExporter with `collectorOptions`:

```js
const collectorOptions = {
timeoutMillis: 15000,
// url is optional and can be omitted - default is localhost:4317
url: '<collector-hostname>:<port>',
metadata, // // an optional grpc.Metadata object to be sent with each request
};

const exporter = new OTLPTraceExporter(collectorOptions);
```

> Providing `timeoutMillis` with `collectorOptions` takes precedence and overrides timeout set with environment variables.

## Exporter Compression Configuration

By default no compression will be used. To use compression, set it programmatically in `collectorOptions` or with environment variables. Supported compression options: `gzip` and `none`.

```js
Expand All @@ -125,13 +146,13 @@ const exporter = new OTLPTraceExporter(collectorOptions);

## Environment Variable Configuration

Set compression with environment variables.

```shell
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION=gzip
```

> Compression set programatically in `collectorOptions` takes precedence over compression set with environment variables. `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` takes precedence and overrides `OTEL_EXPORTER_OTLP_COMPRESSION`.
| Environment variable | Description |
|----------------------|-------------|
| OTEL_EXPORTER_OTLP_TRACES_TIMEOUT | The maximum waiting time, in milliseconds, allowed to send each OTLP trace batch. Default is 10000. |
| OTEL_EXPORTER_OTLP_TIMEOUT | The maximum waiting time, in milliseconds, allowed to send each OTLP trace and metric batch. Default is 10000. |
| OTEL_EXPORTER_OTLP_TRACES_COMPRESSION | The compression type to use on OTLP trace requests. Options include gzip. By default no compression will be used. |
| OTEL_EXPORTER_OTLP_COMPRESSION | The compression type to use on OTLP trace, metric, and log requests. Options include gzip. By default no compression will be used. |
> The per-signal environment variables (`OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`) takes precedence and non-per-signal environment variable (`OTEL_EXPORTER_OTLP_TIMEOUT`).

## Running opentelemetry-collector locally to see the traces

Expand All @@ -141,9 +162,9 @@ OTEL_EXPORTER_OTLP_TRACES_COMPRESSION=gzip

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
+ For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
+ For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
+ For help or feedback on this project, join us in [GitHub Discussions][discussions-url]

## License

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
ensureResourceIsCorrect,
mockedReadableSpan,
} from './traceHelper';
import * as core from '@opentelemetry/core';
import { CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base';
import { GrpcCompressionAlgorithm } from '@opentelemetry/otlp-grpc-exporter-base';

Expand Down Expand Up @@ -197,7 +198,34 @@ const testCollectorExporter = (params: TestParams) =>
ensureMetadataIsCorrect(reqMetadata, params.metadata);
}
done();
}, 200);
}, 500);
});
it('should log deadline exceeded error', done => {
const credentials = params.useTLS
? grpc.credentials.createSsl(
fs.readFileSync('./test/certs/ca.crt'),
fs.readFileSync('./test/certs/client.key'),
fs.readFileSync('./test/certs/client.crt')
)
: undefined;

const collectorExporterWithTimeout = new OTLPTraceExporter({
url: 'grpcs://' + address,
credentials,
metadata: params.metadata,
timeoutMillis: 100,
});

const responseSpy = sinon.spy();
const spans = [Object.assign({}, mockedReadableSpan)];
collectorExporterWithTimeout.export(spans, responseSpy);

setTimeout(() => {
const result = responseSpy.args[0][0] as core.ExportResult;
assert.strictEqual(result.code, core.ExportResultCode.FAILED);
assert.strictEqual(responseSpy.args[0][0].error.details, 'Deadline exceeded');
done();
}, 300);
});
});
describe('export - with gzip compression', () => {
Expand Down
38 changes: 35 additions & 3 deletions experimental/packages/exporter-trace-otlp-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,38 @@ OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=https://metric-service:4317/v1/metrics

For more details, see [OpenTelemetry Specification on Protocol Exporter][opentelemetry-spec-protocol-exporter].

## Exporter Timeout Configuration

The OTLPTraceExporter has a timeout configuration option which is the maximum time, in milliseconds, the OTLP exporter will wait for each batch export. The default value is 10000ms.

To override the default timeout duration, use the following options:

+ Set with environment variables:

| Environment variable | Description |
|----------------------|-------------|
| OTEL_EXPORTER_OTLP_TRACES_TIMEOUT | The maximum waiting time, in milliseconds, allowed to send each OTLP trace batch. Default is 10000. |
| OTEL_EXPORTER_OTLP_TIMEOUT | The maximum waiting time, in milliseconds, allowed to send each OTLP trace and metric batch. Default is 10000. |

> `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` takes precedence and overrides `OTEL_EXPORTER_OTLP_TIMEOUT`.

+ Provide `timeoutMillis` to OTLPTraceExporter with `collectorOptions`:

```js
const collectorOptions = {
timeoutMillis: 15000,
url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:4318/v1/traces
headers: {
foo: 'bar'
}, // an optional object containing custom headers to be sent with each request will only work with http
concurrencyLimit: 10, // an optional limit on pending requests
};

const exporter = new OTLPTraceExporter(collectorOptions);
```

> Providing `timeoutMillis` with `collectorOptions` takes precedence and overrides timeout set with environment variables.

## Running opentelemetry-collector locally to see the traces

1. Go to examples/otlp-exporter-node
Expand All @@ -114,9 +146,9 @@ For more details, see [OpenTelemetry Specification on Protocol Exporter][opentel

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
+ For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
+ For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
+ For help or feedback on this project, join us in [GitHub Discussions][discussions-url]

## License

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
* limitations under the License.
*/

import * as core from '@opentelemetry/core';
import { diag, DiagLogger, DiagLogLevel } from '@opentelemetry/api';
import { ExportResultCode } from '@opentelemetry/core';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import * as assert from 'assert';
import * as sinon from 'sinon';
import { OTLPTraceExporter } from '../../src/platform/browser/index';
import * as otlpTypes from '../../src/types';
import { OTLPExporterError } from '@opentelemetry/otlp-exporter-base';
import { nextTick } from 'process';
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved

import {
ensureSpanIsCorrect,
Expand Down Expand Up @@ -177,7 +180,12 @@ describe('OTLPTraceExporter - web', () => {

describe('when "sendBeacon" is NOT available', () => {
let server: any;
let clock: sinon.SinonFakeTimers;
beforeEach(() => {
// fakeTimers is used to replace the next setTimeout which is
// located in sendWithXhr function called by the export method
clock = sinon.useFakeTimers();

(window.navigator as any).sendBeacon = false;
collectorTraceExporter = new OTLPTraceExporter(
collectorExporterConfig
Expand All @@ -192,7 +200,7 @@ describe('OTLPTraceExporter - web', () => {
collectorTraceExporter.export(spans, () => {
});

setTimeout(() => {
nextTick(() => {
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved
const request = server.requests[0];
assert.strictEqual(request.method, 'POST');
assert.strictEqual(request.url, 'http://foo.bar.com');
Expand All @@ -216,9 +224,9 @@ describe('OTLPTraceExporter - web', () => {
}

assert.strictEqual(stubBeacon.callCount, 0);

ensureExportTraceServiceRequestIsSet(json);

clock.restore();
done();
});
});
Expand All @@ -241,15 +249,15 @@ describe('OTLPTraceExporter - web', () => {
collectorTraceExporter.export(spans, () => {
});

setTimeout(() => {
nextTick(() => {
const request = server.requests[0];
request.respond(200);

const response: any = spyLoggerDebug.args[2][0];
assert.strictEqual(response, 'xhr success');
assert.strictEqual(spyLoggerError.args.length, 0);

assert.strictEqual(stubBeacon.callCount, 0);

clock.restore();
done();
});
});
Expand All @@ -261,21 +269,24 @@ describe('OTLPTraceExporter - web', () => {
done();
});

setTimeout(() => {
nextTick(() => {
const request = server.requests[0];
request.respond(400);
clock.restore();
done();
});
});

it('should send custom headers', done => {
collectorTraceExporter.export(spans, () => {
});

setTimeout(() => {
nextTick(() => {
const request = server.requests[0];
request.respond(200);

assert.strictEqual(stubBeacon.callCount, 0);
clock.restore();
done();
});
});
Expand Down Expand Up @@ -378,7 +389,12 @@ describe('OTLPTraceExporter - web', () => {
});

describe('when "sendBeacon" is available', () => {
let clock: sinon.SinonFakeTimers;
beforeEach(() => {
// fakeTimers is used to replace the next setTimeout which is
// located in sendWithXhr function called by the export method
clock = sinon.useFakeTimers();

collectorTraceExporter = new OTLPTraceExporter(
collectorExporterConfig
);
Expand All @@ -387,20 +403,26 @@ describe('OTLPTraceExporter - web', () => {
collectorTraceExporter.export(spans, () => {
});

setTimeout(() => {
nextTick(() => {
const [{ requestHeaders }] = server.requests;

ensureHeadersContain(requestHeaders, customHeaders);
assert.strictEqual(stubBeacon.callCount, 0);
assert.strictEqual(stubOpen.callCount, 0);

clock.restore();
done();
});
});
});

describe('when "sendBeacon" is NOT available', () => {
let clock: sinon.SinonFakeTimers;
beforeEach(() => {
// fakeTimers is used to replace the next setTimeout which is
// located in sendWithXhr function called by the export method
clock = sinon.useFakeTimers();

(window.navigator as any).sendBeacon = false;
collectorTraceExporter = new OTLPTraceExporter(
collectorExporterConfig
Expand All @@ -411,13 +433,30 @@ describe('OTLPTraceExporter - web', () => {
collectorTraceExporter.export(spans, () => {
});

setTimeout(() => {
nextTick(() => {
const [{ requestHeaders }] = server.requests;

ensureHeadersContain(requestHeaders, customHeaders);
assert.strictEqual(stubBeacon.callCount, 0);
assert.strictEqual(stubOpen.callCount, 0);

clock.restore();
done();
});
});
it('should log the timeout request error message', done => {
const responseSpy = sinon.spy();
collectorTraceExporter.export(spans, responseSpy);
clock.tick(10000);

nextTick(() => {
const result = responseSpy.args[0][0] as core.ExportResult;
assert.strictEqual(result.code, core.ExportResultCode.FAILED);
const error = result.error as OTLPExporterError;
assert.ok(error !== undefined);
assert.strictEqual(error.message, 'Request Timeout');

clock.restore();
done();
});
});
Expand Down
Loading