forked from Azure/azure-event-hubs-go
/
tracing.go
61 lines (52 loc) · 2.29 KB
/
tracing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package eventhub
import (
"context"
"os"
"github.com/opentracing/opentracing-go"
tag "github.com/opentracing/opentracing-go/ext"
)
func (h *Hub) startSpanFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context) {
span, ctx := opentracing.StartSpanFromContext(ctx, operationName, opts...)
ApplyComponentInfo(span)
return span, ctx
}
func (ns *namespace) startSpanFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context) {
span, ctx := opentracing.StartSpanFromContext(ctx, operationName, opts...)
ApplyComponentInfo(span)
return span, ctx
}
func (s *sender) startProducerSpanFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context) {
span, ctx := opentracing.StartSpanFromContext(ctx, operationName, opts...)
ApplyComponentInfo(span)
tag.SpanKindProducer.Set(span)
tag.MessageBusDestination.Set(span, s.getFullIdentifier())
return span, ctx
}
func (r *receiver) startConsumerSpanFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context) {
span, ctx := opentracing.StartSpanFromContext(ctx, operationName, opts...)
ApplyComponentInfo(span)
tag.SpanKindConsumer.Set(span)
tag.MessageBusDestination.Set(span, r.getFullIdentifier())
return span, ctx
}
func (r *receiver) startConsumerSpanFromWire(ctx context.Context, operationName string, reference opentracing.SpanContext, opts ...opentracing.StartSpanOption) (opentracing.Span, context.Context) {
opts = append(opts, opentracing.FollowsFrom(reference))
span := opentracing.StartSpan(operationName, opts...)
ctx = opentracing.ContextWithSpan(ctx, span)
ApplyComponentInfo(span)
tag.SpanKindConsumer.Set(span)
tag.MessageBusDestination.Set(span, r.getFullIdentifier())
return span, ctx
}
// ApplyComponentInfo applies eventhub library and network info to the span
func ApplyComponentInfo(span opentracing.Span) {
tag.Component.Set(span, "github.com/Azure/azure-event-hubs-go")
span.SetTag("version", Version)
applyNetworkInfo(span)
}
func applyNetworkInfo(span opentracing.Span) {
hostname, err := os.Hostname()
if err == nil {
tag.PeerHostname.Set(span, hostname)
}
}