11package config
22
33import (
4+ "os"
45 "testing"
56 "time"
67
@@ -9,6 +10,7 @@ import (
910 "go.uber.org/mock/gomock"
1011
1112 "github.com/stacklok/toolhive/pkg/env/mocks"
13+ "github.com/stacklok/toolhive/pkg/telemetry"
1214 authtypes "github.com/stacklok/toolhive/pkg/vmcp/auth/types"
1315)
1416
@@ -768,3 +770,65 @@ func TestYAMLLoader_transformCompositeTools_WithOutputConfig(t *testing.T) {
768770 })
769771 }
770772}
773+
774+ // TestYAMLLoader_transformTelemetryConfig tests that telemetry configuration is preserved
775+ // when transforming from raw YAML to the final Config struct.
776+ func TestYAMLLoader_transformTelemetryConfig (t * testing.T ) {
777+ t .Parallel ()
778+
779+ // Note: yaml.v3 uses lowercase field names by default (no yaml tags on telemetry.Config)
780+ yamlContent := `
781+ name: telemetry-test
782+ telemetry:
783+ endpoint: "localhost:4318"
784+ servicename: "test-service"
785+ serviceversion: "1.2.3"
786+ tracingenabled: true
787+ metricsenabled: true
788+ samplingrate: 0.75
789+ insecure: true
790+ enableprometheusmetricspath: true
791+ headers:
792+ Authorization: "Bearer token123"
793+ X-Custom-Header: "custom-value"
794+ environmentvariables:
795+ - "NODE_ENV"
796+ - "DEPLOYMENT_ENV"
797+ `
798+
799+ // Write temp file
800+ tmpFile , err := os .CreateTemp ("" , "telemetry-test-*.yaml" )
801+ require .NoError (t , err )
802+ defer os .Remove (tmpFile .Name ())
803+
804+ _ , err = tmpFile .WriteString (yamlContent )
805+ require .NoError (t , err )
806+ require .NoError (t , tmpFile .Close ())
807+
808+ // Load config
809+ ctrl := gomock .NewController (t )
810+ mockEnv := mocks .NewMockReader (ctrl )
811+ mockEnv .EXPECT ().Getenv (gomock .Any ()).Return ("" ).AnyTimes ()
812+
813+ loader := NewYAMLLoader (tmpFile .Name (), mockEnv )
814+ cfg , err := loader .Load ()
815+ require .NoError (t , err )
816+
817+ // Verify telemetry config is fully preserved
818+ require .NotNil (t , cfg .Telemetry , "Telemetry config should not be nil" )
819+
820+ require .Equal (t , telemetry.Config {
821+ Endpoint : "localhost:4318" ,
822+ ServiceName : "test-service" ,
823+ ServiceVersion : "1.2.3" ,
824+ TracingEnabled : true ,
825+ MetricsEnabled : true ,
826+ SamplingRate : 0.75 ,
827+ Insecure : true ,
828+ EnablePrometheusMetricsPath : true ,
829+ Headers : map [string ]string {"Authorization" : "Bearer token123" , "X-Custom-Header" : "custom-value" },
830+ EnvironmentVariables : []string {"NODE_ENV" , "DEPLOYMENT_ENV" },
831+ CustomAttributes : nil ,
832+ }, * cfg .Telemetry )
833+
834+ }
0 commit comments