Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ReceiveResourceSpans to share code with otelSpanToDDSpan fro… #29435

Merged
merged 19 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
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
1 change: 1 addition & 0 deletions cmd/serverless/dependencies_linux_amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ github.com/DataDog/datadog-agent/pkg/trace/stats
github.com/DataDog/datadog-agent/pkg/trace/telemetry
github.com/DataDog/datadog-agent/pkg/trace/timing
github.com/DataDog/datadog-agent/pkg/trace/traceutil
github.com/DataDog/datadog-agent/pkg/trace/transform
github.com/DataDog/datadog-agent/pkg/trace/version
github.com/DataDog/datadog-agent/pkg/trace/watchdog
github.com/DataDog/datadog-agent/pkg/trace/writer
Expand Down
1 change: 1 addition & 0 deletions cmd/serverless/dependencies_linux_arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ github.com/DataDog/datadog-agent/pkg/trace/stats
github.com/DataDog/datadog-agent/pkg/trace/telemetry
github.com/DataDog/datadog-agent/pkg/trace/timing
github.com/DataDog/datadog-agent/pkg/trace/traceutil
github.com/DataDog/datadog-agent/pkg/trace/transform
github.com/DataDog/datadog-agent/pkg/trace/version
github.com/DataDog/datadog-agent/pkg/trace/watchdog
github.com/DataDog/datadog-agent/pkg/trace/writer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ func (c testComponent) SendStatsPayload(p *pb.StatsPayload) {
var _ traceagent.Component = (*testComponent)(nil)

func TestTraceExporter(t *testing.T) {
t.Run("ReceiveResourceSpansV1", func(t *testing.T) {
testTraceExporter(false, t)
})

t.Run("ReceiveResourceSpansV2", func(t *testing.T) {
testTraceExporter(true, t)
})
}

func testTraceExporter(enableReceiveResourceSpansV2 bool, t *testing.T) {
got := make(chan string, 1)
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
assert.Equal(t, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", req.Header.Get("DD-Api-Key"))
Expand Down Expand Up @@ -77,6 +87,9 @@ func TestTraceExporter(t *testing.T) {
tcfg.TraceWriter.FlushPeriodSeconds = 0.1
tcfg.Endpoints[0].APIKey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
tcfg.Endpoints[0].Host = server.URL
if enableReceiveResourceSpansV2 {
tcfg.Features["enable_receive_resource_spans_v2"] = struct{}{}
}
ctx := context.Background()
traceagent := pkgagent.NewAgent(ctx, tcfg, telemetry.NewNoopCollector(), &ddgostatsd.NoOpClient{}, gzip.NewComponent())

Expand All @@ -99,13 +112,26 @@ func TestTraceExporter(t *testing.T) {
}

func TestNewTracesExporter(t *testing.T) {
t.Run("ReceiveResourceSpansV1", func(t *testing.T) {
testNewTracesExporter(false, t)
})

t.Run("ReceiveResourceSpansV2", func(t *testing.T) {
testNewTracesExporter(true, t)
})
}

func testNewTracesExporter(enableReceiveResourceSpansV2 bool, t *testing.T) {
cfg := &Config{}
cfg.API.Key = "ddog_32_characters_long_api_key1"
params := exportertest.NewNopSettings()
tcfg := config.New()
tcfg.Endpoints[0].APIKey = "ddog_32_characters_long_api_key1"
ctx := context.Background()
tcfg.ReceiverEnabled = false
if enableReceiveResourceSpansV2 {
tcfg.Features["enable_receive_resource_spans_v2"] = struct{}{}
}
traceagent := pkgagent.NewAgent(ctx, tcfg, telemetry.NewNoopCollector(), &ddgostatsd.NoOpClient{}, gzip.NewComponent())

// The client should have been created correctly
Expand Down
13 changes: 13 additions & 0 deletions comp/otelcol/otlp/components/statsprocessor/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,24 @@ func TestTraceAgentConfig(t *testing.T) {
}

func TestTraceAgent(t *testing.T) {
t.Run("ReceiveResourceSpansV1", func(t *testing.T) {
testTraceAgent(false, t)
})

t.Run("ReceiveResourceSpansV2", func(t *testing.T) {
testTraceAgent(true, t)
})
}

func testTraceAgent(enableReceiveResourceSpansV2 bool, t *testing.T) {
cfg := traceconfig.New()
attributesTranslator, err := attributes.NewTranslator(componenttest.NewNopTelemetrySettings())
require.NoError(t, err)
cfg.OTLPReceiver.AttributesTranslator = attributesTranslator
cfg.BucketInterval = 50 * time.Millisecond
if enableReceiveResourceSpansV2 {
cfg.Features["enable_receive_resource_spans_v2"] = struct{}{}
}
out := make(chan *pb.StatsPayload, 10)
ctx := context.Background()
_, metricClient, timingReporter := setupMetricClient()
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ api_key:
## The list of items available under apm_config.features is not guaranteed to persist across versions;
## a feature may eventually be promoted to its own configuration option on the agent, or dropped entirely.
#
# features: ["error_rare_sample_tracer_drop","table_names","component2name","sql_cache","sqllexer","enable_otlp_compute_top_level_by_span_kind"]
# features: ["error_rare_sample_tracer_drop","table_names","component2name","sql_cache","sqllexer","enable_otlp_compute_top_level_by_span_kind","enable_receive_resource_spans_v2"]

## @param additional_endpoints - object - optional
## @env DD_APM_ADDITIONAL_ENDPOINTS - object - optional
Expand Down
Loading
Loading