MCPcopy Create free account
hub / github.com/anus-dev/ANUS / parseOtlpEndpoint

Function parseOtlpEndpoint

packages/core/src/telemetry/sdk.ts:52–75  ·  view source on GitHub ↗
(
  otlpEndpointSetting: string | undefined,
  protocol: 'grpc' | 'http',
)

Source from the content-addressed store, hash-verified

50}
51
52function 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
77export function initializeTelemetry(config: Config): void {
78 if (telemetryInitialized || !config.getTelemetryEnabled()) {

Callers 1

initializeTelemetryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected