mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 06:19:57 +00:00
TUN-528: Move cloudflared into a separate repo
This commit is contained in:
198
vendor/github.com/opentracing/opentracing-go/ext/tags.go
generated
vendored
Normal file
198
vendor/github.com/opentracing/opentracing-go/ext/tags.go
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
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 = uint32TagName("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)
|
||||
}
|
148
vendor/github.com/opentracing/opentracing-go/ext/tags_test.go
generated
vendored
Normal file
148
vendor/github.com/opentracing/opentracing-go/ext/tags_test.go
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
package ext_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
"github.com/opentracing/opentracing-go/mocktracer"
|
||||
)
|
||||
|
||||
func TestPeerTags(t *testing.T) {
|
||||
if ext.PeerService != "peer.service" {
|
||||
t.Fatalf("Invalid PeerService %v", ext.PeerService)
|
||||
}
|
||||
tracer := mocktracer.New()
|
||||
span := tracer.StartSpan("my-trace")
|
||||
ext.PeerService.Set(span, "my-service")
|
||||
ext.PeerAddress.Set(span, "my-hostname:8080")
|
||||
ext.PeerHostname.Set(span, "my-hostname")
|
||||
ext.PeerHostIPv4.Set(span, uint32(127<<24|1))
|
||||
ext.PeerHostIPv6.Set(span, "::")
|
||||
ext.PeerPort.Set(span, uint16(8080))
|
||||
ext.SamplingPriority.Set(span, uint16(1))
|
||||
ext.SpanKind.Set(span, ext.SpanKindRPCServerEnum)
|
||||
ext.SpanKindRPCClient.Set(span)
|
||||
span.Finish()
|
||||
|
||||
rawSpan := tracer.FinishedSpans()[0]
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"peer.service": "my-service",
|
||||
"peer.address": "my-hostname:8080",
|
||||
"peer.hostname": "my-hostname",
|
||||
"peer.ipv4": uint32(127<<24 | 1),
|
||||
"peer.ipv6": "::",
|
||||
"peer.port": uint16(8080),
|
||||
"span.kind": ext.SpanKindRPCClientEnum,
|
||||
}, rawSpan.Tags())
|
||||
assert.True(t, span.Context().(mocktracer.MockSpanContext).Sampled)
|
||||
ext.SamplingPriority.Set(span, uint16(0))
|
||||
assert.False(t, span.Context().(mocktracer.MockSpanContext).Sampled)
|
||||
}
|
||||
|
||||
func TestHTTPTags(t *testing.T) {
|
||||
tracer := mocktracer.New()
|
||||
span := tracer.StartSpan("my-trace", ext.SpanKindRPCServer)
|
||||
ext.HTTPUrl.Set(span, "test.biz/uri?protocol=false")
|
||||
ext.HTTPMethod.Set(span, "GET")
|
||||
ext.HTTPStatusCode.Set(span, 301)
|
||||
span.Finish()
|
||||
|
||||
rawSpan := tracer.FinishedSpans()[0]
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"http.url": "test.biz/uri?protocol=false",
|
||||
"http.method": "GET",
|
||||
"http.status_code": uint16(301),
|
||||
"span.kind": ext.SpanKindRPCServerEnum,
|
||||
}, rawSpan.Tags())
|
||||
}
|
||||
|
||||
func TestDBTags(t *testing.T) {
|
||||
tracer := mocktracer.New()
|
||||
span := tracer.StartSpan("my-trace", ext.SpanKindRPCClient)
|
||||
ext.DBInstance.Set(span, "127.0.0.1:3306/customers")
|
||||
ext.DBStatement.Set(span, "SELECT * FROM user_table")
|
||||
ext.DBType.Set(span, "sql")
|
||||
ext.DBUser.Set(span, "customer_user")
|
||||
span.Finish()
|
||||
|
||||
rawSpan := tracer.FinishedSpans()[0]
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"db.instance": "127.0.0.1:3306/customers",
|
||||
"db.statement": "SELECT * FROM user_table",
|
||||
"db.type": "sql",
|
||||
"db.user": "customer_user",
|
||||
"span.kind": ext.SpanKindRPCClientEnum,
|
||||
}, rawSpan.Tags())
|
||||
}
|
||||
|
||||
func TestMiscTags(t *testing.T) {
|
||||
tracer := mocktracer.New()
|
||||
span := tracer.StartSpan("my-trace")
|
||||
ext.Component.Set(span, "my-awesome-library")
|
||||
ext.SamplingPriority.Set(span, 1)
|
||||
ext.Error.Set(span, true)
|
||||
|
||||
span.Finish()
|
||||
|
||||
rawSpan := tracer.FinishedSpans()[0]
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"component": "my-awesome-library",
|
||||
"error": true,
|
||||
}, rawSpan.Tags())
|
||||
}
|
||||
|
||||
func TestRPCServerOption(t *testing.T) {
|
||||
tracer := mocktracer.New()
|
||||
parent := tracer.StartSpan("my-trace")
|
||||
parent.SetBaggageItem("bag", "gage")
|
||||
|
||||
carrier := opentracing.HTTPHeadersCarrier{}
|
||||
err := tracer.Inject(parent.Context(), opentracing.HTTPHeaders, carrier)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
parCtx, err := tracer.Extract(opentracing.HTTPHeaders, carrier)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tracer.StartSpan("my-child", ext.RPCServerOption(parCtx)).Finish()
|
||||
|
||||
rawSpan := tracer.FinishedSpans()[0]
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"span.kind": ext.SpanKindRPCServerEnum,
|
||||
}, rawSpan.Tags())
|
||||
assert.Equal(t, map[string]string{
|
||||
"bag": "gage",
|
||||
}, rawSpan.Context().(mocktracer.MockSpanContext).Baggage)
|
||||
}
|
||||
|
||||
func TestMessageBusProducerTags(t *testing.T) {
|
||||
tracer := mocktracer.New()
|
||||
span := tracer.StartSpan("my-trace", ext.SpanKindProducer)
|
||||
ext.MessageBusDestination.Set(span, "topic name")
|
||||
span.Finish()
|
||||
|
||||
rawSpan := tracer.FinishedSpans()[0]
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"message_bus.destination": "topic name",
|
||||
"span.kind": ext.SpanKindProducerEnum,
|
||||
}, rawSpan.Tags())
|
||||
}
|
||||
|
||||
func TestMessageBusConsumerTags(t *testing.T) {
|
||||
tracer := mocktracer.New()
|
||||
span := tracer.StartSpan("my-trace", ext.SpanKindConsumer)
|
||||
ext.MessageBusDestination.Set(span, "topic name")
|
||||
span.Finish()
|
||||
|
||||
rawSpan := tracer.FinishedSpans()[0]
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"message_bus.destination": "topic name",
|
||||
"span.kind": ext.SpanKindConsumerEnum,
|
||||
}, rawSpan.Tags())
|
||||
}
|
Reference in New Issue
Block a user