From 4908ca59eeb0f003dcc9a4c8a21d981be4f0260e Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Thu, 7 Apr 2022 11:42:19 -0500 Subject: [PATCH 01/15] fix(otlp-http-exporter): append path to no signal endpoint Signed-off-by: Svetlana Brennan --- experimental/packages/exporter-trace-otlp-http/src/index.ts | 2 +- .../src/platform/browser/OTLPTraceExporter.ts | 4 ++-- .../src/platform/node/OTLPTraceExporter.ts | 4 ++-- experimental/packages/exporter-trace-otlp-http/src/util.ts | 4 +--- .../test/browser/CollectorTraceExporter.test.ts | 6 +++--- .../test/node/CollectorTraceExporter.test.ts | 6 +++--- .../exporter-trace-otlp-proto/src/OTLPTraceExporter.ts | 4 ++-- .../test/OTLPTraceExporter.test.ts | 6 +++--- .../src/platform/browser/OTLPMetricExporter.ts | 4 ++-- .../src/platform/node/OTLPMetricExporter.ts | 4 ++-- .../test/browser/CollectorMetricExporter.test.ts | 6 +++--- .../test/node/CollectorMetricExporter.test.ts | 6 +++--- .../src/OTLPMetricExporter.ts | 4 ++-- .../test/OTLPMetricExporter.test.ts | 6 +++--- 14 files changed, 32 insertions(+), 34 deletions(-) diff --git a/experimental/packages/exporter-trace-otlp-http/src/index.ts b/experimental/packages/exporter-trace-otlp-http/src/index.ts index bd025cd4d6f..3c8959c2dd5 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/index.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/index.ts @@ -18,4 +18,4 @@ export * from './OTLPExporterBase'; export * from './platform'; export * as otlpTypes from './types'; export { toCollectorResource, toOTLPExportTraceServiceRequest } from './transform'; -export { appendResourcePathToUrlIfNotPresent } from './util'; +export { appendResourcePathToUrl } from './util'; diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index 91ee1014234..76890ec6b61 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -20,7 +20,7 @@ import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'; import { toOTLPExportTraceServiceRequest } from '../../transform'; import * as otlpTypes from '../../types'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -import { appendResourcePathToUrlIfNotPresent } from '../../util'; +import { appendResourcePathToUrl } from '../../util'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces'; const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; @@ -55,7 +55,7 @@ export class OTLPTraceExporter : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 ? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : 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; } } diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index 82bdff3aef9..045f0d67bf7 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -20,7 +20,7 @@ import { OTLPExporterNodeConfigBase } from './types'; import * as otlpTypes from '../../types'; import { toOTLPExportTraceServiceRequest } from '../../transform'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -import { appendResourcePathToUrlIfNotPresent } from '../../util'; +import { appendResourcePathToUrl } from '../../util'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces'; const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; @@ -56,7 +56,7 @@ export class OTLPTraceExporter : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 ? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : 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; } } diff --git a/experimental/packages/exporter-trace-otlp-http/src/util.ts b/experimental/packages/exporter-trace-otlp-http/src/util.ts index b018000110c..7ae3014643f 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/util.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/util.ts @@ -34,8 +34,6 @@ export function parseHeaders( return headers; } -export function appendResourcePathToUrlIfNotPresent(url: string, path: string): string { - if (url.match(/v\d\/(traces|metrics)$/)) return url; - +export function appendResourcePathToUrl(url: string, path: string): string { return url + path; } diff --git a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts index a66a7c59d08..7d3e3b882c6 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts @@ -311,16 +311,16 @@ 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 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( diff --git a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts index e01ff2980c9..536f4ba43a5 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts @@ -68,16 +68,16 @@ 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 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( diff --git a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts index 9b3c5a6effc..7a0c99acd3b 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts @@ -20,7 +20,7 @@ import { otlpTypes, toOTLPExportTraceServiceRequest, OTLPExporterNodeConfigBase, - appendResourcePathToUrlIfNotPresent, + appendResourcePathToUrl, } from '@opentelemetry/exporter-trace-otlp-http'; import { ServiceClientType } from './types'; import { getEnv, baggageUtils } from '@opentelemetry/core'; @@ -59,7 +59,7 @@ export class OTLPTraceExporter : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 ? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : 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; } diff --git a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts index 67b8c178680..9139f394eaf 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts @@ -49,16 +49,16 @@ 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 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( diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts index 3eb49d96651..ea62f7f13ef 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts @@ -15,7 +15,7 @@ */ import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base'; -import { OTLPExporterBrowserBase, otlpTypes, appendResourcePathToUrlIfNotPresent } from '@opentelemetry/exporter-trace-otlp-http'; +import { OTLPExporterBrowserBase, otlpTypes, appendResourcePathToUrl } from '@opentelemetry/exporter-trace-otlp-http'; import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; import { getEnv, baggageUtils } from '@opentelemetry/core'; @@ -60,7 +60,7 @@ export class OTLPMetricExporter : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 ? getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT : 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; } } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index ebc2cc22948..37c2c7e751f 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -19,7 +19,7 @@ import { OTLPExporterNodeBase, OTLPExporterNodeConfigBase, otlpTypes, - appendResourcePathToUrlIfNotPresent + appendResourcePathToUrl } from '@opentelemetry/exporter-trace-otlp-http'; import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; import { getEnv, baggageUtils } from '@opentelemetry/core'; @@ -65,7 +65,7 @@ export class OTLPMetricExporter : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 ? getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT : 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; } } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index 5eab43664b1..86eb75fbd5a 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -390,16 +390,16 @@ describe('OTLPMetricExporter - web', () => { describe('when configuring via environment', () => { const envSource = window as any; - it('should use url defined in env', () => { + it('should use url defined in env without checking if path is already present', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter.url, - envSource.OTEL_EXPORTER_OTLP_ENDPOINT + `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics` ); 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 OTLPMetricExporter(); assert.strictEqual( diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index 7287d933008..66a62113e86 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -99,16 +99,16 @@ describe('OTLPMetricExporter - 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 without checking if path is already present', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter.url, - envSource.OTEL_EXPORTER_OTLP_ENDPOINT + `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics` ); 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 OTLPMetricExporter(); assert.strictEqual( diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index e7916a34e79..c9cfab5a2bf 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -17,7 +17,7 @@ import { otlpTypes, OTLPExporterNodeConfigBase, - appendResourcePathToUrlIfNotPresent, + appendResourcePathToUrl, } from '@opentelemetry/exporter-trace-otlp-http'; import { toOTLPExportMetricServiceRequest } from '@opentelemetry/exporter-metrics-otlp-http'; import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base'; @@ -65,7 +65,7 @@ export class OTLPMetricExporter : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 ? getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT : 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; } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index 6c7e78507d6..69189f4ff73 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -56,16 +56,16 @@ describe('OTLPMetricExporter - 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 without checking if path is already present', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter.url, - envSource.OTEL_EXPORTER_OTLP_ENDPOINT + `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics` ); 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 OTLPMetricExporter(); assert.strictEqual( From d1f799741c085b68a20e3fe06f3bc94f0baa9655 Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Thu, 7 Apr 2022 14:50:28 -0500 Subject: [PATCH 02/15] fix(otlp-http-exporter): add check for root path and update tests Signed-off-by: Svetlana Brennan --- .../src/platform/browser/OTLPTraceExporter.ts | 4 ++-- .../src/platform/node/OTLPTraceExporter.ts | 4 ++-- .../exporter-trace-otlp-http/src/util.ts | 11 ++++++++++- .../browser/CollectorTraceExporter.test.ts | 9 +++++++++ .../test/node/CollectorTraceExporter.test.ts | 18 ++++++++++++++++++ .../src/OTLPTraceExporter.ts | 4 ++-- .../test/OTLPTraceExporter.test.ts | 9 +++++++++ .../src/platform/browser/OTLPMetricExporter.ts | 4 ++-- .../src/platform/node/OTLPMetricExporter.ts | 4 ++-- .../browser/CollectorMetricExporter.test.ts | 9 +++++++++ .../test/node/CollectorMetricExporter.test.ts | 9 +++++++++ .../src/OTLPMetricExporter.ts | 4 ++-- .../test/OTLPMetricExporter.test.ts | 9 +++++++++ 13 files changed, 85 insertions(+), 13 deletions(-) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index 76890ec6b61..bd4b9271937 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -22,8 +22,8 @@ import * as otlpTypes from '../../types'; import { getEnv, baggageUtils } from '@opentelemetry/core'; import { appendResourcePathToUrl } from '../../util'; -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 diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index 045f0d67bf7..40e4b35127b 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -22,8 +22,8 @@ import { toOTLPExportTraceServiceRequest } from '../../transform'; import { getEnv, baggageUtils } from '@opentelemetry/core'; import { appendResourcePathToUrl } from '../../util'; -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 diff --git a/experimental/packages/exporter-trace-otlp-http/src/util.ts b/experimental/packages/exporter-trace-otlp-http/src/util.ts index 7ae3014643f..a28d3e5b6a8 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/util.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/util.ts @@ -34,6 +34,15 @@ export function parseHeaders( return headers; } +/** + * Adds path (version + signal) to a no per-signal endpoint and returns updated url + * @param url + * @param path + */ export function appendResourcePathToUrl(url: string, path: string): string { - return url + path; + if (url.endsWith('/')) { + return url + path; + } else { + return `${url}/${path}`; + } } diff --git a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts index 7d3e3b882c6..d39aece5ccf 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts @@ -311,6 +311,15 @@ describe('OTLPTraceExporter - browser (getDefaultUrl)', () => { describe('when configuring via environment', () => { const envSource = window as any; + 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(); diff --git a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts index 536f4ba43a5..a51ed8b6f02 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts @@ -68,6 +68,15 @@ describe('OTLPTraceExporter - node with json over http', () => { describe('when configuring via environment', () => { const envSource = process.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(); @@ -97,6 +106,15 @@ describe('OTLPTraceExporter - node with json over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); + // it.only('should add root path when signal url defined in env contains 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 use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPTraceExporter(); diff --git a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts index 7a0c99acd3b..3025c7595cb 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts @@ -25,8 +25,8 @@ import { import { ServiceClientType } from './types'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -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 diff --git a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts index 9139f394eaf..9bbb047e318 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts @@ -49,6 +49,15 @@ describe('OTLPTraceExporter - node with proto over http', () => { describe('when configuring via environment', () => { const envSource = process.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(); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts index ea62f7f13ef..6bfd540a170 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts @@ -19,8 +19,8 @@ import { OTLPExporterBrowserBase, otlpTypes, appendResourcePathToUrl } from '@op import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -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}`; /** * Collector Metric Exporter for Web diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index 37c2c7e751f..62b0b20c01e 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -24,8 +24,8 @@ import { import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -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}`; /** * Collector Metric Exporter for Node diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index 86eb75fbd5a..9f4af76eac8 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -390,6 +390,15 @@ describe('OTLPMetricExporter - web', () => { describe('when configuring via environment', () => { const envSource = window as any; + 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 OTLPMetricExporter(); + assert.strictEqual( + collectorExporter.url, + `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/metrics` + ); + 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/metrics'; const collectorExporter = new OTLPMetricExporter(); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index 66a62113e86..f8e27c7a87f 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -99,6 +99,15 @@ describe('OTLPMetricExporter - node with json over http', () => { describe('when configuring via environment', () => { const envSource = process.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 OTLPMetricExporter(); + assert.strictEqual( + collectorExporter.url, + `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/metrics` + ); + 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/metrics'; const collectorExporter = new OTLPMetricExporter(); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index c9cfab5a2bf..2b89714e643 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -24,8 +24,8 @@ import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base'; import { ServiceClientType, OTLPExporterNodeBase } from '@opentelemetry/exporter-trace-otlp-proto'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -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}`; /** * OTLP Metric Exporter for Node with protobuf diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index 69189f4ff73..3aaf10801f1 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -56,6 +56,15 @@ describe('OTLPMetricExporter - node with proto over http', () => { describe('when configuring via environment', () => { const envSource = process.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 OTLPMetricExporter(); + assert.strictEqual( + collectorExporter.url, + `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/metrics` + ); + 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/metrics'; const collectorExporter = new OTLPMetricExporter(); From 003946df37bd55522bc018ad2f50c60da14b1ccc Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Thu, 7 Apr 2022 16:03:30 -0500 Subject: [PATCH 03/15] fix(otlp-http-exporter): add check for root path logic and tests Signed-off-by: Svetlana Brennan --- .../src/platform/browser/OTLPTraceExporter.ts | 4 ++-- .../src/platform/node/OTLPTraceExporter.ts | 4 ++-- .../exporter-trace-otlp-http/src/util.ts | 12 ++++++---- .../browser/CollectorTraceExporter.test.ts | 13 +++++++++-- .../test/node/CollectorTraceExporter.test.ts | 22 +++++++++---------- .../src/OTLPTraceExporter.ts | 4 ++-- .../test/OTLPTraceExporter.test.ts | 9 ++++++++ .../platform/browser/OTLPMetricExporter.ts | 9 ++++++-- .../src/platform/node/OTLPMetricExporter.ts | 5 +++-- .../browser/CollectorMetricExporter.test.ts | 9 ++++++++ .../test/node/CollectorMetricExporter.test.ts | 9 ++++++++ .../src/OTLPMetricExporter.ts | 3 ++- .../test/OTLPMetricExporter.test.ts | 9 ++++++++ 13 files changed, 84 insertions(+), 28 deletions(-) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index bd4b9271937..2a34315d846 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -20,7 +20,7 @@ import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'; import { toOTLPExportTraceServiceRequest } from '../../transform'; import * as otlpTypes from '../../types'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -import { appendResourcePathToUrl } from '../../util'; +import { appendResourcePathToUrl, appendRootPathToUrlIfNeeded } from '../../util'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces'; const DEFAULT_COLLECTOR_URL=`http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; @@ -53,7 +53,7 @@ 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) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index 40e4b35127b..8f31b25f5da 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -20,7 +20,7 @@ import { OTLPExporterNodeConfigBase } from './types'; import * as otlpTypes from '../../types'; import { toOTLPExportTraceServiceRequest } from '../../transform'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -import { appendResourcePathToUrl } from '../../util'; +import { appendResourcePathToUrl, appendRootPathToUrlIfNeeded } from '../../util'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces'; const DEFAULT_COLLECTOR_URL=`http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; @@ -54,7 +54,7 @@ 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) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/exporter-trace-otlp-http/src/util.ts b/experimental/packages/exporter-trace-otlp-http/src/util.ts index a28d3e5b6a8..5e0b87def96 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/util.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/util.ts @@ -40,9 +40,13 @@ export function parseHeaders( * @param path */ export function appendResourcePathToUrl(url: string, path: string): string { - if (url.endsWith('/')) { - return url + path; - } else { - return `${url}/${path}`; + url = appendRootPathToUrlIfNeeded(url); + return url + path; +} + +export function appendRootPathToUrlIfNeeded(url: string): string { + if (!url.endsWith('/')) { + url = url + '/'; } + return url; } diff --git a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts index d39aece5ccf..8f261d531c2 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts @@ -339,8 +339,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, @@ -349,6 +349,15 @@ 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', () => { + 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 use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPTraceExporter({ headers: {} }); diff --git a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts index a51ed8b6f02..aaffcc6bbc1 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts @@ -96,8 +96,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, @@ -106,15 +106,15 @@ describe('OTLPTraceExporter - node with json over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); - // it.only('should add root path when signal url defined in env contains 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 add root path when signal url defined in env contains 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 use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPTraceExporter(); diff --git a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts index 3025c7595cb..1fa5f872495 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts @@ -20,7 +20,7 @@ import { otlpTypes, toOTLPExportTraceServiceRequest, OTLPExporterNodeConfigBase, - appendResourcePathToUrl, + appendResourcePathToUrl, appendRootPathToUrlIfNeeded } from '@opentelemetry/exporter-trace-otlp-http'; import { ServiceClientType } from './types'; import { getEnv, baggageUtils } from '@opentelemetry/core'; @@ -57,7 +57,7 @@ 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) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts index 9bbb047e318..8b2cf37c159 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts @@ -87,6 +87,15 @@ 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', () => { + 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 use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPTraceExporter(); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts index 6bfd540a170..76ac08d3c8e 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts @@ -15,7 +15,12 @@ */ import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base'; -import { OTLPExporterBrowserBase, otlpTypes, appendResourcePathToUrl } from '@opentelemetry/exporter-trace-otlp-http'; +import { + OTLPExporterBrowserBase, + otlpTypes, + appendResourcePathToUrl, + appendRootPathToUrlIfNeeded + } from '@opentelemetry/exporter-trace-otlp-http'; import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; import { getEnv, baggageUtils } from '@opentelemetry/core'; @@ -58,7 +63,7 @@ export class OTLPMetricExporter 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) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index 62b0b20c01e..1441c599029 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -19,7 +19,8 @@ import { OTLPExporterNodeBase, OTLPExporterNodeConfigBase, otlpTypes, - appendResourcePathToUrl + appendResourcePathToUrl, + appendRootPathToUrlIfNeeded } from '@opentelemetry/exporter-trace-otlp-http'; import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; import { getEnv, baggageUtils } from '@opentelemetry/core'; @@ -63,7 +64,7 @@ export class OTLPMetricExporter 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) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index 9f4af76eac8..91b5cfa9126 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -428,6 +428,15 @@ describe('when configuring via environment', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); + it('should add root path when signal url defined in env contains no path', () => { + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar'; + const collectorExporter = new OTLPMetricExporter(); + assert.strictEqual( + collectorExporter.url, + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}/` + ); + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPMetricExporter({ headers: {} }); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index f8e27c7a87f..8cfd9adc517 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -137,6 +137,15 @@ describe('OTLPMetricExporter - node with json over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); + it('should add root path when signal url defined in env contains no path', () => { + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar'; + const collectorExporter = new OTLPMetricExporter(); + assert.strictEqual( + collectorExporter.url, + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}/` + ); + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPMetricExporter(); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index 2b89714e643..1ea7155f90a 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -18,6 +18,7 @@ import { otlpTypes, OTLPExporterNodeConfigBase, appendResourcePathToUrl, + appendRootPathToUrlIfNeeded, } from '@opentelemetry/exporter-trace-otlp-http'; import { toOTLPExportMetricServiceRequest } from '@opentelemetry/exporter-metrics-otlp-http'; import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base'; @@ -63,7 +64,7 @@ export class OTLPMetricExporter 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) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index 3aaf10801f1..ad230813751 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -94,6 +94,15 @@ describe('OTLPMetricExporter - node with proto over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); + it('should add root path when signal url defined in env contains no path', () => { + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar'; + const collectorExporter = new OTLPMetricExporter(); + assert.strictEqual( + collectorExporter.url, + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}/` + ); + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; + }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; const collectorExporter = new OTLPMetricExporter(); From d1ff795abdaae1212edc6d2de12080f13f48175e Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Fri, 8 Apr 2022 14:57:50 -0500 Subject: [PATCH 04/15] fix(otlp-http-exporter): fix url on metrics tests Signed-off-by: Svetlana Brennan --- .../test/browser/CollectorMetricExporter.test.ts | 4 ++-- .../test/node/CollectorMetricExporter.test.ts | 4 ++-- .../test/OTLPMetricExporter.test.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index f63219f4bbb..eb3e03ddad7 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -400,7 +400,7 @@ describe('when configuring via environment', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/metrics` ); envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; @@ -409,7 +409,7 @@ describe('when configuring via environment', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics` ); envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index fd925e00226..d270119a95a 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -107,7 +107,7 @@ describe('OTLPMetricExporter - node with json over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/metrics` ); envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; @@ -145,7 +145,7 @@ describe('OTLPMetricExporter - node with json over http', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}/` ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index 9f432ebc51f..1f23b3120c2 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -59,7 +59,7 @@ describe('OTLPMetricExporter - node with proto over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}v1/metrics` ); envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; @@ -97,7 +97,7 @@ describe('OTLPMetricExporter - node with proto over http', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}/` ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; From 03e498c8eb1dc67bcc7abb4218f425cd7e1c2d4d Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Mon, 25 Apr 2022 17:06:01 -0500 Subject: [PATCH 05/15] fix(otlp-http-exporter): fix tests Signed-off-by: Svetlana Brennan --- .../src/platform/browser/OTLPTraceExporter.ts | 4 ++-- .../exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts | 4 ++-- .../test/browser/CollectorMetricExporter.test.ts | 4 ++-- .../test/node/CollectorMetricExporter.test.ts | 4 ++-- .../test/OTLPMetricExporter.test.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index ac26b92122f..f082deb9d36 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { appendResourcePathToUrlIfNotPresent, OTLPExporterBrowserBase } from '@opentelemetry/otlp-exporter-base'; import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'; import { toOTLPExportTraceServiceRequest } from '../../transform'; import * as otlpTypes from '../../types'; @@ -22,7 +21,8 @@ import { getEnv, baggageUtils } from '@opentelemetry/core'; import { OTLPExporterConfigBase, appendResourcePathToUrl, - appendRootPathToUrlIfNeeded + appendRootPathToUrlIfNeeded, + OTLPExporterBrowserBase } from '@opentelemetry/otlp-exporter-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces'; diff --git a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts index 482c6b10b43..c4c9fb2f809 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts @@ -76,8 +76,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, diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index ee97972a254..8cbe59e3d84 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -425,8 +425,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_METRICS_ENDPOINT = 'http://foo.metrics'; + envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.metrics/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index f46adcf4e0c..b014655f849 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -132,8 +132,8 @@ describe('OTLPMetricExporter - 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_METRICS_ENDPOINT = 'http://foo.metrics'; + envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.metrics/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index 1cebccb6ade..8ef5ff3e55a 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -83,8 +83,8 @@ describe('OTLPMetricExporter - 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_METRICS_ENDPOINT = 'http://foo.metrics'; + envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.metrics/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, From 29940e33ef4ab3b9ee0c792cc5471f6dbc937fbc Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Mon, 25 Apr 2022 17:08:05 -0500 Subject: [PATCH 06/15] fix(otlp-http-exporter): add changelog Signed-off-by: Svetlana Brennan --- experimental/CHANGELOG.md | 1 + .../src/platform/browser/OTLPTraceExporter.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 4eed8e22176..00a64fda3d6 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -62,6 +62,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 ### :books: (Refine Doc) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index f082deb9d36..d5bce2f8b1e 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -18,7 +18,7 @@ import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'; import { toOTLPExportTraceServiceRequest } from '../../transform'; import * as otlpTypes from '../../types'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -import { +import { OTLPExporterConfigBase, appendResourcePathToUrl, appendRootPathToUrlIfNeeded, From 8964212ab3148b83c8cc4603e7c3645c45a0c720 Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Tue, 26 Apr 2022 11:19:19 -0500 Subject: [PATCH 07/15] fix(otlp-http-exporter): fix lint Signed-off-by: Svetlana Brennan --- .../src/platform/browser/OTLPTraceExporter.ts | 8 ++++---- .../src/platform/node/OTLPTraceExporter.ts | 8 ++++---- .../exporter-trace-otlp-proto/src/OTLPTraceExporter.ts | 8 ++++---- .../src/platform/browser/OTLPMetricExporter.ts | 8 ++++---- .../src/platform/node/OTLPMetricExporter.ts | 8 ++++---- .../src/OTLPMetricExporter.ts | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index d5bce2f8b1e..fa8de2b38d6 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -56,9 +56,9 @@ export class OTLPTraceExporter return typeof config.url === 'string' ? config.url : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) - : DEFAULT_COLLECTOR_URL; + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) + : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 + ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) + : DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index e72089c267a..f0352fd976a 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -55,9 +55,9 @@ export class OTLPTraceExporter return typeof config.url === 'string' ? config.url : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) - : DEFAULT_COLLECTOR_URL; + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) + : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 + ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) + : DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts index ed6535e841a..498c71b17b3 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts @@ -52,10 +52,10 @@ export class OTLPTraceExporter return typeof config.url === 'string' ? config.url : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) - : DEFAULT_COLLECTOR_URL; + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) + : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 + ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) + : DEFAULT_COLLECTOR_URL; } getServiceClientType() { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts index 7a73b41e324..c4a9945a944 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts @@ -49,10 +49,10 @@ class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) - : DEFAULT_COLLECTOR_URL; + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) + : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 + ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) + : DEFAULT_COLLECTOR_URL; } convert( diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index d5632aaf5fd..cb1a3294f03 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -59,10 +59,10 @@ class OTLPExporterNodeProxy extends OTLPExporterNodeBase 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) - : DEFAULT_COLLECTOR_URL; + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) + : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 + ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) + : DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index 014c82beffd..8d69f58e1a1 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -63,10 +63,10 @@ class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) - : DEFAULT_COLLECTOR_URL; + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) + : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 + ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) + : DEFAULT_COLLECTOR_URL; } getServiceClientType() { From fdeb2d196c3c14ad3e58c435bff9ad23e33b0778 Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Tue, 26 Apr 2022 11:47:44 -0500 Subject: [PATCH 08/15] fix(otlp-http-exporter): fix lint Signed-off-by: Svetlana Brennan --- .../src/platform/browser/OTLPTraceExporter.ts | 2 +- .../src/platform/node/OTLPTraceExporter.ts | 2 +- .../packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts | 2 +- .../src/platform/browser/OTLPMetricExporter.ts | 2 +- .../src/platform/node/OTLPMetricExporter.ts | 2 +- .../src/OTLPMetricExporter.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index fa8de2b38d6..1b8d2796a11 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -26,7 +26,7 @@ import { } from '@opentelemetry/otlp-exporter-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces'; -const DEFAULT_COLLECTOR_URL=`http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Trace Exporter for Web diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index f0352fd976a..a3e8be4b7fe 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -26,7 +26,7 @@ import { } from '@opentelemetry/otlp-exporter-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces'; -const DEFAULT_COLLECTOR_URL=`http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Trace Exporter for Node diff --git a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts index 498c71b17b3..26721a9c8a4 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts @@ -21,7 +21,7 @@ import { OTLPExporterNodeConfigBase, appendResourcePathToUrl, appendRootPathToUr import { OTLPProtoExporterNodeBase, ServiceClientType } from '@opentelemetry/otlp-proto-exporter-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces'; -const DEFAULT_COLLECTOR_URL=`http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Trace Exporter for Node with protobuf diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts index c4a9945a944..9682e051f3b 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts @@ -28,7 +28,7 @@ import { } from '@opentelemetry/otlp-exporter-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics'; -const DEFAULT_COLLECTOR_URL=`http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index cb1a3294f03..17ac60a5450 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -28,7 +28,7 @@ import { } from '@opentelemetry/otlp-exporter-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics'; -const DEFAULT_COLLECTOR_URL=`http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; class OTLPExporterNodeProxy extends OTLPExporterNodeBase { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index 8d69f58e1a1..1de23cf912e 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -32,7 +32,7 @@ import { } from '@opentelemetry/otlp-exporter-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics'; -const DEFAULT_COLLECTOR_URL=`http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase { From dec66c78f2d41cfc58f3a0b9b98340a30e54274c Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Wed, 27 Apr 2022 18:43:50 -0500 Subject: [PATCH 09/15] fix(otlp-http-exporter): wip update when root path is added to match spec Signed-off-by: Svetlana Brennan --- .../src/platform/browser/OTLPTraceExporter.ts | 2 +- .../src/platform/node/OTLPTraceExporter.ts | 2 +- .../test/node/CollectorTraceExporter.test.ts | 29 ++++++++++++++++++- .../src/OTLPTraceExporter.ts | 2 +- .../packages/otlp-exporter-base/src/util.ts | 8 +++-- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index 1b8d2796a11..9d736523cff 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -56,7 +56,7 @@ export class OTLPTraceExporter return typeof config.url === 'string' ? config.url : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index a3e8be4b7fe..bb515ca4cd5 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -55,7 +55,7 @@ export class OTLPTraceExporter return typeof config.url === 'string' ? config.url : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts index 4bf5d060b93..fd48bd2a0d5 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts @@ -119,7 +119,7 @@ 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', () => { + 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( @@ -128,6 +128,33 @@ describe('OTLPTraceExporter - node with json over http', () => { ); 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 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 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(); diff --git a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts index 26721a9c8a4..2a4d31f0ea9 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts @@ -52,7 +52,7 @@ export class OTLPTraceExporter return typeof config.url === 'string' ? config.url : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/otlp-exporter-base/src/util.ts b/experimental/packages/otlp-exporter-base/src/util.ts index 5e0b87def96..89206a92b9a 100644 --- a/experimental/packages/otlp-exporter-base/src/util.ts +++ b/experimental/packages/otlp-exporter-base/src/util.ts @@ -40,12 +40,14 @@ export function parseHeaders( * @param path */ export function appendResourcePathToUrl(url: string, path: string): string { - url = appendRootPathToUrlIfNeeded(url); + if (!url.endsWith('/')) { + url = url + '/'; + } return url + path; } -export function appendRootPathToUrlIfNeeded(url: string): string { - if (!url.endsWith('/')) { +export function appendRootPathToUrlIfNeeded(url: string, path: string): string { + if (!url.includes(path) && !url.endsWith('/')) { url = url + '/'; } return url; From be3367de87f834c8f8401a0c16df4bfae7380658 Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Thu, 28 Apr 2022 10:45:19 -0500 Subject: [PATCH 10/15] fix(otlp-http-exporter): add more tests for adding rooth path for signal endpoints Signed-off-by: Svetlana Brennan --- .../browser/CollectorTraceExporter.test.ts | 29 ++++++++++++++++++- .../test/OTLPTraceExporter.test.ts | 29 ++++++++++++++++++- .../platform/browser/OTLPMetricExporter.ts | 2 +- .../src/platform/node/OTLPMetricExporter.ts | 2 +- .../browser/CollectorMetricExporter.test.ts | 29 ++++++++++++++++++- .../test/node/CollectorMetricExporter.test.ts | 29 ++++++++++++++++++- .../src/OTLPMetricExporter.ts | 2 +- .../test/OTLPMetricExporter.test.ts | 29 ++++++++++++++++++- 8 files changed, 143 insertions(+), 8 deletions(-) diff --git a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts index d6e772d4aaf..114abe34b54 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts @@ -515,7 +515,7 @@ 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', () => { + 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( @@ -524,6 +524,33 @@ describe('when configuring via environment', () => { ); 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 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 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: {} }); diff --git a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts index c4c9fb2f809..24bd323503a 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts @@ -86,7 +86,7 @@ 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', () => { + 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( @@ -95,6 +95,33 @@ describe('OTLPTraceExporter - node with proto over http', () => { ); 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 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 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(); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts index 9682e051f3b..91d9ddb97f9 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts @@ -49,7 +49,7 @@ class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index 17ac60a5450..c893b76c845 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -59,7 +59,7 @@ class OTLPExporterNodeProxy extends OTLPExporterNodeBase 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index 8cbe59e3d84..65b4c1d95ac 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -435,7 +435,7 @@ describe('when configuring via environment', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); - it('should add root path when signal url defined in env contains no path', () => { + it('should add root path when signal url defined in env contains no path and no root path', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( @@ -444,6 +444,33 @@ describe('when configuring via environment', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_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 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 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 OTLPMetricExporter({ diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index b014655f849..dbe01f7be9d 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -142,7 +142,7 @@ describe('OTLPMetricExporter - node with json over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); - it('should add root path when signal url defined in env contains no path', () => { + it('should add root path when signal url defined in env contains no path and no root path', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( @@ -151,6 +151,33 @@ describe('OTLPMetricExporter - node with json over http', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_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 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 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 OTLPMetricExporter(); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index 1de23cf912e..eda2f59c8e5 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -63,7 +63,7 @@ class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) + ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 ? appendResourcePathToUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) : DEFAULT_COLLECTOR_URL; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index 8ef5ff3e55a..d46e18ffeac 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -93,7 +93,7 @@ describe('OTLPMetricExporter - node with proto over http', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); - it('should add root path when signal url defined in env contains no path', () => { + it('should add root path when signal url defined in env contains no path and no root path', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( @@ -102,6 +102,33 @@ describe('OTLPMetricExporter - node with proto over http', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_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 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 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 OTLPMetricExporter(); From d37eeaff9b7de4b16cd0087f74bdc37ad6dace86 Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Thu, 28 Apr 2022 10:52:44 -0500 Subject: [PATCH 11/15] fix(otlp-http-exporter): fix typos Signed-off-by: Svetlana Brennan --- .../test/browser/CollectorMetricExporter.test.ts | 12 ++++++------ .../test/node/CollectorMetricExporter.test.ts | 12 ++++++------ .../test/OTLPMetricExporter.test.ts | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index 65b4c1d95ac..038d246695f 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -446,27 +446,27 @@ describe('when configuring via environment', () => { }); 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(); + const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); it('should not 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(); + const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); it('should not 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(); + const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index dbe01f7be9d..8318a956257 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -153,27 +153,27 @@ describe('OTLPMetricExporter - node with json over http', () => { }); 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(); + const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); it('should not 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(); + const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); it('should not 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(); + const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index d46e18ffeac..a2cbe8613f6 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -104,27 +104,27 @@ describe('OTLPMetricExporter - node with proto over http', () => { }); 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(); + const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); it('should not 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(); + const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); it('should not 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(); + const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( - collectorExporter.url, + collectorExporter._otlpExporter.url, `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; From d3d090a5fab20a20e0dca742f7843f8015d0fe8d Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Thu, 28 Apr 2022 11:06:37 -0500 Subject: [PATCH 12/15] fix(otlp-http-exporter): fix typos Signed-off-by: Svetlana Brennan --- .../browser/CollectorMetricExporter.test.ts | 18 +++++++++--------- .../test/node/CollectorMetricExporter.test.ts | 18 +++++++++--------- .../test/OTLPMetricExporter.test.ts | 18 +++++++++--------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index 038d246695f..b6e32b75011 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -445,31 +445,31 @@ describe('when configuring via environment', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_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/'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}` ); - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); it('should not root path when signal url defined in env contains path', () => { - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}` ); - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); it('should not root path when signal url defined in env contains path and ends in /', () => { - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces/'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}` ); - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index 8318a956257..cfc9655acd1 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -152,31 +152,31 @@ describe('OTLPMetricExporter - node with json over http', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_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/'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}` ); - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); it('should not root path when signal url defined in env contains path', () => { - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}` ); - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); it('should not root path when signal url defined in env contains path and ends in /', () => { - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces/'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}` ); - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index a2cbe8613f6..091f2b2fb04 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -103,31 +103,31 @@ describe('OTLPMetricExporter - node with proto over http', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_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/'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}` ); - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); it('should not root path when signal url defined in env contains path', () => { - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}` ); - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); it('should not root path when signal url defined in env contains path and ends in /', () => { - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://foo.bar/v1/traces/'; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( collectorExporter._otlpExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}` + `${envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT}` ); - envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; + envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; From c06a5dd46805c3512536efa10d914c3ec0ec8c3f Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Mon, 2 May 2022 17:09:27 -0500 Subject: [PATCH 13/15] fix(otlp-http-exporter): add unit tests for adding resource and root path to url Signed-off-by: Svetlana Brennan --- .../packages/otlp-exporter-base/src/util.ts | 9 ++- .../test/common/util.test.ts | 56 ++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/experimental/packages/otlp-exporter-base/src/util.ts b/experimental/packages/otlp-exporter-base/src/util.ts index 89206a92b9a..ab8e60fa8fb 100644 --- a/experimental/packages/otlp-exporter-base/src/util.ts +++ b/experimental/packages/otlp-exporter-base/src/util.ts @@ -35,9 +35,10 @@ export function parseHeaders( } /** - * Adds path (version + signal) to a no per-signal endpoint and returns updated url + * Adds path (version + signal) to a no per-signal endpoint * @param url * @param path + * @returns url + path */ export function appendResourcePathToUrl(url: string, path: string): string { if (!url.endsWith('/')) { @@ -46,6 +47,12 @@ export function appendResourcePathToUrl(url: string, path: string): string { return url + path; } +/** + * Adds root path to signal specific endpoint when endpoint contains no path part and no root path + * @param url + * @param path + * @returns url + */ export function appendRootPathToUrlIfNeeded(url: string, path: string): string { if (!url.includes(path) && !url.endsWith('/')) { url = url + '/'; diff --git a/experimental/packages/otlp-exporter-base/test/common/util.test.ts b/experimental/packages/otlp-exporter-base/test/common/util.test.ts index e2414952144..cc29de641d1 100644 --- a/experimental/packages/otlp-exporter-base/test/common/util.test.ts +++ b/experimental/packages/otlp-exporter-base/test/common/util.test.ts @@ -17,7 +17,11 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { diag } from '@opentelemetry/api'; -import { parseHeaders } from '../../src/util'; +import { + parseHeaders, + appendResourcePathToUrl, + appendRootPathToUrlIfNeeded +} from '../../src/util'; describe('utils', () => { afterEach(() => { @@ -50,4 +54,54 @@ describe('utils', () => { assert.deepStrictEqual(result, {}); }); }); + + // only invoked with general endpoint (not signal specific endpoint) + describe('appendResourcePathToUrl - general http endpoint', () => { + it('should append resource path when missing', () => { + const url = 'http://foo.bar/'; + const resourcePath = 'v1/traces'; + + const finalUrl = appendResourcePathToUrl(url, resourcePath); + assert.strictEqual(finalUrl, url + resourcePath); + }); + it('should append root path and resource path when missing', () => { + const url = 'http://foo.bar'; + const resourcePath = 'v1/traces'; + + const finalUrl = appendResourcePathToUrl(url, resourcePath); + assert.strictEqual(finalUrl, url + '/' + resourcePath); + }); + it('should append resourse path even when url already contains path ', () => { + const url = 'http://foo.bar/v1/traces'; + const resourcePath = 'v1/traces'; + + const finalUrl = appendResourcePathToUrl(url, resourcePath); + assert.strictEqual(finalUrl, url + '/' + resourcePath); + }); + }); + + // only invoked with signal specific endpoint + describe('appendRootPathToUrlIfNeeded - specifc signal http endpoint', () => { + it('should append root path when missing', () => { + const url = 'http://foo.bar'; + const resourcePath = 'v1/traces'; + + const finalUrl = appendRootPathToUrlIfNeeded(url, resourcePath); + assert.strictEqual(finalUrl, url + '/'); + }); + it('should not append root path and return same url', () => { + const url = 'http://foo.bar/'; + const resourcePath = 'v1/traces'; + + const finalUrl = appendRootPathToUrlIfNeeded(url, resourcePath); + assert.strictEqual(finalUrl, url); + }); + it('should append root path when url contains resource path', () => { + const url = 'http://foo.bar/v1/traces'; + const resourcePath = 'v1/traces'; + + const finalUrl = appendRootPathToUrlIfNeeded(url, resourcePath); + assert.strictEqual(finalUrl, url); + }); + }); }); From 6547e40ac59324ce03bdbb5af2121c576ad9538d Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Mon, 2 May 2022 18:02:04 -0500 Subject: [PATCH 14/15] fix(otlp-http-exporter): fix typos Signed-off-by: Svetlana Brennan --- .../test/browser/CollectorTraceExporter.test.ts | 4 ++-- .../test/node/CollectorTraceExporter.test.ts | 4 ++-- .../exporter-trace-otlp-proto/src/OTLPTraceExporter.ts | 6 +++++- .../test/OTLPTraceExporter.test.ts | 4 ++-- .../test/browser/CollectorMetricExporter.test.ts | 4 ++-- .../test/node/CollectorMetricExporter.test.ts | 4 ++-- .../test/OTLPMetricExporter.test.ts | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts index 114abe34b54..ba4e60477a9 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts @@ -533,7 +533,7 @@ describe('when configuring via environment', () => { ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path', () => { + 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( @@ -542,7 +542,7 @@ describe('when configuring via environment', () => { ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path and ends in /', () => { + 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( diff --git a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts index fd48bd2a0d5..5283511f548 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts @@ -137,7 +137,7 @@ describe('OTLPTraceExporter - node with json over http', () => { ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path', () => { + 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( @@ -146,7 +146,7 @@ describe('OTLPTraceExporter - node with json over http', () => { ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path and ends in /', () => { + 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( diff --git a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts index 2a4d31f0ea9..0d2fda2290c 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts @@ -17,7 +17,11 @@ import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'; import { otlpTypes, toOTLPExportTraceServiceRequest } from '@opentelemetry/exporter-trace-otlp-http'; import { getEnv, baggageUtils } from '@opentelemetry/core'; -import { OTLPExporterNodeConfigBase, appendResourcePathToUrl, appendRootPathToUrlIfNeeded } from '@opentelemetry/otlp-exporter-base'; +import { + OTLPExporterNodeConfigBase, + appendResourcePathToUrl, + appendRootPathToUrlIfNeeded +} from '@opentelemetry/otlp-exporter-base'; import { OTLPProtoExporterNodeBase, ServiceClientType } from '@opentelemetry/otlp-proto-exporter-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/traces'; diff --git a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts index 24bd323503a..e3ec7a1977d 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts @@ -104,7 +104,7 @@ describe('OTLPTraceExporter - node with proto over http', () => { ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path', () => { + 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( @@ -113,7 +113,7 @@ describe('OTLPTraceExporter - node with proto over http', () => { ); envSource.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path and ends in /', () => { + 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( diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index b6e32b75011..47838680719 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -453,7 +453,7 @@ describe('when configuring via environment', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path', () => { + it('should not add root path when signal url defined in env contains path', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( @@ -462,7 +462,7 @@ describe('when configuring via environment', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path and ends in /', () => { + it('should not add root path when signal url defined in env contains path and ends in /', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index cfc9655acd1..504a52e4379 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -160,7 +160,7 @@ describe('OTLPMetricExporter - node with json over http', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path', () => { + it('should not add root path when signal url defined in env contains path', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( @@ -169,7 +169,7 @@ describe('OTLPMetricExporter - node with json over http', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path and ends in /', () => { + it('should not add root path when signal url defined in env contains path and ends in /', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index 091f2b2fb04..68fedff394f 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -111,7 +111,7 @@ describe('OTLPMetricExporter - node with proto over http', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path', () => { + it('should not add root path when signal url defined in env contains path', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( @@ -120,7 +120,7 @@ describe('OTLPMetricExporter - node with proto over http', () => { ); envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; }); - it('should not root path when signal url defined in env contains path and ends in /', () => { + it('should not add root path when signal url defined in env contains path and ends in /', () => { envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.bar/v1/metrics/'; const collectorExporter = new OTLPMetricExporter(); assert.strictEqual( From 3acb9cfac0e93051f077df9e703e7ad2db1d3a13 Mon Sep 17 00:00:00 2001 From: Svetlana Brennan Date: Mon, 16 May 2022 15:27:22 -0500 Subject: [PATCH 15/15] fix(otlp-http-exporter): move changelog to unreleased section Signed-off-by: Svetlana Brennan --- experimental/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index af522ca32a7..f8a546b341c 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to experimental packages in this project will be documented * fix(opentelemetry-instrumentation-http): use correct origin when port is `null` #2948 @danielgblanco * fix(otlp-exporter-base): include esm and esnext in package files #2952 @dyladan +* fix(otlp-http-exporter): update endpoint to match spec #2895 @svetlanabrennan ### :books: (Refine Doc) @@ -73,7 +74,6 @@ 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 ### :books: (Refine Doc)