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

[exporter/datadog] Add feature flag for updated operation and resourc… #36419

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
27 changes: 27 additions & 0 deletions .chloggen/ibraheem_add-gate-for-operation-name-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadogexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add a feature gate datadog.EnableOperationAndResourceNameV2. Enabling this gate modifies the logic for computing operation and resource names from OTLP spans to produce shorter, more readable names and improve alignment with OpenTelemetry specifications."

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36419]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
5 changes: 5 additions & 0 deletions connector/datadogconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func getTraceAgentCfg(logger *zap.Logger, cfg TracesConfig, attributesTranslator
}
if datadog.ReceiveResourceSpansV2FeatureGate.IsEnabled() {
acfg.Features["enable_receive_resource_spans_v2"] = struct{}{}
} else {
logger.Warn("Please enable feature gate datadog.EnableOperationAndResourceNameV2 for improved operation and resource name logic. This feature will be enabled by default in the future - if you have Datadog monitors or alerts set on operation/resource names, you may need to migrate them to the new convention.")
}
if datadog.OperationAndResourceNameV2FeatureGate.IsEnabled() {
acfg.Features["enable_operation_and_resource_name_logic_v2"] = struct{}{}
}
if v := cfg.BucketInterval; v > 0 {
acfg.BucketInterval = v
Expand Down
20 changes: 20 additions & 0 deletions connector/datadogconnector/connector_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/connector/connectortest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/ptrace"
semconv "go.opentelemetry.io/collector/semconv/v1.27.0"
"go.uber.org/zap"
Expand Down Expand Up @@ -130,6 +131,18 @@ var (
)

func TestMeasuredAndClientKindNative(t *testing.T) {
t.Run("OperationAndResourceNameV1", func(t *testing.T) {
testMeasuredAndClientKindNative(t, false)
})
t.Run("OperationAndResourceNameV2", func(t *testing.T) {
testMeasuredAndClientKindNative(t, true)
})
}

func testMeasuredAndClientKindNative(t *testing.T, enableOperationAndResourceNameV2 bool) {
if err := featuregate.GlobalRegistry().Set("datadog.EnableOperationAndResourceNameV2", enableOperationAndResourceNameV2); err != nil {
t.Fatal(err)
}
cfg := NewFactory().CreateDefaultConfig().(*Config)
cfg.Traces.ComputeTopLevelBySpanKind = true
connector, metricsSink := creteConnectorNativeWithCfg(t, cfg)
Expand Down Expand Up @@ -240,6 +253,13 @@ func TestMeasuredAndClientKindNative(t *testing.T) {
IsTraceRoot: pb.Trilean_TRUE,
},
}

if enableOperationAndResourceNameV2 {
expected[0].Name = "Internal"
expected[1].Name = "client.request"
expected[2].Name = "server.request"
}

if diff := cmp.Diff(
cgss,
expected,
Expand Down
60 changes: 60 additions & 0 deletions connector/datadogconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,66 @@ func testReceiveResourceSpansV2(t *testing.T, enableReceiveResourceSpansV2 bool)
}
}

func TestOperationAndResourceNameV2(t *testing.T) {
t.Run("OperationAndResourceNameV1", func(t *testing.T) {
testOperationAndResourceNameV2(t, false)
})
t.Run("OperationAndResourceNameV2", func(t *testing.T) {
testOperationAndResourceNameV2(t, true)
})
}

func testOperationAndResourceNameV2(t *testing.T, enableOperationAndResourceNameV2 bool) {
if err := featuregate.GlobalRegistry().Set("datadog.EnableOperationAndResourceNameV2", enableOperationAndResourceNameV2); err != nil {
t.Fatal(err)
}
connector, metricsSink := creteConnector(t)
err := connector.Start(context.Background(), componenttest.NewNopHost())
if err != nil {
t.Errorf("Error starting connector: %v", err)
return
}
defer func() {
_ = connector.Shutdown(context.Background())
}()

trace := generateTrace()
rspan := trace.ResourceSpans().At(0)
rspan.Resource().Attributes().PutStr("deployment.environment.name", "new_env")
rspan.ScopeSpans().At(0).Spans().At(0).SetKind(ptrace.SpanKindServer)

err = connector.ConsumeTraces(context.Background(), trace)
assert.NoError(t, err)

for {
if len(metricsSink.AllMetrics()) > 0 {
break
}
time.Sleep(100 * time.Millisecond)
}

// check if the container tags are added to the metrics
metrics := metricsSink.AllMetrics()
assert.Len(t, metrics, 1)

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil)
require.NoError(t, err)
msg := <-ch
sp := &pb.StatsPayload{}

err = proto.Unmarshal(msg, sp)
require.NoError(t, err)

gotName := sp.Stats[0].Stats[0].Stats[0].Name
if enableOperationAndResourceNameV2 {
assert.Equal(t, "server.request", gotName)
} else {
assert.Equal(t, "opentelemetry.server", gotName)
}
}

func newTranslatorWithStatsChannel(t *testing.T, logger *zap.Logger, ch chan []byte) *otlpmetrics.Translator {
options := []otlpmetrics.TranslatorOption{
otlpmetrics.WithHistogramMode(otlpmetrics.HistogramModeDistributions),
Expand Down
5 changes: 5 additions & 0 deletions exporter/datadogexporter/traces_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ func newTraceAgentConfig(ctx context.Context, params exporter.Settings, cfg *Con
return clientutil.NewHTTPClient(cfg.ClientConfig)
}
}
if datadog.OperationAndResourceNameV2FeatureGate.IsEnabled() {
acfg.Features["enable_operation_and_resource_name_logic_v2"] = struct{}{}
} else {
params.Logger.Warn("Please enable feature gate datadog.EnableOperationAndResourceNameV2 for improved operation and resource name logic. This feature will be enabled by default in the future - if you have Datadog monitors or alerts set on operation/resource names, you may need to migrate them to the new convention.")
}
if v := cfg.Traces.GetFlushInterval(); v > 0 {
acfg.TraceWriter.FlushPeriodSeconds = v
}
Expand Down
68 changes: 53 additions & 15 deletions exporter/datadogexporter/traces_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func testTracesSource(t *testing.T, enableReceiveResourceSpansV2 bool) {
} {
t.Run("", func(t *testing.T) {
ctx := context.Background()
err = exporter.ConsumeTraces(ctx, simpleTracesWithResAttributes(tt.attrs))
err = exporter.ConsumeTraces(ctx, simpleTraces(tt.attrs, nil, ptrace.SpanKindInternal))
assert.NoError(err)
timeout := time.After(time.Second)
select {
Expand Down Expand Up @@ -307,7 +307,7 @@ func testTraceExporter(t *testing.T, enableReceiveResourceSpansV2 bool) {
assert.NoError(t, err)

ctx := context.Background()
err = exporter.ConsumeTraces(ctx, simpleTraces())
err = exporter.ConsumeTraces(ctx, simpleTraces(nil, nil, ptrace.SpanKindInternal))
assert.NoError(t, err)
timeout := time.After(2 * time.Second)
select {
Expand Down Expand Up @@ -428,7 +428,7 @@ func testPushTraceDataNewEnvConvention(t *testing.T, enableReceiveResourceSpansV
exp, err := f.CreateTraces(context.Background(), params, cfg)
assert.NoError(t, err)

err = exp.ConsumeTraces(context.Background(), simpleTracesWithResAttributes(map[string]any{conventions127.AttributeDeploymentEnvironmentName: "new_env"}))
err = exp.ConsumeTraces(context.Background(), simpleTraces(map[string]any{conventions127.AttributeDeploymentEnvironmentName: "new_env"}, nil, ptrace.SpanKindInternal))
assert.NoError(t, err)

reqBytes := <-tracesRec.ReqChan
Expand All @@ -443,6 +443,51 @@ func testPushTraceDataNewEnvConvention(t *testing.T, enableReceiveResourceSpansV
assert.Equal(t, "new_env", traces.TracerPayloads[0].GetEnv())
}

func TestPushTraceData_OperationAndResourceNameV2(t *testing.T) {
err := featuregate.GlobalRegistry().Set("datadog.EnableOperationAndResourceNameV2", true)
if err != nil {
t.Fatal(err)
}
tracesRec := &testutil.HTTPRequestRecorderWithChan{Pattern: testutil.TraceEndpoint, ReqChan: make(chan []byte)}
server := testutil.DatadogServerMock(tracesRec.HandlerFunc)
defer server.Close()
cfg := &Config{
API: APIConfig{
Key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
TagsConfig: TagsConfig{
Hostname: "test-host",
},
Metrics: MetricsConfig{
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL},
},
Traces: TracesConfig{
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL},
},
}
cfg.Traces.SetFlushInterval(0.1)

params := exportertest.NewNopSettings()
f := NewFactory()
exp, err := f.CreateTraces(context.Background(), params, cfg)
assert.NoError(t, err)

err = exp.ConsumeTraces(context.Background(), simpleTraces(map[string]any{conventions127.AttributeDeploymentEnvironmentName: "new_env"}, nil, ptrace.SpanKindServer))
assert.NoError(t, err)

reqBytes := <-tracesRec.ReqChan
buf := bytes.NewBuffer(reqBytes)
reader, err := gzip.NewReader(buf)
require.NoError(t, err)
slurp, err := io.ReadAll(reader)
require.NoError(t, err)
var traces pb.AgentPayload
require.NoError(t, proto.Unmarshal(slurp, &traces))
assert.Len(t, traces.TracerPayloads, 1)
assert.Equal(t, "new_env", traces.TracerPayloads[0].GetEnv())
assert.Equal(t, "server.request", traces.TracerPayloads[0].Chunks[0].Spans[0].Name)
}

func TestResRelatedAttributesInSpanAttributes_ReceiveResourceSpansV2Enabled(t *testing.T) {
if err := featuregate.GlobalRegistry().Set("datadog.EnableReceiveResourceSpansV2", true); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -480,7 +525,7 @@ func TestResRelatedAttributesInSpanAttributes_ReceiveResourceSpansV2Enabled(t *t
"service.name": "do-not-use",
"service.version": "do-not-use",
}
err = exp.ConsumeTraces(context.Background(), simpleTracesWithResAndSpanAttributes(nil, sattr))
err = exp.ConsumeTraces(context.Background(), simpleTraces(nil, sattr, ptrace.SpanKindInternal))
assert.NoError(t, err)

reqBytes := <-tracesRec.ReqChan
Expand All @@ -501,24 +546,17 @@ func TestResRelatedAttributesInSpanAttributes_ReceiveResourceSpansV2Enabled(t *t
assert.Empty(t, span.Meta["version"])
}

func simpleTraces() ptrace.Traces {
return genTraces([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}, nil, nil)
}

func simpleTracesWithResAttributes(rattrs map[string]any) ptrace.Traces {
return genTraces([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}, rattrs, nil)
}

func simpleTracesWithResAndSpanAttributes(rattrs map[string]any, sattrs map[string]any) ptrace.Traces {
return genTraces([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}, rattrs, sattrs)
func simpleTraces(rattrs map[string]any, sattrs map[string]any, kind ptrace.SpanKind) ptrace.Traces {
return genTraces([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}, rattrs, sattrs, kind)
}

func genTraces(traceID pcommon.TraceID, rattrs map[string]any, sattrs map[string]any) ptrace.Traces {
func genTraces(traceID pcommon.TraceID, rattrs map[string]any, sattrs map[string]any, kind ptrace.SpanKind) ptrace.Traces {
traces := ptrace.NewTraces()
rspans := traces.ResourceSpans().AppendEmpty()
span := rspans.ScopeSpans().AppendEmpty().Spans().AppendEmpty()
span.SetTraceID(traceID)
span.SetSpanID([8]byte{0, 0, 0, 0, 1, 2, 3, 4})
span.SetKind(kind)
if rattrs == nil {
return traces
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/datadog/gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ var ReceiveResourceSpansV2FeatureGate = featuregate.GlobalRegistry().MustRegiste
featuregate.WithRegisterFromVersion("v0.118.0"),
featuregate.WithRegisterToVersion("v0.124.0"),
)

var OperationAndResourceNameV2FeatureGate = featuregate.GlobalRegistry().MustRegister(
"datadog.EnableOperationAndResourceNameV2",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("When enabled, datadogexporter and datadogconnector use improved logic to compute operation name and resource name."),
featuregate.WithRegisterFromVersion("v0.118.0"),
)
Loading