Skip to content

Commit 0ff74b6

Browse files
authored
Merge pull request #5467 from michaeldmitry/otlp-insecure-flag
Add `--otlp-insecure` flag
2 parents 03cff40 + 76b16c8 commit 0ff74b6

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ Flags:
9898
logfmt
9999
--otlp-address=STRING The endpoint to send OTLP traces to.
100100
--otlp-exporter="grpc" The OTLP exporter to use.
101+
--otlp-insecure If true, disables TLS for OTLP exporters (both
102+
gRPC and HTTP).
101103
--cors-allowed-origins=CORS-ALLOWED-ORIGINS,...
102104
Allowed CORS origins.
103105
--version Show application version.

pkg/parca/parca.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ type FlagsLogs struct {
139139
type FlagsOTLP struct {
140140
Address string `help:"The endpoint to send OTLP traces to."`
141141
Exporter string `default:"grpc" enum:"grpc,http,stdout" help:"The OTLP exporter to use."`
142+
Insecure bool `default:"true" help:"If true, disables TLS for OTLP exporters (both gRPC and HTTP)."`
142143
}
143144

144145
type FlagsStorage struct {
@@ -193,7 +194,7 @@ func Run(ctx context.Context, logger log.Logger, reg *prometheus.Registry, flags
193194
if flags.OTLP.Address != "" {
194195
var err error
195196

196-
exporter, err = tracer.NewExporter(flags.OTLP.Exporter, flags.OTLP.Address)
197+
exporter, err = tracer.NewExporter(flags.OTLP.Exporter, flags.OTLP.Address, flags.OTLP.Insecure)
197198
if err != nil {
198199
level.Error(logger).Log("msg", "failed to create tracing exporter", "err", err)
199200
}

pkg/tracer/tracer.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)