@@ -28,3 +28,168 @@ func TestRedactedStringLogging(t *testing.T) {
2828 t .Error ("text slog handler should not have contained the secret string" )
2929 }
3030}
31+
32+ func TestOtelConfigProtocol (t * testing.T ) {
33+ type test struct {
34+ name string
35+ config OtelConfig
36+ protocol string
37+ }
38+
39+ tests := []test {
40+ {
41+ name : "Defaults to http" ,
42+ config : OtelConfig {},
43+ protocol : "http" ,
44+ },
45+ {
46+ name : "Explicit Grpc Rust enum variant" ,
47+ config : OtelConfig {Protocol : "Grpc" },
48+ protocol : "grpc" ,
49+ },
50+ {
51+ name : "Explicit Http Rust enum variant" ,
52+ config : OtelConfig {Protocol : "Http" },
53+ protocol : "http" ,
54+ },
55+ }
56+
57+ for _ , tc := range tests {
58+ if tc .config .OtelProtocol () != tc .protocol {
59+ t .Fatalf ("%s / OtelProtocol: expected %q, got: %q" , tc .name , tc .protocol , tc .config .OtelProtocol ())
60+ }
61+ }
62+ }
63+
64+ func TestOtelConfigURLs (t * testing.T ) {
65+ type test struct {
66+ name string
67+ config OtelConfig
68+ tracesURL string
69+ metricsURL string
70+ logsURL string
71+ }
72+
73+ tests := []test {
74+ {
75+ name : "Defaults with HTTP" ,
76+ config : OtelConfig {},
77+ tracesURL : "http://localhost:4318/v1/traces" ,
78+ metricsURL : "http://localhost:4318/v1/metrics" ,
79+ logsURL : "http://localhost:4318/v1/logs" ,
80+ },
81+ {
82+ name : "Defaults with gRPC" ,
83+ config : OtelConfig {Protocol : "Grpc" },
84+ tracesURL : "http://localhost:4317" ,
85+ metricsURL : "http://localhost:4317" ,
86+ logsURL : "http://localhost:4317" ,
87+ },
88+ {
89+ name : "Custom ObservabilityEndpoint" ,
90+ config : OtelConfig {ObservabilityEndpoint : "https://api.opentelemetry.com" },
91+ tracesURL : "https://api.opentelemetry.com/v1/traces" ,
92+ metricsURL : "https://api.opentelemetry.com/v1/metrics" ,
93+ logsURL : "https://api.opentelemetry.com/v1/logs" ,
94+ },
95+ {
96+ name : "Custom ObservabilityEndpoint with gRPC" ,
97+ config : OtelConfig {Protocol : "grpc" , ObservabilityEndpoint : "https://api.opentelemetry.com" },
98+ tracesURL : "https://api.opentelemetry.com" ,
99+ metricsURL : "https://api.opentelemetry.com" ,
100+ logsURL : "https://api.opentelemetry.com" ,
101+ },
102+ {
103+ name : "Custom TracesEndpoint" ,
104+ config : OtelConfig {TracesEndpoint : "https://api.opentelemetry.com/v1/traces" },
105+ tracesURL : "https://api.opentelemetry.com/v1/traces" ,
106+ metricsURL : "http://localhost:4318/v1/metrics" ,
107+ logsURL : "http://localhost:4318/v1/logs" ,
108+ },
109+ {
110+ name : "Custom MetricsEndpoint" ,
111+ config : OtelConfig {MetricsEndpoint : "https://api.opentelemetry.com/v1/metrics" },
112+ tracesURL : "http://localhost:4318/v1/traces" ,
113+ metricsURL : "https://api.opentelemetry.com/v1/metrics" ,
114+ logsURL : "http://localhost:4318/v1/logs" ,
115+ },
116+ {
117+ name : "Custom LogsEndpoint" ,
118+ config : OtelConfig {LogsEndpoint : "https://api.opentelemetry.com/v1/logs" },
119+ tracesURL : "http://localhost:4318/v1/traces" ,
120+ metricsURL : "http://localhost:4318/v1/metrics" ,
121+ logsURL : "https://api.opentelemetry.com/v1/logs" ,
122+ },
123+ }
124+
125+ for _ , tc := range tests {
126+ if tc .config .TracesURL () != tc .tracesURL {
127+ t .Fatalf ("%s / TracesURL: expected %s, got: %s" , tc .name , tc .tracesURL , tc .config .TracesURL ())
128+ }
129+ if tc .config .MetricsURL () != tc .metricsURL {
130+ t .Fatalf ("%s / MetricsURL: expected %s, got: %s" , tc .name , tc .metricsURL , tc .config .MetricsURL ())
131+ }
132+ if tc .config .LogsURL () != tc .logsURL {
133+ t .Fatalf ("%s / LogsURL: expected %s, got: %s" , tc .name , tc .logsURL , tc .config .LogsURL ())
134+ }
135+ }
136+ }
137+
138+ func TestOtelConfigBooleans (t * testing.T ) {
139+ type test struct {
140+ name string
141+ config OtelConfig
142+ tracesEnabled bool
143+ metricsEnabled bool
144+ logsEnabled bool
145+ }
146+
147+ tests := []test {
148+ {
149+ name : "Defaults" ,
150+ config : OtelConfig {},
151+ tracesEnabled : false ,
152+ metricsEnabled : false ,
153+ logsEnabled : false ,
154+ },
155+ {
156+ name : "Enable all with EnableObservability" ,
157+ config : OtelConfig {EnableObservability : true },
158+ tracesEnabled : true ,
159+ metricsEnabled : true ,
160+ logsEnabled : true ,
161+ },
162+ {
163+ name : "Enable just traces" ,
164+ config : OtelConfig {EnableTraces : true },
165+ tracesEnabled : true ,
166+ metricsEnabled : false ,
167+ logsEnabled : false ,
168+ },
169+ {
170+ name : "Enable just metrics" ,
171+ config : OtelConfig {EnableMetrics : true },
172+ tracesEnabled : false ,
173+ metricsEnabled : true ,
174+ logsEnabled : false ,
175+ },
176+ {
177+ name : "Enable just logs" ,
178+ config : OtelConfig {EnableLogs : true },
179+ tracesEnabled : false ,
180+ metricsEnabled : false ,
181+ logsEnabled : true ,
182+ },
183+ }
184+ for _ , tc := range tests {
185+ if tc .config .TracesEnabled () != tc .tracesEnabled {
186+ t .Fatalf ("%s / TracesEnabled: expected %t, got: %t" , tc .name , tc .tracesEnabled , tc .config .TracesEnabled ())
187+ }
188+ if tc .config .MetricsEnabled () != tc .metricsEnabled {
189+ t .Fatalf ("%s / MetricsEnabled: expected %t, got: %t" , tc .name , tc .metricsEnabled , tc .config .MetricsEnabled ())
190+ }
191+ if tc .config .LogsEnabled () != tc .logsEnabled {
192+ t .Fatalf ("%s / LogsEnabled: expected %t, got: %t" , tc .name , tc .logsEnabled , tc .config .LogsEnabled ())
193+ }
194+ }
195+ }
0 commit comments