mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 22:00:02 +00:00
TUN-6689: Utilize new RegisterUDPSession to begin tracing
This commit is contained in:
@@ -93,7 +93,7 @@ type TracedContext struct {
|
||||
*cfdTracer
|
||||
}
|
||||
|
||||
// NewTracedHTTPRequest creates a new tracer for the current HTTP request context.
|
||||
// NewTracedContext creates a new tracer for the current context.
|
||||
func NewTracedContext(ctx context.Context, traceContext string, log *zerolog.Logger) *TracedContext {
|
||||
ctx, exists := extractTraceFromString(ctx, traceContext)
|
||||
if !exists {
|
||||
@@ -155,6 +155,24 @@ func (cft *cfdTracer) GetSpans() (enc string) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetProtoSpans returns the spans as the otlp traces in protobuf byte array.
|
||||
func (cft *cfdTracer) GetProtoSpans() (proto []byte) {
|
||||
proto, err := cft.exporter.ProtoSpans()
|
||||
switch err {
|
||||
case nil:
|
||||
break
|
||||
case errNoTraces:
|
||||
cft.log.Trace().Err(err).Msgf("expected traces to be available")
|
||||
return
|
||||
case errNoopTracer:
|
||||
return // noop tracer has no traces
|
||||
default:
|
||||
cft.log.Debug().Err(err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AddSpans assigns spans as base64 encoded protobuf otlp traces to provided
|
||||
// HTTP headers.
|
||||
func (cft *cfdTracer) AddSpans(headers http.Header) {
|
||||
@@ -171,6 +189,11 @@ func (cft *cfdTracer) AddSpans(headers http.Header) {
|
||||
headers[CanonicalCloudflaredTracingHeader] = []string{enc}
|
||||
}
|
||||
|
||||
// End will set the OK status for the span and then end it.
|
||||
func End(span trace.Span) {
|
||||
endSpan(span, -1, codes.Ok, nil)
|
||||
}
|
||||
|
||||
// EndWithErrorStatus will set a status for the span and then end it.
|
||||
func EndWithErrorStatus(span trace.Span, err error) {
|
||||
endSpan(span, -1, codes.Error, err)
|
||||
|
Reference in New Issue
Block a user