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(otlp-http-exporter): update endpoint to match spec #2895

Merged
merged 30 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4908ca5
fix(otlp-http-exporter): append path to no signal endpoint
svetlanabrennan Apr 7, 2022
d1f7997
fix(otlp-http-exporter): add check for root path and update tests
svetlanabrennan Apr 7, 2022
003946d
fix(otlp-http-exporter): add check for root path logic and tests
svetlanabrennan Apr 7, 2022
cf8e9ed
Merge branch 'main' into fix-general-endpoint
svetlanabrennan Apr 8, 2022
d1ff795
fix(otlp-http-exporter): fix url on metrics tests
svetlanabrennan Apr 8, 2022
15b156b
Merge branch 'main' into fix-general-endpoint
svetlanabrennan Apr 11, 2022
73daa78
Merge branch 'main' into add-exporter-timeout
svetlanabrennan Apr 25, 2022
03e498c
fix(otlp-http-exporter): fix tests
svetlanabrennan Apr 25, 2022
29940e3
fix(otlp-http-exporter): add changelog
svetlanabrennan Apr 25, 2022
ac5b48a
Merge branch 'main' into fix-general-endpoint
svetlanabrennan Apr 26, 2022
8964212
fix(otlp-http-exporter): fix lint
svetlanabrennan Apr 26, 2022
fdeb2d1
fix(otlp-http-exporter): fix lint
svetlanabrennan Apr 26, 2022
79159c0
Merge branch 'main' into fix-general-endpoint
svetlanabrennan Apr 27, 2022
dec66c7
fix(otlp-http-exporter): wip update when root path is added to match …
svetlanabrennan Apr 27, 2022
be3367d
fix(otlp-http-exporter): add more tests for adding rooth path for sig…
svetlanabrennan Apr 28, 2022
d37eeaf
fix(otlp-http-exporter): fix typos
svetlanabrennan Apr 28, 2022
d3d090a
fix(otlp-http-exporter): fix typos
svetlanabrennan Apr 28, 2022
c9f75cf
Merge branch 'main' into fix-general-endpoint
svetlanabrennan May 2, 2022
c06a5dd
fix(otlp-http-exporter): add unit tests for adding resource and root …
svetlanabrennan May 2, 2022
6547e40
fix(otlp-http-exporter): fix typos
svetlanabrennan May 2, 2022
b221fdc
Merge branch 'main' into fix-general-endpoint
svetlanabrennan May 5, 2022
3b6d9fe
Merge branch 'main' into fix-general-endpoint
svetlanabrennan May 9, 2022
c76895d
Merge branch 'main' into fix-general-endpoint
svetlanabrennan May 10, 2022
67566d5
Merge branch 'main' into fix-general-endpoint
dyladan May 11, 2022
ecb4dfe
Merge branch 'main' into fix-general-endpoint
svetlanabrennan May 11, 2022
fb67714
Merge branch 'main' into fix-general-endpoint
svetlanabrennan May 12, 2022
6b72177
Merge branch 'main' into fix-general-endpoint
dyladan May 12, 2022
3acb9cf
fix(otlp-http-exporter): move changelog to unreleased section
svetlanabrennan May 16, 2022
8173b05
Merge branch 'main' into fix-general-endpoint
svetlanabrennan May 16, 2022
294e544
Merge branch 'main' into fix-general-endpoint
legendecas May 17, 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 @@ -69,6 +69,7 @@ All notable changes to experimental packages in this project will be documented
* fix(sdk-metrics-base): remove aggregator.toMetricData dependency on AggregationTemporality #2676 @legendecas
* fix(sdk-metrics-base): coerce histogram boundaries to be implicit Infinity #2859 @legendecas
* fix(instrumentation-http): HTTP 400 status code should not set span status to error on servers #2789 @nordfjord
* fix(otlp-http-exporter): update endpoint to match spec #2895 @svetlanabrennan
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved

### :books: (Refine Doc)

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

import { appendResourcePathToUrlIfNotPresent, OTLPExporterBrowserBase } from '@opentelemetry/otlp-exporter-base';
import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
import { getEnv, baggageUtils } from '@opentelemetry/core';
import { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';
import {
OTLPExporterConfigBase,
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded,
OTLPExporterBrowserBase
} from '@opentelemetry/otlp-exporter-base';
import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';

const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;

/**
* Collector Trace Exporter for Web
Expand Down Expand Up @@ -49,9 +53,9 @@ export class OTLPTraceExporter
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: DEFAULT_COLLECTOR_URL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import { getEnv, baggageUtils } from '@opentelemetry/core';
import { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base';
import {
OTLPExporterNodeConfigBase,
appendResourcePathToUrlIfNotPresent
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded
} from '@opentelemetry/otlp-exporter-base';
import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';

const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;

/**
* Collector Trace Exporter for Node
Expand All @@ -51,9 +52,9 @@ export class OTLPTraceExporter
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: DEFAULT_COLLECTOR_URL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,25 @@ describe('OTLPTraceExporter - browser (getDefaultUrl)', () => {

describe('when configuring via environment', () => {
const envSource = window as any;
it('should use url defined in env', () => {
it('should use url defined in env that ends with root path and append version and signal path', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/traces`
);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should use url defined in env without checking if path is already present', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/traces';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
envSource.OTEL_EXPORTER_OTLP_ENDPOINT
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`
);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should use url defined in env and append version and signal when not present', () => {
it('should use url defined in env and append version and signal', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
Expand All @@ -491,8 +500,8 @@ describe('when configuring via environment', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should override global exporter url with signal url defined in env', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces';
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
Expand All @@ -501,6 +510,42 @@ describe('when configuring via environment', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should add root path when signal url defined in env contains no path and no root path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}/`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should not add root path when signal url defined in env contains root path but no path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should not add root path when signal url defined in env contains path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should not add root path when signal url defined in env contains path and ends in /', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should use headers defined via env', () => {
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
const collectorExporter = new OTLPTraceExporter({ headers: {} });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,25 @@ describe('OTLPTraceExporter - node with json over http', () => {

describe('when configuring via environment', () => {
const envSource = process.env;
it('should use url defined in env', () => {
it('should use url defined in env that ends with root path and append version and signal path', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/traces`
);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should use url defined in env without checking if path is already present', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/traces';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
envSource.OTEL_EXPORTER_OTLP_ENDPOINT
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`
);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should use url defined in env and append version and signal when not present', () => {
it('should use url defined in env and append version and signal', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
Expand All @@ -100,8 +109,8 @@ describe('OTLPTraceExporter - node with json over http', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should override global exporter url with signal url defined in env', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces';
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
Expand All @@ -110,6 +119,42 @@ describe('OTLPTraceExporter - node with json over http', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should add root path when signal url defined in env contains no path and no root path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}/`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should not add root path when signal url defined in env contains root path but no path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should not add root path when signal url defined in env contains path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should not add root path when signal url defined in env contains path and ends in /', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
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 @@ -16,12 +16,16 @@

import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
import { getEnv, baggageUtils } from '@opentelemetry/core';
import { appendResourcePathToUrlIfNotPresent, OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base';
import {
OTLPExporterNodeConfigBase,
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded
} from '@opentelemetry/otlp-exporter-base';
import { OTLPProtoExporterNodeBase, ServiceClientType } from '@opentelemetry/otlp-proto-exporter-base';
import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';

const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;

/**
* Collector Trace Exporter for Node with protobuf
Expand Down Expand Up @@ -50,9 +54,9 @@ export class OTLPTraceExporter
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: DEFAULT_COLLECTOR_URL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,25 @@ describe('OTLPTraceExporter - node with proto over http', () => {

describe('when configuring via environment', () => {
const envSource = process.env;
it('should use url defined in env', () => {
it('should use url defined in env that ends with root path and append version and signal path', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/traces`
);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should use url defined in env without checking if path is already present', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/traces';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
envSource.OTEL_EXPORTER_OTLP_ENDPOINT
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`
);
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should use url defined in env and append version and signal when not present', () => {
it('should use url defined in env and append version and signal', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
Expand All @@ -65,8 +74,8 @@ describe('OTLPTraceExporter - node with proto over http', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
});
it('should override global exporter url with signal url defined in env', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces';
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
Expand All @@ -75,6 +84,42 @@ describe('OTLPTraceExporter - node with proto over http', () => {
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should add root path when signal url defined in env contains no path and no root path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}/`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should not add root path when signal url defined in env contains root path but no path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should not add root path when signal url defined in env contains path', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
it('should not add root path when signal url defined in env contains path and ends in /', () => {
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces/';
const collectorExporter = new OTLPTraceExporter();
assert.strictEqual(
collectorExporter.url,
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
);
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
});
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 @@ -19,14 +19,15 @@ import { baggageUtils, getEnv } from '@opentelemetry/core';
import { defaultOptions, OTLPMetricExporterOptions } from '../../OTLPMetricExporterOptions';
import { OTLPMetricExporterBase } from '../../OTLPMetricExporterBase';
import {
appendResourcePathToUrlIfNotPresent,
OTLPExporterBrowserBase,
OTLPExporterConfigBase
OTLPExporterConfigBase,
appendResourcePathToUrl,
appendRootPathToUrlIfNeeded
} from '@opentelemetry/otlp-exporter-base';
import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';

const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;

class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase<ResourceMetrics, IExportMetricsServiceRequest> {

Expand All @@ -44,9 +45,9 @@ class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase<ResourceMetrics,
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0
? getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: DEFAULT_COLLECTOR_URL;
}

Expand Down
Loading