datadog

package
v1.20220411.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 14 Imported by: 2

Documentation

Overview

Package datadog includes helpers for interacting with datadog.

Index

Constants

View Source
const (
	// DefaultPort is the default port.
	DefaultPort = "8125"
	// DefaultTracePort is the default trace port.
	DefaultTracePort = "8126"
	// DefaultTracingEnabled is the default value for tracing enabled.
	DefaultTracingEnabled = true
	// DefaultProfilingEnabled is the default value for profiling enabled.
	DefaultProfilingEnabled = true
	// DefaultTraceSampleRate returns the default trace sample rate of 25%
	DefaultTraceSampleRate = 0.25
	// DefaultAddress is the default address for datadog.
	DefaultAddress = "unix:///var/run/datadog/dsd.socket"
)
View Source
const (
	TagService  = "service"
	TagEnv      = "env"
	TagHostname = "hostname"
)

Default Tags

View Source
const (
	// DefaultDatadogBufferDepth is the default number of statsd messages to buffer.
	DefaultDatadogBufferDepth = 128
)

Variables

This section is empty.

Functions

func ConvertEvent

func ConvertEvent(e stats.Event) *dogstatsd.Event

ConvertEvent converts a stats event to a statsd (datadog) event.

func NewTracer

func NewTracer(opts ...TracerOption) opentracing.Tracer

NewTracer returns a new tracer.

It defaults to the service environment as named by the `SERVICE_ENV` environment variable. It defaults the sample rate to the sample rate as returned by the configuration.

func UseProfiler added in v1.20210103.1

func UseProfiler(cfg Config) bool

UseProfiler returns if profiling is enabled and the profiler address is configured.

It should be used to gate if you should create a profiler with `profiler.Start`.

func UseTracing

func UseTracing(cfg Config) bool

UseTracing returns if tracing is enabled and the trace address is configured.

It should be used to gate if you should create tracers with `NewTracer`.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector is a class that wraps the statsd collector we're using.

func MustNew

func MustNew(cfg Config) *Collector

MustNew returns a new stats collector from a config, but panics on error.

func New

func New(cfg Config, opts ...dogstatsd.Option) (*Collector, error)

New returns a new stats collector from a config.

func (*Collector) AddDefaultTag

func (dc *Collector) AddDefaultTag(name, value string)

AddDefaultTag adds a new default tag.

func (*Collector) AddDefaultTags

func (dc *Collector) AddDefaultTags(tags ...string)

AddDefaultTags adds new default tags.

func (*Collector) Close

func (dc *Collector) Close() error

Close closes the statsd client.

func (*Collector) Count

func (dc *Collector) Count(name string, value int64, tags ...string) error

Count increments a counter by a value.

func (*Collector) CreateEvent

func (dc *Collector) CreateEvent(title, text string, tags ...string) stats.Event

CreateEvent makes a new Event with the collectors default tags.

func (*Collector) DefaultTags

func (dc *Collector) DefaultTags() []string

DefaultTags returns the default tags for the collector.

func (*Collector) Distribution added in v1.20210103.1

func (dc *Collector) Distribution(name string, value float64, tags ...string) error

Distribution sets a gauge value that statistics are computed on the server.

func (*Collector) Flush

func (dc *Collector) Flush() error

Flush forces a flush of all the queued statsd payloads.

func (*Collector) Gauge

func (dc *Collector) Gauge(name string, value float64, tags ...string) error

Gauge sets a gauge value.

func (*Collector) Histogram

func (dc *Collector) Histogram(name string, value float64, tags ...string) error

Histogram sets a gauge value that statistics are computed on the agent.

func (*Collector) Increment

func (dc *Collector) Increment(name string, tags ...string) error

Increment increments a counter by 1.

func (*Collector) SendEvent

func (dc *Collector) SendEvent(event stats.Event) error

SendEvent sends any *dogstatsd.Event

func (*Collector) SimpleEvent

func (dc *Collector) SimpleEvent(title, text string) error

SimpleEvent sends an event w/ title and text

func (*Collector) TimeInMilliseconds

func (dc *Collector) TimeInMilliseconds(name string, value time.Duration, tags ...string) error

TimeInMilliseconds sets a timing value.

type Config

type Config struct {
	// Address is the address of the datadog collector in the form of "hostname:port" or "unix:///path/to/socket"
	// It will supercede `Hostname` and `Port`.
	Address string `json:"address,omitempty" yaml:"address,omitempty" env:"DATADOG_ADDRESS"`
	// TraceAddress is the address of the datadog collector in the form of "hostname:port" or "unix:///path/to/trace-socket"
	// It will supercede `TraceHostname` and `TracePort`
	TraceAddress string `json:"traceAddress,omitempty" yaml:"traceAddress,omitempty" env:"DATADOG_TRACE_ADDRESS"`
	// ProfilerAddress is the address of the datadog collector in the form of "hostname:port" or "unix:///path/to/profiler-socket"
	ProfilerAddress string `json:"profilerAddress,omitempty" yaml:"profilerAddress,omitempty" env:"DATADOG_PROFILER_ADDRESS"`

	// Hostname is the host portion of a <host>:<port> address. It will be used in conjunction with `Port`
	// to form the default `Address`.
	Hostname string `json:"hostname,omitempty" yaml:"hostname,omitempty" env:"DATADOG_HOSTNAME"`
	// Port is the port portion of a <host>:<port> address. It will be used in conjunction with `Host`
	// to form the default `Address`.
	Port string `json:"port,omitempty" yaml:"port,omitempty" env:"DATADOG_PORT"`

	// TraceHostname is the host portion of a <host>:<port> address. It will be used in conjunction with `TracePort`
	// to form the default `TraceAddress`.
	TraceHostname string `json:"traceHostname,omitempty" yaml:"traceHostname,omitempty" env:"DATADOG_TRACE_HOSTNAME"`
	// TracePort is the port portion of a <host>:<port> address. It will be used in conjunction with `TraceHost`
	// to form the default `TraceAddress`.
	TracePort string `json:"tracePort,omitempty" yaml:"tracePort,omitempty" env:"DATADOG_TRACE_PORT"`

	// TracingEnabled returns if we should use tracing or not.
	TracingEnabled *bool `json:"tracingEnabled,omitempty" yaml:"tracingEnabled,omitempty" env:"DATADOG_APM_ENABLED"`
	// TracingSampleRate is the default tracing sample rate, on the interval [0-1]
	TraceSampleRate *float64 `json:"traceSampleRate,omitempty" yaml:"traceSampleRate,omitempty" env:"DATADOG_APM_SAMPLE_RATE"`

	// ProfilingEnabled returns if we should use profiling or not.
	ProfilingEnabled *bool `json:"profilingEnabled,omitempty" yaml:"profilingEnabled,omitempty" env:"DATADOG_PROFILING_ENABLED"`

	// Buffered indicates if we should buffer statsd metrics.
	Buffered *bool `json:"buffered,omitempty" yaml:"buffered,omitempty" env:"DATADOG_BUFFERED"`
	// BufferDepth is the depth of the buffer for statsd metrics.
	BufferDepth int `json:"bufferDepth,omitempty" yaml:"bufferDepth,omitempty" env:"DATADOG_BUFFER_DEPTH"`

	// Namespace is an optional namespace.
	// The namespace is a prefix on all statsd metric names submitted to the collector.
	Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty" env:"DATADOG_NAMESPACE"`
	// DefaultTags are the default tags associated with any stat metric.
	DefaultTags []string `json:"defaultTags,omitempty" yaml:"defaultTags,omitempty" env:"DATADOG_DEFAULT_TAGS,csv"`
}

Config is the datadog config.

func (Config) BufferDepthOrDefault

func (c Config) BufferDepthOrDefault() int

BufferDepthOrDefault returns the buffer depth.

func (Config) BufferedOrDefault

func (c Config) BufferedOrDefault() bool

BufferedOrDefault returns if the client should buffer messages or not.

func (Config) GetAddress

func (c Config) GetAddress() string

GetAddress returns the datadog collector address string.

func (Config) GetProfilerAddress added in v1.20210103.1

func (c Config) GetProfilerAddress() string

GetProfilerAddress gets the profiler address.

func (Config) GetTraceAddress

func (c Config) GetTraceAddress() string

GetTraceAddress returns the datadog collector address string.

func (Config) IsZero

func (c Config) IsZero() bool

IsZero returns if the config is unset.

func (Config) PortOrDefault

func (c Config) PortOrDefault() string

PortOrDefault returns the port or a default.

func (Config) ProfilingEnabledOrDefault added in v1.20210103.1

func (c Config) ProfilingEnabledOrDefault() bool

ProfilingEnabledOrDefault returns if tracing is enabled.

func (*Config) Resolve

func (c *Config) Resolve(ctx context.Context) error

Resolve implements configutil.ConfigResolver.

func (Config) TracePortOrDefault

func (c Config) TracePortOrDefault() string

TracePortOrDefault returns the trace port or a default.

func (Config) TraceSampleRateOrDefault

func (c Config) TraceSampleRateOrDefault() float64

TraceSampleRateOrDefault returns the trace sample rate or a default.

func (Config) TracingEnabledOrDefault

func (c Config) TracingEnabledOrDefault() bool

TracingEnabledOrDefault returns if tracing is enabled.

type RateSampler

type RateSampler float64

RateSampler samples from a sample rate.

func (RateSampler) Rate

func (r RateSampler) Rate() float64

Rate returns the rate.

func (RateSampler) Sample

func (r RateSampler) Sample(spn ddtrace.Span) bool

Sample returns true if the given span should be sampled.

func (RateSampler) SetRate

func (r RateSampler) SetRate(newRate float64)

SetRate is a no-op

type TracerOption added in v1.20210103.1

type TracerOption func(*TracerOptions)

TracerOption mutates tracer options

func OptTraceAgentAddr added in v1.20210103.1

func OptTraceAgentAddr(addr string) TracerOption

OptTraceAgentAddr returns a dd tracer start option that sets the agent addr.

func OptTraceConfig added in v1.20210103.1

func OptTraceConfig(cfg Config) TracerOption

OptTraceConfig sets relevant fields from the datadog config.

func OptTraceHostname added in v1.20210103.1

func OptTraceHostname(hostname string) TracerOption

OptTraceHostname returns a dd tracer start option that sets the service hostname.

func OptTraceLog added in v1.20210103.1

func OptTraceLog(log logger.Triggerable) TracerOption

OptTraceLog returns an option that sets the log output.

func OptTraceSampleRate

func OptTraceSampleRate(rate float64) TracerOption

OptTraceSampleRate returns a dd tracer start option that sets trace sampler with a given rate.

func OptTraceServiceEnv

func OptTraceServiceEnv(serviceEnv string) TracerOption

OptTraceServiceEnv returns a dd tracer start option that sets the service environment.

func OptTraceServiceName added in v1.20210103.1

func OptTraceServiceName(serviceName string) TracerOption

OptTraceServiceName returns a dd tracer start option that sets the service.

func OptTraceVersion added in v1.20210103.1

func OptTraceVersion(version string) TracerOption

OptTraceVersion returns a dd tracer start option that sets the service version.

type TracerOptions added in v1.20210103.1

type TracerOptions struct {
	Addr        string
	StatsAddr   string
	ServiceName string
	ServiceEnv  string
	Version     string
	Hostname    string
	SampleRate  float64
	Tags        map[string]string
	Log         logger.Triggerable
}

TracerOptions are all the options we can set when creating a tracer.

Directories

Path Synopsis
Package traceserver is a mocked APM trace server that calls a handler for each spanlists payload it gets.
Package traceserver is a mocked APM trace server that calls a handler for each spanlists payload it gets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL