Skip to content

Commit 3b4f3a3

Browse files
authored
Merge pull request #355 from tsloughter/composite-report-cb
add report_cb to format log messages in composite propagator
2 parents e518fcc + c88bb51 commit 3b4f3a3

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

apps/opentelemetry_api/src/otel_propagator_text_map_composite.erl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
-export([create/1,
3232
fields/1,
3333
inject/4,
34-
extract/5]).
34+
extract/5,
35+
report_cb/1]).
3536

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

@@ -65,9 +66,9 @@ run_extractors(Context, Extractors, Carrier, CarrierKeysFun, CarrierGetFun) when
6566
try otel_propagator_text_map:extract_to(ContextAcc, Propagator, Carrier, CarrierKeysFun, CarrierGetFun)
6667
catch
6768
C:E:S ->
68-
?LOG_INFO("text map propagator failed to extract from carrier",
69-
#{extractor => Propagator, carrier => Carrier,
70-
class => C, exception => E, stacktrace => S}),
69+
?LOG_INFO(#{extractor => Propagator, carrier => Carrier,
70+
class => C, exception => E, stacktrace => S},
71+
#{report_cb => fun ?MODULE:report_cb/1}),
7172
ContextAcc
7273
end
7374
end, Context, otel_propagator:builtins_to_modules(Extractors)).
@@ -77,9 +78,18 @@ run_injectors(Context, Injectors, Carrier, Setter) when is_list(Injectors) ->
7778
try otel_propagator_text_map:inject_from(Context, Propagator, CarrierAcc, Setter)
7879
catch
7980
C:E:S ->
80-
?LOG_INFO("text map propagator failed to inject to carrier",
81-
#{injector => Propagator, carrier => CarrierAcc,
82-
class => C, exception => E, stacktrace => S}),
81+
?LOG_INFO(#{injector => Propagator, carrier => CarrierAcc,
82+
class => C, exception => E, stacktrace => S},
83+
#{report_cb => fun ?MODULE:report_cb/1}),
8384
CarrierAcc
8485
end
8586
end, Carrier, otel_propagator:builtins_to_modules(Injectors)).
87+
88+
report_cb(#{extractor := Propagator, carrier := _Carrier,
89+
class := Class, exception := Exception, stacktrace := StackTrace}) ->
90+
{"text map propagator failed to extract from carrier: propagator=~ts exception=~ts",
91+
[Propagator, otel_utils:format_exception(Class, Exception, StackTrace)]};
92+
report_cb(#{injector := Propagator, carrier := _Carrier,
93+
class := Class, exception := Exception, stacktrace := StackTrace}) ->
94+
{"text map propagator failed to inject to carrier: propagator=~ts exception=~ts",
95+
[Propagator, otel_utils:format_exception(Class, Exception, StackTrace)]}.

0 commit comments

Comments
 (0)