From 9df80eefaedcf07e8801ae769b0133e1fbdef001 Mon Sep 17 00:00:00 2001 From: Adam Rudd Date: Mon, 7 Aug 2023 09:46:12 +0200 Subject: [PATCH 1/2] Add secure option to otel config Signed-off-by: Adam Rudd --- internal/impl/otlp/tracer_otlp.go | 41 +++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/internal/impl/otlp/tracer_otlp.go b/internal/impl/otlp/tracer_otlp.go index 3aa5a4ad2e..ce0d027774 100644 --- a/internal/impl/otlp/tracer_otlp.go +++ b/internal/impl/otlp/tracer_otlp.go @@ -25,11 +25,17 @@ func init() { service.NewURLField("url"). Description("The URL of a collector to send tracing events to."). Default("localhost:4318"), + service.NewBoolField("secure"). + Description("Connect to the collector over HTTPS"). + Default(false), ).Description("A list of http collectors.")). Field(service.NewObjectListField("grpc", service.NewURLField("url"). Description("The URL of a collector to send tracing events to."). Default("localhost:4317"), + service.NewBoolField("secure"). + Description("Connect to the collector with client transport security"). + Default(false), ).Description("A list of grpc collectors.")). Field(service.NewStringMapField("tags"). Description("A map of tags to add to all tracing spans."). @@ -52,7 +58,8 @@ func init() { } type collector struct { - url string + url string + secure bool } type otlp struct { @@ -95,7 +102,16 @@ func collectors(conf *service.ParsedConfig, name string) ([]collector, error) { if err != nil { return nil, err } - collectors = append(collectors, collector{u}) + + secure, err := pc.FieldBool("secure") + if err != nil { + return nil, err + } + + collectors = append(collectors, collector{ + url: u, + secure: secure, + }) } return collectors, nil } @@ -142,10 +158,15 @@ func addGrpcCollectors(ctx context.Context, collectors []collector, opts []trace defer cancel() for _, c := range collectors { - exp, err := otlptrace.New(ctx, otlptracegrpc.NewClient( - otlptracegrpc.WithInsecure(), + clientOpts := []otlptracegrpc.Option{ otlptracegrpc.WithEndpoint(c.url), - )) + } + + if !c.secure { + clientOpts = append(clientOpts, otlptracegrpc.WithInsecure()) + } + + exp, err := otlptrace.New(ctx, otlptracegrpc.NewClient(clientOpts...)) if err != nil { return nil, err } @@ -159,10 +180,14 @@ func addHTTPCollectors(ctx context.Context, collectors []collector, opts []trace defer cancel() for _, c := range collectors { - exp, err := otlptrace.New(ctx, otlptracehttp.NewClient( - otlptracehttp.WithInsecure(), + clientOpts := []otlptracehttp.Option{ otlptracehttp.WithEndpoint(c.url), - )) + } + + if !c.secure { + clientOpts = append(clientOpts, otlptracehttp.WithInsecure()) + } + exp, err := otlptrace.New(ctx, otlptracehttp.NewClient(clientOpts...)) if err != nil { return nil, err } From 2c712ac869b5d7cd40fcdab29c64e474c8bfe593 Mon Sep 17 00:00:00 2001 From: Adam Rudd Date: Mon, 21 Aug 2023 13:34:43 +0200 Subject: [PATCH 2/2] Update documentation Signed-off-by: Adam Rudd --- .../tracers/open_telemetry_collector.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/website/docs/components/tracers/open_telemetry_collector.md b/website/docs/components/tracers/open_telemetry_collector.md index b1b179fdb4..5a3038f64f 100644 --- a/website/docs/components/tracers/open_telemetry_collector.md +++ b/website/docs/components/tracers/open_telemetry_collector.md @@ -66,6 +66,14 @@ The URL of a collector to send tracing events to. Type: `string` Default: `"localhost:4318"` +### `http[].secure` + +Connect to the collector over HTTPS + + +Type: `bool` +Default: `false` + ### `grpc` A list of grpc collectors. @@ -81,6 +89,14 @@ The URL of a collector to send tracing events to. Type: `string` Default: `"localhost:4317"` +### `grpc[].secure` + +Connect to the collector with client transport security + + +Type: `bool` +Default: `false` + ### `tags` A map of tags to add to all tracing spans.