Documentation ¶
Overview ¶
Example (HttpRoutePatternMatching) ¶
This example demonstrates how to instrument a 3rd-party HTTP router that uses pattern matching to make sure the original path template is forwarded to Instana
package main import ( "log" "net/http" instana "github.com/instana/go-sensor" ) func main() { sensor := instana.NewSensor("my-http-server") // Initialize your router. Here for simplicity we use stdlib http.ServeMux, however you // can use any router that supports http.Handler/http.HandlerFunc, such as github.com/gorilla/mux r := http.NewServeMux() // Wrap the handler using instana.TracingHandlerFunc() and pass the path template // used to route requests to it. This value will be attached to the span and displayed // in UI as `http.path_tpl` if the request path is different (we assume that this request // has been routed to the handler via a matched pattern) r.HandleFunc("/articles/{category}/{id:[0-9]+}", instana.TracingHandlerFunc( sensor, "/articles/{category}/{id:[0-9]+}", func(w http.ResponseWriter, req *http.Request) { // ... }, )) if err := http.ListenAndServe(":0", nil); err != nil { log.Fatalf("failed to start server: %s", err) } }
Output:
Example (RoundTripper) ¶
This example shows how to instrument an HTTP client with Instana tracing
package main import ( "context" "log" "net/http" instana "github.com/instana/go-sensor" "github.com/opentracing/opentracing-go/ext" ) func main() { sensor := instana.NewSensor("my-http-client") // Wrap the original http.Client transport with instana.RoundTripper(). // The http.DefaultTransport will be used if there was no transport provided. client := &http.Client{ Transport: instana.RoundTripper(sensor, nil), } // The call should always start with an entry span (https://docs.instana.io/quick_start/custom_tracing/#always-start-new-traces-with-entry-spans) // Normally this would be your HTTP/GRPC/message queue request span, but here we need to // create it explicitly. sp := sensor.Tracer().StartSpan("client-call") sp.SetTag(string(ext.SpanKind), "entry") req, err := http.NewRequest(http.MethodGet, "https://www.instana.com", nil) if err != nil { log.Fatalf("failed to create request: %s", err) } // Inject the parent span into request context ctx := instana.ContextWithSpan(context.Background(), sp) // Use your instrumented http.Client to propagate tracing context with the request _, err = client.Do(req.WithContext(ctx)) if err != nil { log.Fatalf("failed to GET https://www.instana.com: %s", err) } }
Output:
Example (TracingHandlerFunc) ¶
This example shows how to instrument an HTTP server with Instana tracing
package main import ( "log" "net/http" instana "github.com/instana/go-sensor" ) func main() { sensor := instana.NewSensor("my-http-server") // To instrument a handler function, pass it as an argument to instana.TracingHandlerFunc() http.HandleFunc("/", instana.TracingHandlerFunc(sensor, "/", func(w http.ResponseWriter, req *http.Request) { // Extract the parent span and use its tracer to initialize any child spans to trace the calls // inside the handler, e.g. database queries, 3rd-party API requests, etc. if parent, ok := instana.SpanFromContext(req.Context()); ok { sp := parent.Tracer().StartSpan("index") defer sp.Finish() } // ... w.Write([]byte("OK")) })) // In case your handler is implemented as an http.Handler, pass its ServeHTTP method instead http.HandleFunc("/files", instana.TracingHandlerFunc(sensor, "index", http.FileServer(http.Dir("./")).ServeHTTP)) if err := http.ListenAndServe(":0", nil); err != nil { log.Fatalf("failed to start server: %s", err) } }
Output:
Index ¶
- Constants
- func BatchSize(n int) ot.Tag
- func ContextWithSpan(ctx context.Context, sp ot.Span) context.Context
- func EumSnippet(apiKey string, traceID string, meta map[string]string) stringdeprecated
- func FormatID(id int64) string
- func Header2ID(header string) (int64, error)deprecated
- func ID2Header(id int64) (string, error)deprecated
- func InitSensor(options *Options)
- func NewTracer() ot.Tracer
- func NewTracerWithEverything(options *Options, recorder SpanRecorder) ot.Tracer
- func NewTracerWithOptions(options *Options) ot.Tracer
- func ParseID(header string) (int64, error)
- func RoundTripper(sensor *Sensor, original http.RoundTripper) http.RoundTripper
- func SendDefaultServiceEvent(title string, text string, sev severity, duration time.Duration)
- func SendHostEvent(title string, text string, sev severity, duration time.Duration)
- func SendServiceEvent(service string, title string, text string, sev severity, ...)
- func SetLogger(l LeveledLogger)
- func SpanFromContext(ctx context.Context) (ot.Span, bool)
- func SuppressTracing() ot.Tag
- func TracingHandlerFunc(sensor *Sensor, pathTemplate string, handler http.HandlerFunc) http.HandlerFunc
- type ContextSensitiveFunc
- type EntityData
- type EventData
- type ForeignParent
- type HTTPSpanData
- type HTTPSpanTags
- type KafkaSpanData
- type KafkaSpanTags
- type LeveledLogger
- type MemoryS
- type MetricsS
- type Options
- type RPCSpanData
- type RPCSpanTags
- type Recorder
- type RegisteredSpanType
- type SDKSpanData
- type SDKSpanTags
- type Sensor
- func (s *Sensor) Logger() LeveledLogger
- func (s *Sensor) SetLogger(l LeveledLogger)
- func (s *Sensor) TraceHandler(name, pattern string, handler http.HandlerFunc) (string, http.HandlerFunc)deprecated
- func (s *Sensor) Tracer() ot.Tracer
- func (s *Sensor) TracingHandler(name string, handler http.HandlerFunc) http.HandlerFuncdeprecated
- func (s *Sensor) TracingHttpRequest(name string, parent, req *http.Request, client http.Client) (*http.Response, error)deprecated
- func (s *Sensor) WithTracingContext(name string, w http.ResponseWriter, req *http.Request, f ContextSensitiveFunc)deprecated
- func (s *Sensor) WithTracingSpan(operationName string, w http.ResponseWriter, req *http.Request, ...)deprecated
- type SnapshotCollector
- type SnapshotS
- type Span
- type SpanContext
- type SpanData
- type SpanKind
- type SpanRecorder
- type SpanSensitiveFunc
- type Tracer
- type TracerOptions
Examples ¶
Constants ¶
const ( SeverityChange severity = -1 SeverityWarning severity = 5 SeverityCritical severity = 10 )
Severity values for events sent to the instana agent
const ( ServicePlugin = "com.instana.forge.connection.http.logical.LogicalWebApp" ServiceHost = "" )
Defaults for the Event API
const ( // SDK span, a generic span containing arbitrary data. Spans with operation name // not listed in the subsequent list will be sent as an SDK spans forwarding all // attached tags to the agent SDKSpanType = RegisteredSpanType("sdk") // HTTP server and client spans HTTPServerSpanType = RegisteredSpanType("g.http") HTTPClientSpanType = RegisteredSpanType("http") // RPC server and client spans RPCServerSpanType = RegisteredSpanType("rpc-server") RPCClientSpanType = RegisteredSpanType("rpc-client") // Kafka consumer/producer span KafkaSpanType = RegisteredSpanType("kafka") )
Registered types supported by Instana. The span type is determined based on the operation name passed to the `StartSpan()` call of a tracer.
It is NOT RECOMMENDED to use operation names that match any of these constants in your custom instrumentation code unless you explicitly wish to send data as a registered span. The conversion will result in loss of custom tags that are not supported for this span type. The list of supported tags can be found in the godoc of the respective span tags type below.
const ( Error = 0 Warn = 1 Info = 2 Debug = 3 )
Valid log levels
const ( // FieldT Trace ID header FieldT = "x-instana-t" // FieldS Span ID header FieldS = "x-instana-s" // FieldL Level header FieldL = "x-instana-l" // FieldB OT Baggage header FieldB = "x-instana-b-" // FieldSynthetic if set to 1, marks the call as synthetic, e.g. // a healthcheck request FieldSynthetic = "x-instana-synthetic" )
Instana header constants
const ( DefaultMaxBufferedSpans = 1000 DefaultForceSpanSendAt = 500 )
const (
// MaxLogsPerSpan The maximum number of logs allowed on a span.
MaxLogsPerSpan = 2
)
const (
// SnapshotPeriod is the amount of time in seconds between snapshot reports.
SnapshotPeriod = 600
)
Variables ¶
This section is empty.
Functions ¶
func BatchSize ¶ added in v1.10.0
BatchSize returns an opentracing.Tag to mark the span as a batched span representing similar span categories. An example of such span would be batch writes to a queue, a database, etc. If the batch size less than 2, then this option has no effect
func ContextWithSpan ¶ added in v1.7.0
ContextWithSpan returns a new context.Context holding a reference to an active span
func EumSnippet
deprecated
EumSnippet generates javascript code to initialize JavaScript agent
Deprecated: this snippet is outdated and this method will be removed in the next major version. To learn about the way to install Instana EUM snippet please refer to https://docs.instana.io/products/website_monitoring/#installation
func FormatID ¶ added in v1.8.0
FormatID converts an Instana ID to a value that can be used in context propagation (such as HTTP headers). More specifically, this converts a signed 64 bit integer into an unsigned hex string.
func InitSensor ¶
func InitSensor(options *Options)
InitSensor intializes the sensor (without tracing) to begin collecting and reporting metrics.
func NewTracerWithEverything ¶
func NewTracerWithEverything(options *Options, recorder SpanRecorder) ot.Tracer
NewTracerWithEverything Get a new Tracer with the works.
func NewTracerWithOptions ¶
NewTracerWithOptions Get a new Tracer with the specified options.
func ParseID ¶ added in v1.8.0
Header2ID converts an header context value into an Instana ID. More specifically, this converts an unsigned 64 bit hex value into a signed 64bit integer.
func RoundTripper ¶ added in v1.8.0
func RoundTripper(sensor *Sensor, original http.RoundTripper) http.RoundTripper
RoundTripper wraps an existing http.RoundTripper and injects the tracing headers into the outgoing request. If the original RoundTripper is nil, the http.DefaultTransport will be used.
Example ¶
This example demonstrates how to instrument an HTTP client with Instana
package main import ( "context" "net/http" instana "github.com/instana/go-sensor" ) func main() { // Here we initialize a new instance of instana.Sensor, however it is STRONGLY recommended // to use a single instance throughout your application sensor := instana.NewSensor("my-http-client") span := sensor.Tracer().StartSpan("entry") // http.DefaultTransport is used as a default RoundTripper, however you can provide // your own implementation client := &http.Client{ Transport: instana.RoundTripper(sensor, nil), } // Inject parent span into therequest context ctx := instana.ContextWithSpan(context.Background(), span) req, _ := http.NewRequest("GET", "https://www.instana.com", nil) // Execute request as usual client.Do(req.WithContext(ctx)) }
Output:
func SendDefaultServiceEvent ¶
SendDefaultServiceEvent sends a default event which already contains the service and host
func SendHostEvent ¶
SendHostEvent sends an event on the current host
func SendServiceEvent ¶
func SendServiceEvent(service string, title string, text string, sev severity, duration time.Duration)
SendServiceEvent sends an event on a specific service
func SetLogger ¶ added in v1.8.0
func SetLogger(l LeveledLogger)
SetLogger configures the default logger to be used by Instana go-sensor. Note that changing the logger will not affect already initialized instana.Sensor instances. To make them use the new logger please call (*instana.Sensor).SetLogger() explicitly.
func SpanFromContext ¶ added in v1.7.0
SpanFromContext retrieves previously stored active span from context. If there is no span, this method returns false.
func SuppressTracing ¶ added in v1.11.0
SuppressTracing returns an opentracing.Tag to mark the span and any of its child spans as not to be sent to the agent
func TracingHandlerFunc ¶ added in v1.8.0
func TracingHandlerFunc(sensor *Sensor, pathTemplate string, handler http.HandlerFunc) http.HandlerFunc
TracingHandlerFunc is an HTTP middleware that captures the tracing data and ensures trace context propagation via OpenTracing headers. The pathTemplate parameter, when provided, will be added to the span as a template string used to match the route containing variables, regular expressions, etc.
The wrapped handler will also propagate the W3C trace context (https://www.w3.org/TR/trace-context/) if found in request.
Example ¶
This example demonstrates how to instrument an HTTP handler with Instana and register it in http.DefaultServeMux
package main import ( "net/http" instana "github.com/instana/go-sensor" ) func main() { // Here we initialize a new instance of instana.Sensor, however it is STRONGLY recommended // to use a single instance throughout your application sensor := instana.NewSensor("my-http-server") http.HandleFunc("/", instana.TracingHandlerFunc(sensor, "root", func(w http.ResponseWriter, req *http.Request) { // handler code })) }
Output:
Types ¶
type ContextSensitiveFunc ¶ added in v1.4.14
type EventData ¶
type EventData struct { Title string `json:"title"` Text string `json:"text"` // Duration in milliseconds Duration int `json:"duration"` // Severity with value of -1, 5, 10 : see type severity Severity int `json:"severity"` Plugin string `json:"plugin,omitempty"` ID string `json:"id,omitempty"` Host string `json:"host"` }
EventData is the construct serialized for the host agent
type ForeignParent ¶ added in v1.13.0
type ForeignParent struct { TraceID string `json:"t"` ParentID string `json:"p"` LatestTraceState string `json:"lts,omitempty"` }
ForeignParent represents a related 3rd-party trace context, e.g. a W3C Trace Context
type HTTPSpanData ¶ added in v1.9.0
type HTTPSpanData struct { SpanData Tags HTTPSpanTags `json:"http"` }
HTTPSpanData represents the `data` section of an HTTP span sent within an OT span document
func NewHTTPSpanData ¶ added in v1.9.0
func NewHTTPSpanData(span *spanS) HTTPSpanData
NewHTTPSpanData initializes a new HTTP span data from tracer span
type HTTPSpanTags ¶ added in v1.9.0
type HTTPSpanTags struct { // Full request/response URL URL string `json:"url,omitempty"` // The HTTP status code returned with client/server response Status int `json:"status,omitempty"` // The HTTP method of the request Method string `json:"method,omitempty"` // Path is the path part of the request URL Path string `json:"path,omitempty"` // PathTemplate is the raw template string used to route the request PathTemplate string `json:"path_tpl,omitempty"` // The name:port of the host to which the request had been sent Host string `json:"host,omitempty"` // The name of the protocol used for request ("http" or "https") Protocol string `json:"protocol,omitempty"` // The message describing an error occured during the request handling Error string `json:"error,omitempty"` }
HTTPSpanTags contains fields within the `data.http` section of an OT span document
func NewHTTPSpanTags ¶ added in v1.9.0
func NewHTTPSpanTags(span *spanS) HTTPSpanTags
NewHTTPSpanTags extracts HTTP-specific span tags from a tracer span
type KafkaSpanData ¶ added in v1.9.0
type KafkaSpanData struct { SpanData Tags KafkaSpanTags `json:"kafka"` }
KafkaSpanData represents the `data` section of an Kafka span sent within an OT span document
func NewKafkaSpanData ¶ added in v1.9.0
func NewKafkaSpanData(span *spanS) KafkaSpanData
NewKafkaSpanData initializes a new Kafka span data from tracer span
type KafkaSpanTags ¶ added in v1.9.0
type KafkaSpanTags struct { // Kafka topic Service string `json:"service"` // The access mode:, either "send" for publisher or "consume" for consumer Access string `json:"access"` }
KafkaSpanTags contains fields within the `data.kafka` section of an OT span document
func NewKafkaSpanTags ¶ added in v1.9.0
func NewKafkaSpanTags(span *spanS) KafkaSpanTags
NewKafkaSpanTags extracts Kafka-specific span tags from a tracer span
type LeveledLogger ¶ added in v1.8.0
type LeveledLogger interface { Debug(v ...interface{}) Info(v ...interface{}) Warn(v ...interface{}) Error(v ...interface{}) }
LeveledLogger is an interface of a generic logger that support different message levels. By default instana.Sensor uses logger.Logger with log.Logger as an output, however this interface is also compatible with such popular loggers as github.com/sirupsen/logrus.Logger and go.uber.org/zap.SugaredLogger
type Options ¶
type Options struct { Service string AgentHost string AgentPort int MaxBufferedSpans int ForceTransmissionStartingAt int LogLevel int EnableAutoProfile bool MaxBufferedProfiles int IncludeProfilerFrames bool }
Options allows the user to configure the to-be-initialized sensor
func DefaultOptions ¶ added in v1.11.0
func DefaultOptions() *Options
DefaultOptions returns the default set of options to configure Instana sensor. The service name is set to the name of current executable, the MaxBufferedSpans and ForceTransmissionStartingAt are set to instana.DefaultMaxBufferedSpans and instana.DefaultForceSpanSendAt correspondigly. The AgentHost and AgentPort are taken from the env INSTANA_AGENT_HOST and INSTANA_AGENT_PORT if set, and default to localhost and 46999 otherwise.
type RPCSpanData ¶ added in v1.9.0
type RPCSpanData struct { SpanData Tags RPCSpanTags `json:"rpc"` }
RPCSpanData represents the `data` section of an RPC span sent within an OT span document
func NewRPCSpanData ¶ added in v1.9.0
func NewRPCSpanData(span *spanS) RPCSpanData
NewRPCSpanData initializes a new RPC span data from tracer span
type RPCSpanTags ¶ added in v1.9.0
type RPCSpanTags struct { // The name of the remote host for an RPC call Host string `json:"host,omitempty"` // The port of the remote host for an RPC call Port string `json:"port,omitempty"` // The name of the remote method to invoke Call string `json:"call,omitempty"` // The type of an RPC call, e.g. either "unary" or "stream" for GRPC requests CallType string `json:"call_type,omitempty"` // The RPC flavor used for this call, e.g. "grpc" for GRPC requests Flavor string `json:"flavor,omitempty"` // The message describing an error occured during the request handling Error string `json:"error,omitempty"` }
RPCSpanTags contains fields within the `data.rpc` section of an OT span document
func NewRPCSpanTags ¶ added in v1.9.0
func NewRPCSpanTags(span *spanS) RPCSpanTags
NewRPCSpanTags extracts RPC-specific span tags from a tracer span
type Recorder ¶
Recorder accepts spans, processes and queues them for delivery to the backend.
func NewTestRecorder ¶
func NewTestRecorder() *Recorder
NewTestRecorder initializes a new span recorder that keeps all collected until they are requested. This recorder does not send spans to the agent (used for testing)
func (*Recorder) GetQueuedSpans ¶
GetQueuedSpans returns a copy of the queued spans and clears the queue.
func (*Recorder) QueuedSpansCount ¶
QueuedSpansCount returns the number of queued spans
Used only in tests currently.
func (*Recorder) RecordSpan ¶
func (r *Recorder) RecordSpan(span *spanS)
RecordSpan accepts spans to be recorded and and added to the span queue for eventual reporting to the host agent.
type RegisteredSpanType ¶ added in v1.9.0
type RegisteredSpanType string
RegisteredSpanType represents the span type supported by Instana
func (RegisteredSpanType) ExtractData ¶ added in v1.9.0
func (st RegisteredSpanType) ExtractData(span *spanS) typedSpanData
ExtractData is a factory method to create the `data` section for a typed span
type SDKSpanData ¶ added in v1.9.0
type SDKSpanData struct { SpanData Tags SDKSpanTags `json:"sdk"` }
SDKSpanData represents the `data` section of an SDK span sent within an OT span document
func NewSDKSpanData ¶ added in v1.9.0
func NewSDKSpanData(span *spanS) SDKSpanData
NewSDKSpanData initializes a new SDK span data from tracer span
type SDKSpanTags ¶ added in v1.9.0
type SDKSpanTags struct { Name string `json:"name"` Type string `json:"type,omitempty"` Arguments string `json:"arguments,omitempty"` Return string `json:"return,omitempty"` Custom map[string]interface{} `json:"custom,omitempty"` }
SDKSpanTags contains fields within the `data.sdk` section of an OT span document
func NewSDKSpanTags ¶ added in v1.9.0
func NewSDKSpanTags(span *spanS, spanType string) SDKSpanTags
NewSDKSpanTags extracts SDK span tags from a tracer span
type Sensor ¶ added in v1.4.14
type Sensor struct {
// contains filtered or unexported fields
}
Sensor is used to inject tracing information into requests
func NewSensorWithTracer ¶ added in v1.7.0
NewSensorWithTracer returns a new instana.Sensor that uses provided tracer to report spans
func (*Sensor) Logger ¶ added in v1.8.0
func (s *Sensor) Logger() LeveledLogger
Logger returns the logger instance for this sensor
func (*Sensor) SetLogger ¶ added in v1.8.0
func (s *Sensor) SetLogger(l LeveledLogger)
SetLogger sets the logger for this sensor
func (*Sensor) TraceHandler
deprecated
added in
v1.4.14
func (s *Sensor) TraceHandler(name, pattern string, handler http.HandlerFunc) (string, http.HandlerFunc)
TraceHandler is similar to TracingHandler in regards, that it wraps an existing http.HandlerFunc into a named instance to support capturing tracing information and data. The returned values are compatible with handler registration methods, e.g. http.Handle()
Deprecated: please use instana.TracingHandlerFunc() instead
func (*Sensor) TracingHandler
deprecated
added in
v1.4.14
func (s *Sensor) TracingHandler(name string, handler http.HandlerFunc) http.HandlerFunc
TracingHandler wraps an existing http.HandlerFunc into a named instance to support capturing tracing information and response data
Deprecated: please use instana.TracingHandlerFunc() instead
func (*Sensor) TracingHttpRequest
deprecated
added in
v1.4.14
func (s *Sensor) TracingHttpRequest(name string, parent, req *http.Request, client http.Client) (*http.Response, error)
TracingHttpRequest wraps an existing http.Request instance into a named instance to inject tracing and span header information into the actual HTTP wire transfer
Deprecated: please use instana.RoundTripper() instead
func (*Sensor) WithTracingContext
deprecated
added in
v1.4.14
func (s *Sensor) WithTracingContext(name string, w http.ResponseWriter, req *http.Request, f ContextSensitiveFunc)
Executes the given ContextSensitiveFunc and executes it under the scope of a newly created context.Context, that provides access to the parent span as 'parentSpan'.
Deprecated: please use instana.TracingHandlerFunc() to instrument an HTTP handler
func (*Sensor) WithTracingSpan
deprecated
added in
v1.4.14
func (s *Sensor) WithTracingSpan(operationName string, w http.ResponseWriter, req *http.Request, f SpanSensitiveFunc)
WithTracingSpan takes the given SpanSensitiveFunc and executes it under the scope of a child span, which is injected as an argument when calling the function. It uses the name of the caller as a span operation name unless a non-empty value is provided
Deprecated: please use instana.TracingHandlerFunc() to instrument an HTTP handler
type SnapshotCollector ¶ added in v1.13.2
type SnapshotCollector struct { ServiceName string CollectionInterval time.Duration // contains filtered or unexported fields }
SnapshotCollector returns a snapshot of Go runtime
func (*SnapshotCollector) Collect ¶ added in v1.13.2
func (sc *SnapshotCollector) Collect() *acceptor.RuntimeInfo
Collect returns a snaphot of current runtime state. Any call this method made before the next interval elapses will return nil
type Span ¶ added in v1.9.0
type Span struct { TraceID int64 `json:"t"` ParentID int64 `json:"p,omitempty"` SpanID int64 `json:"s"` Timestamp uint64 `json:"ts"` Duration uint64 `json:"d"` Name string `json:"n"` From *fromS `json:"f"` Batch *batchInfo `json:"b,omitempty"` Kind int `json:"k"` Ec int `json:"ec,omitempty"` Data typedSpanData `json:"data"` Synthetic bool `json:"sy,omitempty"` ForeignParent *ForeignParent `json:"fp,omitempty"` }
Span represents the OpenTracing span document to be sent to the agent
type SpanContext ¶
type SpanContext struct { // A probabilistically unique identifier for a [multi-span] trace. TraceID int64 // A probabilistically unique identifier for a span. SpanID int64 // An optional parent span ID, 0 if this is the root span context. ParentID int64 // Whether the trace is sampled. Sampled bool // Whether the trace is suppressed and should not be sent to the agent. Suppressed bool // The span's associated baggage. Baggage map[string]string // initialized on first use // The W3C trace context W3CContext w3ctrace.Context // The 3rd party parent if the context is derived from non-Instana trace ForeignParent interface{} }
SpanContext holds the basic Span metadata.
func NewRootSpanContext ¶ added in v1.9.0
func NewRootSpanContext() SpanContext
NewRootSpanContext initializes a new root span context issuing a new trace ID
func NewSpanContext ¶ added in v1.9.0
func NewSpanContext(parent SpanContext) SpanContext
NewSpanContext initializes a new child span context from its parent. It will ignore the parent context if it contains neither Instana trace and span IDs nor a W3C trace context
func (SpanContext) Clone ¶ added in v1.9.0
func (c SpanContext) Clone() SpanContext
Clone returns a deep copy of a SpanContext
func (SpanContext) ForeachBaggageItem ¶
func (c SpanContext) ForeachBaggageItem(handler func(k, v string) bool)
ForeachBaggageItem belongs to the opentracing.SpanContext interface
func (SpanContext) WithBaggageItem ¶
func (c SpanContext) WithBaggageItem(key, val string) SpanContext
WithBaggageItem returns an entirely new SpanContext with the given key:value baggage pair set.
type SpanData ¶ added in v1.9.0
type SpanData struct { Service string `json:"service,omitempty"` // contains filtered or unexported fields }
SpanData contains fields to be sent in the `data` section of an OT span document. These fields are common for all span types.
func NewSpanData ¶ added in v1.9.0
func NewSpanData(span *spanS, st RegisteredSpanType) SpanData
NewSpanData initializes a new span data from tracer span
func (SpanData) Kind ¶ added in v1.9.1
Kind returns the kind of the span. It handles the github.com/opentracing/opentracing-go/ext.SpanKindEnum values as well as generic "entry" and "exit"
func (SpanData) Type ¶ added in v1.9.0
func (d SpanData) Type() RegisteredSpanType
Name returns the registered name for the span type suitable for use as the value of `n` field.
type SpanKind ¶ added in v1.9.0
type SpanKind uint8
SpanKind represents values of field `k` in OpenTracing span representation. It represents the direction of the call associated with a span.
const ( // The kind of a span associated with an inbound call, this must be the first span in the trace. EntrySpanKind SpanKind = iota + 1 // The kind of a span associated with an outbound call, e.g. an HTTP client request, posting to a message bus, etc. ExitSpanKind // The default kind for a span that is associated with a call within the same service. IntermediateSpanKind )
Valid span kinds
type SpanRecorder ¶
type SpanRecorder interface {
// Implementations must determine whether and where to store `span`.
RecordSpan(span *spanS)
}
A SpanRecorder handles all of the `RawSpan` data generated via an associated `Tracer` (see `NewStandardTracer`) instance. It also names the containing process and provides access to a straightforward tag map.
type SpanSensitiveFunc ¶ added in v1.4.14
type Tracer ¶
type Tracer interface { opentracing.Tracer // Options gets the Options used in New() or NewWithOptions(). Options() TracerOptions }
Tracer extends the opentracing.Tracer interface
type TracerOptions ¶
type TracerOptions struct { // ShouldSample is a function which is called when creating a new Span and // determines whether that Span is sampled. The randomized TraceID is supplied // to allow deterministic sampling decisions to be made across different nodes. // For example, // // func(traceID uint64) { return traceID % 64 == 0 } // // samples every 64th trace on average. ShouldSample func(traceID int64) bool // TrimUnsampledSpans turns potentially expensive operations on unsampled // Spans into no-ops. More precisely, tags and log events are silently // discarded. If NewSpanEventListener is set, the callbacks will still fire. TrimUnsampledSpans bool // Recorder receives Spans which have been finished. Recorder SpanRecorder // NewSpanEventListener can be used to enhance the tracer by effectively // attaching external code to trace events. See NetTraceIntegrator for a // practical example, and event.go for the list of possible events. NewSpanEventListener func() func(bt.SpanEvent) // DropAllLogs turns log events on all Spans into no-ops. // If NewSpanEventListener is set, the callbacks will still fire. DropAllLogs bool // MaxLogsPerSpan limits the number of Logs in a span (if set to a nonzero // value). If a span has more logs than this value, logs are dropped as // necessary (and replaced with a log describing how many were dropped). // // About half of the MaxLogPerSpan logs kept are the oldest logs, and about // half are the newest logs. // // If NewSpanEventListener is set, the callbacks will still fire for all log // events. This value is ignored if DropAllLogs is true. MaxLogsPerSpan int // DebugAssertSingleGoroutine internally records the ID of the goroutine // creating each Span and verifies that no operation is carried out on // it on a different goroutine. // Provided strictly for development purposes. // Passing Spans between goroutine without proper synchronization often // results in use-after-Finish() errors. For a simple example, consider the // following pseudocode: // // func (s *Server) Handle(req http.Request) error { // sp := s.StartSpan("server") // defer sp.Finish() // wait := s.queueProcessing(opentracing.ContextWithSpan(context.Background(), sp), req) // select { // case resp := <-wait: // return resp.Error // case <-time.After(10*time.Second): // sp.LogEvent("timed out waiting for processing") // return ErrTimedOut // } // } // // This looks reasonable at first, but a request which spends more than ten // seconds in the queue is abandoned by the main goroutine and its trace // finished, leading to use-after-finish when the request is finally // processed. Note also that even joining on to a finished Span via // StartSpanWithOptions constitutes an illegal operation. // // Code bases which do not require (or decide they do not want) Spans to // be passed across goroutine boundaries can run with this flag enabled in // tests to increase their chances of spotting wrong-doers. DebugAssertSingleGoroutine bool // DebugAssertUseAfterFinish is provided strictly for development purposes. // When set, it attempts to exacerbate issues emanating from use of Spans // after calling Finish by running additional assertions. DebugAssertUseAfterFinish bool // EnableSpanPool enables the use of a pool, so that the tracer reuses spans // after Finish has been called on it. Adds a slight performance gain as it // reduces allocations. However, if you have any use-after-finish race // conditions the code may panic. EnableSpanPool bool }
TracerOptions allows creating a customized Tracer via NewWithOptions. The object must not be updated when there is an active tracer using it.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package acceptor provides marshaling structs for Instana serverless acceptor API
|
Package acceptor provides marshaling structs for Instana serverless acceptor API |
internal/pprof/profile
Package profile provides a representation of profile.proto and methods to encode/decode profiles in this format.
|
Package profile provides a representation of profile.proto and methods to encode/decode profiles in this format. |
beego
Module
|
|
echo
Module
|
|
gin
Module
|
|
grpc-client-server
Module
|
|
httprouter
Module
|
|
instrumentation
|
|
cloud.google.com/go
Module
|
|
go.opencensus.io
Module
|
|
instaamqp
Module
|
|
instaamqp091
Module
|
|
instaawssdk
Module
|
|
instaawsv2
Module
|
|
instaazurefunction
Module
|
|
instabeego
Module
|
|
instacosmos
Module
|
|
instaecho
Module
|
|
instafasthttp
Module
|
|
instafiber
Module
|
|
instagin
Module
|
|
instagocb
Module
|
|
instagorm
Module
|
|
instagraphql
Module
|
|
instagrpc
Module
|
|
instahttprouter
Module
|
|
instalambda
Module
|
|
instalogrus
Module
|
|
instamongo
Module
|
|
instamux
Module
|
|
instapgx
Module
|
|
instaredigo
Module
|
|
instaredis
Module
|
|
instasarama
Module
|
|
instasarama/example
Module
|
|