Merge pull request #6443 from kzys/otel-fix
tracing: fix OTLP tracer's initialization
This commit is contained in:
commit
fd35ca2351
@ -17,8 +17,10 @@
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
@ -29,12 +31,13 @@ import (
|
|||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const exporterPlugin = "otlp"
|
const exporterPlugin = "otlp"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
|
||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
ID: exporterPlugin,
|
ID: exporterPlugin,
|
||||||
Type: plugin.TracingProcessorPlugin,
|
Type: plugin.TracingProcessorPlugin,
|
||||||
@ -44,15 +47,22 @@ func init() {
|
|||||||
if cfg.Endpoint == "" {
|
if cfg.Endpoint == "" {
|
||||||
return nil, fmt.Errorf("otlp endpoint not set: %w", plugin.ErrSkipPlugin)
|
return nil, fmt.Errorf("otlp endpoint not set: %w", plugin.ErrSkipPlugin)
|
||||||
}
|
}
|
||||||
dialOpts := []grpc.DialOption{grpc.WithBlock()}
|
|
||||||
|
opts := []otlptracegrpc.Option{
|
||||||
|
otlptracegrpc.WithEndpoint(cfg.Endpoint),
|
||||||
|
otlptracegrpc.WithDialOption(
|
||||||
|
grpc.WithBlock(),
|
||||||
|
grpc.WithReturnConnectionError(),
|
||||||
|
),
|
||||||
|
}
|
||||||
if cfg.Insecure {
|
if cfg.Insecure {
|
||||||
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
opts = append(opts, otlptracegrpc.WithInsecure())
|
||||||
}
|
}
|
||||||
|
|
||||||
exp, err := otlptracegrpc.New(ic.Context,
|
ctx, cancel := context.WithTimeout(ic.Context, timeout)
|
||||||
otlptracegrpc.WithEndpoint(cfg.Endpoint),
|
defer cancel()
|
||||||
otlptracegrpc.WithDialOption(dialOpts...),
|
|
||||||
)
|
exp, err := otlptracegrpc.New(ctx, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create otlp exporter: %w", err)
|
return nil, fmt.Errorf("failed to create otlp exporter: %w", err)
|
||||||
}
|
}
|
||||||
@ -63,7 +73,7 @@ func init() {
|
|||||||
ID: "tracing",
|
ID: "tracing",
|
||||||
Type: plugin.InternalPlugin,
|
Type: plugin.InternalPlugin,
|
||||||
Requires: []plugin.Type{plugin.TracingProcessorPlugin},
|
Requires: []plugin.Type{plugin.TracingProcessorPlugin},
|
||||||
Config: &TraceConfig{ServiceName: "containerd"},
|
Config: &TraceConfig{ServiceName: "containerd", TraceSamplingRatio: 1.0},
|
||||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
return newTracer(ic)
|
return newTracer(ic)
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user