mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-01 00:23:56 +08:00 
			
		
		
		
	enable opentelemetry support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
		
							
								
								
									
										30
									
								
								util/tracing/trace.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								util/tracing/trace.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| package tracing | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"os" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/moby/buildkit/util/tracing/detect" | ||||
| 	"go.opentelemetry.io/otel/attribute" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| ) | ||||
|  | ||||
| func TraceCurrentCommand(ctx context.Context, name string) (context.Context, func(error), error) { | ||||
| 	tp, err := detect.TracerProvider() | ||||
| 	if err != nil { | ||||
| 		return context.Background(), nil, err | ||||
| 	} | ||||
| 	ctx, span := tp.Tracer("").Start(ctx, name, trace.WithAttributes( | ||||
| 		attribute.String("command", strings.Join(os.Args, " ")), | ||||
| 	)) | ||||
|  | ||||
| 	return ctx, func(err error) { | ||||
| 		if err != nil { | ||||
| 			span.RecordError(err) | ||||
| 		} | ||||
| 		span.End() | ||||
|  | ||||
| 		detect.Shutdown(context.TODO()) | ||||
| 	}, nil | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Tonis Tiigi
					Tonis Tiigi