Skip to content

Commit

Permalink
Add component tag to tracing spans
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenX1993 committed Oct 6, 2024
1 parent af146f5 commit 726488c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
// NB: the string value is what's actually shared between implementations
const zipkinSpanFormat = "zipkin-span-format"

const componentName = "tchannel-go"

// Span is an internal representation of Zipkin-compatible OpenTracing Span.
// It is used as OpenTracing inject/extract Carrier with ZipkinSpanFormat.
type Span struct {
Expand Down Expand Up @@ -151,6 +153,7 @@ func (c *Connection) startOutboundSpan(ctx context.Context, serviceName, methodN
}
ext.SpanKindRPCClient.Set(span)
ext.PeerService.Set(span, serviceName)
ext.Component.Set(span, componentName)
c.setPeerHostPort(span)
span.SetTag("as", call.callReq.Headers[ArgScheme])
var injectable injectableSpan
Expand Down Expand Up @@ -214,6 +217,7 @@ func (c *Connection) extractInboundSpan(callReq *callReq) opentracing.Span {
span := c.Tracer().StartSpan(operationName, ext.RPCServerOption(spanCtx))
span.SetTag("as", callReq.Headers[ArgScheme])
ext.PeerService.Set(span, callReq.Headers[CallerName])
ext.Component.Set(span, componentName)
c.setPeerHostPort(span)
return span
}
Expand Down Expand Up @@ -252,6 +256,7 @@ func ExtractInboundSpan(ctx context.Context, call *InboundCall, headers map[stri
}
span = tracer.StartSpan(call.MethodString(), ext.RPCServerOption(parent))
ext.PeerService.Set(span, call.CallerName())
ext.Component.Set(span, componentName)
span.SetTag("as", string(call.Format()))
call.conn.setPeerHostPort(span)
call.Response().span = span
Expand Down
2 changes: 2 additions & 0 deletions tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func TestTracingSpanAttributes(t *testing.T) {
assert.NotNil(t, child.Tag("peer.ipv4"))
assert.NotNil(t, parent.Tag("peer.port"))
assert.NotNil(t, child.Tag("peer.port"))
assert.Equal(t, "tchannel-go", parent.Tag("component"))
assert.Equal(t, "tchannel-go", child.Tag("component"))
})
}

Expand Down

0 comments on commit 726488c

Please sign in to comment.