Skip to content

Commit

Permalink
Add component tag to tracing spans (#923)
Browse files Browse the repository at this point in the history
This PR is making a minor change to add span component tag to tracing spans. According to the [OpneTracing sematic conventions](https://github.com/opentracing/specification/blob/master/semantic_conventions.md), the component tag indicates the library that created the spans. At Uber, It is quite useful for the tracing team to understand the span creation distribution among libraries in order to optimize the operational cost.
> The software package, framework, library, or module that generated the associated Span. E.g., "grpc", "django", "JDBI".
  • Loading branch information
ChenX1993 authored Oct 8, 2024
1 parent af146f5 commit efa094c
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 efa094c

Please sign in to comment.