11/**
2- * otelEnvironment: the OpenTelemetry kill switch and endpoint variables,
2+ * otelEnvironment: the OpenTelemetry kill switch, exporter, and endpoint variables,
33 * shared by the server and the desktop main process so both agree on what
44 * turns export off and where it goes.
55 *
@@ -23,8 +23,9 @@ type OtlpSignalName = "TRACES" | "METRICS" | "LOGS";
2323
2424/**
2525 * What the OTEL variables say about one signal. `Off` is a signal they
26- * claimed with an endpoint, protocol, or headers that do not read, so it is
27- * exported nowhere rather than to the bootstrap or Settings collector.
26+ * claimed with an endpoint, protocol, or headers that do not read, or turned
27+ * off with `OTEL_<SIGNAL>_EXPORTER=none`, so it is exported nowhere rather
28+ * than to the bootstrap or Settings collector.
2829 */
2930export type OtelSignal = Data . TaggedEnum < {
3031 Unset : { } ;
@@ -179,6 +180,38 @@ const headers = (name: string) =>
179180 `${ name } is not a list of key=value pairs with percent-encoded values, ${ NOT_EXPORTED } ` ,
180181 ) ;
181182
183+ type Exporter = "otlp" | "none" ;
184+
185+ const EXPORTERS : ReadonlySet < string > = new Set < Exporter > ( [ "otlp" , "none" ] ) ;
186+
187+ const isExporter = ( entry : string ) : entry is Exporter => EXPORTERS . has ( entry ) ;
188+
189+ /**
190+ * `OTEL_<SIGNAL>_EXPORTER`, a case-insensitive list whose default is `otlp`.
191+ * Entries T3 Code has no exporter for are named in a warning and dropped, and
192+ * a list left with nothing to honor reads as unset, as the specification asks
193+ * of any enum value an implementation does not recognize.
194+ */
195+ const exporter = ( name : string ) : Config . Config < Setting < Exporter > > =>
196+ Config . String ( name ) . pipe (
197+ Config . option ,
198+ Config . map ( ( option ) : Setting < Exporter > => {
199+ const entries = ( Option . getOrUndefined ( option ) ?? "" )
200+ . split ( "," )
201+ . map ( ( entry ) => entry . trim ( ) . toLowerCase ( ) )
202+ . filter ( ( entry ) => entry !== "" ) ;
203+ const ignored = [ ...new Set ( entries . filter ( ( entry ) => ! isExporter ( entry ) ) ) ] ;
204+ const known = new Set ( entries . filter ( isExporter ) ) ;
205+ const value = known . has ( "otlp" ) ? "otlp" : known . has ( "none" ) ? "none" : undefined ;
206+ return ignored . length === 0
207+ ? { value }
208+ : {
209+ value,
210+ warning : `${ name } names ${ ignored . join ( ", " ) } , which T3 Code does not export to, so ${ ignored . length === 1 ? "it was" : "they were" } ignored` ,
211+ } ;
212+ } ) ,
213+ ) ;
214+
182215interface Settings {
183216 readonly endpoint : Setting < URL > ;
184217 readonly protocol : Setting < OtlpProtocol > ;
@@ -215,9 +248,23 @@ interface ResolvedSignal {
215248/**
216249 * A signal whose endpoint, protocol, or headers do not read is not exported
217250 * rather than sent somewhere, in a format, or without the credentials its
218- * collector expects.
251+ * collector expects. `none` turns the signal off before any of those are read,
252+ * whether or not an endpoint was named.
219253 */
220- const signal = ( name : OtlpSignalName , own : Settings , generic : Settings ) : ResolvedSignal => {
254+ const signal = (
255+ name : OtlpSignalName ,
256+ exporter : Setting < Exporter > ,
257+ own : Settings ,
258+ generic : Settings ,
259+ ) : ResolvedSignal => {
260+ if ( exporter . value === "none" ) {
261+ return { signal : OtelSignal . Off ( ) , used : [ exporter ] } ;
262+ }
263+ const resolved = endpointSignal ( name , own , generic ) ;
264+ return { signal : resolved . signal , used : [ exporter , ...resolved . used ] } ;
265+ } ;
266+
267+ const endpointSignal = ( name : OtlpSignalName , own : Settings , generic : Settings ) : ResolvedSignal => {
221268 const ownEndpoint = isClaimed ( own . endpoint ) ;
222269 const endpoint = ownEndpoint ? own . endpoint : generic . endpoint ;
223270 if ( endpoint . value === undefined ) {
@@ -263,16 +310,21 @@ export const load: Effect.Effect<OtelEnvironment> = Config.all({
263310 traces : settings ( "OTEL_EXPORTER_OTLP_TRACES_" ) ,
264311 metrics : settings ( "OTEL_EXPORTER_OTLP_METRICS_" ) ,
265312 logs : settings ( "OTEL_EXPORTER_OTLP_LOGS_" ) ,
313+ exporters : Config . all ( {
314+ traces : exporter ( "OTEL_TRACES_EXPORTER" ) ,
315+ metrics : exporter ( "OTEL_METRICS_EXPORTER" ) ,
316+ logs : exporter ( "OTEL_LOGS_EXPORTER" ) ,
317+ } ) ,
266318} ) . pipe (
267- Effect . map ( ( { t3, spec, resource, generic, ...own } ) => {
319+ Effect . map ( ( { t3, spec, resource, generic, exporters , ...own } ) => {
268320 const disabled = t3 . value ?? spec . value ?? false ;
269321 // The kill switch wins outright, so the signals say nothing once it is set.
270322 const signals = disabled
271323 ? undefined
272324 : {
273- traces : signal ( "TRACES" , own . traces , generic ) ,
274- metrics : signal ( "METRICS" , own . metrics , generic ) ,
275- logs : signal ( "LOGS" , own . logs , generic ) ,
325+ traces : signal ( "TRACES" , exporters . traces , own . traces , generic ) ,
326+ metrics : signal ( "METRICS" , exporters . metrics , own . metrics , generic ) ,
327+ logs : signal ( "LOGS" , exporters . logs , own . logs , generic ) ,
276328 } ;
277329 // A generic variable read by several signals warns once.
278330 const used = new Set (
0 commit comments