88 "fmt"
99 "io"
1010 "net/http"
11+ "strconv"
1112 "testing"
1213
1314 pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace"
@@ -28,7 +29,7 @@ var data = [2]any{
2829 2 : "elasticsearch.version" ,
2930 3 : "7.0" ,
3031 4 : "my-name" ,
31- 5 : "X " ,
32+ 5 : "numeric_attribute " ,
3233 6 : "my-service" ,
3334 7 : "my-resource" ,
3435 8 : "_sampling_priority_v1" ,
@@ -86,26 +87,27 @@ func TestTracePayloadV05Unmarshalling(t *testing.T) {
8687 require .NoError (t , traces .UnmarshalMsgDictionary (payload ), "Must not error when marshaling content" )
8788 req , _ := http .NewRequest (http .MethodPost , "/v0.5/traces" , io .NopCloser (bytes .NewReader (payload )))
8889
89- translated := ToTraces (& pb.TracerPayload {
90- LanguageName : req .Header .Get (header .Lang ),
91- LanguageVersion : req .Header .Get (header .LangVersion ),
92- TracerVersion : req .Header .Get (header .TracerVersion ),
93- Chunks : traceChunksFromTraces (traces ),
94- }, req )
90+ tracePayloads , _ := HandleTracesPayload (req )
91+ assert .Len (t , tracePayloads , 1 , "Expected one translated payload" )
92+ tracePayload := tracePayloads [0 ]
93+ translated := ToTraces (tracePayload , req )
9594 assert .Equal (t , 1 , translated .SpanCount (), "Span Count wrong" )
9695 span := translated .ResourceSpans ().At (0 ).ScopeSpans ().At (0 ).Spans ().At (0 )
9796 assert .NotNil (t , span )
98- assert .Equal (t , 9 , span .Attributes ().Len (), "missing attributes" )
97+ assert .Equal (t , "my-name" , span .Name ())
98+ assert .Equal (t , 10 , span .Attributes ().Len (), "missing attributes" )
9999 value , exists := span .Attributes ().Get ("service.name" )
100- serviceVersionValue , _ := span .Attributes ().Get ("service.version" )
101100 assert .True (t , exists , "service.name missing" )
102101 assert .Equal (t , "my-service" , value .AsString (), "service.name attribute value incorrect" )
103- assert . Equal ( t , "my-name" , span .Name () )
102+ serviceVersionValue , _ := span .Attributes (). Get ( "service.version" )
104103 assert .Equal (t , "1.0.1" , serviceVersionValue .AsString ())
105104 spanResource , _ := span .Attributes ().Get ("dd.span.Resource" )
106105 assert .Equal (t , "my-resource" , spanResource .Str ())
107106 spanResource1 , _ := span .Attributes ().Get ("sampling.priority" )
108107 assert .Equal (t , fmt .Sprintf ("%f" , 1.0 ), spanResource1 .Str ())
108+ numericAttributeValue , _ := span .Attributes ().Get ("numeric_attribute" )
109+ numericAttributeFloat , _ := strconv .ParseFloat (numericAttributeValue .AsString (), 64 )
110+ assert .Equal (t , 1.2 , numericAttributeFloat )
109111}
110112
111113func TestTracePayloadV07Unmarshalling (t * testing.T ) {
0 commit comments