@@ -374,7 +374,7 @@ func TestTracesTranslationErrorsAndResource(t *testing.T) {
374
374
// ensure that version gives resource service.version priority
375
375
assert .Equal (t , "test-version" , datadogPayload .Traces [0 ].Spans [0 ].Meta ["version" ])
376
376
377
- assert .Equal (t , 19 , len (datadogPayload .Traces [0 ].Spans [0 ].Meta ))
377
+ assert .Equal (t , 20 , len (datadogPayload .Traces [0 ].Spans [0 ].Meta ))
378
378
379
379
assert .Contains (t , datadogPayload .Traces [0 ].Spans [0 ].Meta [tagContainersTags ], "container_id:3249847017410247" )
380
380
assert .Contains (t , datadogPayload .Traces [0 ].Spans [0 ].Meta [tagContainersTags ], "pod_name:example-pod-name" )
@@ -617,7 +617,7 @@ func TestTracesTranslationOkStatus(t *testing.T) {
617
617
// ensure that version gives resource service.version priority
618
618
assert .Equal (t , "test-version" , datadogPayload .Traces [0 ].Spans [0 ].Meta ["version" ])
619
619
620
- assert .Equal (t , 19 , len (datadogPayload .Traces [0 ].Spans [0 ].Meta ))
620
+ assert .Equal (t , 20 , len (datadogPayload .Traces [0 ].Spans [0 ].Meta ))
621
621
}
622
622
623
623
// ensure that the datadog span uses the configured unified service tags
@@ -664,7 +664,7 @@ func TestTracesTranslationConfig(t *testing.T) {
664
664
// ensure that version gives resource service.version priority
665
665
assert .Equal (t , "test-version" , datadogPayload .Traces [0 ].Spans [0 ].Meta ["version" ])
666
666
667
- assert .Equal (t , 16 , len (datadogPayload .Traces [0 ].Spans [0 ].Meta ))
667
+ assert .Equal (t , 17 , len (datadogPayload .Traces [0 ].Spans [0 ].Meta ))
668
668
}
669
669
670
670
// ensure that the translation returns early if no resource instrumentation library spans
@@ -1399,3 +1399,54 @@ func TestSpanNameMapping(t *testing.T) {
1399
1399
1400
1400
assert .Equal (t , "bang.client" , aggregatedTraces [0 ].Traces [0 ].Spans [0 ].Name )
1401
1401
}
1402
+
1403
+ // ensure that sanitization of trace payloads occurs
1404
+ func TestSpanEnvClobbering (t * testing.T ) {
1405
+ mockTraceID := [16 ]byte {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0A , 0x0B , 0x0C , 0x0D , 0x0E , 0x0F }
1406
+ mockSpanID := [8 ]byte {0xF1 , 0xF2 , 0xF3 , 0xF4 , 0xF5 , 0xF6 , 0xF7 , 0xF8 }
1407
+ mockParentSpanID := [8 ]byte {0xEF , 0xEE , 0xED , 0xEC , 0xEB , 0xEA , 0xE9 , 0xE8 }
1408
+ endTime := time .Now ().Round (time .Second )
1409
+ pdataEndTime := pdata .TimestampFromTime (endTime )
1410
+ startTime := endTime .Add (- 90 * time .Second )
1411
+ pdataStartTime := pdata .TimestampFromTime (startTime )
1412
+
1413
+ denylister := newDenylister ([]string {})
1414
+ buildInfo := component.BuildInfo {
1415
+ Version : "1.0" ,
1416
+ }
1417
+
1418
+ traces := pdata .NewTraces ()
1419
+ traces .ResourceSpans ().Resize (1 )
1420
+ rs := traces .ResourceSpans ().At (0 )
1421
+ resource := rs .Resource ()
1422
+ resource .Attributes ().InitFromMap (map [string ]pdata.AttributeValue {
1423
+ conventions .AttributeDeploymentEnvironment : pdata .NewAttributeValueString ("correctenv" ),
1424
+ "env" : pdata .NewAttributeValueString ("incorrectenv" ),
1425
+ })
1426
+
1427
+ rs .InstrumentationLibrarySpans ().Resize (1 )
1428
+ ilss := rs .InstrumentationLibrarySpans ().At (0 )
1429
+ instrumentationLibrary := ilss .InstrumentationLibrary ()
1430
+ instrumentationLibrary .SetName ("flash" )
1431
+ instrumentationLibrary .SetVersion ("v1" )
1432
+ span := ilss .Spans ().AppendEmpty ()
1433
+
1434
+ traceID := pdata .NewTraceID (mockTraceID )
1435
+ spanID := pdata .NewSpanID (mockSpanID )
1436
+ parentSpanID := pdata .NewSpanID (mockParentSpanID )
1437
+ span .SetTraceID (traceID )
1438
+ span .SetSpanID (spanID )
1439
+ span .SetParentSpanID (parentSpanID )
1440
+ span .SetName ("End-To-End Here" )
1441
+ span .SetKind (pdata .SpanKindServer )
1442
+ span .SetStartTimestamp (pdataStartTime )
1443
+ span .SetEndTimestamp (pdataEndTime )
1444
+
1445
+ config := config.Config {Traces : config.TracesConfig {SpanNameRemappings : map [string ]string {"flash.server" : "bang.client" }}}
1446
+
1447
+ outputTraces , _ := convertToDatadogTd (traces , "test-host" , & config , denylister , buildInfo )
1448
+
1449
+ // Ensure the deployment.environment value is copied to both deployment.environment and env
1450
+ assert .Equal (t , "correctenv" , outputTraces [0 ].Traces [0 ].Spans [0 ].Meta ["env" ])
1451
+ assert .Equal (t , "correctenv" , outputTraces [0 ].Traces [0 ].Spans [0 ].Meta ["deployment.environment" ])
1452
+ }
0 commit comments