MCPcopy Index your code
hub / github.com/coder/coder / TracerProvider

Function TracerProvider

coderd/tracing/exporter.go:37–128  ·  view source on GitHub ↗

TracerProvider creates a grpc otlp exporter and configures a trace provider. Caller is responsible for calling TracerProvider.Shutdown to ensure all data is flushed.

(ctx context.Context, service string, opts TracerOpts)

Source from the content-addressed store, hash-verified

35// TracerProvider creates a grpc otlp exporter and configures a trace provider.
36// Caller is responsible for calling TracerProvider.Shutdown to ensure all data is flushed.
37func TracerProvider(ctx context.Context, service string, opts TracerOpts) (*sdktrace.TracerProvider, func(context.Context) error, error) {
38 res := resource.NewWithAttributes(
39 semconv.SchemaURL,
40 // the service name used to display traces in backends
41 semconv.ServiceNameKey.String(service),
42 )
43
44 var (
45 tracerOpts = []sdktrace.TracerProviderOption{
46 sdktrace.WithResource(res),
47 }
48 closers = []func(context.Context) error{}
49 )
50
51 if opts.DataDog {
52 // See more:
53 // https://docs.datadoghq.com/tracing/metrics/runtime_metrics/go/
54 dd := ddotel.NewTracerProvider(ddtracer.WithRuntimeMetrics())
55 closers = append(closers, func(_ context.Context) error {
56 // For some reason, this doesn't appear to actually wind down
57 // the goroutines.
58 return dd.Shutdown()
59 })
60
61 // See https://docs.datadoghq.com/profiler/enabling/go/
62 _ = ddprofiler.Start(
63 ddprofiler.WithService("coderd"),
64 ddprofiler.WithProfileTypes(
65 ddprofiler.CPUProfile,
66 ddprofiler.HeapProfile,
67 ddprofiler.GoroutineProfile,
68
69 // In the future, we may want to enable:
70 // ddprofiler.BlockProfile,
71 // ddprofiler.MutexProfile,
72 ),
73 )
74 closers = append(closers, func(_ context.Context) error {
75 ddprofiler.Stop()
76 return nil
77 })
78 }
79
80 if opts.Default {
81 exporter, err := DefaultExporter(ctx)
82 if err != nil {
83 return nil, nil, xerrors.Errorf("default exporter: %w", err)
84 }
85 closers = append(closers, exporter.Shutdown)
86 tracerOpts = append(tracerOpts, sdktrace.WithBatcher(exporter))
87 }
88 if opts.Honeycomb != "" {
89 exporter, err := HoneycombExporter(ctx, opts.Honeycomb)
90 if err != nil {
91 return nil, nil, xerrors.Errorf("honeycomb exporter: %w", err)
92 }
93 closers = append(closers, exporter.Shutdown)
94 tracerOpts = append(tracerOpts, sdktrace.WithBatcher(exporter))

Callers 3

ConfigureTraceProviderFunction · 0.92
providerMethod · 0.92
StartMethod · 0.92

Calls 9

DefaultExporterFunction · 0.85
HoneycombExporterFunction · 0.85
ShutdownMethod · 0.65
StartMethod · 0.65
StopMethod · 0.65
SetLoggerMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected