( otlpEndpointSetting: string | undefined, protocol: 'grpc' | 'http', )
| 50 | } |
| 51 | |
| 52 | function parseOtlpEndpoint( |
| 53 | otlpEndpointSetting: string | undefined, |
| 54 | protocol: 'grpc' | 'http', |
| 55 | ): string | undefined { |
| 56 | if (!otlpEndpointSetting) { |
| 57 | return undefined; |
| 58 | } |
| 59 | // Trim leading/trailing quotes that might come from env variables |
| 60 | const trimmedEndpoint = otlpEndpointSetting.replace(/^["']|["']$/g, ''); |
| 61 | |
| 62 | try { |
| 63 | const url = new URL(trimmedEndpoint); |
| 64 | if (protocol === 'grpc') { |
| 65 | // OTLP gRPC exporters expect an endpoint in the format scheme://host:port |
| 66 | // The `origin` property provides this, stripping any path, query, or hash. |
| 67 | return url.origin; |
| 68 | } |
| 69 | // For http, use the full href. |
| 70 | return url.href; |
| 71 | } catch (error) { |
| 72 | diag.error('Invalid OTLP endpoint URL provided:', trimmedEndpoint, error); |
| 73 | return undefined; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | export function initializeTelemetry(config: Config): void { |
| 78 | if (telemetryInitialized || !config.getTelemetryEnabled()) { |
no outgoing calls
no test coverage detected