Documentation
¶
Overview ¶
Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2016-2019 Datadog, Inc.
Index ¶
- Constants
- Variables
- func CL(ctx context.Context, opts ...zap.Option) *zap.Logger
- func CLS(ctx context.Context, opts ...zap.Option) *zap.SugaredLogger
- func ClientTypeFromSpan(sp tracer.Span) string
- func ContextWithClientType(ctx context.Context, ct string) context.Context
- func ContextWithStatsd(ctx context.Context, sink statsd.ClientInterface) context.Context
- func GetClientTypeFromContext(ctx context.Context) string
- func GetHttpRequestHeader(ctx context.Context) (http.Header, bool)
- func GetStatsdFromContext(ctx context.Context) statsd.ClientInterface
- func ImbueContext(ctx context.Context, logger *zap.Logger) context.Context
- func InstrumentWithMetrics(ctx context.Context, fn func(context.Context) error) error
- func MakeMetricContext(ctx context.Context, opName string) context.Context
- func MakeTraceHooks(serviceName string) *twirp.ServerHooks
- func NewMultiValueContext(parent context.Context, dataList ...interface{}) context.Context
- func NewResponseCodeCapturer(writer http.ResponseWriter) *responseCapturer
- func RunInstrumented(ctx context.Context, name string, fn func(context.Context) error) error
- func SetupTracing(ctx context.Context, appName, envName string, logger *zap.Logger) (statsd.ClientInterface, error)
- func TearDownTracing(ctx context.Context, client statsd.ClientInterface)
- func WithStack(err twirp.Error) twirp.Error
- type FakeSpan
- func (f *FakeSpan) BaggageItem(key string) string
- func (f *FakeSpan) Context() ddtrace.SpanContext
- func (f *FakeSpan) Finish(opts ...ddtrace.FinishOption)
- func (f *FakeSpan) SetBaggageItem(key, val string)
- func (f *FakeSpan) SetOperationName(operationName string)
- func (f *FakeSpan) SetTag(key string, value interface{})
- type GenericTwirpServer
- type MetricEntry
- type MetricsContext
- func (m *MetricsContext) AddCount(name string, val float64)
- func (m *MetricsContext) AddDuration(name string, duration time.Duration)
- func (m *MetricsContext) AddMetric(name string, val float64, unit cloudwatch.StandardUnit)
- func (m *MetricsContext) Benchmark(name string) *TimeMeasurement
- func (m *MetricsContext) CopyToSpan(span tracer.Span)
- func (m *MetricsContext) CopyToStatsd(client statsd.ClientInterface, clientType string)
- func (m *MetricsContext) GetMetric(name string) (val float64, unit cloudwatch.StandardUnit)
- func (m *MetricsContext) GetMetricVal(name string) float64
- func (m *MetricsContext) Reset()
- func (m *MetricsContext) SetCount(name string, val float64)
- func (m *MetricsContext) SetDuration(name string, duration time.Duration)
- func (m *MetricsContext) SetMetric(name string, val float64, unit cloudwatch.StandardUnit)
- type MultiValueContext
- type NopLogger
- type ProcessContext
- type ProcessRegistry
- type RecordingSink
- func (r *RecordingSink) Clear()
- func (r *RecordingSink) Close() error
- func (r *RecordingSink) Count(name string, value int64, tags []string, _ float64) error
- func (r *RecordingSink) Decr(_ string, _ []string, _ float64) error
- func (r *RecordingSink) Distribution(name string, value float64, tags []string, _ float64) error
- func (r *RecordingSink) Event(_ *statsd.Event) error
- func (r *RecordingSink) Flush() error
- func (r *RecordingSink) Gauge(_ string, _ float64, _ []string, _ float64) error
- func (r *RecordingSink) Histogram(_ string, _ float64, _ []string, _ float64) error
- func (r *RecordingSink) Incr(_ string, _ []string, _ float64) error
- func (r *RecordingSink) ServiceCheck(_ *statsd.ServiceCheck) error
- func (r *RecordingSink) Set(_ string, _ string, _ []string, _ float64) error
- func (r *RecordingSink) SetWriteTimeout(_ time.Duration) error
- func (r *RecordingSink) SimpleEvent(_, _ string) error
- func (r *RecordingSink) SimpleServiceCheck(_ string, _ statsd.ServiceCheckStatus) error
- func (r *RecordingSink) TimeInMilliseconds(_ string, _ float64, _ []string, _ float64) error
- func (r *RecordingSink) Timing(_ string, _ time.Duration, _ []string, _ float64) error
- type ShortenedStackTrace
- type StackElement
- type TimeMeasurement
- type TracedGorilla
- type TracedTwirp
- type TwirpHttpClient
Constants ¶
const ClientTypeCanary = "canary"
const ClientTypeNormal = "normal"
const ClientTypeTag = "client-type"
const MetricsContextKey = "MetricContext"
const RequestHeaderKey = 11
const (
RequestTimingKey contextKey = 1
)
const StackTraceKey = "StackTrace"
Variables ¶
var DefAnalyticsRate = math.NaN()
Functions ¶
func ClientTypeFromSpan ¶
func ContextWithClientType ¶
func ContextWithStatsd ¶
func GetStatsdFromContext ¶
func GetStatsdFromContext(ctx context.Context) statsd.ClientInterface
func InstrumentWithMetrics ¶
func MakeTraceHooks ¶
func MakeTraceHooks(serviceName string) *twirp.ServerHooks
func NewMultiValueContext ¶
Create a multi-value context and populate it with data, dataList must be a list in "key, value, key, value..." format.
func NewResponseCodeCapturer ¶
func NewResponseCodeCapturer(writer http.ResponseWriter) *responseCapturer
func RunInstrumented ¶
RunInstrumented() traces the provided synchronous function by beginning and closing a new subsegment around its execution. If the parent segment doesn't exist yet then a new top-level segment is created
func SetupTracing ¶
func TearDownTracing ¶
func TearDownTracing(ctx context.Context, client statsd.ClientInterface)
Types ¶
type FakeSpan ¶
type FakeSpan struct {
// contains filtered or unexported fields
}
func (*FakeSpan) BaggageItem ¶
func (*FakeSpan) Context ¶
func (f *FakeSpan) Context() ddtrace.SpanContext
func (*FakeSpan) Finish ¶
func (f *FakeSpan) Finish(opts ...ddtrace.FinishOption)
func (*FakeSpan) SetBaggageItem ¶
func (*FakeSpan) SetOperationName ¶
type GenericTwirpServer ¶
type MetricEntry ¶
type MetricEntry struct { Val float64 Unit cloudwatch.StandardUnit Timestamp time.Time }
func (MetricEntry) Normalize ¶
func (e MetricEntry) Normalize() (float64, cloudwatch.StandardUnit)
Normalize unit to use the smallest possible unit: microsecond, bit, byte
type MetricsContext ¶
type MetricsContext struct { Lock sync.Mutex OpName string Metrics map[string]*MetricEntry // contains filtered or unexported fields }
func GetMetricsFromContext ¶
func GetMetricsFromContext(ctx context.Context) *MetricsContext
func TryGetMetricsFromContext ¶
func TryGetMetricsFromContext(ctx context.Context) *MetricsContext
func (*MetricsContext) AddCount ¶
func (m *MetricsContext) AddCount(name string, val float64)
func (*MetricsContext) AddDuration ¶
func (m *MetricsContext) AddDuration(name string, duration time.Duration)
func (*MetricsContext) AddMetric ¶
func (m *MetricsContext) AddMetric(name string, val float64, unit cloudwatch.StandardUnit)
func (*MetricsContext) Benchmark ¶
func (m *MetricsContext) Benchmark(name string) *TimeMeasurement
func (*MetricsContext) CopyToSpan ¶
func (m *MetricsContext) CopyToSpan(span tracer.Span)
func (*MetricsContext) CopyToStatsd ¶
func (m *MetricsContext) CopyToStatsd(client statsd.ClientInterface, clientType string)
func (*MetricsContext) GetMetric ¶
func (m *MetricsContext) GetMetric(name string) (val float64, unit cloudwatch.StandardUnit)
func (*MetricsContext) GetMetricVal ¶
func (m *MetricsContext) GetMetricVal(name string) float64
func (*MetricsContext) Reset ¶
func (m *MetricsContext) Reset()
Remove all metrics for the context, useful for tests
func (*MetricsContext) SetCount ¶
func (m *MetricsContext) SetCount(name string, val float64)
func (*MetricsContext) SetDuration ¶
func (m *MetricsContext) SetDuration(name string, duration time.Duration)
func (*MetricsContext) SetMetric ¶
func (m *MetricsContext) SetMetric(name string, val float64, unit cloudwatch.StandardUnit)
type MultiValueContext ¶
func (*MultiValueContext) Deadline ¶
func (m *MultiValueContext) Deadline() (deadline time.Time, ok bool)
func (*MultiValueContext) Done ¶
func (m *MultiValueContext) Done() <-chan struct{}
func (*MultiValueContext) Err ¶
func (m *MultiValueContext) Err() error
func (*MultiValueContext) Value ¶
func (m *MultiValueContext) Value(key interface{}) interface{}
type ProcessContext ¶
type ProcessContext struct { Parent *ProcessRegistry Name string Done chan struct{} }
func (*ProcessContext) RunPeriodicProcess ¶
func (*ProcessContext) TryRun ¶
func (pc *ProcessContext) TryRun(proc func(ctx context.Context) error) bool
func (*ProcessContext) Wait ¶
func (pc *ProcessContext) Wait()
type ProcessRegistry ¶
type ProcessRegistry struct {
// contains filtered or unexported fields
}
func NewProcessRegistry ¶
func NewProcessRegistry(parentCtx context.Context) *ProcessRegistry
func (*ProcessRegistry) Close ¶
func (p *ProcessRegistry) Close()
func (*ProcessRegistry) CreateProcessContext ¶
func (p *ProcessRegistry) CreateProcessContext(name string) ProcessContext
func (*ProcessRegistry) GetWaitChannel ¶
func (p *ProcessRegistry) GetWaitChannel(processName string) <-chan struct{}
func (*ProcessRegistry) HasProcess ¶
func (p *ProcessRegistry) HasProcess(name string) bool
func (*ProcessRegistry) LogRunning ¶
func (p *ProcessRegistry) LogRunning() string
type RecordingSink ¶
type RecordingSink struct { Distributions map[string]float64 Counts map[string]int64 Tags map[string][]string }
func NewRecordingSink ¶
func NewRecordingSink() *RecordingSink
func (*RecordingSink) Clear ¶
func (r *RecordingSink) Clear()
func (*RecordingSink) Close ¶
func (r *RecordingSink) Close() error
func (*RecordingSink) Distribution ¶
func (*RecordingSink) Flush ¶
func (r *RecordingSink) Flush() error
func (*RecordingSink) ServiceCheck ¶
func (r *RecordingSink) ServiceCheck(_ *statsd.ServiceCheck) error
func (*RecordingSink) SetWriteTimeout ¶
func (r *RecordingSink) SetWriteTimeout(_ time.Duration) error
func (*RecordingSink) SimpleEvent ¶
func (r *RecordingSink) SimpleEvent(_, _ string) error
func (*RecordingSink) SimpleServiceCheck ¶
func (r *RecordingSink) SimpleServiceCheck(_ string, _ statsd.ServiceCheckStatus) error
func (*RecordingSink) TimeInMilliseconds ¶
type ShortenedStackTrace ¶
type ShortenedStackTrace struct {
// contains filtered or unexported fields
}
func NewShortenedStackTrace ¶
func NewShortenedStackTrace(skipFrames int, skipToFirstPanic bool, msg interface{}) *ShortenedStackTrace
Create a new shortened stack trace, that can optionally skip all the frames after the first panic() call (typically deferred error handlers).
func (*ShortenedStackTrace) Error ¶
func (s *ShortenedStackTrace) Error() string
func (*ShortenedStackTrace) Field ¶
func (s *ShortenedStackTrace) Field() zap.Field
func (*ShortenedStackTrace) JSONStack ¶
func (s *ShortenedStackTrace) JSONStack() []StackElement
Create a nice stack trace, skipping all the deferred frames after the first panic() call.
func (*ShortenedStackTrace) StackTrace ¶
func (s *ShortenedStackTrace) StackTrace() []uintptr
func (*ShortenedStackTrace) StringStack ¶
func (s *ShortenedStackTrace) StringStack() string
Create a nice stack trace, skipping all the deferred frames after the first panic() call.
type StackElement ¶
type TimeMeasurement ¶
type TimeMeasurement struct {
// contains filtered or unexported fields
}
func (*TimeMeasurement) Done ¶
func (t *TimeMeasurement) Done()
type TracedGorilla ¶
type TracedGorilla struct {
// contains filtered or unexported fields
}
func NewTracedGorilla ¶
func NewTracedGorilla(twirpServer GenericTwirpServer, logger *zap.Logger, sink statsd.ClientInterface, sampleRate *float64, errorSampleRate *float64) *TracedGorilla
func (*TracedGorilla) AttachGorillaToMuxer ¶
func (t *TracedGorilla) AttachGorillaToMuxer(router *mux.Router)
type TracedTwirp ¶
type TracedTwirp struct {
// contains filtered or unexported fields
}
type TwirpHttpClient ¶
TwirpHttpClient is duplicated from twirp's generated service code. It is declared in this package so that the client can be wrapped to initiate traces.
func WrapTwirpClient ¶
func WrapTwirpClient(c TwirpHttpClient, clientServiceName string, analyticsRate float64, clientType string) TwirpHttpClient
WrapTwirpClient wraps an TwirpHttpClient to add distributed tracing to its requests.
func WrapTwirpClientDef ¶
func WrapTwirpClientDef(c TwirpHttpClient, clientServiceName string) TwirpHttpClient