aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/opentracing/opentracing-go/ext/tags.go
blob: 8800129a237de963045e8780e60f0f4864be3bbd (plain) (blame)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package ext

import opentracing "github.com/opentracing/opentracing-go"

// These constants define common tag names recommended for better portability across
// tracing systems and languages/platforms.
//
// The tag names are defined as typed strings, so that in addition to the usual use
//
//     span.setTag(TagName, value)
//
// they also support value type validation via this additional syntax:
//
//    TagName.Set(span, value)
//
var (
    //////////////////////////////////////////////////////////////////////
    // SpanKind (client/server or producer/consumer)
    //////////////////////////////////////////////////////////////////////

    // SpanKind hints at relationship between spans, e.g. client/server
    SpanKind = spanKindTagName("span.kind")

    // SpanKindRPCClient marks a span representing the client-side of an RPC
    // or other remote call
    SpanKindRPCClientEnum = SpanKindEnum("client")
    SpanKindRPCClient     = opentracing.Tag{Key: string(SpanKind), Value: SpanKindRPCClientEnum}

    // SpanKindRPCServer marks a span representing the server-side of an RPC
    // or other remote call
    SpanKindRPCServerEnum = SpanKindEnum("server")
    SpanKindRPCServer     = opentracing.Tag{Key: string(SpanKind), Value: SpanKindRPCServerEnum}

    // SpanKindProducer marks a span representing the producer-side of a
    // message bus
    SpanKindProducerEnum = SpanKindEnum("producer")
    SpanKindProducer     = opentracing.Tag{Key: string(SpanKind), Value: SpanKindProducerEnum}

    // SpanKindConsumer marks a span representing the consumer-side of a
    // message bus
    SpanKindConsumerEnum = SpanKindEnum("consumer")
    SpanKindConsumer     = opentracing.Tag{Key: string(SpanKind), Value: SpanKindConsumerEnum}

    //////////////////////////////////////////////////////////////////////
    // Component name
    //////////////////////////////////////////////////////////////////////

    // Component is a low-cardinality identifier of the module, library,
    // or package that is generating a span.
    Component = stringTagName("component")

    //////////////////////////////////////////////////////////////////////
    // Sampling hint
    //////////////////////////////////////////////////////////////////////

    // SamplingPriority determines the priority of sampling this Span.
    SamplingPriority = uint16TagName("sampling.priority")

    //////////////////////////////////////////////////////////////////////
    // Peer tags. These tags can be emitted by either client-side of
    // server-side to describe the other side/service in a peer-to-peer
    // communications, like an RPC call.
    //////////////////////////////////////////////////////////////////////

    // PeerService records the service name of the peer.
    PeerService = stringTagName("peer.service")

    // PeerAddress records the address name of the peer. This may be a "ip:port",
    // a bare "hostname", a FQDN or even a database DSN substring
    // like "mysql://username@127.0.0.1:3306/dbname"
    PeerAddress = stringTagName("peer.address")

    // PeerHostname records the host name of the peer
    PeerHostname = stringTagName("peer.hostname")

    // PeerHostIPv4 records IP v4 host address of the peer
    PeerHostIPv4 = ipv4Tag("peer.ipv4")

    // PeerHostIPv6 records IP v6 host address of the peer
    PeerHostIPv6 = stringTagName("peer.ipv6")

    // PeerPort records port number of the peer
    PeerPort = uint16TagName("peer.port")

    //////////////////////////////////////////////////////////////////////
    // HTTP Tags
    //////////////////////////////////////////////////////////////////////

    // HTTPUrl should be the URL of the request being handled in this segment
    // of the trace, in standard URI format. The protocol is optional.
    HTTPUrl = stringTagName("http.url")

    // HTTPMethod is the HTTP method of the request, and is case-insensitive.
    HTTPMethod = stringTagName("http.method")

    // HTTPStatusCode is the numeric HTTP status code (200, 404, etc) of the
    // HTTP response.
    HTTPStatusCode = uint16TagName("http.status_code")

    //////////////////////////////////////////////////////////////////////
    // DB Tags
    //////////////////////////////////////////////////////////////////////

    // DBInstance is database instance name.
    DBInstance = stringTagName("db.instance")

    // DBStatement is a database statement for the given database type.
    // It can be a query or a prepared statement (i.e., before substitution).
    DBStatement = stringTagName("db.statement")

    // DBType is a database type. For any SQL database, "sql".
    // For others, the lower-case database category, e.g. "redis"
    DBType = stringTagName("db.type")

    // DBUser is a username for accessing database.
    DBUser = stringTagName("db.user")

    //////////////////////////////////////////////////////////////////////
    // Message Bus Tag
    //////////////////////////////////////////////////////////////////////

    // MessageBusDestination is an address at which messages can be exchanged
    MessageBusDestination = stringTagName("message_bus.destination")

    //////////////////////////////////////////////////////////////////////
    // Error Tag
    //////////////////////////////////////////////////////////////////////

    // Error indicates that operation represented by the span resulted in an error.
    Error = boolTagName("error")
)

// ---

// SpanKindEnum represents common span types
type SpanKindEnum string

type spanKindTagName string

// Set adds a string tag to the `span`
func (tag spanKindTagName) Set(span opentracing.Span, value SpanKindEnum) {
    span.SetTag(string(tag), value)
}

type rpcServerOption struct {
    clientContext opentracing.SpanContext
}

func (r rpcServerOption) Apply(o *opentracing.StartSpanOptions) {
    if r.clientContext != nil {
        opentracing.ChildOf(r.clientContext).Apply(o)
    }
    SpanKindRPCServer.Apply(o)
}

// RPCServerOption returns a StartSpanOption appropriate for an RPC server span
// with `client` representing the metadata for the remote peer Span if available.
// In case client == nil, due to the client not being instrumented, this RPC
// server span will be a root span.
func RPCServerOption(client opentracing.SpanContext) opentracing.StartSpanOption {
    return rpcServerOption{client}
}

// ---

type stringTagName string

// Set adds a string tag to the `span`
func (tag stringTagName) Set(span opentracing.Span, value string) {
    span.SetTag(string(tag), value)
}

// ---

type uint32TagName string

// Set adds a uint32 tag to the `span`
func (tag uint32TagName) Set(span opentracing.Span, value uint32) {
    span.SetTag(string(tag), value)
}

// ---

type uint16TagName string

// Set adds a uint16 tag to the `span`
func (tag uint16TagName) Set(span opentracing.Span, value uint16) {
    span.SetTag(string(tag), value)
}

// ---

type boolTagName string

// Add adds a bool tag to the `span`
func (tag boolTagName) Set(span opentracing.Span, value bool) {
    span.SetTag(string(tag), value)
}

type ipv4Tag string

// Set adds IP v4 host address of the peer as an uint32 value to the `span`, keep this for backward and zipkin compatibility
func (tag ipv4Tag) Set(span opentracing.Span, value uint32) {
    span.SetTag(string(tag), value)
}

// SetString records IP v4 host address of the peer as a .-separated tuple to the `span`. E.g., "127.0.0.1"
func (tag ipv4Tag) SetString(span opentracing.Span, value string) {
    span.SetTag(string(tag), value)
}