| 68 | // "k=v,k2=v2" form. A malformed pair is skipped rather than failing the boot: |
| 69 | // losing traces must never cost the operator their server. |
| 70 | const parseHeaders = (raw: string | undefined): Record<string, string> | undefined => { |
| 71 | const entries = (raw ?? "") |
| 72 | .split(",") |
| 73 | .map((pair) => pair.trim()) |
| 74 | .filter((pair) => pair.length > 0) |
| 75 | .flatMap((pair) => { |
| 76 | const separator = pair.indexOf("="); |
| 77 | if (separator <= 0) return []; |
| 78 | return [[pair.slice(0, separator).trim(), pair.slice(separator + 1).trim()] as const]; |
| 79 | }); |
| 80 | return entries.length > 0 ? Object.fromEntries(entries) : undefined; |
| 81 | }; |
| 82 | |
| 83 | /** |
| 84 | * OTLP export layer for the self-hosted server, or {@link Layer.empty} when no |