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