-
Notifications
You must be signed in to change notification settings - Fork 69
/
tracing.go
87 lines (75 loc) · 2.94 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package eventhub
import (
"context"
"net/http"
"os"
"strconv"
"go.opencensus.io/trace"
)
func (h *Hub) startSpanFromContext(ctx context.Context, operationName string, opts ...trace.StartOption) (*trace.Span, context.Context) {
ctx, span := trace.StartSpan(ctx, operationName, opts...)
ApplyComponentInfo(span)
return span, ctx
}
func (ns *namespace) startSpanFromContext(ctx context.Context, operationName string, opts ...trace.StartOption) (*trace.Span, context.Context) {
ctx, span := trace.StartSpan(ctx, operationName, opts...)
ApplyComponentInfo(span)
return span, ctx
}
func (s *sender) startProducerSpanFromContext(ctx context.Context, operationName string, opts ...trace.StartOption) (*trace.Span, context.Context) {
ctx, span := trace.StartSpan(ctx, operationName, opts...)
ApplyComponentInfo(span)
span.AddAttributes(
trace.StringAttribute("span.kind", "producer"),
trace.StringAttribute("message_bus.destination", s.getFullIdentifier()),
)
return span, ctx
}
func (r *receiver) startConsumerSpanFromContext(ctx context.Context, operationName string, opts ...trace.StartOption) (*trace.Span, context.Context) {
ctx, span := trace.StartSpan(ctx, operationName, opts...)
ApplyComponentInfo(span)
span.AddAttributes(
trace.StringAttribute("span.kind", "consumer"),
trace.StringAttribute("message_bus.destination", r.getFullIdentifier()),
)
return span, ctx
}
func (r *receiver) startConsumerSpanFromWire(ctx context.Context, operationName string, reference trace.SpanContext, opts ...trace.StartOption) (*trace.Span, context.Context) {
ctx, span := trace.StartSpanWithRemoteParent(ctx, operationName, reference, opts...)
ApplyComponentInfo(span)
span.AddAttributes(
trace.StringAttribute("span.kind", "consumer"),
trace.StringAttribute("message_bus.destination", r.getFullIdentifier()),
)
return span, ctx
}
func (em *entityManager) startSpanFromContext(ctx context.Context, operationName string, opts ...trace.StartOption) (*trace.Span, context.Context) {
ctx, span := trace.StartSpan(ctx, operationName, opts...)
ApplyComponentInfo(span)
span.AddAttributes(trace.StringAttribute("span.kind", "client"))
return span, ctx
}
// ApplyComponentInfo applies eventhub library and network info to the span
func ApplyComponentInfo(span *trace.Span) {
span.AddAttributes(
trace.StringAttribute("component", "github.com/Azure/azure-event-hubs-go"),
trace.StringAttribute("version", Version))
applyNetworkInfo(span)
}
func applyNetworkInfo(span *trace.Span) {
hostname, err := os.Hostname()
if err == nil {
span.AddAttributes(trace.StringAttribute("peer.hostname", hostname))
}
}
func applyRequestInfo(span *trace.Span, req *http.Request) {
span.AddAttributes(
trace.StringAttribute("http.url", req.URL.String()),
trace.StringAttribute("http.method", req.Method),
)
}
func applyResponseInfo(span *trace.Span, res *http.Response) {
if res != nil {
span.AddAttributes(trace.StringAttribute("http.status_code", strconv.Itoa(res.StatusCode)))
}
}