From b13b235d1ad8d241b7c0772659e50ab49c57baf4 Mon Sep 17 00:00:00 2001 From: Tim Whitbeck Date: Wed, 31 Jan 2024 09:06:36 -0500 Subject: [PATCH] fix: only regex a string (#16) Co-authored-by: Vasilis Spilka --- lib/logger_json/plug/metadata_formatters/datadog_logger.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/logger_json/plug/metadata_formatters/datadog_logger.ex b/lib/logger_json/plug/metadata_formatters/datadog_logger.ex index 1c0f4e0..6503a53 100644 --- a/lib/logger_json/plug/metadata_formatters/datadog_logger.ex +++ b/lib/logger_json/plug/metadata_formatters/datadog_logger.ex @@ -108,7 +108,7 @@ if Code.ensure_loaded?(Plug) do - The expected outcome would be something like "stord_sk_publickeyasdfasdf_*******", assuming "*******" is the scrub value. - You can use DataDog's regex to extract the public key part and turn it into a standard attribute. """ - def extract_public_key(value, scrub_value) do + def extract_public_key(value, scrub_value) when is_binary(value) do case Regex.named_captures( ~r/Bearer stord_(?sk|ak)_(?[A-Za-z0-9+\/]+)_(?.+)/, value @@ -121,6 +121,8 @@ if Code.ensure_loaded?(Plug) do end end + def extract_public_key(_value, scrub_value), do: scrub_value + defp scrubbed_value(key, actual_value, scrub_map) do case Map.get(scrub_map, key) do {mod, func, args} when is_atom(mod) and is_atom(func) and is_list(args) ->