@@ -21,13 +21,10 @@ import (
2121
2222 snapshotsapi "github.com/containerd/containerd/api/services/snapshots/v1"
2323 ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
24- "go.opentelemetry.io/otel"
2524 "go.opentelemetry.io/otel/attribute"
2625 "go.opentelemetry.io/otel/trace"
2726)
2827
29- const tracerName = "accelerated-container-image/snapshotter"
30-
3128// TracingSnapshotter wraps a snapshotter service with OpenTelemetry tracing
3229type TracingSnapshotter struct {
3330 server snapshotsapi.SnapshotsServer
@@ -45,7 +42,7 @@ func WithTracing(server snapshotsapi.SnapshotsServer) snapshotsapi.SnapshotsServ
4542}
4643
4744func (s * TracingSnapshotter ) Prepare (ctx context.Context , pr * snapshotsapi.PrepareSnapshotRequest ) (* snapshotsapi.PrepareSnapshotResponse , error ) {
48- ctx , span := otel . GetTracerProvider (). Tracer ( tracerName ).Start (ctx , "snapshotter.Prepare" , trace .WithAttributes (
45+ ctx , span := GetDefaultTracer ( ).Start (ctx , "snapshotter.Prepare" , trace .WithAttributes (
4946 attribute .String ("key" , pr .Key ),
5047 attribute .String ("parent" , pr .Parent ),
5148 ))
@@ -59,7 +56,7 @@ func (s *TracingSnapshotter) Prepare(ctx context.Context, pr *snapshotsapi.Prepa
5956}
6057
6158func (s * TracingSnapshotter ) View (ctx context.Context , pr * snapshotsapi.ViewSnapshotRequest ) (* snapshotsapi.ViewSnapshotResponse , error ) {
62- ctx , span := otel . GetTracerProvider (). Tracer ( tracerName ).Start (ctx , "snapshotter.View" , trace .WithAttributes (
59+ ctx , span := GetDefaultTracer ( ).Start (ctx , "snapshotter.View" , trace .WithAttributes (
6360 attribute .String ("key" , pr .Key ),
6461 attribute .String ("parent" , pr .Parent ),
6562 ))
@@ -73,7 +70,7 @@ func (s *TracingSnapshotter) View(ctx context.Context, pr *snapshotsapi.ViewSnap
7370}
7471
7572func (s * TracingSnapshotter ) Mounts (ctx context.Context , mr * snapshotsapi.MountsRequest ) (* snapshotsapi.MountsResponse , error ) {
76- ctx , span := otel . GetTracerProvider (). Tracer ( tracerName ).Start (ctx , "snapshotter.Mounts" , trace .WithAttributes (
73+ ctx , span := GetDefaultTracer ( ).Start (ctx , "snapshotter.Mounts" , trace .WithAttributes (
7774 attribute .String ("key" , mr .Key ),
7875 ))
7976 defer span .End ()
@@ -86,7 +83,7 @@ func (s *TracingSnapshotter) Mounts(ctx context.Context, mr *snapshotsapi.Mounts
8683}
8784
8885func (s * TracingSnapshotter ) Commit (ctx context.Context , cr * snapshotsapi.CommitSnapshotRequest ) (* ptypes.Empty , error ) {
89- ctx , span := otel . GetTracerProvider (). Tracer ( tracerName ).Start (ctx , "snapshotter.Commit" , trace .WithAttributes (
86+ ctx , span := GetDefaultTracer ( ).Start (ctx , "snapshotter.Commit" , trace .WithAttributes (
9087 attribute .String ("name" , cr .Name ),
9188 attribute .String ("key" , cr .Key ),
9289 ))
@@ -100,7 +97,7 @@ func (s *TracingSnapshotter) Commit(ctx context.Context, cr *snapshotsapi.Commit
10097}
10198
10299func (s * TracingSnapshotter ) Remove (ctx context.Context , rr * snapshotsapi.RemoveSnapshotRequest ) (* ptypes.Empty , error ) {
103- ctx , span := otel . GetTracerProvider (). Tracer ( tracerName ).Start (ctx , "snapshotter.Remove" , trace .WithAttributes (
100+ ctx , span := GetDefaultTracer ( ).Start (ctx , "snapshotter.Remove" , trace .WithAttributes (
104101 attribute .String ("key" , rr .Key ),
105102 ))
106103 defer span .End ()
@@ -113,20 +110,12 @@ func (s *TracingSnapshotter) Remove(ctx context.Context, rr *snapshotsapi.Remove
113110}
114111
115112func (s * TracingSnapshotter ) Stat (ctx context.Context , sr * snapshotsapi.StatSnapshotRequest ) (* snapshotsapi.StatSnapshotResponse , error ) {
116- ctx , span := otel .GetTracerProvider ().Tracer (tracerName ).Start (ctx , "snapshotter.Stat" , trace .WithAttributes (
117- attribute .String ("key" , sr .Key ),
118- ))
119- defer span .End ()
120-
121113 resp , err := s .server .Stat (ctx , sr )
122- if err != nil {
123- span .RecordError (err )
124- }
125114 return resp , err
126115}
127116
128117func (s * TracingSnapshotter ) Update (ctx context.Context , sr * snapshotsapi.UpdateSnapshotRequest ) (* snapshotsapi.UpdateSnapshotResponse , error ) {
129- ctx , span := otel . GetTracerProvider (). Tracer ( tracerName ).Start (ctx , "snapshotter.Update" , trace .WithAttributes (
118+ ctx , span := GetDefaultTracer ( ).Start (ctx , "snapshotter.Update" , trace .WithAttributes (
130119 attribute .String ("name" , sr .Info .Name ),
131120 ))
132121 defer span .End ()
@@ -139,7 +128,7 @@ func (s *TracingSnapshotter) Update(ctx context.Context, sr *snapshotsapi.Update
139128}
140129
141130func (s * TracingSnapshotter ) List (sr * snapshotsapi.ListSnapshotsRequest , ss snapshotsapi.Snapshots_ListServer ) error {
142- ctx , span := otel . GetTracerProvider (). Tracer ( tracerName ).Start (ss .Context (), "snapshotter.List" )
131+ ctx , span := GetDefaultTracer ( ).Start (ss .Context (), "snapshotter.List" )
143132 defer span .End ()
144133
145134 err := s .server .List (sr , & tracingListServer {
@@ -162,26 +151,12 @@ func (t *tracingListServer) Context() context.Context {
162151}
163152
164153func (s * TracingSnapshotter ) Usage (ctx context.Context , ur * snapshotsapi.UsageRequest ) (* snapshotsapi.UsageResponse , error ) {
165- ctx , span := otel .GetTracerProvider ().Tracer (tracerName ).Start (ctx , "snapshotter.Usage" , trace .WithAttributes (
166- attribute .String ("key" , ur .Key ),
167- ))
168- defer span .End ()
169-
170154 resp , err := s .server .Usage (ctx , ur )
171- if err != nil {
172- span .RecordError (err )
173- }
174- if resp != nil {
175- span .SetAttributes (
176- attribute .Int64 ("inodes" , resp .Inodes ),
177- attribute .Int64 ("size" , resp .Size ),
178- )
179- }
180155 return resp , err
181156}
182157
183158func (s * TracingSnapshotter ) Cleanup (ctx context.Context , cr * snapshotsapi.CleanupRequest ) (* ptypes.Empty , error ) {
184- ctx , span := otel . GetTracerProvider (). Tracer ( tracerName ).Start (ctx , "snapshotter.Cleanup" )
159+ ctx , span := GetDefaultTracer ( ).Start (ctx , "snapshotter.Cleanup" )
185160 defer span .End ()
186161
187162 resp , err := s .server .Cleanup (ctx , cr )
0 commit comments