Skip to content
Merged
2 changes: 1 addition & 1 deletion ddtrace/tracer/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func logStartup(t *tracer) {
RuntimeMetricsEnabled: t.config.internalConfig.RuntimeMetricsEnabled(),
RuntimeMetricsV2Enabled: t.config.internalConfig.RuntimeMetricsV2Enabled(),
ApplicationVersion: t.config.version,
ProfilerCodeHotspotsEnabled: t.config.profilerHotspots,
ProfilerCodeHotspotsEnabled: t.config.internalConfig.ProfilerHotspotsEnabled(),
ProfilerEndpointsEnabled: t.config.profilerEndpoints,
Architecture: runtime.GOARCH,
GlobalService: globalconfig.ServiceName(),
Expand Down
6 changes: 1 addition & 5 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@ type config struct {
// errors will record a stack trace when this option is set.
noDebugStack bool

// profilerHotspots specifies whether profiler Code Hotspots is enabled.
profilerHotspots bool

// profilerEndpoints specifies whether profiler endpoint filtering is enabled.
profilerEndpoints bool

Expand Down Expand Up @@ -472,7 +469,6 @@ func newConfig(opts ...StartOption) (*config, error) {
c.enabled.cfgOrigin = telemetry.OriginEnvVar
}
c.profilerEndpoints = internal.BoolEnv(traceprof.EndpointEnvVar, true)
c.profilerHotspots = internal.BoolEnv(traceprof.CodeHotspotsEnvVar, true)
if compatMode := env.Get("DD_TRACE_CLIENT_HOSTNAME_COMPAT"); compatMode != "" {
if semver.IsValid(compatMode) {
c.enableHostnameDetection = semver.Compare(semver.MajorMinor(compatMode), "v1.66") <= 0
Expand Down Expand Up @@ -1299,7 +1295,7 @@ func WithLogStartup(enabled bool) StartOption {
// DD_PROFILING_CODE_HOTSPOTS_COLLECTION_ENABLED env variable or true.
func WithProfilerCodeHotspots(enabled bool) StartOption {
return func(c *config) {
c.profilerHotspots = enabled
c.internalConfig.SetProfilerHotspotsEnabled(enabled, telemetry.OriginCode)
}
}

Expand Down
4 changes: 2 additions & 2 deletions ddtrace/tracer/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,14 +778,14 @@ func TestTracerOptionsDefaults(t *testing.T) {
t.Run("default", func(t *testing.T) {
c, err := newTestConfig(WithAgentTimeout(2))
assert.NoError(t, err)
assert.True(t, c.profilerHotspots)
assert.True(t, c.internalConfig.ProfilerHotspotsEnabled())
})

t.Run("override", func(t *testing.T) {
t.Setenv(traceprof.CodeHotspotsEnvVar, "false")
c, err := newTestConfig(WithAgentTimeout(2))
assert.NoError(t, err)
assert.False(t, c.profilerHotspots)
assert.False(t, c.internalConfig.ProfilerHotspotsEnabled())
})
})

Expand Down
2 changes: 1 addition & 1 deletion ddtrace/tracer/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func startTelemetry(c *config) telemetry.Client {
{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},
{Name: "profiling_hotspots_enabled", Value: c.internalConfig.ProfilerHotspotsEnabled()},
{Name: "profiling_endpoints_enabled", Value: c.profilerEndpoints},
{Name: "trace_span_attribute_schema", Value: c.spanAttributeSchemaVersion},
{Name: "trace_peer_service_defaults_enabled", Value: c.peerServiceDefaultsEnabled},
Expand Down
6 changes: 3 additions & 3 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ func (t *tracer) StartSpan(operationName string, options ...StartSpanOption) *Sp
log.Debug("Started Span: %v, Operation: %s, Resource: %s, Tags: %v, %v", //nolint:gocritic // Debug logging needs full span representation
span, span.name, span.resource, span.meta, span.metrics)
}
if t.config.profilerHotspots || t.config.profilerEndpoints {
if t.config.internalConfig.ProfilerHotspotsEnabled() || t.config.profilerEndpoints {
t.applyPPROFLabels(span.pprofCtxRestore, span)
} else {
span.pprofCtxRestore = nil
Expand Down Expand Up @@ -835,12 +835,12 @@ func (t *tracer) applyPPROFLabels(ctx gocontext.Context, span *Span) {
// https://go-review.googlesource.com/c/go/+/574516 for more information.
labels := make([]string, 0, 3*2 /* 3 key value pairs */)
localRootSpan := span.Root()
if t.config.profilerHotspots && localRootSpan != nil {
if t.config.internalConfig.ProfilerHotspotsEnabled() && localRootSpan != nil {
localRootSpan.mu.RLock()
labels = append(labels, traceprof.LocalRootSpanID, strconv.FormatUint(localRootSpan.spanID, 10))
localRootSpan.mu.RUnlock()
}
if t.config.profilerHotspots {
if t.config.internalConfig.ProfilerHotspotsEnabled() {
labels = append(labels, traceprof.SpanID, strconv.FormatUint(span.spanID, 10))
}
if t.config.profilerEndpoints && localRootSpan != nil {
Expand Down
16 changes: 15 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/DataDog/dd-trace-go/v2/internal/telemetry"
"github.com/DataDog/dd-trace-go/v2/internal/traceprof"
)

var (
Expand Down Expand Up @@ -82,7 +83,7 @@ func loadConfig() *Config {
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", true)
cfg.profilerHotspots = provider.getBool("DD_PROFILING_CODE_HOTSPOTS_COLLECTION_ENABLED", false)
cfg.profilerHotspots = provider.getBool("DD_PROFILING_CODE_HOTSPOTS_COLLECTION_ENABLED", true)
cfg.profilerEndpoints = provider.getBool("DD_PROFILING_ENDPOINT_COLLECTION_ENABLED", false)
cfg.spanAttributeSchemaVersion = provider.getInt("DD_TRACE_SPAN_ATTRIBUTE_SCHEMA", 0)
cfg.peerServiceDefaultsEnabled = provider.getBool("DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED", false)
Expand Down Expand Up @@ -136,6 +137,18 @@ func (c *Config) SetDebug(enabled bool, origin telemetry.Origin) {
telemetry.RegisterAppConfig("DD_TRACE_DEBUG", enabled, origin)
}

func (c *Config) ProfilerHotspotsEnabled() bool {
c.mu.RLock()
defer c.mu.RUnlock()
return c.profilerHotspots
}

func (c *Config) SetProfilerHotspotsEnabled(enabled bool, origin telemetry.Origin) {
c.mu.Lock()
defer c.mu.Unlock()
c.profilerHotspots = enabled
telemetry.RegisterAppConfig(traceprof.CodeHotspotsEnvVar, enabled, origin)
}
func (c *Config) RuntimeMetricsEnabled() bool {
c.mu.RLock()
defer c.mu.RUnlock()
Expand All @@ -148,6 +161,7 @@ func (c *Config) SetRuntimeMetricsEnabled(enabled bool, origin telemetry.Origin)
c.runtimeMetrics = enabled
telemetry.RegisterAppConfig("DD_RUNTIME_METRICS_ENABLED", enabled, origin)
}

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