MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / resolveTarget

Function resolveTarget

apps/host-selfhost/src/telemetry.ts:46–62  ·  view source on GitHub ↗
(env: Record<string, string | undefined>)

Source from the content-addressed store, hash-verified

44// POST to /v1/traces/v1/traces, which a collector answers with a 404 that never
45// reaches the operator — the export just silently produces nothing.
46const resolveTarget = (env: Record<string, string | undefined>): TelemetryTarget | undefined => {
47 const base = env.OTEL_EXPORTER_OTLP_ENDPOINT?.trim().replace(/\/+$/, "");
48 const tracesUrl =
49 env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT?.trim() ?? (base ? `${base}/v1/traces` : undefined);
50 if (!tracesUrl) return undefined;
51 // Logs are opt-in separately from traces: they are the noisier and more
52 // sensitive of the two, carrying every request line and whatever the
53 // operator's own log calls hold. Traces answer "where did the time go" by
54 // themselves, so shipping logs stays a second, deliberate choice. Set the
55 // signal endpoint explicitly if only the traces endpoint is configured —
56 // there is no base to derive a logs URL from, and guessing one would export
57 // to a path the operator never named.
58 const logsUrl = isTruthy(env.EXECUTOR_OTEL_EXPORT_LOGS)
59 ? (env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT?.trim() ?? (base ? `${base}/v1/logs` : undefined))
60 : undefined;
61 return { tracesUrl, logsUrl, headers: parseHeaders(env.OTEL_EXPORTER_OTLP_HEADERS) };
62};
63
64const isTruthy = (value: string | undefined): boolean =>
65 value === "1" || value === "true" || value === "yes";

Callers 1

makeTelemetryLiveFunction · 0.70

Calls 3

isTruthyFunction · 0.85
parseHeadersFunction · 0.85
replaceMethod · 0.65

Tested by

no test coverage detected