Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add component tag to tracing spans #923

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add -go suffix since we have tchannel library for java as well.


// 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
Loading