internal

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAgentHostname  = "localhost"
	DefaultTraceAgentPort = "8126"
)
View Source
const (
	// EnvGitMetadataEnabledFlag specifies the environment variable name for enable/disable
	EnvGitMetadataEnabledFlag = "DD_TRACE_GIT_METADATA_ENABLED"
	// EnvGitRepositoryURL specifies the environment variable name for git repository URL
	EnvGitRepositoryURL = "DD_GIT_REPOSITORY_URL"
	// EnvGitCommitSha specifies the environment variable name git commit sha
	EnvGitCommitSha = "DD_GIT_COMMIT_SHA"
	// EnvDDTags specifies the environment variable name global tags
	EnvDDTags = "DD_TAGS"

	// TagRepositoryURL specifies the tag name for git repository URL
	TagRepositoryURL = "git.repository_url"
	// TagCommitSha specifies the tag name for git commit sha
	TagCommitSha = "git.commit.sha"
	// TagGoPath specifies the tag name for go module path
	TagGoPath = "go_path"

	// TraceTagRepositoryURL specifies the trace tag name for git repository URL
	TraceTagRepositoryURL = "_dd.git.repository_url"
	// TraceTagCommitSha specifies the trace tag name for git commit sha
	TraceTagCommitSha = "_dd.git.commit.sha"
	// TraceTagGoPath specifies the trace tag name for go module path
	TraceTagGoPath = "_dd.go_path"
)
View Source
const DDTagsDelimiter = ":"

DDTagsDelimiter is the separator between key-val pairs for DD env vars

View Source
const DefaultDogstatsdAddr = "localhost:8125"
View Source
const OtelTagsDelimeter = "="

OtelTagsDelimeter is the separator between key-val pairs for OTEL env vars

Variables

View Source
var ActiveSpanKey = contextKey{}

ActiveSpanKey is used to set tracer context on a context.Context objects with a unique key

View Source
var DefaultTraceAgentUDSPath = "/var/run/datadog/apm.socket"

This is a variable rather than a constant so it can be replaced in unit tests

Functions

func AgentURLFromEnv

func AgentURLFromEnv() *url.URL

AgentURLFromEnv resolves the URL for the trace agent based on the default host/port and UDS path, and via standard environment variables. AgentURLFromEnv has the following priority order:

  • First, DD_TRACE_AGENT_URL if it is set
  • Then, if either of DD_AGENT_HOST and DD_TRACE_AGENT_PORT are set, use http://DD_AGENT_HOST:DD_TRACE_AGENT_PORT, defaulting to localhost and 8126, respectively
  • Then, DefaultTraceAgentUDSPath, if the path exists
  • Finally, localhost:8126

func BoolEnv

func BoolEnv(key string, def bool) bool

BoolEnv returns the parsed boolean value of an environment variable, or def otherwise.

func BoolVal

func BoolVal(val string, def bool) bool

BoolVal returns the parsed boolean value of string val, or def if not parseable

func CleanGitMetadataTags

func CleanGitMetadataTags(tags map[string]string)

CleanGitMetadataTags cleans up tags from git metadata

func ContainerID

func ContainerID() string

ContainerID attempts to return the container ID from /proc/self/cgroup or empty on failure.

func CreateMemfd

func CreateMemfd(name string, data []byte) (int, error)

func DurationEnv

func DurationEnv(key string, def time.Duration) time.Duration

DurationEnv returns the parsed duration value of an environment variable, or def otherwise.

func EntityID

func EntityID() string

EntityID attempts to return the container ID or the cgroup node controller's inode if the container ID is not available. The cid is prefixed with `ci-` and the inode with `in-`.

func ExternalEnvironment

func ExternalEnvironment() string

ExternalEnvironment returns the value of the DD_EXTERNAL_ENV environment variable.

func FloatEnv

func FloatEnv(key string, def float64) float64

FloatEnv returns the parsed float64 value of an environment variable, or def otherwise.

func ForEachStringTag

func ForEachStringTag(str string, delimiter string, fn func(key string, val string))

ForEachStringTag runs fn on every key val pair encountered in str. str may contain multiple key val pairs separated by either space or comma (but not a mixture of both), and each key val pair is separated by a delimiter.

func GetGitMetadataTags

func GetGitMetadataTags() map[string]string

GetGitMetadataTags returns git metadata tags. Returned map is read-only

func GetTracerGitMetadataTags

func GetTracerGitMetadataTags() map[string]string

GetTracerGitMetadataTags returns git metadata tags for tracer NB: Currently tracer inject tags with some workaround (only with _dd prefix and only for the first span in payload) So we provide different tag names

func IPEnv

func IPEnv(key string, def net.IP) net.IP

IPEnv returns the valid IP value of an environment variable, or def otherwise.

func IntEnv

func IntEnv(key string, def int) int

IntEnv returns the parsed int value of an environment variable, or def otherwise.

func IsExecutionTraced

func IsExecutionTraced(ctx context.Context) bool

IsExecutionTraced returns whether ctx is associated with an execution trace task, as indicated via WithExecutionTraced

func ParseTagString

func ParseTagString(str string) map[string]string

ParseTagString returns tags parsed from string as map

func RefreshGitMetadataTags

func RefreshGitMetadataTags()

RefreshGitMetadataTags reset cached metadata tags. NOT thread-safe, use for testing only

func SetTracerInitialized

func SetTracerInitialized(val bool)

func ToFloat64

func ToFloat64(value any) (f float64, ok bool)

ToFloat64 attempts to convert value into a float64. If the value is an integer greater or equal to 2^53 or less than or equal to -2^53, it will not be converted into a float64 to avoid losing precision. If it succeeds in converting, toFloat64 returns the value and true, otherwise 0 and false.

func TracerInitialized

func TracerInitialized() bool

func UnixDataSocketURL

func UnixDataSocketURL(path string) *url.URL

func VerifyTraceSourceEnabled

func VerifyTraceSourceEnabled(hexStr string, target TraceSource) bool

func WithExecutionNotTraced

func WithExecutionNotTraced(ctx context.Context) context.Context

WithExecutionNotTraced marks that the context is *not* covered by an execution trace task. This is intended to prevent child spans (which inherit information from ctx) from being considered covered by a task, when an integration may create its own child span with its own execution trace task.

func WithExecutionTraced

func WithExecutionTraced(ctx context.Context) context.Context

WithExecutionTraced marks ctx as being associated with an execution trace task. It is assumed that ctx already contains a trace task. The caller is responsible for ending the task.

This is intended for a specific case where the database/sql contrib package only creates spans *after* an operation, in case the operation was unavailable, and thus execution trace tasks tied to the span only capture the very end. This function enables creating a task *before* creating a span, and communicating to the APM tracer that it does not need to create a task. In general, APM instrumentation should prefer creating tasks around the operation rather than after the fact, if possible.

Types

type LockMap

type LockMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LockMap uses an RWMutex to synchronize map access to allow for concurrent access. This should not be used for cases with heavy write load and performance concerns.

func NewLockMap

func NewLockMap(m map[string]string) *LockMap

func (*LockMap) Clear

func (l *LockMap) Clear()

func (*LockMap) Get

func (l *LockMap) Get(k string) string

func (*LockMap) Iter

func (l *LockMap) Iter(f func(key string, val string))

Iter iterates over all the map entries passing in keys and values to provided func f. Note this is READ ONLY.

func (*LockMap) Len

func (l *LockMap) Len() int

func (*LockMap) Set

func (l *LockMap) Set(k, v string)

type MetaStructValue

type MetaStructValue struct {
	Value any // TODO: further constraining Value's type, especially if it becomes public
}

MetaStructValue is a custom type wrapper used to send metadata to the agent via the `meta_struct` field instead of the `meta` inside a span.

type StatsdClient

type StatsdClient interface {
	Incr(name string, tags []string, rate float64) error
	Count(name string, value int64, tags []string, rate float64) error
	CountWithTimestamp(name string, value int64, tags []string, rate float64, timestamp time.Time) error
	Gauge(name string, value float64, tags []string, rate float64) error
	GaugeWithTimestamp(name string, value float64, tags []string, rate float64, timestamp time.Time) error
	DistributionSamples(name string, values []float64, tags []string, rate float64) error
	Timing(name string, value time.Duration, tags []string, rate float64) error
	Flush() error
	Close() error
}

func NewStatsdClient

func NewStatsdClient(addr string, globalTags []string) (StatsdClient, error)

NewStatsdClient returns a new statsd client with the provided address and globaltags

type TraceSource

type TraceSource uint8

TraceSource represents the 8-bit bitmask for the _dd.p.ts tag

const (
	APMTraceSource TraceSource = 0x01
	ASMTraceSource TraceSource = 0x02
	DSMTraceSource TraceSource = 0x04
	DJMTraceSource TraceSource = 0x08
	DBMTraceSource TraceSource = 0x10
)

func ParseTraceSource

func ParseTraceSource(hexStr string) (TraceSource, error)

ParseTraceSource parses a hexadecimal string into a TraceSource bitmask

func (TraceSource) IsSet

func (ts TraceSource) IsSet(src TraceSource) bool

IsSet checks if a specific TraceSource (bit) is enabled

func (*TraceSource) Set

func (ts *TraceSource) Set(src TraceSource)

Set enables specific TraceSource (bit) in the bitmask

func (TraceSource) String

func (ts TraceSource) String() string

String converts the bitmask to a two-character hexadecimal string

func (*TraceSource) Unset

func (ts *TraceSource) Unset(src TraceSource)

Unset disables specific TraceSource (bit) in the bitmask

type TraceSourceTagValue

type TraceSourceTagValue struct {
	Value TraceSource
}

TraceSourceTagValue is a custom type wrapper used to create the trace source (_dd.p.ts) tag that will be propagated to downstream distributed traces via the `X-Datadog-Tags` HTTP header for example. It is represented as a 2 character hexadecimal string

type XSyncMapCounterMap

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

XSyncMapCounterMap uses xsync protect counter increments and reads during concurrent access. Implementation and related tests were taken/inspired by felixge/countermap https://github.com/felixge/countermap/pull/2

func NewXSyncMapCounterMap

func NewXSyncMapCounterMap() *XSyncMapCounterMap

func (*XSyncMapCounterMap) GetAndReset

func (cm *XSyncMapCounterMap) GetAndReset() map[string]int64

func (*XSyncMapCounterMap) Inc

func (cm *XSyncMapCounterMap) Inc(key string)

Directories

Path Synopsis
Package globalconfig stores configuration which applies globally to both the tracer and integrations.
Package globalconfig stores configuration which applies globally to both the tracer and integrations.
cachedfetch
Package cachedfetch provides a read-through cache for fetched values.
Package cachedfetch provides a read-through cache for fetched values.
ec2
ecs
gce
validate
Package validate provides hostname validation helpers
Package validate provides hostname validation helpers
Package log provides logging utilities for the tracer.
Package log provides logging utilities for the tracer.
Package namingschema allows to use the naming schema from the integrations to set different service and span/operation names based on the value of the DD_TRACE_SPAN_ATTRIBUTE_SCHEMA environment variable.
Package namingschema allows to use the naming schema from the integrations to set different service and span/operation names based on the value of the DD_TRACE_SPAN_ATTRIBUTE_SCHEMA environment variable.
Package normalizer provides tag normalization
Package normalizer provides tag normalization
generator command
This program generates the `orchestrion.tool.go` file at `./orchestrion/all` from the root of the repository, which contains the necessary directives to facilitate onboarding of orchestrion.
This program generates the `orchestrion.tool.go` file at `./orchestrion/all` from the root of the repository, which contains the necessary directives to facilitate onboarding of orchestrion.
matrix command
Package stableconfig provides utilities to load and manage APM configurations loaded from YAML configuration files
Package stableconfig provides utilities to load and manage APM configurations loaded from YAML configuration files
Package telemetry provides a telemetry client that is thread-safe burden-less telemetry client following the specification of the instrumentation telemetry from Datadog.
Package telemetry provides a telemetry client that is thread-safe burden-less telemetry client following the specification of the instrumentation telemetry from Datadog.
log
telemetrytest
Package telemetrytest provides a mock implementation of the telemetry client for testing purposes
Package telemetrytest provides a mock implementation of the telemetry client for testing purposes
Package traceprof contains shared logic for cross-cutting tracer/profiler features.
Package traceprof contains shared logic for cross-cutting tracer/profiler features.
testapp
Package testapp has the protbuf/grpc definitions for the test application implemented in traceproftest.
Package testapp has the protbuf/grpc definitions for the test application implemented in traceproftest.
Package urlsanitizer provides utilities for sanitizing URLs and DSNs by removing sensitive information.
Package urlsanitizer provides utilities for sanitizing URLs and DSNs by removing sensitive information.

Jump to

Keyboard shortcuts

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