Signed-off-by: Derek McGowan <derek@mcg.dev>
| ... | ... |
@@ -28,6 +28,7 @@ import ( |
| 28 | 28 |
buildkit "github.com/docker/docker/daemon/internal/builder-next" |
| 29 | 29 |
"github.com/docker/docker/daemon/internal/builder-next/exporter" |
| 30 | 30 |
"github.com/docker/docker/daemon/internal/libcontainerd/supervisor" |
| 31 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 31 | 32 |
"github.com/docker/docker/daemon/listeners" |
| 32 | 33 |
dopts "github.com/docker/docker/daemon/pkg/opts" |
| 33 | 34 |
"github.com/docker/docker/daemon/pkg/plugin" |
| ... | ... |
@@ -48,7 +49,6 @@ import ( |
| 48 | 48 |
systemrouter "github.com/docker/docker/daemon/server/router/system" |
| 49 | 49 |
"github.com/docker/docker/daemon/server/router/volume" |
| 50 | 50 |
"github.com/docker/docker/dockerversion" |
| 51 |
- "github.com/docker/docker/internal/otelutil" |
|
| 52 | 51 |
"github.com/docker/docker/pkg/authorization" |
| 53 | 52 |
"github.com/docker/docker/pkg/homedir" |
| 54 | 53 |
"github.com/docker/docker/pkg/pidfile" |
| ... | ... |
@@ -20,8 +20,8 @@ import ( |
| 20 | 20 |
"github.com/docker/docker/daemon/internal/image" |
| 21 | 21 |
"github.com/docker/docker/daemon/internal/metrics" |
| 22 | 22 |
"github.com/docker/docker/daemon/internal/multierror" |
| 23 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 23 | 24 |
"github.com/docker/docker/errdefs" |
| 24 |
- "github.com/docker/docker/internal/otelutil" |
|
| 25 | 25 |
"github.com/docker/docker/runconfig" |
| 26 | 26 |
"github.com/moby/moby/api/types/backend" |
| 27 | 27 |
containertypes "github.com/moby/moby/api/types/container" |
| ... | ... |
@@ -27,6 +27,7 @@ import ( |
| 27 | 27 |
"github.com/docker/docker/daemon/container" |
| 28 | 28 |
"github.com/docker/docker/daemon/initlayer" |
| 29 | 29 |
"github.com/docker/docker/daemon/internal/libcontainerd/remote" |
| 30 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 30 | 31 |
"github.com/docker/docker/daemon/internal/usergroup" |
| 31 | 32 |
"github.com/docker/docker/daemon/libnetwork" |
| 32 | 33 |
nwconfig "github.com/docker/docker/daemon/libnetwork/config" |
| ... | ... |
@@ -38,7 +39,6 @@ import ( |
| 38 | 38 |
"github.com/docker/docker/daemon/pkg/opts" |
| 39 | 39 |
volumemounts "github.com/docker/docker/daemon/volume/mounts" |
| 40 | 40 |
"github.com/docker/docker/errdefs" |
| 41 |
- "github.com/docker/docker/internal/otelutil" |
|
| 42 | 41 |
"github.com/docker/docker/pkg/sysinfo" |
| 43 | 42 |
"github.com/docker/docker/runconfig" |
| 44 | 43 |
"github.com/moby/moby/api/types/blkiodev" |
| 45 | 44 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,43 @@ |
| 0 |
+package otelutil |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "context" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/containerd/log" |
|
| 6 |
+ "go.opentelemetry.io/otel/baggage" |
|
| 7 |
+) |
|
| 8 |
+ |
|
| 9 |
+// TriggerKey is the key used for the 'trigger' member in the baggage. It is |
|
| 10 |
+// used to know what triggered a code path (e.g. API call, libnet init, etc...) |
|
| 11 |
+const TriggerKey = "trigger" |
|
| 12 |
+ |
|
| 13 |
+// MustNewBaggage creates an OTel Baggage containing the provided members. It |
|
| 14 |
+// panics if the baggage cannot be created. |
|
| 15 |
+// |
|
| 16 |
+// DO NOT USE this function with dynamic values. |
|
| 17 |
+func MustNewBaggage(members ...baggage.Member) baggage.Baggage {
|
|
| 18 |
+ b, err := baggage.New(members...) |
|
| 19 |
+ if err != nil {
|
|
| 20 |
+ log.G(context.Background()).WithFields(log.Fields{
|
|
| 21 |
+ "error": err, |
|
| 22 |
+ "members": members, |
|
| 23 |
+ }).Fatal("OTel baggage creation failure")
|
|
| 24 |
+ } |
|
| 25 |
+ return b |
|
| 26 |
+} |
|
| 27 |
+ |
|
| 28 |
+// MustNewMemberRaw creates an OTel Baggage member with the provided key and |
|
| 29 |
+// value. It panics if the key or value aren't valid UTF-8 strings. |
|
| 30 |
+// |
|
| 31 |
+// DO NOT USE this function with dynamic key/value. |
|
| 32 |
+func MustNewMemberRaw(key, value string) baggage.Member {
|
|
| 33 |
+ m, err := baggage.NewMemberRaw(key, value) |
|
| 34 |
+ if err != nil {
|
|
| 35 |
+ log.G(context.Background()).WithFields(log.Fields{
|
|
| 36 |
+ "error": err, |
|
| 37 |
+ "key": key, |
|
| 38 |
+ "value": value, |
|
| 39 |
+ }).Fatal("OTel baggage member creation failure")
|
|
| 40 |
+ } |
|
| 41 |
+ return m |
|
| 42 |
+} |
| 0 | 43 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,71 @@ |
| 0 |
+package otelutil |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "os" |
|
| 4 |
+) |
|
| 5 |
+ |
|
| 6 |
+const ( |
|
| 7 |
+ traceParentKey = "traceparent" |
|
| 8 |
+ traceStateKey = "tracestate" |
|
| 9 |
+ |
|
| 10 |
+ // See https://github.com/open-telemetry/opentelemetry-specification/issues/740 |
|
| 11 |
+ // and https://github.com/open-telemetry/oteps/pull/258. |
|
| 12 |
+ traceParentEnvVar = "TRACEPARENT" |
|
| 13 |
+ traceStateEnvVar = "TRACESTATE" |
|
| 14 |
+) |
|
| 15 |
+ |
|
| 16 |
+type EnvironCarrier struct {
|
|
| 17 |
+ TraceParent, TraceState string |
|
| 18 |
+} |
|
| 19 |
+ |
|
| 20 |
+// Get returns the value associated with the passed key. |
|
| 21 |
+func (c *EnvironCarrier) Get(key string) string {
|
|
| 22 |
+ switch key {
|
|
| 23 |
+ case traceParentKey: |
|
| 24 |
+ return c.TraceParent |
|
| 25 |
+ case traceStateKey: |
|
| 26 |
+ return c.TraceState |
|
| 27 |
+ } |
|
| 28 |
+ return "" |
|
| 29 |
+} |
|
| 30 |
+ |
|
| 31 |
+// Set stores the key-value pair. |
|
| 32 |
+func (c *EnvironCarrier) Set(key, value string) {
|
|
| 33 |
+ switch key {
|
|
| 34 |
+ case traceParentKey: |
|
| 35 |
+ c.TraceParent = value |
|
| 36 |
+ case traceStateKey: |
|
| 37 |
+ c.TraceState = value |
|
| 38 |
+ } |
|
| 39 |
+ // Other keys are not supported at this time. |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 42 |
+// Keys lists the keys stored in this carrier. |
|
| 43 |
+func (c *EnvironCarrier) Keys() []string {
|
|
| 44 |
+ var k []string |
|
| 45 |
+ if c.TraceParent != "" {
|
|
| 46 |
+ k = append(k, traceParentKey) |
|
| 47 |
+ } |
|
| 48 |
+ if c.TraceState != "" {
|
|
| 49 |
+ k = append(k, traceStateKey) |
|
| 50 |
+ } |
|
| 51 |
+ return k |
|
| 52 |
+} |
|
| 53 |
+ |
|
| 54 |
+func (c *EnvironCarrier) Environ() []string {
|
|
| 55 |
+ var env []string |
|
| 56 |
+ if c.TraceParent != "" {
|
|
| 57 |
+ env = append(env, traceParentEnvVar+"="+c.TraceParent) |
|
| 58 |
+ } |
|
| 59 |
+ if c.TraceState != "" {
|
|
| 60 |
+ env = append(env, traceStateEnvVar+"="+c.TraceState) |
|
| 61 |
+ } |
|
| 62 |
+ return env |
|
| 63 |
+} |
|
| 64 |
+ |
|
| 65 |
+func PropagateFromEnvironment() *EnvironCarrier {
|
|
| 66 |
+ return &EnvironCarrier{
|
|
| 67 |
+ TraceParent: os.Getenv(traceParentEnvVar), |
|
| 68 |
+ TraceState: os.Getenv(traceStateEnvVar), |
|
| 69 |
+ } |
|
| 70 |
+} |
| 0 | 71 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,39 @@ |
| 0 |
+package otelutil |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "context" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/containerd/log" |
|
| 6 |
+ "github.com/moby/buildkit/util/tracing/detect" |
|
| 7 |
+ "go.opentelemetry.io/contrib/processors/baggagecopy" |
|
| 8 |
+ "go.opentelemetry.io/otel/baggage" |
|
| 9 |
+ "go.opentelemetry.io/otel/sdk/resource" |
|
| 10 |
+ sdktrace "go.opentelemetry.io/otel/sdk/trace" |
|
| 11 |
+ "go.opentelemetry.io/otel/trace" |
|
| 12 |
+ "go.opentelemetry.io/otel/trace/noop" |
|
| 13 |
+) |
|
| 14 |
+ |
|
| 15 |
+func NewTracerProvider(ctx context.Context, allowNoop bool) (trace.TracerProvider, func(context.Context) error) {
|
|
| 16 |
+ noopShutdown := func(ctx context.Context) error { return nil }
|
|
| 17 |
+ |
|
| 18 |
+ exp, err := detect.NewSpanExporter(ctx) |
|
| 19 |
+ if err != nil {
|
|
| 20 |
+ log.G(ctx).WithError(err).Warn("Failed to initialize tracing, skipping")
|
|
| 21 |
+ if allowNoop {
|
|
| 22 |
+ return noop.NewTracerProvider(), noopShutdown |
|
| 23 |
+ } |
|
| 24 |
+ } |
|
| 25 |
+ |
|
| 26 |
+ if allowNoop && detect.IsNoneSpanExporter(exp) {
|
|
| 27 |
+ log.G(ctx).Info("OTEL tracing is not configured, using no-op tracer provider")
|
|
| 28 |
+ return noop.NewTracerProvider(), noopShutdown |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ tp := sdktrace.NewTracerProvider( |
|
| 32 |
+ sdktrace.WithResource(resource.Default()), |
|
| 33 |
+ sdktrace.WithSyncer(detect.Recorder), |
|
| 34 |
+ sdktrace.WithBatcher(exp), |
|
| 35 |
+ sdktrace.WithSpanProcessor(baggagecopy.NewSpanProcessor(func(member baggage.Member) bool { return true })),
|
|
| 36 |
+ ) |
|
| 37 |
+ return tp, tp.Shutdown |
|
| 38 |
+} |
| 0 | 39 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,17 @@ |
| 0 |
+package otelutil |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "go.opentelemetry.io/otel/codes" |
|
| 4 |
+ "go.opentelemetry.io/otel/trace" |
|
| 5 |
+) |
|
| 6 |
+ |
|
| 7 |
+// RecordStatus records the status of a span based on the error provided. |
|
| 8 |
+// |
|
| 9 |
+// If err is nil, the span status is unmodified. If err is not nil, the span |
|
| 10 |
+// takes status Error, and the error message is recorded. |
|
| 11 |
+func RecordStatus(span trace.Span, err error) {
|
|
| 12 |
+ if err != nil {
|
|
| 13 |
+ span.RecordError(err) |
|
| 14 |
+ span.SetStatus(codes.Error, err.Error()) |
|
| 15 |
+ } |
|
| 16 |
+} |
| ... | ... |
@@ -54,6 +54,7 @@ import ( |
| 54 | 54 |
"time" |
| 55 | 55 |
|
| 56 | 56 |
"github.com/containerd/log" |
| 57 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 57 | 58 |
"github.com/docker/docker/daemon/libnetwork/cluster" |
| 58 | 59 |
"github.com/docker/docker/daemon/libnetwork/config" |
| 59 | 60 |
"github.com/docker/docker/daemon/libnetwork/datastore" |
| ... | ... |
@@ -68,7 +69,6 @@ import ( |
| 68 | 68 |
"github.com/docker/docker/daemon/libnetwork/osl" |
| 69 | 69 |
"github.com/docker/docker/daemon/libnetwork/scope" |
| 70 | 70 |
"github.com/docker/docker/daemon/libnetwork/types" |
| 71 |
- "github.com/docker/docker/internal/otelutil" |
|
| 72 | 71 |
"github.com/docker/docker/pkg/plugingetter" |
| 73 | 72 |
"github.com/docker/docker/pkg/plugins" |
| 74 | 73 |
"github.com/docker/docker/pkg/stringid" |
| ... | ... |
@@ -16,6 +16,7 @@ import ( |
| 16 | 16 |
"syscall" |
| 17 | 17 |
|
| 18 | 18 |
"github.com/containerd/log" |
| 19 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 19 | 20 |
"github.com/docker/docker/daemon/libnetwork/datastore" |
| 20 | 21 |
"github.com/docker/docker/daemon/libnetwork/driverapi" |
| 21 | 22 |
"github.com/docker/docker/daemon/libnetwork/drivers/bridge/internal/firewaller" |
| ... | ... |
@@ -34,7 +35,6 @@ import ( |
| 34 | 34 |
"github.com/docker/docker/daemon/libnetwork/scope" |
| 35 | 35 |
"github.com/docker/docker/daemon/libnetwork/types" |
| 36 | 36 |
"github.com/docker/docker/errdefs" |
| 37 |
- "github.com/docker/docker/internal/otelutil" |
|
| 38 | 37 |
"github.com/docker/docker/internal/sliceutil" |
| 39 | 38 |
"github.com/docker/docker/pkg/stringid" |
| 40 | 39 |
"github.com/pkg/errors" |
| ... | ... |
@@ -11,11 +11,11 @@ import ( |
| 11 | 11 |
"strings" |
| 12 | 12 |
|
| 13 | 13 |
"github.com/containerd/log" |
| 14 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 14 | 15 |
"github.com/docker/docker/daemon/libnetwork/datastore" |
| 15 | 16 |
"github.com/docker/docker/daemon/libnetwork/drivers/bridge/internal/firewaller" |
| 16 | 17 |
"github.com/docker/docker/daemon/libnetwork/portmapperapi" |
| 17 | 18 |
"github.com/docker/docker/daemon/libnetwork/types" |
| 18 |
- "github.com/docker/docker/internal/otelutil" |
|
| 19 | 19 |
"go.opentelemetry.io/otel" |
| 20 | 20 |
"go.opentelemetry.io/otel/attribute" |
| 21 | 21 |
"go.opentelemetry.io/otel/baggage" |
| ... | ... |
@@ -13,8 +13,8 @@ import ( |
| 13 | 13 |
"path/filepath" |
| 14 | 14 |
|
| 15 | 15 |
"github.com/containerd/log" |
| 16 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 16 | 17 |
"github.com/docker/docker/daemon/libnetwork/types" |
| 17 |
- "github.com/docker/docker/internal/otelutil" |
|
| 18 | 18 |
"github.com/docker/docker/pkg/stringid" |
| 19 | 19 |
"github.com/moby/sys/reexec" |
| 20 | 20 |
"github.com/opencontainers/runtime-spec/specs-go" |
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
clustertypes "github.com/docker/docker/daemon/cluster/provider" |
| 15 | 15 |
"github.com/docker/docker/daemon/config" |
| 16 | 16 |
"github.com/docker/docker/daemon/container" |
| 17 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 17 | 18 |
"github.com/docker/docker/daemon/libnetwork" |
| 18 | 19 |
lncluster "github.com/docker/docker/daemon/libnetwork/cluster" |
| 19 | 20 |
"github.com/docker/docker/daemon/libnetwork/driverapi" |
| ... | ... |
@@ -25,7 +26,6 @@ import ( |
| 25 | 25 |
"github.com/docker/docker/daemon/network" |
| 26 | 26 |
"github.com/docker/docker/daemon/pkg/opts" |
| 27 | 27 |
"github.com/docker/docker/errdefs" |
| 28 |
- "github.com/docker/docker/internal/otelutil" |
|
| 29 | 28 |
"github.com/docker/docker/pkg/plugingetter" |
| 30 | 29 |
"github.com/docker/go-connections/nat" |
| 31 | 30 |
"github.com/moby/moby/api/types/backend" |
| ... | ... |
@@ -11,8 +11,8 @@ import ( |
| 11 | 11 |
|
| 12 | 12 |
"github.com/containerd/containerd/v2/defaults" |
| 13 | 13 |
"github.com/containerd/log" |
| 14 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 14 | 15 |
"github.com/docker/docker/daemon/server/router" |
| 15 |
- "github.com/docker/docker/internal/otelutil" |
|
| 16 | 16 |
"github.com/moby/buildkit/util/grpcerrors" |
| 17 | 17 |
"github.com/moby/buildkit/util/stack" |
| 18 | 18 |
"github.com/moby/buildkit/util/tracing" |
| ... | ... |
@@ -5,12 +5,12 @@ import ( |
| 5 | 5 |
"net/http" |
| 6 | 6 |
|
| 7 | 7 |
"github.com/containerd/log" |
| 8 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 8 | 9 |
"github.com/docker/docker/daemon/server/httpstatus" |
| 9 | 10 |
"github.com/docker/docker/daemon/server/httputils" |
| 10 | 11 |
"github.com/docker/docker/daemon/server/middleware" |
| 11 | 12 |
"github.com/docker/docker/daemon/server/router" |
| 12 | 13 |
"github.com/docker/docker/dockerversion" |
| 13 |
- "github.com/docker/docker/internal/otelutil" |
|
| 14 | 14 |
"github.com/gorilla/mux" |
| 15 | 15 |
"github.com/moby/moby/api/types" |
| 16 | 16 |
"github.com/moby/moby/api/types/versions" |
| ... | ... |
@@ -11,8 +11,8 @@ import ( |
| 11 | 11 |
mobyc8dstore "github.com/docker/docker/daemon/containerd" |
| 12 | 12 |
"github.com/docker/docker/daemon/internal/libcontainerd" |
| 13 | 13 |
"github.com/docker/docker/daemon/internal/metrics" |
| 14 |
+ "github.com/docker/docker/daemon/internal/otelutil" |
|
| 14 | 15 |
"github.com/docker/docker/errdefs" |
| 15 |
- "github.com/docker/docker/internal/otelutil" |
|
| 16 | 16 |
"github.com/moby/moby/api/types/backend" |
| 17 | 17 |
"github.com/moby/moby/api/types/events" |
| 18 | 18 |
"github.com/pkg/errors" |
| 19 | 19 |
deleted file mode 100644 |
| ... | ... |
@@ -1,43 +0,0 @@ |
| 1 |
-package otelutil |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "context" |
|
| 5 |
- |
|
| 6 |
- "github.com/containerd/log" |
|
| 7 |
- "go.opentelemetry.io/otel/baggage" |
|
| 8 |
-) |
|
| 9 |
- |
|
| 10 |
-// TriggerKey is the key used for the 'trigger' member in the baggage. It is |
|
| 11 |
-// used to know what triggered a code path (e.g. API call, libnet init, etc...) |
|
| 12 |
-const TriggerKey = "trigger" |
|
| 13 |
- |
|
| 14 |
-// MustNewBaggage creates an OTel Baggage containing the provided members. It |
|
| 15 |
-// panics if the baggage cannot be created. |
|
| 16 |
-// |
|
| 17 |
-// DO NOT USE this function with dynamic values. |
|
| 18 |
-func MustNewBaggage(members ...baggage.Member) baggage.Baggage {
|
|
| 19 |
- b, err := baggage.New(members...) |
|
| 20 |
- if err != nil {
|
|
| 21 |
- log.G(context.Background()).WithFields(log.Fields{
|
|
| 22 |
- "error": err, |
|
| 23 |
- "members": members, |
|
| 24 |
- }).Fatal("OTel baggage creation failure")
|
|
| 25 |
- } |
|
| 26 |
- return b |
|
| 27 |
-} |
|
| 28 |
- |
|
| 29 |
-// MustNewMemberRaw creates an OTel Baggage member with the provided key and |
|
| 30 |
-// value. It panics if the key or value aren't valid UTF-8 strings. |
|
| 31 |
-// |
|
| 32 |
-// DO NOT USE this function with dynamic key/value. |
|
| 33 |
-func MustNewMemberRaw(key, value string) baggage.Member {
|
|
| 34 |
- m, err := baggage.NewMemberRaw(key, value) |
|
| 35 |
- if err != nil {
|
|
| 36 |
- log.G(context.Background()).WithFields(log.Fields{
|
|
| 37 |
- "error": err, |
|
| 38 |
- "key": key, |
|
| 39 |
- "value": value, |
|
| 40 |
- }).Fatal("OTel baggage member creation failure")
|
|
| 41 |
- } |
|
| 42 |
- return m |
|
| 43 |
-} |
| 44 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,71 +0,0 @@ |
| 1 |
-package otelutil |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "os" |
|
| 5 |
-) |
|
| 6 |
- |
|
| 7 |
-const ( |
|
| 8 |
- traceParentKey = "traceparent" |
|
| 9 |
- traceStateKey = "tracestate" |
|
| 10 |
- |
|
| 11 |
- // See https://github.com/open-telemetry/opentelemetry-specification/issues/740 |
|
| 12 |
- // and https://github.com/open-telemetry/oteps/pull/258. |
|
| 13 |
- traceParentEnvVar = "TRACEPARENT" |
|
| 14 |
- traceStateEnvVar = "TRACESTATE" |
|
| 15 |
-) |
|
| 16 |
- |
|
| 17 |
-type EnvironCarrier struct {
|
|
| 18 |
- TraceParent, TraceState string |
|
| 19 |
-} |
|
| 20 |
- |
|
| 21 |
-// Get returns the value associated with the passed key. |
|
| 22 |
-func (c *EnvironCarrier) Get(key string) string {
|
|
| 23 |
- switch key {
|
|
| 24 |
- case traceParentKey: |
|
| 25 |
- return c.TraceParent |
|
| 26 |
- case traceStateKey: |
|
| 27 |
- return c.TraceState |
|
| 28 |
- } |
|
| 29 |
- return "" |
|
| 30 |
-} |
|
| 31 |
- |
|
| 32 |
-// Set stores the key-value pair. |
|
| 33 |
-func (c *EnvironCarrier) Set(key, value string) {
|
|
| 34 |
- switch key {
|
|
| 35 |
- case traceParentKey: |
|
| 36 |
- c.TraceParent = value |
|
| 37 |
- case traceStateKey: |
|
| 38 |
- c.TraceState = value |
|
| 39 |
- } |
|
| 40 |
- // Other keys are not supported at this time. |
|
| 41 |
-} |
|
| 42 |
- |
|
| 43 |
-// Keys lists the keys stored in this carrier. |
|
| 44 |
-func (c *EnvironCarrier) Keys() []string {
|
|
| 45 |
- var k []string |
|
| 46 |
- if c.TraceParent != "" {
|
|
| 47 |
- k = append(k, traceParentKey) |
|
| 48 |
- } |
|
| 49 |
- if c.TraceState != "" {
|
|
| 50 |
- k = append(k, traceStateKey) |
|
| 51 |
- } |
|
| 52 |
- return k |
|
| 53 |
-} |
|
| 54 |
- |
|
| 55 |
-func (c *EnvironCarrier) Environ() []string {
|
|
| 56 |
- var env []string |
|
| 57 |
- if c.TraceParent != "" {
|
|
| 58 |
- env = append(env, traceParentEnvVar+"="+c.TraceParent) |
|
| 59 |
- } |
|
| 60 |
- if c.TraceState != "" {
|
|
| 61 |
- env = append(env, traceStateEnvVar+"="+c.TraceState) |
|
| 62 |
- } |
|
| 63 |
- return env |
|
| 64 |
-} |
|
| 65 |
- |
|
| 66 |
-func PropagateFromEnvironment() *EnvironCarrier {
|
|
| 67 |
- return &EnvironCarrier{
|
|
| 68 |
- TraceParent: os.Getenv(traceParentEnvVar), |
|
| 69 |
- TraceState: os.Getenv(traceStateEnvVar), |
|
| 70 |
- } |
|
| 71 |
-} |
| 72 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,39 +0,0 @@ |
| 1 |
-package otelutil |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "context" |
|
| 5 |
- |
|
| 6 |
- "github.com/containerd/log" |
|
| 7 |
- "github.com/moby/buildkit/util/tracing/detect" |
|
| 8 |
- "go.opentelemetry.io/contrib/processors/baggagecopy" |
|
| 9 |
- "go.opentelemetry.io/otel/baggage" |
|
| 10 |
- "go.opentelemetry.io/otel/sdk/resource" |
|
| 11 |
- sdktrace "go.opentelemetry.io/otel/sdk/trace" |
|
| 12 |
- "go.opentelemetry.io/otel/trace" |
|
| 13 |
- "go.opentelemetry.io/otel/trace/noop" |
|
| 14 |
-) |
|
| 15 |
- |
|
| 16 |
-func NewTracerProvider(ctx context.Context, allowNoop bool) (trace.TracerProvider, func(context.Context) error) {
|
|
| 17 |
- noopShutdown := func(ctx context.Context) error { return nil }
|
|
| 18 |
- |
|
| 19 |
- exp, err := detect.NewSpanExporter(ctx) |
|
| 20 |
- if err != nil {
|
|
| 21 |
- log.G(ctx).WithError(err).Warn("Failed to initialize tracing, skipping")
|
|
| 22 |
- if allowNoop {
|
|
| 23 |
- return noop.NewTracerProvider(), noopShutdown |
|
| 24 |
- } |
|
| 25 |
- } |
|
| 26 |
- |
|
| 27 |
- if allowNoop && detect.IsNoneSpanExporter(exp) {
|
|
| 28 |
- log.G(ctx).Info("OTEL tracing is not configured, using no-op tracer provider")
|
|
| 29 |
- return noop.NewTracerProvider(), noopShutdown |
|
| 30 |
- } |
|
| 31 |
- |
|
| 32 |
- tp := sdktrace.NewTracerProvider( |
|
| 33 |
- sdktrace.WithResource(resource.Default()), |
|
| 34 |
- sdktrace.WithSyncer(detect.Recorder), |
|
| 35 |
- sdktrace.WithBatcher(exp), |
|
| 36 |
- sdktrace.WithSpanProcessor(baggagecopy.NewSpanProcessor(func(member baggage.Member) bool { return true })),
|
|
| 37 |
- ) |
|
| 38 |
- return tp, tp.Shutdown |
|
| 39 |
-} |
| 40 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,17 +0,0 @@ |
| 1 |
-package otelutil |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "go.opentelemetry.io/otel/codes" |
|
| 5 |
- "go.opentelemetry.io/otel/trace" |
|
| 6 |
-) |
|
| 7 |
- |
|
| 8 |
-// RecordStatus records the status of a span based on the error provided. |
|
| 9 |
-// |
|
| 10 |
-// If err is nil, the span status is unmodified. If err is not nil, the span |
|
| 11 |
-// takes status Error, and the error message is recorded. |
|
| 12 |
-func RecordStatus(span trace.Span, err error) {
|
|
| 13 |
- if err != nil {
|
|
| 14 |
- span.RecordError(err) |
|
| 15 |
- span.SetStatus(codes.Error, err.Error()) |
|
| 16 |
- } |
|
| 17 |
-} |