From 5d6482e35b43bbfb4ffc6a29cc5d034745669664 Mon Sep 17 00:00:00 2001 From: Mikael Date: Mon, 18 Mar 2024 16:46:05 +0100 Subject: [PATCH] fix: erlang & elixir sampler --- content/en/docs/languages/erlang/sampling.md | 30 +++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/content/en/docs/languages/erlang/sampling.md b/content/en/docs/languages/erlang/sampling.md index f7e6afe6ffd0..5547ff179092 100644 --- a/content/en/docs/languages/erlang/sampling.md +++ b/content/en/docs/languages/erlang/sampling.md @@ -159,12 +159,16 @@ description(_) -> <<"AttributeSampler">>. should_sample(_Ctx, _TraceId, _Links, _SpanName, _SpanKind, Attributes, ConfigAttributes) -> - case maps:intersect(Attributes, ConfigAttributes) of - Map when map_size(Map) > 0 -> - {?DROP, [], []}; - _ -> - {?RECORD_AND_SAMPLE, [], []} - end. + case maps:intersect(Attributes, ConfigAttributes) of + Intersection when map_size(Intersection) > 0 -> + Keys = maps:keys(Intersection), + ConfAttrPairs = [{maps:get(Key, Attr), maps:get(Key, Conf)} || Key <- Keys], + case lists:any(fun({A, B}) -> A == B end, ConfAttrPairs) of + true -> {?DROP, [], []}; + _ -> {?RECORD_AND_SAMPLE, [], []} + end; + _ -> {?RECORD_AND_SAMPLE, [], []} + end ``` {{% /tab %}} {{% tab Elixir %}} @@ -184,13 +188,13 @@ defmodule AttributesSampler do end def should_sample(_ctx, _trace_id, _links, _span_name, _span_kind, attributes, config_attributes) do - case :maps.intersect(attributes, config_attributes) do - map when map_size(map) > 0 -> - {:drop, [], []} - _ -> - {:record_and_sample, [], []} - end - end + attr_match = + Map.intersect(attributes, config_attributes) + |> Map.keys() + |> Enum.map(fn key -> {Map.get(attributes, key), Map.get(config_attributes, key)} end) + |> Enum.any?(fn {attr, conf} -> attr == conf end) + + if attr_match, do: {:drop, [], []}, else: {:record_and_sample, [], []} end ```