1import * as Config from "../../Config.ts"
2import * as Schema from "../../Schema.ts"
3
4export type Signal = "LOGS" | "METRICS" | "TRACES"
5
6const exporterList = (path: string) =>
7 Config.Array(Schema.String, path).pipe(
8 Config.map((_) => _.map((_) => _.toLowerCase().trim()).filter((_) => _ !== ""))
9 )
10
11const headersRecord = (path: string) => Config.Record(Schema.String, Schema.StringFromUriComponent, path)
12
13export const headers = (signal: Signal) =>
14 headersRecord(`OTEL_EXPORTER_OTLP_${signal}_HEADERS`).pipe(
15 Config.orElse(() => headersRecord("OTEL_EXPORTER_OTLP_HEADERS")),
16 Config.withDefault(undefined)
17 )
18
19export const endpoint = (signal: Signal) =>
20 Config.URL(`OTEL_EXPORTER_OTLP_${signal}_ENDPOINT`).pipe(
21 Config.orElse(() =>
22 Config.URL("OTEL_EXPORTER_OTLP_ENDPOINT").pipe(
23 Config.map((url) => {
24 const slash = url.pathname.endsWith("/") ? "" : "/"
25 url.pathname += `${slash}v1/${signal.toLowerCase()}`
26 return url
27 })
28 )
29 ),
30 Config.withDefault(undefined)
31 )
32
33export const exporters = (signal: Signal) =>
34 exporterList(`OTEL_${signal}_EXPORTER`).pipe(
35 Config.withDefault<ReadonlyArray<string>>([])
36 )