Skip to content

Commit

Permalink
Merge pull request #2032 from adamvr/main
Browse files Browse the repository at this point in the history
Add secure option to open_telemetry_collector tracer
  • Loading branch information
Jeffail authored Aug 22, 2023
2 parents f5ea47b + 2c712ac commit 17b0e20
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
41 changes: 33 additions & 8 deletions internal/impl/otlp/tracer_otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.").
Expand All @@ -52,7 +58,8 @@ func init() {
}

type collector struct {
url string
url string
secure bool
}

type otlp struct {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions website/docs/components/tracers/open_telemetry_collector.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 17b0e20

Please sign in to comment.