@@ -18,6 +18,7 @@ import {
1818} from "@t3tools/contracts" ;
1919import * as NetService from "@t3tools/shared/Net" ;
2020import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability" ;
21+ import * as OtelEnvironment from "@t3tools/shared/otelEnvironment" ;
2122import * as NodeServices from "@effect/platform-node/NodeServices" ;
2223import { deriveServerPaths } from "../config.ts" ;
2324import { resolveServerConfig } from "./config.ts" ;
@@ -56,6 +57,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
5657 otlpMetricsExport : DEFAULT_SIGNAL_EXPORT ,
5758 otlpLogsExport : DEFAULT_SIGNAL_EXPORT ,
5859 otlpServiceName : "t3-server" ,
60+ otelEnvironment : OtelEnvironment . none ,
5961 devAllowedOrigins : [ ] ,
6062 } as const ;
6163
@@ -666,6 +668,109 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
666668 } ) ,
667669 ) ;
668670
671+ it . effect ( "zeroes an endpoint stored in Settings when the SDK is disabled" , ( ) =>
672+ Effect . gen ( function * ( ) {
673+ const fs = yield * FileSystem . FileSystem ;
674+ const path = yield * Path . Path ;
675+ const baseDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-cli-config-otel-off-" } ) ;
676+ const derivedPaths = yield * deriveExplicitServerPaths ( baseDir , undefined ) ;
677+ yield * fs . makeDirectory ( path . dirname ( derivedPaths . settingsPath ) , { recursive : true } ) ;
678+ yield * fs . writeFileString (
679+ derivedPaths . settingsPath ,
680+ // @effect -diagnostics-next-line preferSchemaOverJson:off
681+ `${ JSON . stringify ( {
682+ observability : {
683+ otlpTracesUrl : "http://localhost:4318/v1/traces" ,
684+ otlpMetricsUrl : "http://localhost:4318/v1/metrics" ,
685+ otlpLogsUrl : "http://localhost:4318/v1/logs" ,
686+ } ,
687+ } ) } \n`,
688+ ) ;
689+
690+ const resolved = yield * resolveServerConfig (
691+ {
692+ mode : Option . some ( "desktop" ) ,
693+ port : Option . some ( 4888 ) ,
694+ host : Option . none ( ) ,
695+ baseDir : Option . some ( baseDir ) ,
696+ cwd : Option . none ( ) ,
697+ devUrl : Option . none ( ) ,
698+ noBrowser : Option . none ( ) ,
699+ bootstrapFd : Option . none ( ) ,
700+ autoBootstrapProjectFromCwd : Option . none ( ) ,
701+ logWebSocketEvents : Option . none ( ) ,
702+ tailscaleServeEnabled : Option . none ( ) ,
703+ tailscaleServePort : Option . none ( ) ,
704+ } ,
705+ Option . none ( ) ,
706+ ) . pipe (
707+ Effect . provide (
708+ Layer . mergeAll (
709+ ConfigProvider . layer ( ConfigProvider . fromEnv ( { env : { OTEL_SDK_DISABLED : "true" } } ) ) ,
710+ NetService . layer ,
711+ ) ,
712+ ) ,
713+ ) ;
714+
715+ // The switch beats every source, including an endpoint stored in Settings.
716+ expect ( resolved . otlpTracesUrl ) . toBeUndefined ( ) ;
717+ expect ( resolved . otlpMetricsUrl ) . toBeUndefined ( ) ;
718+ expect ( resolved . otlpLogsUrl ) . toBeUndefined ( ) ;
719+ expect ( resolved . otelEnvironment . disabled ) . toBe ( true ) ;
720+ } ) ,
721+ ) ;
722+
723+ it . effect ( "lets T3CODE_OTEL_SDK_DISABLED=false override an ambient OTEL_SDK_DISABLED=true" , ( ) =>
724+ Effect . gen ( function * ( ) {
725+ const fs = yield * FileSystem . FileSystem ;
726+ const path = yield * Path . Path ;
727+ const baseDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-cli-config-otel-on-" } ) ;
728+ const derivedPaths = yield * deriveExplicitServerPaths ( baseDir , undefined ) ;
729+ yield * fs . makeDirectory ( path . dirname ( derivedPaths . settingsPath ) , { recursive : true } ) ;
730+ yield * fs . writeFileString (
731+ derivedPaths . settingsPath ,
732+ // @effect -diagnostics-next-line preferSchemaOverJson:off
733+ `${ JSON . stringify ( {
734+ observability : {
735+ otlpTracesUrl : "http://localhost:4318/v1/traces" ,
736+ } ,
737+ } ) } \n`,
738+ ) ;
739+
740+ const resolved = yield * resolveServerConfig (
741+ {
742+ mode : Option . some ( "desktop" ) ,
743+ port : Option . some ( 4888 ) ,
744+ host : Option . none ( ) ,
745+ baseDir : Option . some ( baseDir ) ,
746+ cwd : Option . none ( ) ,
747+ devUrl : Option . none ( ) ,
748+ noBrowser : Option . none ( ) ,
749+ bootstrapFd : Option . none ( ) ,
750+ autoBootstrapProjectFromCwd : Option . none ( ) ,
751+ logWebSocketEvents : Option . none ( ) ,
752+ tailscaleServeEnabled : Option . none ( ) ,
753+ tailscaleServePort : Option . none ( ) ,
754+ } ,
755+ Option . none ( ) ,
756+ ) . pipe (
757+ Effect . provide (
758+ Layer . mergeAll (
759+ ConfigProvider . layer (
760+ ConfigProvider . fromEnv ( {
761+ env : { T3CODE_OTEL_SDK_DISABLED : "false" , OTEL_SDK_DISABLED : "true" } ,
762+ } ) ,
763+ ) ,
764+ NetService . layer ,
765+ ) ,
766+ ) ,
767+ ) ;
768+
769+ expect ( resolved . otelEnvironment . disabled ) . toBe ( false ) ;
770+ expect ( resolved . otlpTracesUrl ) . toBe ( "http://localhost:4318/v1/traces" ) ;
771+ } ) ,
772+ ) ;
773+
669774 it . effect ( "forces noBrowser and disables auto-bootstrap for headless startup presentation" , ( ) =>
670775 Effect . gen ( function * ( ) {
671776 const { join } = yield * Path . Path ;
0 commit comments