X Tutup
Skip to content

Commit 69ae955

Browse files
author
Kazuyoshi Kato
committed
tracing: fix OTLP tracer's initialization
- insecure.NewCredential was simply wrong. It has to use otlptracegrpc.WithInsecure to disable TLS. - context.WithTimeout is nice to have, in case the endpoint is not correctly configured. Otherwise, the plugin initialization blocks indefinitely. - grpc.WithReturnConnectionError is nice to have. Otherwise, otlptracegrpc.New returns "context deadline exceeded" without underlying errors. - TraceSamplingRatio should be 1.0 by default. Otherwise, users need to configure both io.containerd.internal.v1.tracing and io.containerd.tracing.processor.v1.otlp. Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
1 parent c3177ca commit 69ae955

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tracing/plugin/otlp.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package plugin
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"io"
23+
"time"
2224

2325
"github.com/containerd/containerd/log"
2426
"github.com/containerd/containerd/plugin"
@@ -29,12 +31,13 @@ import (
2931
sdktrace "go.opentelemetry.io/otel/sdk/trace"
3032
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
3133
"google.golang.org/grpc"
32-
"google.golang.org/grpc/credentials/insecure"
3334
)
3435

3536
const exporterPlugin = "otlp"
3637

3738
func init() {
39+
const timeout = 5 * time.Second
40+
3841
plugin.Register(&plugin.Registration{
3942
ID: exporterPlugin,
4043
Type: plugin.TracingProcessorPlugin,
@@ -44,15 +47,22 @@ func init() {
4447
if cfg.Endpoint == "" {
4548
return nil, fmt.Errorf("otlp endpoint not set: %w", plugin.ErrSkipPlugin)
4649
}
47-
dialOpts := []grpc.DialOption{grpc.WithBlock()}
50+
51+
opts := []otlptracegrpc.Option{
52+
otlptracegrpc.WithEndpoint(cfg.Endpoint),
53+
otlptracegrpc.WithDialOption(
54+
grpc.WithBlock(),
55+
grpc.WithReturnConnectionError(),
56+
),
57+
}
4858
if cfg.Insecure {
49-
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
59+
opts = append(opts, otlptracegrpc.WithInsecure())
5060
}
5161

52-
exp, err := otlptracegrpc.New(ic.Context,
53-
otlptracegrpc.WithEndpoint(cfg.Endpoint),
54-
otlptracegrpc.WithDialOption(dialOpts...),
55-
)
62+
ctx, cancel := context.WithTimeout(ic.Context, timeout)
63+
defer cancel()
64+
65+
exp, err := otlptracegrpc.New(ctx, opts...)
5666
if err != nil {
5767
return nil, fmt.Errorf("failed to create otlp exporter: %w", err)
5868
}
@@ -63,7 +73,7 @@ func init() {
6373
ID: "tracing",
6474
Type: plugin.InternalPlugin,
6575
Requires: []plugin.Type{plugin.TracingProcessorPlugin},
66-
Config: &TraceConfig{ServiceName: "containerd"},
76+
Config: &TraceConfig{ServiceName: "containerd", TraceSamplingRatio: 1.0},
6777
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
6878
return newTracer(ic)
6979
},

0 commit comments

Comments
 (0)
X Tutup