File tree 2 files changed +24
-0
lines changed
lib/datadog/tracing/distributed
spec/datadog/tracing/distributed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,8 @@ def build_tags(digest)
116
116
def extract_trace_id! ( trace_id , tags )
117
117
return trace_id unless tags
118
118
return trace_id unless ( high_order = tags . delete ( Tracing ::Metadata ::Ext ::Distributed ::TAG_TID ) )
119
+ return trace_id unless high_order . size == 16
120
+ return trace_id unless /\A [0-9a-f]+\z /i . match? ( high_order )
119
121
120
122
Tracing ::Utils ::TraceId . concatenate ( high_order . to_i ( 16 ) , trace_id )
121
123
end
Original file line number Diff line number Diff line change 503
503
it { expect ( digest . span_id ) . to eq ( 0xbbbbbbbbbbbbbbbb ) }
504
504
it { expect ( digest . trace_distributed_tags ) . not_to include ( '_dd.p.tid' ) }
505
505
end
506
+
507
+ context 'with a trace id and an invalid distributed tags `_dd.p.tid`' do
508
+ [
509
+ '00123456789abcdef' , # too long
510
+ '234567890abcdef' , # too short
511
+ 'g123456789abcdef' , # invalid character
512
+ ] . each do |invalid_trace_id |
513
+ context "when given invalid trace_id: #{ invalid_trace_id } " do
514
+ let ( :data ) do
515
+ {
516
+ prepare_key [ 'x-datadog-trace-id' ] => 0xffffffffffffffff . to_s ,
517
+ prepare_key [ 'x-datadog-parent-id' ] => 0xbbbbbbbbbbbbbbbb . to_s ,
518
+ prepare_key [ 'x-datadog-tags' ] => "_dd.p.tid= #{ invalid_trace_id } "
519
+ }
520
+ end
521
+
522
+ it { expect ( digest . trace_id ) . to eq ( 0xffffffffffffffff ) }
523
+ it { expect ( digest . span_id ) . to eq ( 0xbbbbbbbbbbbbbbbb ) }
524
+ it { expect ( digest . trace_distributed_tags ) . not_to include ( '_dd.p.tid' ) }
525
+ end
526
+ end
527
+ end
506
528
end
507
529
end
508
530
You can’t perform that action at this time.
0 commit comments