Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ddtrace/tracer/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func logStartup(t *tracer) {
SpanSamplingRules: t.config.spanRules,
ServiceMappings: t.config.serviceMappings,
Tags: tags,
RuntimeMetricsEnabled: t.config.runtimeMetrics,
RuntimeMetricsV2Enabled: t.config.runtimeMetricsV2,
RuntimeMetricsEnabled: t.config.internalConfig.RuntimeMetricsEnabled(),
RuntimeMetricsV2Enabled: t.config.internalConfig.RuntimeMetricsV2Enabled(),
ApplicationVersion: t.config.version,
ProfilerCodeHotspotsEnabled: t.config.profilerHotspots,
ProfilerEndpointsEnabled: t.config.profilerEndpoints,
Expand Down
14 changes: 3 additions & 11 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,6 @@ type config struct {
// will be used.
logger Logger

// runtimeMetrics specifies whether collection of runtime metrics is enabled.
runtimeMetrics bool

// runtimeMetricsV2 specifies whether collection of runtime metrics v2 is enabled.
runtimeMetricsV2 bool

// dogstatsdAddr specifies the address to connect for sending metrics to the
// Datadog Agent. If not set, it defaults to "localhost:8125" or to the
// combination of the environment variables DD_AGENT_HOST and DD_DOGSTATSD_PORT.
Expand Down Expand Up @@ -472,8 +466,6 @@ func newConfig(opts ...StartOption) (*config, error) {
c.isLambdaFunction = true
}
}
c.runtimeMetrics = internal.BoolVal(getDDorOtelConfig("metrics"), false)
c.runtimeMetricsV2 = internal.BoolEnv("DD_RUNTIME_METRICS_V2_ENABLED", true)
c.logDirectory = env.Get("DD_TRACE_LOG_DIRECTORY")
c.enabled = newDynamicConfig("tracing_enabled", internal.BoolVal(getDDorOtelConfig("enabled"), true), func(_ bool) bool { return true }, equal[bool])
if _, ok := env.Lookup("DD_TRACE_ENABLED"); ok {
Expand Down Expand Up @@ -686,8 +678,8 @@ func apmTracingDisabled(c *config) {
WithGlobalTag("_dd.apm.enabled", 0)(c)
// Disable runtime metrics. In `tracingAsTransport` mode, we'll still
// tell the agent we computed them, so it doesn't do it either.
c.runtimeMetrics = false
c.runtimeMetricsV2 = false
c.internalConfig.SetRuntimeMetricsEnabled(false, internalconfig.OriginCalculated)
c.internalConfig.SetRuntimeMetricsV2Enabled(false, internalconfig.OriginCalculated)
}

// resolveDogstatsdAddr resolves the Dogstatsd address to use, based on the user-defined
Expand Down Expand Up @@ -1224,7 +1216,7 @@ func WithAnalyticsRate(rate float64) StartOption {
func WithRuntimeMetrics() StartOption {
return func(cfg *config) {
telemetry.RegisterAppConfig("runtime_metrics_enabled", true, telemetry.OriginCode)
cfg.runtimeMetrics = true
cfg.internalConfig.SetRuntimeMetricsEnabled(true, internalconfig.OriginCode)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ddtrace/tracer/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func startTelemetry(c *config) telemetry.Client {
{Name: "version", Value: c.version},
{Name: "trace_agent_url", Value: c.agentURL.String()},
{Name: "agent_hostname", Value: c.hostname},
{Name: "runtime_metrics_v2_enabled", Value: c.runtimeMetricsV2},
{Name: "runtime_metrics_v2_enabled", Value: c.internalConfig.RuntimeMetricsV2Enabled()},
{Name: "dogstatsd_addr", Value: c.dogstatsdAddr},
{Name: "debug_stack_enabled", Value: !c.noDebugStack},
{Name: "profiling_hotspots_enabled", Value: c.profilerHotspots},
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func Start(opts ...StartOption) error {
return nil
}

if t.config.runtimeMetricsV2 {
if t.config.internalConfig.RuntimeMetricsV2Enabled() {
l := slog.New(slogHandler{})
opts := &runtimemetrics.Options{Logger: l}
if t.runtimeMetrics, err = runtimemetrics.NewEmitter(t.statsd, opts); err == nil {
Expand Down Expand Up @@ -482,7 +482,7 @@ func newTracer(opts ...StartOption) (*tracer, error) {
}
c := t.config
t.statsd.Incr("datadog.tracer.started", nil, 1)
if c.runtimeMetrics {
if c.internalConfig.RuntimeMetricsEnabled() {
log.Debug("Runtime metrics enabled.")
t.wg.Add(1)
go func() {
Expand Down
6 changes: 3 additions & 3 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func TestTracerRuntimeMetrics(t *testing.T) {
t.Setenv("OTEL_METRICS_EXPORTER", "none")
c, err := newTestConfig()
assert.NoError(t, err)
assert.False(t, c.runtimeMetrics)
assert.False(t, c.internalConfig.RuntimeMetricsEnabled())
})

t.Run("override-chain", func(t *testing.T) {
Expand All @@ -761,12 +761,12 @@ func TestTracerRuntimeMetrics(t *testing.T) {
t.Setenv("DD_RUNTIME_METRICS_ENABLED", "true")
c, err := newTestConfig()
assert.NoError(t, err)
assert.True(t, c.runtimeMetrics)
assert.True(t, c.internalConfig.RuntimeMetricsEnabled())
// tracer option overrides dd env
t.Setenv("DD_RUNTIME_METRICS_ENABLED", "false")
c, err = newTestConfig(WithRuntimeMetrics())
assert.NoError(t, err)
assert.True(t, c.runtimeMetrics)
assert.True(t, c.internalConfig.RuntimeMetricsEnabled())
})
}

Expand Down
27 changes: 26 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func loadConfig() *Config {
cfg.serviceMappings = provider.getMap("DD_SERVICE_MAPPING", nil)
cfg.hostname = provider.getString("DD_TRACE_SOURCE_HOSTNAME", "")
cfg.runtimeMetrics = provider.getBool("DD_RUNTIME_METRICS_ENABLED", false)
cfg.runtimeMetricsV2 = provider.getBool("DD_RUNTIME_METRICS_V2_ENABLED", false)
cfg.runtimeMetricsV2 = provider.getBool("DD_RUNTIME_METRICS_V2_ENABLED", true)
cfg.profilerHotspots = provider.getBool("DD_PROFILING_CODE_HOTSPOTS_COLLECTION_ENABLED", false)
cfg.profilerEndpoints = provider.getBool("DD_PROFILING_ENDPOINT_COLLECTION_ENABLED", false)
cfg.spanAttributeSchemaVersion = provider.getInt("DD_TRACE_SPAN_ATTRIBUTE_SCHEMA", 0)
Expand Down Expand Up @@ -136,6 +136,31 @@ func (c *Config) SetDebug(enabled bool, origin telemetry.Origin) {
telemetry.RegisterAppConfig("DD_TRACE_DEBUG", enabled, origin)
}

func (c *Config) RuntimeMetricsEnabled() bool {
c.mu.RLock()
defer c.mu.RUnlock()
return c.runtimeMetrics
}

func (c *Config) SetRuntimeMetricsEnabled(enabled bool, origin telemetry.Origin) {
c.mu.Lock()
defer c.mu.Unlock()
c.runtimeMetrics = enabled
telemetry.RegisterAppConfig("DD_RUNTIME_METRICS_ENABLED", enabled, origin)
}
func (c *Config) RuntimeMetricsV2Enabled() bool {
c.mu.RLock()
defer c.mu.RUnlock()
return c.runtimeMetricsV2
}

func (c *Config) SetRuntimeMetricsV2Enabled(enabled bool, origin telemetry.Origin) {
c.mu.Lock()
defer c.mu.Unlock()
c.runtimeMetricsV2 = enabled
telemetry.RegisterAppConfig("DD_RUNTIME_METRICS_V2_ENABLED", enabled, origin)
}

func (c *Config) DataStreamsMonitoringEnabled() bool {
c.mu.RLock()
defer c.mu.RUnlock()
Expand Down
Loading