diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 373fe3ea1c..c6b64299f0 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to experimental packages in this project will be documented ### :bug: (Bug Fix) * fix(otlp-transformer): remove type dependency on Long #3022 @legendecas +* fix(grpc-exporter): use non-normalized URL to determine channel security #3019 @pichlermarc ### :books: (Refine Doc) diff --git a/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts index baafc4773a..f4b0554715 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts @@ -48,13 +48,7 @@ export class OTLPTraceExporter } getDefaultUrl(config: OTLPGRPCExporterConfigNode) { - return typeof config.url === 'string' - ? validateAndNormalizeUrl(config.url) - : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT) - : validateAndNormalizeUrl(DEFAULT_COLLECTOR_URL); + return validateAndNormalizeUrl(this.getUrlFromConfig(config)); } getServiceClientType() { @@ -64,4 +58,14 @@ export class OTLPTraceExporter getServiceProtoPath(): string { return 'opentelemetry/proto/collector/trace/v1/trace_service.proto'; } + + getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string { + if (typeof config.url === 'string') { + return config.url; + } + + return getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT || + getEnv().OTEL_EXPORTER_OTLP_ENDPOINT || + DEFAULT_COLLECTOR_URL; + } } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts index 71e6e9b105..90c6ceb92b 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts @@ -51,18 +51,22 @@ class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase 0 - ? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT) - : validateAndNormalizeUrl(DEFAULT_COLLECTOR_URL); + return validateAndNormalizeUrl(this.getUrlFromConfig(config)); } convert(metrics: ResourceMetrics[]): IExportMetricsServiceRequest { return createExportMetricsServiceRequest(metrics); } + + getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string { + if (typeof config.url === 'string') { + return config.url; + } + + return getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT || + getEnv().OTEL_EXPORTER_OTLP_ENDPOINT || + DEFAULT_COLLECTOR_URL; + } } /** diff --git a/experimental/packages/otlp-grpc-exporter-base/src/OTLPGRPCExporterNodeBase.ts b/experimental/packages/otlp-grpc-exporter-base/src/OTLPGRPCExporterNodeBase.ts index 9cc349fe4e..87d7e01787 100644 --- a/experimental/packages/otlp-grpc-exporter-base/src/OTLPGRPCExporterNodeBase.ts +++ b/experimental/packages/otlp-grpc-exporter-base/src/OTLPGRPCExporterNodeBase.ts @@ -116,4 +116,5 @@ export abstract class OTLPGRPCExporterNodeBase< abstract getServiceProtoPath(): string; abstract getServiceClientType(): ServiceClientType; + abstract getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string; } diff --git a/experimental/packages/otlp-grpc-exporter-base/src/util.ts b/experimental/packages/otlp-grpc-exporter-base/src/util.ts index 313618fa72..1d3791bd38 100644 --- a/experimental/packages/otlp-grpc-exporter-base/src/util.ts +++ b/experimental/packages/otlp-grpc-exporter-base/src/util.ts @@ -33,7 +33,7 @@ export function onInit( ): void { collector.grpcQueue = []; - const credentials: grpc.ChannelCredentials = configureSecurity(config.credentials, collector.url); + const credentials: grpc.ChannelCredentials = configureSecurity(config.credentials, collector.getUrlFromConfig(config)); const includeDirs = [path.resolve(__dirname, '..', 'protos')]; @@ -92,7 +92,7 @@ export function send( collector.serviceClient.export( serviceRequest, collector.metadata || new grpc.Metadata(), - {deadline: deadline}, + { deadline: deadline }, (err: ExportServiceError) => { if (err) { diag.error('Service request', serviceRequest); @@ -225,7 +225,7 @@ function retrieveCertChain(): Buffer | undefined { } function toGrpcCompression(compression: CompressionAlgorithm): GrpcCompressionAlgorithm { - if(compression === CompressionAlgorithm.NONE) + if (compression === CompressionAlgorithm.NONE) return GrpcCompressionAlgorithm.NONE; else if (compression === CompressionAlgorithm.GZIP) return GrpcCompressionAlgorithm.GZIP; @@ -246,6 +246,6 @@ export function configureCompression(compression: CompressionAlgorithm | undefin } else { const definedCompression = getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION || getEnv().OTEL_EXPORTER_OTLP_COMPRESSION; - return definedCompression === 'gzip' ? GrpcCompressionAlgorithm.GZIP: GrpcCompressionAlgorithm.NONE; + return definedCompression === 'gzip' ? GrpcCompressionAlgorithm.GZIP : GrpcCompressionAlgorithm.NONE; } } diff --git a/experimental/packages/otlp-grpc-exporter-base/test/OTLPGRPCExporterNodeBase.test.ts b/experimental/packages/otlp-grpc-exporter-base/test/OTLPGRPCExporterNodeBase.test.ts index aca3540763..ec28b53011 100644 --- a/experimental/packages/otlp-grpc-exporter-base/test/OTLPGRPCExporterNodeBase.test.ts +++ b/experimental/packages/otlp-grpc-exporter-base/test/OTLPGRPCExporterNodeBase.test.ts @@ -52,6 +52,10 @@ class MockCollectorExporter extends OTLPGRPCExporterNodeBase< getServiceProtoPath(): string { return 'opentelemetry/proto/collector/trace/v1/trace_service.proto'; } + + getUrlFromConfig(config: OTLPGRPCExporterConfigNode): string { + return ''; + } } // Mocked _send which just saves the callbacks for later