From 2320b43c94e0c2daa5144fa3a6a97ee1505dfdf8 Mon Sep 17 00:00:00 2001 From: Hannah Kim Date: Fri, 8 Nov 2024 11:12:41 -0500 Subject: [PATCH] ddtrace/tracer: support reading statsd port from tracer (#2931) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dario Castañé --- ddtrace/tracer/log_test.go | 11 +++++----- ddtrace/tracer/option.go | 31 ++++++++++++++++++++------- ddtrace/tracer/option_test.go | 40 +++++++++++++++++------------------ 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/ddtrace/tracer/log_test.go b/ddtrace/tracer/log_test.go index c743a3fe00..3bc2998569 100644 --- a/ddtrace/tracer/log_test.go +++ b/ddtrace/tracer/log_test.go @@ -32,7 +32,7 @@ func TestStartupLog(t *testing.T) { tp.Ignore("appsec: ", telemetry.LogPrefix) logStartup(tracer) require.Len(t, tp.Logs(), 2) - assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"","service":"tracer\.test(\.exe)?","agent_url":"http://localhost:9/v0.4/traces","agent_error":"Post .*","debug":false,"analytics_enabled":false,"sample_rate":"NaN","sample_rate_limit":"disabled","trace_sampling_rules":null,"span_sampling_rules":null,"sampling_rules_error":"","service_mappings":null,"tags":{"runtime-id":"[^"]*"},"runtime_metrics_enabled":false,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":false,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"","architecture":"[^"]*","global_service":"","lambda_mode":"false","appsec":((true)|(false)),"agent_features":{"DropP0s":((true)|(false)),"Stats":((true)|(false)),"StatsdPort":0},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":false},"feature_flags":\[\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[1]) + assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"","service":"tracer\.test(\.exe)?","agent_url":"http://localhost:9/v0.4/traces","agent_error":"Post .*","debug":false,"analytics_enabled":false,"sample_rate":"NaN","sample_rate_limit":"disabled","trace_sampling_rules":null,"span_sampling_rules":null,"sampling_rules_error":"","service_mappings":null,"tags":{"runtime-id":"[^"]*"},"runtime_metrics_enabled":false,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":false,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"","architecture":"[^"]*","global_service":"","lambda_mode":"false","appsec":((true)|(false)),"agent_features":{"DropP0s":((true)|(false)),"Stats":((true)|(false)),"StatsdPort":(0|8125)},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":false},"feature_flags":\[\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[1]) }) t.Run("configured", func(t *testing.T) { @@ -64,7 +64,7 @@ func TestStartupLog(t *testing.T) { tp.Ignore("appsec: ", telemetry.LogPrefix) logStartup(tracer) require.Len(t, tp.Logs(), 2) - assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"configuredEnv","service":"configured.service","agent_url":"http://localhost:9/v0.4/traces","agent_error":"Post .*","debug":true,"analytics_enabled":true,"sample_rate":"0\.123000","sample_rate_limit":"100","trace_sampling_rules":\[{"service":"mysql","sample_rate":0\.75}\],"span_sampling_rules":null,"sampling_rules_error":"","service_mappings":{"initial_service":"new_service"},"tags":{"runtime-id":"[^"]*","tag":"value","tag2":"NaN"},"runtime_metrics_enabled":true,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":true,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"2.3.4","architecture":"[^"]*","global_service":"configured.service","lambda_mode":"false","appsec":((true)|(false)),"agent_features":{"DropP0s":false,"Stats":false,"StatsdPort":0},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":true,"metadata":{"version":"v1"}},"feature_flags":\["discovery"\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[1]) + assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"configuredEnv","service":"configured.service","agent_url":"http://localhost:9/v0.4/traces","agent_error":"Post .*","debug":true,"analytics_enabled":true,"sample_rate":"0\.123000","sample_rate_limit":"100","trace_sampling_rules":\[{"service":"mysql","sample_rate":0\.75}\],"span_sampling_rules":null,"sampling_rules_error":"","service_mappings":{"initial_service":"new_service"},"tags":{"runtime-id":"[^"]*","tag":"value","tag2":"NaN"},"runtime_metrics_enabled":true,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":true,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"2.3.4","architecture":"[^"]*","global_service":"configured.service","lambda_mode":"false","appsec":((true)|(false)),"agent_features":{"DropP0s":false,"Stats":false,"StatsdPort":(0|8125)},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":true,"metadata":{"version":"v1"}},"feature_flags":\["discovery"\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[1]) }) t.Run("limit", func(t *testing.T) { @@ -94,7 +94,7 @@ func TestStartupLog(t *testing.T) { tp.Ignore("appsec: ", telemetry.LogPrefix) logStartup(tracer) require.Len(t, tp.Logs(), 2) - assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"configuredEnv","service":"configured.service","agent_url":"http://localhost:9/v0.4/traces","agent_error":"Post .*","debug":true,"analytics_enabled":true,"sample_rate":"0\.123000","sample_rate_limit":"1000.001","trace_sampling_rules":\[{"service":"mysql","sample_rate":0\.75}\],"span_sampling_rules":null,"sampling_rules_error":"","service_mappings":{"initial_service":"new_service"},"tags":{"runtime-id":"[^"]*","tag":"value","tag2":"NaN"},"runtime_metrics_enabled":true,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":true,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"2.3.4","architecture":"[^"]*","global_service":"configured.service","lambda_mode":"false","appsec":((true)|(false)),"agent_features":{"DropP0s":false,"Stats":false,"StatsdPort":0},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":false},"feature_flags":\[\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[1]) + assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"configuredEnv","service":"configured.service","agent_url":"http://localhost:9/v0.4/traces","agent_error":"Post .*","debug":true,"analytics_enabled":true,"sample_rate":"0\.123000","sample_rate_limit":"1000.001","trace_sampling_rules":\[{"service":"mysql","sample_rate":0\.75}\],"span_sampling_rules":null,"sampling_rules_error":"","service_mappings":{"initial_service":"new_service"},"tags":{"runtime-id":"[^"]*","tag":"value","tag2":"NaN"},"runtime_metrics_enabled":true,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":true,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"2.3.4","architecture":"[^"]*","global_service":"configured.service","lambda_mode":"false","appsec":((true)|(false)),"agent_features":{"DropP0s":false,"Stats":false,"StatsdPort":(0|8125)},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":false},"feature_flags":\[\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[1]) }) t.Run("errors", func(t *testing.T) { @@ -108,7 +108,8 @@ func TestStartupLog(t *testing.T) { tp.Ignore("appsec: ", telemetry.LogPrefix) logStartup(tracer) require.Len(t, tp.Logs(), 2) - assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"","service":"tracer\.test(\.exe)?","agent_url":"http://localhost:9/v0.4/traces","agent_error":"Post .*","debug":false,"analytics_enabled":false,"sample_rate":"NaN","sample_rate_limit":"100","trace_sampling_rules":\[{"service":"some\.service","sample_rate":0\.234}\],"span_sampling_rules":null,"sampling_rules_error":"\\n\\tat index 1: ignoring rule {Service:other.service Rate:2}: rate is out of \[0\.0, 1\.0] range","service_mappings":null,"tags":{"runtime-id":"[^"]*"},"runtime_metrics_enabled":false,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":false,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"","architecture":"[^"]*","global_service":"","lambda_mode":"false","appsec":((true)|(false)),"agent_features":{"DropP0s":((true)|(false)),"Stats":((true)|(false)),"StatsdPort":0},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":false},"feature_flags":\[\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[1]) + fmt.Println(tp.Logs()[1]) + assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"","service":"tracer\.test(\.exe)?","agent_url":"http://localhost:9/v0.4/traces","agent_error":"Post .*","debug":false,"analytics_enabled":false,"sample_rate":"NaN","sample_rate_limit":"100","trace_sampling_rules":\[{"service":"some\.service","sample_rate":0\.234}\],"span_sampling_rules":null,"sampling_rules_error":"\\n\\tat index 1: ignoring rule {Service:other.service Rate:2}: rate is out of \[0\.0, 1\.0] range","service_mappings":null,"tags":{"runtime-id":"[^"]*"},"runtime_metrics_enabled":false,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":false,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"","architecture":"[^"]*","global_service":"","lambda_mode":"false","appsec":((true)|(false)),"agent_features":{"DropP0s":((true)|(false)),"Stats":((true)|(false)),"StatsdPort":(0|8125)},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":false},"feature_flags":\[\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[1]) }) t.Run("lambda", func(t *testing.T) { @@ -121,7 +122,7 @@ func TestStartupLog(t *testing.T) { tp.Ignore("appsec: ", telemetry.LogPrefix) logStartup(tracer) assert.Len(tp.Logs(), 1) - assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"","service":"tracer\.test(\.exe)?","agent_url":"http://localhost:9/v0.4/traces","agent_error":"","debug":false,"analytics_enabled":false,"sample_rate":"NaN","sample_rate_limit":"disabled","trace_sampling_rules":null,"span_sampling_rules":null,"sampling_rules_error":"","service_mappings":null,"tags":{"runtime-id":"[^"]*"},"runtime_metrics_enabled":false,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":false,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"","architecture":"[^"]*","global_service":"","lambda_mode":"true","appsec":((true)|(false)),"agent_features":{"DropP0s":false,"Stats":false,"StatsdPort":0},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":false},"feature_flags":\[\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[0]) + assert.Regexp(logPrefixRegexp+` INFO: DATADOG TRACER CONFIGURATION {"date":"[^"]*","os_name":"[^"]*","os_version":"[^"]*","version":"[^"]*","lang":"Go","lang_version":"[^"]*","env":"","service":"tracer\.test(\.exe)?","agent_url":"http://localhost:9/v0.4/traces","agent_error":"","debug":false,"analytics_enabled":false,"sample_rate":"NaN","sample_rate_limit":"disabled","trace_sampling_rules":null,"span_sampling_rules":null,"sampling_rules_error":"","service_mappings":null,"tags":{"runtime-id":"[^"]*"},"runtime_metrics_enabled":false,"runtime_metrics_v2_enabled":false,"health_metrics_enabled":false,"profiler_code_hotspots_enabled":((false)|(true)),"profiler_endpoints_enabled":((false)|(true)),"dd_version":"","architecture":"[^"]*","global_service":"","lambda_mode":"true","appsec":((true)|(false)),"agent_features":{"DropP0s":false,"Stats":false,"StatsdPort":(0|8125)},"integrations":{.*},"partial_flush_enabled":false,"partial_flush_min_spans":1000,"orchestrion":{"enabled":false},"feature_flags":\[\],"propagation_style_inject":"datadog,tracecontext","propagation_style_extract":"datadog,tracecontext"}`, tp.Logs()[0]) }) t.Run("integrations", func(t *testing.T) { diff --git a/ddtrace/tracer/option.go b/ddtrace/tracer/option.go index 98297b3eba..8415b29ee5 100644 --- a/ddtrace/tracer/option.go +++ b/ddtrace/tracer/option.go @@ -524,7 +524,9 @@ func newConfig(opts ...StartOption) *config { } // if using stdout or traces are disabled, agent is disabled agentDisabled := c.logToStdout || !c.enabled.current + ignoreStatsdPort := c.agent.ignore // preserve the value of c.agent.ignore when testing c.agent = loadAgentFeatures(agentDisabled, c.agentURL, c.httpClient) + c.agent.ignore = ignoreStatsdPort info, ok := debug.ReadBuildInfo() if !ok { c.loadContribIntegrations([]*debug.Module{}) @@ -538,7 +540,7 @@ func newConfig(opts ...StartOption) *config { // no config defined address; use defaults addr = defaultDogstatsdAddr() } - if agentport := c.agent.StatsdPort; agentport > 0 { + if agentport := c.agent.StatsdPort; agentport > 0 && !c.agent.ignore { // the agent reported a non-standard port host, _, err := net.SplitHostPort(addr) if err == nil { @@ -644,6 +646,9 @@ type agentFeatures struct { // featureFlags specifies all the feature flags reported by the trace-agent. featureFlags map[string]struct{} + // ignore indicates that we should ignore the agent in favor of user set values. + // It should only be used during testing. + ignore bool // peerTags specifies precursor tags to aggregate stats on when client stats is enabled peerTags []string @@ -678,12 +683,13 @@ func loadAgentFeatures(agentDisabled bool, agentURL *url.URL, httpClient *http.C DefaultEnv string `json:"default_env"` } type infoResponse struct { - Endpoints []string `json:"endpoints"` - ClientDropP0s bool `json:"client_drop_p0s"` - StatsdPort int `json:"statsd_port"` - FeatureFlags []string `json:"feature_flags"` - PeerTags []string `json:"peer_tags"` - Config agentConfig `json:"config"` + Endpoints []string `json:"endpoints"` + ClientDropP0s bool `json:"client_drop_p0s"` + FeatureFlags []string `json:"feature_flags"` + PeerTags []string `json:"peer_tags"` + Config struct { + StatsdPort int `json:"statsd_port"` + } `json:"config"` } var info infoResponse @@ -692,7 +698,7 @@ func loadAgentFeatures(agentDisabled bool, agentURL *url.URL, httpClient *http.C return } features.DropP0s = info.ClientDropP0s - features.StatsdPort = info.StatsdPort + features.StatsdPort = info.Config.StatsdPort for _, endpoint := range info.Endpoints { switch endpoint { case "/v0.6/stats": @@ -811,6 +817,15 @@ func WithFeatureFlags(feats ...string) StartOption { } } +// withIgnoreAgent allows tests to ignore the agent running in CI so that we can +// properly test user set StatsdPort. +// This should only be used during testing. +func withIgnoreAgent(ignore bool) StartOption { + return func(c *config) { + c.agent.ignore = ignore + } +} + // WithLogger sets logger as the tracer's error printer. // Diagnostic and startup tracer logs are prefixed to simplify the search within logs. // If JSON logging format is required, it's possible to wrap tracer logs using an existing JSON logger with this diff --git a/ddtrace/tracer/option_test.go b/ddtrace/tracer/option_test.go index 078c3ce243..aa9fbbe8e3 100644 --- a/ddtrace/tracer/option_test.go +++ b/ddtrace/tracer/option_test.go @@ -66,8 +66,8 @@ func testStatsd(t *testing.T, cfg *config, addr string) { func TestStatsdUDPConnect(t *testing.T) { t.Setenv("DD_DOGSTATSD_PORT", "8111") - testStatsd(t, newConfig(), net.JoinHostPort(defaultHostname, "8111")) - cfg := newConfig() + testStatsd(t, newConfig(withIgnoreAgent(true)), net.JoinHostPort(defaultHostname, "8111")) + cfg := newConfig(withIgnoreAgent(true)) addr := net.JoinHostPort(defaultHostname, "8111") client, err := newStatsdClient(cfg) @@ -132,7 +132,7 @@ func TestAutoDetectStatsd(t *testing.T) { defer conn.Close() conn.SetDeadline(time.Now().Add(5 * time.Second)) - cfg := newConfig(WithAgentTimeout(2)) + cfg := newConfig(WithAgentTimeout(2), withIgnoreAgent(true)) statsd, err := newStatsdClient(cfg) require.NoError(t, err) defer statsd.Close() @@ -151,22 +151,22 @@ func TestAutoDetectStatsd(t *testing.T) { t.Run("env", func(t *testing.T) { t.Setenv("DD_DOGSTATSD_PORT", "8111") - testStatsd(t, newConfig(), net.JoinHostPort(defaultHostname, "8111")) + testStatsd(t, newConfig(withIgnoreAgent(true)), net.JoinHostPort(defaultHostname, "8111")) }) t.Run("agent", func(t *testing.T) { t.Run("default", func(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - w.Write([]byte(`{"statsd_port":0}`)) + w.Write([]byte(`{"endpoints": [], "config": {"statsd_port":0}}`)) })) defer srv.Close() - cfg := newConfig(WithAgentAddr(strings.TrimPrefix(srv.URL, "http://")), WithAgentTimeout(2)) + cfg := newConfig(WithAgentAddr(strings.TrimPrefix(srv.URL, "http://")), WithAgentTimeout(2), withIgnoreAgent(true)) testStatsd(t, cfg, net.JoinHostPort(defaultHostname, "8125")) }) t.Run("port", func(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - w.Write([]byte(`{"statsd_port":8999}`)) + w.Write([]byte(`{"endpoints": [], "config": {"statsd_port":8999}}`)) })) defer srv.Close() cfg := newConfig(WithAgentAddr(strings.TrimPrefix(srv.URL, "http://"))) @@ -211,10 +211,10 @@ func TestLoadAgentFeatures(t *testing.T) { t.Run("OK", func(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - w.Write([]byte(`{"endpoints":["/v0.6/stats"],"feature_flags":["a","b"],"client_drop_p0s":true,"statsd_port":8999}`)) + w.Write([]byte(`{"endpoints":["/v0.6/stats"],"feature_flags":["a","b"],"client_drop_p0s":true,"config": {"statsd_port":8999}}`)) })) defer srv.Close() - cfg := newConfig(WithAgentAddr(strings.TrimPrefix(srv.URL, "http://")), WithAgentTimeout(2)) + cfg := newConfig(WithAgentAddr(strings.TrimPrefix(srv.URL, "http://")), WithAgentTimeout(2), withIgnoreAgent(true)) assert.True(t, cfg.agent.DropP0s) assert.Equal(t, cfg.agent.StatsdPort, 8999) assert.EqualValues(t, cfg.agent.featureFlags, map[string]struct{}{ @@ -229,10 +229,10 @@ func TestLoadAgentFeatures(t *testing.T) { t.Run("discovery", func(t *testing.T) { t.Setenv("DD_TRACE_FEATURES", "discovery") srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - w.Write([]byte(`{"endpoints":["/v0.6/stats"],"client_drop_p0s":true,"statsd_port":8999}`)) + w.Write([]byte(`{"endpoints":["/v0.6/stats"],"client_drop_p0s":true,"config":{"statsd_port":8999}}`)) })) defer srv.Close() - cfg := newConfig(WithAgentAddr(strings.TrimPrefix(srv.URL, "http://")), WithAgentTimeout(2)) + cfg := newConfig(WithAgentAddr(strings.TrimPrefix(srv.URL, "http://")), WithAgentTimeout(2), withIgnoreAgent(true)) assert.True(t, cfg.agent.DropP0s) assert.True(t, cfg.agent.Stats) assert.Equal(t, 8999, cfg.agent.StatsdPort) @@ -451,7 +451,7 @@ func TestTracerOptionsDefaults(t *testing.T) { t.Run("dogstatsd", func(t *testing.T) { t.Run("default", func(t *testing.T) { - tracer := newTracer(WithAgentTimeout(2)) + tracer := newTracer(WithAgentTimeout(2), withIgnoreAgent(true)) defer tracer.Stop() c := tracer.config assert.Equal(t, c.dogstatsdAddr, "localhost:8125") @@ -460,7 +460,7 @@ func TestTracerOptionsDefaults(t *testing.T) { t.Run("env-host", func(t *testing.T) { t.Setenv("DD_AGENT_HOST", "my-host") - tracer := newTracer(WithAgentTimeout(2)) + tracer := newTracer(WithAgentTimeout(2), withIgnoreAgent(true)) defer tracer.Stop() c := tracer.config assert.Equal(t, c.dogstatsdAddr, "my-host:8125") @@ -469,17 +469,17 @@ func TestTracerOptionsDefaults(t *testing.T) { t.Run("env-port", func(t *testing.T) { t.Setenv("DD_DOGSTATSD_PORT", "123") - tracer := newTracer(WithAgentTimeout(2)) + tracer := newTracer(WithAgentTimeout(2), withIgnoreAgent(true)) defer tracer.Stop() c := tracer.config - assert.Equal(t, c.dogstatsdAddr, "localhost:123") - assert.Equal(t, globalconfig.DogstatsdAddr(), "localhost:123") + assert.Equal(t, "localhost:123", c.dogstatsdAddr) + assert.Equal(t, "localhost:123", globalconfig.DogstatsdAddr()) }) t.Run("env-both", func(t *testing.T) { t.Setenv("DD_AGENT_HOST", "my-host") t.Setenv("DD_DOGSTATSD_PORT", "123") - tracer := newTracer(WithAgentTimeout(2)) + tracer := newTracer(WithAgentTimeout(2), withIgnoreAgent(true)) defer tracer.Stop() c := tracer.config assert.Equal(t, c.dogstatsdAddr, "my-host:123") @@ -488,14 +488,14 @@ func TestTracerOptionsDefaults(t *testing.T) { t.Run("env-env", func(t *testing.T) { t.Setenv("DD_ENV", "testEnv") - tracer := newTracer(WithAgentTimeout(2)) + tracer := newTracer(WithAgentTimeout(2), withIgnoreAgent(true)) defer tracer.Stop() c := tracer.config assert.Equal(t, "testEnv", c.env) }) t.Run("option", func(t *testing.T) { - tracer := newTracer(WithDogstatsdAddress("10.1.0.12:4002")) + tracer := newTracer(WithDogstatsdAddress("10.1.0.12:4002"), withIgnoreAgent(true)) defer tracer.Stop() c := tracer.config assert.Equal(t, c.dogstatsdAddr, "10.1.0.12:4002") @@ -509,7 +509,7 @@ func TestTracerOptionsDefaults(t *testing.T) { } addr := filepath.Join(dir, "dsd.socket") defer os.RemoveAll(addr) - tracer := newTracer(WithDogstatsdAddress("unix://" + addr)) + tracer := newTracer(WithDogstatsdAddress("unix://"+addr), withIgnoreAgent(true)) defer tracer.Stop() c := tracer.config assert.Equal("unix://"+addr, c.dogstatsdAddr)