From c88bb5159eb83352584782a32b6f47b07f7aad8e Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Thu, 3 Feb 2022 16:01:50 -0700 Subject: [PATCH] add report_cb to format log messages in composite propagator --- .../otel_propagator_text_map_composite.erl | 24 +++++++++++++------ .../src/otel_utils.erl | 0 2 files changed, 17 insertions(+), 7 deletions(-) rename apps/{opentelemetry => opentelemetry_api}/src/otel_utils.erl (100%) diff --git a/apps/opentelemetry_api/src/otel_propagator_text_map_composite.erl b/apps/opentelemetry_api/src/otel_propagator_text_map_composite.erl index 319ef69b..82c0d402 100644 --- a/apps/opentelemetry_api/src/otel_propagator_text_map_composite.erl +++ b/apps/opentelemetry_api/src/otel_propagator_text_map_composite.erl @@ -31,7 +31,8 @@ -export([create/1, fields/1, inject/4, - extract/5]). + extract/5, + report_cb/1]). -include_lib("kernel/include/logger.hrl"). @@ -65,9 +66,9 @@ run_extractors(Context, Extractors, Carrier, CarrierKeysFun, CarrierGetFun) when try otel_propagator_text_map:extract_to(ContextAcc, Propagator, Carrier, CarrierKeysFun, CarrierGetFun) catch C:E:S -> - ?LOG_INFO("text map propagator failed to extract from carrier", - #{extractor => Propagator, carrier => Carrier, - class => C, exception => E, stacktrace => S}), + ?LOG_INFO(#{extractor => Propagator, carrier => Carrier, + class => C, exception => E, stacktrace => S}, + #{report_cb => fun ?MODULE:report_cb/1}), ContextAcc end end, Context, otel_propagator:builtins_to_modules(Extractors)). @@ -77,9 +78,18 @@ run_injectors(Context, Injectors, Carrier, Setter) when is_list(Injectors) -> try otel_propagator_text_map:inject_from(Context, Propagator, CarrierAcc, Setter) catch C:E:S -> - ?LOG_INFO("text map propagator failed to inject to carrier", - #{injector => Propagator, carrier => CarrierAcc, - class => C, exception => E, stacktrace => S}), + ?LOG_INFO(#{injector => Propagator, carrier => CarrierAcc, + class => C, exception => E, stacktrace => S}, + #{report_cb => fun ?MODULE:report_cb/1}), CarrierAcc end end, Carrier, otel_propagator:builtins_to_modules(Injectors)). + +report_cb(#{extractor := Propagator, carrier := _Carrier, + class := Class, exception := Exception, stacktrace := StackTrace}) -> + {"text map propagator failed to extract from carrier: propagator=~ts exception=~ts", + [Propagator, otel_utils:format_exception(Class, Exception, StackTrace)]}; +report_cb(#{injector := Propagator, carrier := _Carrier, + class := Class, exception := Exception, stacktrace := StackTrace}) -> + {"text map propagator failed to inject to carrier: propagator=~ts exception=~ts", + [Propagator, otel_utils:format_exception(Class, Exception, StackTrace)]}. diff --git a/apps/opentelemetry/src/otel_utils.erl b/apps/opentelemetry_api/src/otel_utils.erl similarity index 100% rename from apps/opentelemetry/src/otel_utils.erl rename to apps/opentelemetry_api/src/otel_utils.erl