@@ -107,12 +107,12 @@ func NewProvider(ctx context.Context, version string, exporter sdktrace.SpanExpo
107107 return provider , nil
108108}
109109
110- func NewExporter (exType , otlpAddress string ) (Exporter , error ) {
110+ func NewExporter (exType , otlpAddress string , otlpInsecure bool ) (Exporter , error ) {
111111 switch strings .ToLower (exType ) {
112112 case string (ExporterTypeGRPC ):
113- return NewGRPCExporter (otlpAddress )
113+ return NewGRPCExporter (otlpAddress , otlpInsecure )
114114 case string (ExporterTypeHTTP ):
115- return NewHTTPExporter (otlpAddress )
115+ return NewHTTPExporter (otlpAddress , otlpInsecure )
116116 case string (ExporterTypeStdio ):
117117 return NewConsoleExporter (os .Stdout )
118118 default :
@@ -144,18 +144,23 @@ func NewConsoleExporter(w io.Writer) (Exporter, error) {
144144}
145145
146146// NewGRPCExporter returns a gRPC exporter.
147- func NewGRPCExporter (otlpAddress string ) (Exporter , error ) {
148- return otlptracegrpc .NewUnstarted (
149- otlptracegrpc .WithInsecure (),
150- otlptracegrpc .WithEndpoint (otlpAddress ),
151- ), nil
147+ func NewGRPCExporter (otlpAddress string , otlpInsecure bool ) (Exporter , error ) {
148+ opts := []otlptracegrpc.Option {otlptracegrpc .WithEndpoint (otlpAddress )}
149+ if otlpInsecure {
150+ opts = append (opts , otlptracegrpc .WithInsecure ())
151+ }
152+
153+ return otlptracegrpc .NewUnstarted (opts ... ), nil
152154}
153155
154156// NewHTTPExporter returns a HTTP exporter.
155- func NewHTTPExporter (otlpAddress string ) (Exporter , error ) {
157+ func NewHTTPExporter (otlpAddress string , otlpInsecure bool ) (Exporter , error ) {
158+ opts := []otlptracehttp.Option {otlptracehttp .WithEndpoint (otlpAddress )}
159+ if otlpInsecure {
160+ opts = append (opts , otlptracehttp .WithInsecure ())
161+ }
156162 return otlptrace .NewUnstarted (otlptracehttp .NewClient (
157- otlptracehttp .WithInsecure (),
158- otlptracehttp .WithEndpoint (otlpAddress ),
163+ opts ... ,
159164 )), nil
160165}
161166
0 commit comments