1717package plugin
1818
1919import (
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
3536const exporterPlugin = "otlp"
3637
3738func 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