@@ -33,7 +33,7 @@ all_cases() ->
3333 root_span_sampling_always_on , root_span_sampling_always_off ,
3434 record_but_not_sample , record_exception_works , record_exception_with_message_works ,
3535 propagator_configuration , propagator_configuration_with_os_env , force_flush ,
36- dropped_attributes , too_many_attributes ].
36+ dropped_attributes , too_many_attributes , truncated_binary_attributes ].
3737
3838groups () ->
3939 [{otel_simple_processor , [], all_cases ()},
@@ -693,13 +693,32 @@ dropped_attributes(Config) ->
693693 ? set_current_span (SpanCtx ),
694694
695695 ? set_attribute (<<" attr-1" >>, <<" attr-value-1" >>),
696- ? set_attribute (<<" attr-2" >>, {not_allowed , in , attributes }),
696+ ? set_attribute (<<" attr-2" >>, {non_homogeneous , << " attribute " >> }),
697697
698698 otel_span :end_span (SpanCtx ),
699699 [Span ] = assert_exported (Tid , SpanCtx ),
700700
701701 ? assertEqual (#{<<" attr-1" >> => <<" at" >>}, otel_attributes :map (Span # span .attributes )),
702- ? assertEqual (1 , otel_attributes :dropped (Span # span .attributes )),
702+
703+ ok .
704+
705+ truncated_binary_attributes (_Config ) ->
706+ InfinityLengthAttributes = otel_attributes :new (#{<<" attr-1" >> => <<" abcde" >>,
707+ <<" attr-2" >> => [<<" a" >>, <<" abcde" >>, <<" abcde" >>]},
708+ 128 , infinity ),
709+
710+ % % when length limit is inifinity
711+ ? assertMatch (#{<<" attr-1" >> := <<" abcde" >>,
712+ <<" attr-2" >> := [<<" a" >>, <<" abcde" >>, <<" abcde" >>]},
713+ otel_attributes :map (InfinityLengthAttributes )),
714+
715+ LengthLimitAttributes = otel_attributes :new (#{<<" attr-1" >> => <<" abcde" >>,
716+ <<" attr-2" >> => [<<" a" >>, <<" abcde" >>, <<" abcde" >>]},
717+ 128 , 2 ),
718+ % with default
719+ ? assertMatch (#{<<" attr-1" >> := <<" ab" >>,
720+ <<" attr-2" >> := [<<" a" >>, <<" ab" >>, <<" ab" >>]},
721+ otel_attributes :map (LengthLimitAttributes )),
703722
704723 ok .
705724
@@ -709,33 +728,39 @@ too_many_attributes(Config) ->
709728
710729 ? set_current_span (SpanCtx ),
711730
712- ? set_attribute (<<" attr-1" >>, <<" attr-value-1" >>),
731+ % % tuple tests cover lists, as well.
732+ ? set_attribute (attr1 , {homogenous , tuple }),
713733
714- % % dropped because of tuple as value
715- ? set_attribute (<<" attr-2" >>, {not_allowed , in , attributes }),
734+ % % dropped because of non-homogenous
735+ ? set_attribute (<<" attr-2-dropped " >>, {non_homogenous , << " attributes" >> }),
716736
717- ? set_attribute (<<" attr-3" >>, << " attr-value-3 " >> ),
737+ ? set_attribute (<<" attr-3" >>, attr_3_value ),
718738
719739 % % dropped because count limit was set to 2
720740 ? set_attribute (<<" attr-4" >>, <<" attr-value-4" >>),
721741 % % won't be dropped because attr-1 already exists so it overrides the value
722742 ? set_attribute (<<" attr-1" >>, <<" attr-value-5" >>),
743+ % % already exists and not a binary, so skips the binary length check.
744+ ? set_attribute (<<" attr-3" >>, 4 ),
745+
746+ % % dropping skips all checks now that we're already dropping attrs
747+ ? set_attribute (<<" attr-6" >>, <<" attr-value-6" >>),
723748
724749 otel_span :end_span (SpanCtx ),
725750 [Span ] = assert_exported (Tid , SpanCtx ),
726751
727- ? assertEqual (#{<< " attr-1 " >> => << " attr-value-5 " >> ,
728- <<" attr-3" >> => << " attr-value-3 " >> }, otel_attributes :map (Span # span .attributes )),
729- ? assertEqual (2 , otel_attributes :dropped (Span # span .attributes )),
752+ ? assertEqual (#{attr1 => [ homogenous , tuple ] ,
753+ <<" attr-3" >> => 4 }, otel_attributes :map (Span # span .attributes )),
754+ ? assertEqual (3 , otel_attributes :dropped (Span # span .attributes )),
730755
731756 % % test again using the `set_attributes' macro
732757 SpanCtx2 = ? start_span (<<" span-2" >>),
733758
734759 ? set_current_span (SpanCtx2 ),
735760
736761 ? set_attributes (#{<<" attr-1" >> => <<" attr-value-1" >>,
737- <<" attr-2" >> => {not_allowed , in , attributes },
738- <<" attr-3" >> => << " attr-value-3 " >> ,
762+ <<" attr-2" >> => {homogenous , attribute },
763+ <<" attr-3" >> => attr_3_value ,
739764 <<" attr-4" >> => <<" attr-value-4" >>}),
740765
741766 % % won't be dropped because attr-1 already exists so it overrides the value
@@ -744,6 +769,7 @@ too_many_attributes(Config) ->
744769 otel_span :end_span (SpanCtx2 ),
745770 [Span2 ] = assert_exported (Tid , SpanCtx2 ),
746771
772+
747773 % % order isn't guaranteed so just verify the number dropped is right
748774 ? assertEqual (2 , otel_attributes :dropped (Span2 # span .attributes )),
749775
0 commit comments