Skip to content

Commit

Permalink
Merge pull request #355 from tsloughter/composite-report-cb
Browse files Browse the repository at this point in the history
add report_cb to format log messages in composite propagator
  • Loading branch information
tsloughter authored Feb 3, 2022
2 parents e518fcc + c88bb51 commit 3b4f3a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions apps/opentelemetry_api/src/otel_propagator_text_map_composite.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
-export([create/1,
fields/1,
inject/4,
extract/5]).
extract/5,
report_cb/1]).

-include_lib("kernel/include/logger.hrl").

Expand Down Expand Up @@ -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)).
Expand All @@ -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)]}.
File renamed without changes.

0 comments on commit 3b4f3a3

Please sign in to comment.