@@ -2,6 +2,7 @@ package otel
22
33import (
44 "context"
5+ "strings"
56 "time"
67
78 sdkotel "go.opentelemetry.io/otel"
@@ -88,10 +89,18 @@ func (opts *Opts) buildResource() *resource.Resource {
8889
8990func BuildTracerProvider (opts * Opts ) (* sdktrace.TracerProvider , func ()) {
9091 // Create HTTP client to talk to OTEL collector
91- client := otlptracehttp .NewClient (
92+ clientOpts := [] otlptracehttp.Option {
9293 otlptracehttp .WithEndpoint (opts .Endpoint ),
9394 otlptracehttp .WithHeaders (opts .Headers ),
94- )
95+ }
96+
97+ // If endpoint doesn't use port 443, assume insecure (HTTP not HTTPS)
98+ if ! strings .Contains (opts .Endpoint , ":443" ) {
99+ log .Debugf ("Using insecure connection for OTEL endpoint %v" , opts .Endpoint )
100+ clientOpts = append (clientOpts , otlptracehttp .WithInsecure ())
101+ }
102+
103+ client := otlptracehttp .NewClient (clientOpts ... )
95104
96105 // Create an exporter that exports to the OTEL collector
97106 exporter , err := otlptrace .New (context .Background (), client )
@@ -127,7 +136,7 @@ func BuildTracerProvider(opts *Opts) (*sdktrace.TracerProvider, func()) {
127136}
128137
129138func InitGlobalMeterProvider (opts * Opts ) (func (), error ) {
130- exp , err := otlpmetrichttp .New ( context . Background (),
139+ metricOpts := [] otlpmetrichttp.Option {
131140 otlpmetrichttp .WithEndpoint (opts .Endpoint ),
132141 otlpmetrichttp .WithHeaders (opts .Headers ),
133142 otlpmetrichttp .WithTemporalitySelector (func (kind sdkmetric.InstrumentKind ) metricdata.Temporality {
@@ -142,7 +151,15 @@ func InitGlobalMeterProvider(opts *Opts) (func(), error) {
142151 return metricdata .CumulativeTemporality
143152 }
144153 }),
145- )
154+ }
155+
156+ // If endpoint doesn't use port 443, assume insecure (HTTP not HTTPS)
157+ if ! strings .Contains (opts .Endpoint , ":443" ) {
158+ log .Debugf ("Using insecure connection for OTEL metrics endpoint %v" , opts .Endpoint )
159+ metricOpts = append (metricOpts , otlpmetrichttp .WithInsecure ())
160+ }
161+
162+ exp , err := otlpmetrichttp .New (context .Background (), metricOpts ... )
146163 if err != nil {
147164 return nil , err
148165 }
0 commit comments