Skip to content

Commit 037b689

Browse files
jackgopack4chengchuanpeng
authored andcommitted
[connector/datadog] support obfuscation in datadogconnector (open-telemetry#37457)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Support obfuscating SQL and Redis queries in APM stats in Datadog Connector. replace statement in otelcontribcol was necessary due to failing build in pipeline. It doesn't appear that any modules use any affected functions, but building otelcontribcol with ocb failed due to an API change. Also opened an issue to bump the `receiver/awscontainerinsight` dependency so that this replace can be removed in the future: open-telemetry#37486 <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Replaces open-telemetry#35401 <!--Describe what testing was performed and which tests were added.--> #### Testing Added TestObfuscate in connector_native_test.go <!--Describe the documentation added.--> #### Documentation added release note and link to semantics on Datadog vendor website <!--Please delete paragraphs that you did not use before submitting.-->
1 parent a222f83 commit 037b689

File tree

10 files changed

+275
-105
lines changed

10 files changed

+275
-105
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: datadogconnector
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Support obfuscating sql queries in APM stats
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37457]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
Ensure that feature flags "enable_receive_resource_spans_v2" and "enable_operation_and_resource_name_logic_v2"
20+
are also enabled on both Datadog Exporter and Datadog Connector so that span attributes are properly
21+
mapped to span type and span resource in Datadog APM; otherwise spans and apm stats may not be
22+
obfuscated and attributes on stats payloads may not match traces.
23+
See https://docs.datadoghq.com/opentelemetry/schema_semantics/semantic_mapping/?tab=datadogexporter#mapping-opentelemetry-database-system-type-to-datadog-span-type
24+
25+
NOTE: Long/complex SQL queries may cause a performance impact on APM Stats calculation in Datadog Connector.
26+
Consider implementing sampling in your pipeline prior to sending traces to Datadog Connector if you experience this.
27+
28+
# If your change doesn't affect end users or the exported elements of any package,
29+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
30+
# Optional: The change log or logs in which this entry should be included.
31+
# e.g. '[user]' or '[user, api]'
32+
# Include 'user' if the change is relevant to end users.
33+
# Include 'api' if there is a change to a library API.
34+
# Default: '[user]'
35+
change_logs: [user]

cmd/otelcontribcol/builder-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,4 @@ replaces:
515515
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/dorisexporter => ../../exporter/dorisexporter
516516
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/redisstorageextension => ../../extension/storage/redisstorageextension
517517
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver => ../../receiver/huaweicloudcesreceiver
518+
- github.com/opencontainers/runc v1.1.14 => github.com/opencontainers/runc v1.2.4

connector/datadogconnector/connector_native.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/statsprocessor"
12+
"github.com/DataDog/datadog-agent/pkg/obfuscate"
1213
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace"
1314
"github.com/DataDog/datadog-agent/pkg/trace/config"
1415
"github.com/DataDog/datadog-agent/pkg/trace/stats"
@@ -48,6 +49,10 @@ type traceToMetricConnectorNative struct {
4849
// resulting from ingested traces.
4950
statsout chan *pb.StatsPayload
5051

52+
// obfuscator is used to obfuscate sensitive data from various span
53+
// tags based on their type.
54+
obfuscator *obfuscate.Obfuscator
55+
5156
// exit specifies the exit channel, which will be closed upon shutdown.
5257
exit chan struct{}
5358

@@ -73,6 +78,10 @@ func newTraceToMetricConnectorNative(set component.TelemetrySettings, cfg compon
7378
}
7479

7580
tcfg := getTraceAgentCfg(set.Logger, cfg.(*Config).Traces, attributesTranslator)
81+
oconf := tcfg.Obfuscation.Export(tcfg)
82+
oconf.Statsd = metricsClient
83+
oconf.Redis.Enabled = true
84+
7685
return &traceToMetricConnectorNative{
7786
logger: set.Logger,
7887
translator: trans,
@@ -82,6 +91,7 @@ func newTraceToMetricConnectorNative(set component.TelemetrySettings, cfg compon
8291
concentrator: stats.NewConcentrator(tcfg, statsWriter, time.Now(), metricsClient),
8392
statsout: statsout,
8493
metricsConsumer: metricsConsumer,
94+
obfuscator: obfuscate.NewObfuscator(oconf),
8595
exit: make(chan struct{}),
8696
}, nil
8797
}
@@ -103,8 +113,9 @@ func (c *traceToMetricConnectorNative) Shutdown(context.Context) error {
103113
return nil
104114
}
105115
c.logger.Info("Shutting down datadog connector")
106-
c.logger.Info("Stopping concentrator")
107-
// stop the concentrator and wait for the run loop to exit
116+
c.logger.Info("Stopping obfuscator and concentrator")
117+
// stop the obfuscator and concentrator and wait for the run loop to exit
118+
c.obfuscator.Stop()
108119
c.concentrator.Stop()
109120
c.exit <- struct{}{} // signal exit
110121
<-c.exit // wait for close
@@ -118,7 +129,7 @@ func (c *traceToMetricConnectorNative) Capabilities() consumer.Capabilities {
118129
}
119130

120131
func (c *traceToMetricConnectorNative) ConsumeTraces(_ context.Context, traces ptrace.Traces) error {
121-
inputs := stats.OTLPTracesToConcentratorInputs(traces, c.tcfg, c.ctagKeys, c.peerTagKeys)
132+
inputs := stats.OTLPTracesToConcentratorInputsWithObfuscation(traces, c.tcfg, c.ctagKeys, c.peerTagKeys, c.obfuscator)
122133
for _, input := range inputs {
123134
c.concentrator.Add(input)
124135
}

connector/datadogconnector/connector_native_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12+
"github.com/DataDog/datadog-agent/pkg/obfuscate"
1213
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace"
1314
"github.com/google/go-cmp/cmp"
1415
"github.com/stretchr/testify/assert"
@@ -72,6 +73,8 @@ func creteConnectorNativeWithCfg(t *testing.T, cfg *Config) (*traceToMetricConne
7273

7374
connector, ok := tconn.(*traceToMetricConnectorNative)
7475
require.True(t, ok)
76+
oconf := obfuscate.Config{Redis: obfuscate.RedisConfig{Enabled: false}}
77+
connector.obfuscator = obfuscate.NewObfuscator(oconf)
7578
return connector, metricsSink
7679
}
7780

@@ -268,3 +271,87 @@ func testMeasuredAndClientKindNative(t *testing.T, enableOperationAndResourceNam
268271
t.Errorf("Diff between APM stats -want +got:\n%v", diff)
269272
}
270273
}
274+
275+
func TestObfuscate(t *testing.T) {
276+
cfg := NewFactory().CreateDefaultConfig().(*Config)
277+
cfg.Traces.BucketInterval = time.Second
278+
279+
if err := featuregate.GlobalRegistry().Set("datadog.EnableReceiveResourceSpansV2", true); err != nil {
280+
t.Fatal(err)
281+
}
282+
if err := featuregate.GlobalRegistry().Set("datadog.EnableOperationAndResourceNameV2", true); err != nil {
283+
t.Fatal(err)
284+
}
285+
286+
connector, metricsSink := creteConnectorNativeWithCfg(t, cfg)
287+
288+
err := connector.Start(context.Background(), componenttest.NewNopHost())
289+
require.NoError(t, err)
290+
defer func() {
291+
require.NoError(t, connector.Shutdown(context.Background()))
292+
}()
293+
294+
td := ptrace.NewTraces()
295+
res := td.ResourceSpans().AppendEmpty().Resource()
296+
res.Attributes().PutStr(semconv.AttributeServiceName, "svc")
297+
res.Attributes().PutStr(semconv.AttributeDeploymentEnvironmentName, "my-env")
298+
299+
ss := td.ResourceSpans().At(0).ScopeSpans().AppendEmpty().Spans()
300+
s := ss.AppendEmpty()
301+
s.SetName("name")
302+
s.SetKind(ptrace.SpanKindClient)
303+
s.SetTraceID(testTraceID)
304+
s.SetSpanID(testSpanID1)
305+
s.Attributes().PutStr(semconv.AttributeDBSystem, semconv.AttributeDBSystemMySQL)
306+
s.Attributes().PutStr(semconv.AttributeDBOperationName, "SELECT")
307+
s.Attributes().PutStr(semconv.AttributeDBQueryText, "SELECT username FROM users WHERE id = 123") // id value 123 should be obfuscated
308+
309+
err = connector.ConsumeTraces(context.Background(), td)
310+
require.NoError(t, err)
311+
312+
timeout := time.Now().Add(1 * time.Minute)
313+
for time.Now().Before(timeout) {
314+
if len(metricsSink.AllMetrics()) > 0 {
315+
break
316+
}
317+
time.Sleep(100 * time.Millisecond)
318+
}
319+
320+
metrics := metricsSink.AllMetrics()
321+
require.Len(t, metrics, 1)
322+
323+
ch := make(chan []byte, 100)
324+
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
325+
_, err = tr.MapMetrics(context.Background(), metrics[0], nil)
326+
require.NoError(t, err)
327+
msg := <-ch
328+
sp := &pb.StatsPayload{}
329+
330+
err = proto.Unmarshal(msg, sp)
331+
require.NoError(t, err)
332+
assert.Len(t, sp.Stats, 1)
333+
assert.Len(t, sp.Stats[0].Stats, 1)
334+
assert.Equal(t, "my-env", sp.Stats[0].Env)
335+
assert.Len(t, sp.Stats[0].Stats[0].Stats, 1)
336+
cgss := sp.Stats[0].Stats[0].Stats
337+
expected := []*pb.ClientGroupedStats{
338+
{
339+
Service: "svc",
340+
Name: "mysql.query",
341+
Resource: "SELECT username FROM users WHERE id = ?",
342+
Type: "sql",
343+
Hits: 1,
344+
TopLevelHits: 1,
345+
SpanKind: "client",
346+
IsTraceRoot: pb.Trilean_TRUE,
347+
PeerTags: []string{"db.system:mysql"},
348+
},
349+
}
350+
if diff := cmp.Diff(
351+
cgss,
352+
expected,
353+
protocmp.Transform(),
354+
protocmp.IgnoreFields(&pb.ClientGroupedStats{}, "duration", "okSummary", "errorSummary")); diff != "" {
355+
t.Errorf("Diff between APM stats -want +got:\n%v", diff)
356+
}
357+
}

connector/datadogconnector/go.mod

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ go 1.22.0
55
require (
66
github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/metricsclient v0.61.0
77
github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/statsprocessor v0.61.0
8-
github.com/DataDog/datadog-agent/pkg/proto v0.63.0-devel
9-
github.com/DataDog/datadog-agent/pkg/trace v0.61.0
8+
github.com/DataDog/datadog-agent/pkg/obfuscate v0.63.0-devel.0.20250123185937-1feb84b482c8
9+
github.com/DataDog/datadog-agent/pkg/proto v0.63.0-devel.0.20250123185937-1feb84b482c8
10+
github.com/DataDog/datadog-agent/pkg/trace v0.63.0-devel.0.20250123185937-1feb84b482c8
1011
github.com/DataDog/datadog-go/v5 v5.6.0
1112
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.24.0
1213
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.24.0
@@ -49,6 +50,7 @@ require (
4950
github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface v0.61.0 // indirect
5051
github.com/DataDog/datadog-agent/comp/core/log/def v0.61.0 // indirect
5152
github.com/DataDog/datadog-agent/comp/core/secrets v0.61.0 // indirect
53+
github.com/DataDog/datadog-agent/comp/core/tagger/origindetection v0.0.0-20241217122454-175edb6c74f2 // indirect
5254
github.com/DataDog/datadog-agent/comp/core/telemetry v0.61.0 // indirect
5355
github.com/DataDog/datadog-agent/comp/def v0.61.0 // indirect
5456
github.com/DataDog/datadog-agent/comp/logs/agent/config v0.61.0 // indirect
@@ -78,7 +80,6 @@ require (
7880
github.com/DataDog/datadog-agent/pkg/logs/sources v0.61.0 // indirect
7981
github.com/DataDog/datadog-agent/pkg/logs/status/statusinterface v0.61.0 // indirect
8082
github.com/DataDog/datadog-agent/pkg/logs/status/utils v0.61.0 // indirect
81-
github.com/DataDog/datadog-agent/pkg/obfuscate v0.61.0 // indirect
8283
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.61.0 // indirect
8384
github.com/DataDog/datadog-agent/pkg/status/health v0.61.0 // indirect
8485
github.com/DataDog/datadog-agent/pkg/telemetry v0.61.0 // indirect
@@ -89,7 +90,7 @@ require (
8990
github.com/DataDog/datadog-agent/pkg/util/fxutil v0.61.0 // indirect
9091
github.com/DataDog/datadog-agent/pkg/util/hostname/validate v0.61.0 // indirect
9192
github.com/DataDog/datadog-agent/pkg/util/http v0.61.0 // indirect
92-
github.com/DataDog/datadog-agent/pkg/util/log v0.61.0 // indirect
93+
github.com/DataDog/datadog-agent/pkg/util/log v0.63.0-devel.0.20250123185937-1feb84b482c8 // indirect
9394
github.com/DataDog/datadog-agent/pkg/util/optional v0.61.0 // indirect
9495
github.com/DataDog/datadog-agent/pkg/util/pointer v0.61.0 // indirect
9596
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.61.0 // indirect
@@ -101,7 +102,7 @@ require (
101102
github.com/DataDog/datadog-agent/pkg/version v0.61.0 // indirect
102103
github.com/DataDog/datadog-api-client-go/v2 v2.34.0 // indirect
103104
github.com/DataDog/dd-sensitive-data-scanner/sds-go/go v0.0.0-20240816154533-f7f9beb53a42 // indirect
104-
github.com/DataDog/go-sqllexer v0.0.16 // indirect
105+
github.com/DataDog/go-sqllexer v0.0.20 // indirect
105106
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
106107
github.com/DataDog/gohai v0.0.0-20230524154621-4316413895ee // indirect
107108
github.com/DataDog/opentelemetry-mapping-go/pkg/inframetadata v0.24.0 // indirect
@@ -136,7 +137,7 @@ require (
136137
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
137138
github.com/cespare/xxhash/v2 v2.3.0 // indirect
138139
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
139-
github.com/containerd/cgroups/v3 v3.0.3 // indirect
140+
github.com/containerd/cgroups/v3 v3.0.4 // indirect
140141
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
141142
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
142143
github.com/docker/go-units v0.5.0 // indirect
@@ -158,10 +159,10 @@ require (
158159
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
159160
github.com/gobwas/glob v0.2.3 // indirect
160161
github.com/goccy/go-json v0.10.4 // indirect
161-
github.com/godbus/dbus/v5 v5.0.6 // indirect
162+
github.com/godbus/dbus/v5 v5.1.0 // indirect
162163
github.com/gogo/protobuf v1.3.2 // indirect
163164
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
164-
github.com/golang/mock v1.6.0 // indirect
165+
github.com/golang/mock v1.7.0-rc.1 // indirect
165166
github.com/golang/protobuf v1.5.4 // indirect
166167
github.com/golang/snappy v0.0.4 // indirect
167168
github.com/google/gnostic-models v0.6.8 // indirect
@@ -195,6 +196,7 @@ require (
195196
github.com/mitchellh/copystructure v1.2.0 // indirect
196197
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
197198
github.com/mitchellh/reflectwalk v1.0.2 // indirect
199+
github.com/moby/sys/userns v0.1.0 // indirect
198200
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
199201
github.com/modern-go/reflect2 v1.0.2 // indirect
200202
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
@@ -208,10 +210,10 @@ require (
208210
github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders v0.118.0 // indirect
209211
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.118.0 // indirect
210212
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.118.0 // indirect
211-
github.com/opencontainers/runtime-spec v1.1.0-rc.3 // indirect
213+
github.com/opencontainers/runtime-spec v1.2.0 // indirect
212214
github.com/openshift/api v3.9.0+incompatible // indirect
213215
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 // indirect
214-
github.com/outcaste-io/ristretto v0.2.1 // indirect
216+
github.com/outcaste-io/ristretto v0.2.3 // indirect
215217
github.com/pelletier/go-toml v1.9.5 // indirect
216218
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
217219
github.com/pierrec/lz4/v4 v4.1.22 // indirect
@@ -224,7 +226,7 @@ require (
224226
github.com/prometheus/common v0.62.0 // indirect
225227
github.com/prometheus/procfs v0.15.1 // indirect
226228
github.com/rs/cors v1.11.1 // indirect
227-
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
229+
github.com/secure-systems-lab/go-securesystemslib v0.8.0 // indirect
228230
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
229231
github.com/shirou/gopsutil/v4 v4.24.12 // indirect
230232
github.com/shoenig/go-m1cpu v0.1.6 // indirect

0 commit comments

Comments
 (0)