github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/tracing/util.go (about)

     1  package tracing
     2  
     3  import (
     4  	"go.opentelemetry.io/otel/attribute"
     5  	"go.opentelemetry.io/otel/codes"
     6  	"go.opentelemetry.io/otel/trace"
     7  
     8  	"github.com/telepresenceio/telepresence/rpc/v2/manager"
     9  )
    10  
    11  func RecordInterceptSpec(span trace.Span, spec *manager.InterceptSpec) {
    12  	span.SetAttributes(
    13  		attribute.String("tel2.service-name", spec.ServiceName),
    14  		attribute.String("tel2.service-namespace", spec.Namespace),
    15  		attribute.String("tel2.mechanism", spec.Mechanism),
    16  		attribute.String("tel2.intercept-name", spec.Name),
    17  		attribute.String("tel2.agent-name", spec.Agent),
    18  		attribute.String("tel2.workload-kind", spec.WorkloadKind),
    19  	)
    20  }
    21  
    22  func RecordInterceptInfo(span trace.Span, info *manager.InterceptInfo) {
    23  	span.SetAttributes(
    24  		attribute.String("tel2.intercept-id", info.Id),
    25  		attribute.String("tel2.session-id", info.ClientSession.SessionId),
    26  		attribute.String("tel2.disposition", info.Disposition.String()),
    27  	)
    28  	if info.Spec != nil {
    29  		RecordInterceptSpec(span, info.Spec)
    30  	}
    31  }
    32  
    33  func EndAndRecord(span trace.Span, err error) {
    34  	if err != nil {
    35  		span.RecordError(err)
    36  		span.SetStatus(codes.Error, err.Error())
    37  	}
    38  	span.End()
    39  }