Documentation ¶
Overview ¶
Package opentracing-exts provides opentracing span options and span logging utilities.
See https://github.com/opentracing/specification/blob/master/semantic_conventions.md.
Index ¶
- Constants
- func LogError(span opentracing.Span, err error)
- func LogErrorWithFields(span opentracing.Span, err error, fields map[string]interface{})
- func LogErrorf(span opentracing.Span, err error, format string, args ...interface{})
- func SetDBTags(span opentracing.Span, t DBTags)
- func SetHTTPTags(span opentracing.Span, t HTTPTags)
- func SetRPCTags(span opentracing.Span, t RPCTags)
- type DBTags
- type HTTPTags
- type LogFields
- type RPCTags
Examples ¶
Constants ¶
const ( LogFieldErrorKind = "error.kind" LogFieldErrorObject = "error.object" LogFieldEvent = "event" LogFieldMessage = "message" LogFieldStack = "stack" LogEventError = "error" )
Standard opentracing log field names. See https://github.com/opentracing/specification/blob/master/semantic_conventions.md#log-fields-table.
Variables ¶
This section is empty.
Functions ¶
func LogError ¶
func LogError(span opentracing.Span, err error)
LogError logs an error for an opentracing span, setting the standard error tags and log fields.
func LogErrorWithFields ¶
LogErrorWithFields logs an error with the specified extra lof fields for an opentracing span, setting the standard error tags and log fields. The log field names "event", "error.kind", and "message" are reserved and will be ignored if set in the specified fields.
func LogErrorf ¶
LogErrorf logs an error with the specified format for an opentracing span, setting the standard error tags and log fields.
func SetDBTags ¶
func SetDBTags(span opentracing.Span, t DBTags)
SetDBTags sets the standard database tags on the specified span.
func SetHTTPTags ¶
func SetHTTPTags(span opentracing.Span, t HTTPTags)
SetHTTPTags sets the standard HTTP tags on the specified span.
func SetRPCTags ¶
func SetRPCTags(span opentracing.Span, t RPCTags)
SetRPCTags sets the standard RPC tags on the specified span.
Types ¶
type DBTags ¶
type DBTags struct { Type string // The database type. Instance string // The database instance name. User string // The username of the database accessor. Statement string // The database statement used. // Optional tags that describe the database peer. PeerAddr string // The remote address. PeerHostname string // The remote hostname. PeerIPv4 net.IP // The remote IPv4 address. PeerIPv6 net.IP // The remote IPv6 address. PeerPort uint16 // The remote port. PeerService string // The remote service name. }
DBTags is an opentracing.StartSpanOption that sets the standard database tags for a database client call.
Example (Nosql) ¶
// Start a new span with database client tags set. span := opentracing.StartSpan("name", otexts.DBTags{ Type: "redis", Instance: "test", User: "username", Statement: "SET mykey 'WuValue'", }) defer span.Finish()
Output:
Example (Sql) ¶
// Start a new span with database client tags set. span := opentracing.StartSpan("name", otexts.DBTags{ Type: "sql", Instance: "test", User: "username", Statement: "SELECT * FROM test", }) defer span.Finish()
Output:
type HTTPTags ¶
type HTTPTags struct { Method string // The HTTP request method. URL string // The HTTP request URL. StatusCode int // The HTTP response status code. }
HTTPTags is an opentracing.StartSpanOption that sets the standard HTTP tags.
See https://github.com/opentracing/specification/blob/master/semantic_conventions.md#span-tags-table.
Example ¶
// Start a new span with HTTP tags set. span := opentracing.StartSpan("name", otexts.HTTPTags{ Method: http.MethodGet, URL: "http://example.com/test?foo=bar", StatusCode: http.StatusOK, }) defer span.Finish()
Output:
type LogFields ¶
type LogFields map[string]interface{}
LogFields is a map of opentracing span log field names to values.
type RPCTags ¶
type RPCTags struct { Kind ext.SpanKindEnum // The span kind, "client" or "server". // Optional tags that describe the RPC peer. PeerAddr string // The remote address. PeerHostname string // The remote hostname. PeerIPv4 net.IP // The remote IPv4 address. PeerIPv6 net.IP // The remote IPv6 address. PeerPort uint16 // The remote port. PeerService string // The remote service name. }
RPCTags is an opentracing.StartSpanOption that sets the standard RPC tags.
See https://github.com/opentracing/specification/blob/master/semantic_conventions.md#rpcs.
Example (Client) ¶
// Start a new span with RPC client tags set. span := opentracing.StartSpan("name", otexts.RPCTags{ Kind: ext.SpanKindRPCClientEnum, PeerAddr: "http://service.name.io/", PeerService: "service", }) defer span.Finish()
Output:
Example (Server) ¶
// Start a new span with RPC server tags set. span := opentracing.StartSpan("name", otexts.RPCTags{ Kind: ext.SpanKindRPCServerEnum, PeerAddr: "http://service.name.io/", PeerService: "service", PeerIPv4: net.IPv4(127, 0, 0, 1), PeerPort: 8080, }) defer span.Finish()
Output: