Skip to content

Commit 69cced2

Browse files
svetlanabrennandyladanlegendecas
authored
fix(otlp-http-exporter): update endpoint to match spec (#2895)
Co-authored-by: Daniel Dyla <[email protected]> Co-authored-by: Chengzhong Wu <[email protected]>
1 parent a9c59da commit 69cced2

File tree

15 files changed

+428
-69
lines changed

15 files changed

+428
-69
lines changed

experimental/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All notable changes to experimental packages in this project will be documented
2020

2121
* fix(opentelemetry-instrumentation-http): use correct origin when port is `null` #2948 @danielgblanco
2222
* fix(otlp-exporter-base): include esm and esnext in package files #2952 @dyladan
23+
* fix(otlp-http-exporter): update endpoint to match spec #2895 @svetlanabrennan
2324

2425
### :books: (Refine Doc)
2526

experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { appendResourcePathToUrlIfNotPresent, OTLPExporterBrowserBase } from '@opentelemetry/otlp-exporter-base';
1817
import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
1918
import { getEnv, baggageUtils } from '@opentelemetry/core';
20-
import { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';
19+
import {
20+
OTLPExporterConfigBase,
21+
appendResourcePathToUrl,
22+
appendRootPathToUrlIfNeeded,
23+
OTLPExporterBrowserBase
24+
} from '@opentelemetry/otlp-exporter-base';
2125
import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';
2226

23-
const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
24-
const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
27+
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';
28+
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
2529

2630
/**
2731
* Collector Trace Exporter for Web
@@ -49,9 +53,9 @@ export class OTLPTraceExporter
4953
return typeof config.url === 'string'
5054
? config.url
5155
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
52-
? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
56+
? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
5357
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
54-
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
58+
? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
5559
: DEFAULT_COLLECTOR_URL;
5660
}
5761
}

experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ import { getEnv, baggageUtils } from '@opentelemetry/core';
1919
import { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base';
2020
import {
2121
OTLPExporterNodeConfigBase,
22-
appendResourcePathToUrlIfNotPresent
22+
appendResourcePathToUrl,
23+
appendRootPathToUrlIfNeeded
2324
} from '@opentelemetry/otlp-exporter-base';
2425
import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';
2526

26-
const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
27-
const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
27+
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';
28+
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
2829

2930
/**
3031
* Collector Trace Exporter for Node
@@ -51,9 +52,9 @@ export class OTLPTraceExporter
5152
return typeof config.url === 'string'
5253
? config.url
5354
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
54-
? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
55+
? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
5556
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
56-
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
57+
? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
5758
: DEFAULT_COLLECTOR_URL;
5859
}
5960
}

experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,16 +508,25 @@ describe('OTLPTraceExporter - browser (getDefaultUrl)', () => {
508508

509509
describe('when configuring via environment', () => {
510510
const envSource = window as any;
511-
it('should use url defined in env', () => {
511+
it('should use url defined in env that ends with root path and append version and signal path', () => {
512+
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
513+
const collectorExporter = new OTLPTraceExporter();
514+
assert.strictEqual(
515+
collectorExporter.url,
516+
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/traces`
517+
);
518+
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
519+
});
520+
it('should use url defined in env without checking if path is already present', () => {
512521
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/traces';
513522
const collectorExporter = new OTLPTraceExporter();
514523
assert.strictEqual(
515524
collectorExporter.url,
516-
envSource.OTEL_EXPORTER_OTLP_ENDPOINT
525+
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`
517526
);
518527
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
519528
});
520-
it('should use url defined in env and append version and signal when not present', () => {
529+
it('should use url defined in env and append version and signal', () => {
521530
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
522531
const collectorExporter = new OTLPTraceExporter();
523532
assert.strictEqual(
@@ -527,8 +536,8 @@ describe('when configuring via environment', () => {
527536
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
528537
});
529538
it('should override global exporter url with signal url defined in env', () => {
530-
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
531-
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces';
539+
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
540+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces/';
532541
const collectorExporter = new OTLPTraceExporter();
533542
assert.strictEqual(
534543
collectorExporter.url,
@@ -537,6 +546,42 @@ describe('when configuring via environment', () => {
537546
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
538547
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
539548
});
549+
it('should add root path when signal url defined in env contains no path and no root path', () => {
550+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar';
551+
const collectorExporter = new OTLPTraceExporter();
552+
assert.strictEqual(
553+
collectorExporter.url,
554+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}/`
555+
);
556+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
557+
});
558+
it('should not add root path when signal url defined in env contains root path but no path', () => {
559+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/';
560+
const collectorExporter = new OTLPTraceExporter();
561+
assert.strictEqual(
562+
collectorExporter.url,
563+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
564+
);
565+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
566+
});
567+
it('should not add root path when signal url defined in env contains path', () => {
568+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces';
569+
const collectorExporter = new OTLPTraceExporter();
570+
assert.strictEqual(
571+
collectorExporter.url,
572+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
573+
);
574+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
575+
});
576+
it('should not add root path when signal url defined in env contains path and ends in /', () => {
577+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces/';
578+
const collectorExporter = new OTLPTraceExporter();
579+
assert.strictEqual(
580+
collectorExporter.url,
581+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
582+
);
583+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
584+
});
540585
it('should use headers defined via env', () => {
541586
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
542587
const collectorExporter = new OTLPTraceExporter({ headers: {} });

experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,25 @@ describe('OTLPTraceExporter - node with json over http', () => {
8282

8383
describe('when configuring via environment', () => {
8484
const envSource = process.env;
85-
it('should use url defined in env', () => {
85+
it('should use url defined in env that ends with root path and append version and signal path', () => {
86+
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
87+
const collectorExporter = new OTLPTraceExporter();
88+
assert.strictEqual(
89+
collectorExporter.url,
90+
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/traces`
91+
);
92+
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
93+
});
94+
it('should use url defined in env without checking if path is already present', () => {
8695
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/traces';
8796
const collectorExporter = new OTLPTraceExporter();
8897
assert.strictEqual(
8998
collectorExporter.url,
90-
envSource.OTEL_EXPORTER_OTLP_ENDPOINT
99+
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`
91100
);
92101
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
93102
});
94-
it('should use url defined in env and append version and signal when not present', () => {
103+
it('should use url defined in env and append version and signal', () => {
95104
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
96105
const collectorExporter = new OTLPTraceExporter();
97106
assert.strictEqual(
@@ -101,8 +110,8 @@ describe('OTLPTraceExporter - node with json over http', () => {
101110
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
102111
});
103112
it('should override global exporter url with signal url defined in env', () => {
104-
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
105-
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces';
113+
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
114+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces/';
106115
const collectorExporter = new OTLPTraceExporter();
107116
assert.strictEqual(
108117
collectorExporter.url,
@@ -111,6 +120,42 @@ describe('OTLPTraceExporter - node with json over http', () => {
111120
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
112121
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
113122
});
123+
it('should add root path when signal url defined in env contains no path and no root path', () => {
124+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar';
125+
const collectorExporter = new OTLPTraceExporter();
126+
assert.strictEqual(
127+
collectorExporter.url,
128+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}/`
129+
);
130+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
131+
});
132+
it('should not add root path when signal url defined in env contains root path but no path', () => {
133+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/';
134+
const collectorExporter = new OTLPTraceExporter();
135+
assert.strictEqual(
136+
collectorExporter.url,
137+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
138+
);
139+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
140+
});
141+
it('should not add root path when signal url defined in env contains path', () => {
142+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces';
143+
const collectorExporter = new OTLPTraceExporter();
144+
assert.strictEqual(
145+
collectorExporter.url,
146+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
147+
);
148+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
149+
});
150+
it('should not add root path when signal url defined in env contains path and ends in /', () => {
151+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces/';
152+
const collectorExporter = new OTLPTraceExporter();
153+
assert.strictEqual(
154+
collectorExporter.url,
155+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
156+
);
157+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
158+
});
114159
it('should use headers defined via env', () => {
115160
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
116161
const collectorExporter = new OTLPTraceExporter();

experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
1818
import { getEnv, baggageUtils } from '@opentelemetry/core';
19-
import { appendResourcePathToUrlIfNotPresent, OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base';
19+
import {
20+
OTLPExporterNodeConfigBase,
21+
appendResourcePathToUrl,
22+
appendRootPathToUrlIfNeeded
23+
} from '@opentelemetry/otlp-exporter-base';
2024
import { OTLPProtoExporterNodeBase, ServiceClientType } from '@opentelemetry/otlp-proto-exporter-base';
2125
import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';
2226

23-
const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
24-
const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
27+
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces';
28+
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
2529

2630
/**
2731
* Collector Trace Exporter for Node with protobuf
@@ -50,9 +54,9 @@ export class OTLPTraceExporter
5054
return typeof config.url === 'string'
5155
? config.url
5256
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
53-
? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
57+
? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
5458
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
55-
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
59+
? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
5660
: DEFAULT_COLLECTOR_URL;
5761
}
5862

experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,25 @@ describe('OTLPTraceExporter - node with proto over http', () => {
4747

4848
describe('when configuring via environment', () => {
4949
const envSource = process.env;
50-
it('should use url defined in env', () => {
50+
it('should use url defined in env that ends with root path and append version and signal path', () => {
51+
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
52+
const collectorExporter = new OTLPTraceExporter();
53+
assert.strictEqual(
54+
collectorExporter.url,
55+
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/traces`
56+
);
57+
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
58+
});
59+
it('should use url defined in env without checking if path is already present', () => {
5160
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/traces';
5261
const collectorExporter = new OTLPTraceExporter();
5362
assert.strictEqual(
5463
collectorExporter.url,
55-
envSource.OTEL_EXPORTER_OTLP_ENDPOINT
64+
`${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`
5665
);
5766
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
5867
});
59-
it('should use url defined in env and append version and signal when not present', () => {
68+
it('should use url defined in env and append version and signal', () => {
6069
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
6170
const collectorExporter = new OTLPTraceExporter();
6271
assert.strictEqual(
@@ -66,8 +75,8 @@ describe('OTLPTraceExporter - node with proto over http', () => {
6675
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
6776
});
6877
it('should override global exporter url with signal url defined in env', () => {
69-
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar';
70-
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces';
78+
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/';
79+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.traces/';
7180
const collectorExporter = new OTLPTraceExporter();
7281
assert.strictEqual(
7382
collectorExporter.url,
@@ -76,6 +85,42 @@ describe('OTLPTraceExporter - node with proto over http', () => {
7685
envSource.OTEL_EXPORTER_OTLP_ENDPOINT = '';
7786
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
7887
});
88+
it('should add root path when signal url defined in env contains no path and no root path', () => {
89+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar';
90+
const collectorExporter = new OTLPTraceExporter();
91+
assert.strictEqual(
92+
collectorExporter.url,
93+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}/`
94+
);
95+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
96+
});
97+
it('should not add root path when signal url defined in env contains root path but no path', () => {
98+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/';
99+
const collectorExporter = new OTLPTraceExporter();
100+
assert.strictEqual(
101+
collectorExporter.url,
102+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
103+
);
104+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
105+
});
106+
it('should not add root path when signal url defined in env contains path', () => {
107+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces';
108+
const collectorExporter = new OTLPTraceExporter();
109+
assert.strictEqual(
110+
collectorExporter.url,
111+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
112+
);
113+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
114+
});
115+
it('should not add root path when signal url defined in env contains path and ends in /', () => {
116+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces/';
117+
const collectorExporter = new OTLPTraceExporter();
118+
assert.strictEqual(
119+
collectorExporter.url,
120+
`${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}`
121+
);
122+
envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '';
123+
});
79124
it('should use headers defined via env', () => {
80125
envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar';
81126
const collectorExporter = new OTLPTraceExporter();

experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ import { baggageUtils, getEnv } from '@opentelemetry/core';
1919
import { defaultOptions, OTLPMetricExporterOptions } from '../../OTLPMetricExporterOptions';
2020
import { OTLPMetricExporterBase } from '../../OTLPMetricExporterBase';
2121
import {
22-
appendResourcePathToUrlIfNotPresent,
2322
OTLPExporterBrowserBase,
24-
OTLPExporterConfigBase
23+
OTLPExporterConfigBase,
24+
appendResourcePathToUrl,
25+
appendRootPathToUrlIfNeeded
2526
} from '@opentelemetry/otlp-exporter-base';
2627
import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';
2728

28-
const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics';
29-
const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
29+
const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics';
30+
const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
3031

3132
class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase<ResourceMetrics, IExportMetricsServiceRequest> {
3233

@@ -44,9 +45,9 @@ class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase<ResourceMetrics,
4445
return typeof config.url === 'string'
4546
? config.url
4647
: getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0
47-
? getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
48+
? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
4849
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
49-
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
50+
? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
5051
: DEFAULT_COLLECTOR_URL;
5152
}
5253

0 commit comments

Comments
 (0)