Skip to content

Commit 01f0853

Browse files
committed
Include telemetry in raw config
Signed-off-by: Jeremy Drouillard <jeremy@stacklok.com>
1 parent 2b2d168 commit 01f0853

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

pkg/vmcp/config/yaml_loader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"gopkg.in/yaml.v3"
99

1010
"github.com/stacklok/toolhive/pkg/env"
11+
"github.com/stacklok/toolhive/pkg/telemetry"
1112
"github.com/stacklok/toolhive/pkg/vmcp"
1213
authtypes "github.com/stacklok/toolhive/pkg/vmcp/auth/types"
1314
)
@@ -58,6 +59,8 @@ type rawConfig struct {
5859
Operational *OperationalConfig `yaml:"operational"`
5960

6061
CompositeTools []*rawCompositeTool `yaml:"composite_tools"`
62+
63+
Telemetry *telemetry.Config `yaml:"telemetry"`
6164
}
6265

6366
type rawIncomingAuth struct {
@@ -214,6 +217,8 @@ func (l *YAMLLoader) transformToConfig(raw *rawConfig) (*Config, error) {
214217
cfg.CompositeTools = compositeTools
215218
}
216219

220+
cfg.Telemetry = raw.Telemetry
221+
217222
// Apply operational defaults (fills missing values)
218223
cfg.EnsureOperationalDefaults()
219224

pkg/vmcp/config/yaml_loader_transform_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
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

Comments
 (0)