21
21
export_traces /4 ,
22
22
export_metrics /4 ,
23
23
export_logs /4 ,
24
+ export /5 ,
24
25
shutdown /1 ,
25
26
report_cb /1 ]).
26
27
28
+ -export_type ([otel_signal / 0 ,
29
+ exporter_config / 0 ]).
30
+
27
31
% % Do any initialization of the exporter here and return configuration
28
32
% % that will be passed along with a list of spans to the `export' function.
29
- -callback init (term ()) -> {ok , term ()} | ignore .
33
+ -callback init (Config ) -> {ok , ExporterState } | {error , Reason } | ignore when
34
+ Config :: term (),
35
+ ExporterState :: term (),
36
+ Reason :: term ().
30
37
31
38
% % This function is called when the configured interval expires with any
32
39
% % spans that have been collected so far and the configuration returned in `init'.
33
40
% % Do whatever needs to be done to export each span here, the caller will block
34
41
% % until it returns.
35
- -callback export (traces | metrics , ets :tab (), otel_resource :t (), term ()) -> ok |
36
- success |
37
- failed_not_retryable |
38
- failed_retryable .
39
- -callback shutdown (term ()) -> ok .
42
+ -callback export (otel_signal (), ets :tab (), otel_resource :t (), term ()) -> ok | error | {error , term ()}.
43
+
44
+ -callback shutdown (State ) -> ok when State :: term ().
45
+
46
+ -type otel_signal () :: traces | metrics | logs .
47
+ -type exporter_config () :: module () | {module (), Config :: term ()} | undefined | none | ignore .
40
48
41
49
-include_lib (" kernel/include/logger.hrl" ).
42
50
51
+ -spec init (exporter_config ()) -> {module (), term ()} | error | ignore .
43
52
init ({ExporterModule , Config }) when is_atom (ExporterModule ) ->
44
53
try ExporterModule :init (Config ) of
45
54
{ok , ExporterState } when ExporterModule =:= opentelemetry_exporter ->
@@ -49,8 +58,12 @@ init({ExporterModule, Config}) when is_atom(ExporterModule) ->
49
58
{ok , ExporterState } ->
50
59
? LOG_INFO (" Exporter ~tp successfully initialized" , [ExporterModule ]),
51
60
{ExporterModule , ExporterState };
61
+ {error , Reason } ->
62
+ ? LOG_ERROR (" Exporter failed to initalize, error: ~p " ,
63
+ [ExporterModule , Reason ]),
64
+ error ;
52
65
ignore ->
53
- undefined
66
+ ignore
54
67
catch
55
68
Kind :Reason :StackTrace ->
56
69
% % logging in debug level since config argument in stacktrace could have secrets
@@ -72,14 +85,14 @@ init({ExporterModule, Config}) when is_atom(ExporterModule) ->
72
85
% % the dependency needs to be added
73
86
try grpcbox :module_info () of
74
87
_ ->
75
- undefined
88
+ error
76
89
catch
77
90
_ :_ ->
78
91
? LOG_WARNING (" OTLP exporter failed to initialize when using the GRPC "
79
92
" protocol and `grpcbox` module is not available in the "
80
93
" code path. Verify that you have the `grpcbox` dependency "
81
94
" included and rerun." , []),
82
- undefined
95
+ error
83
96
end ;
84
97
_ ->
85
98
% % same as the debug log above
@@ -89,17 +102,17 @@ init({ExporterModule, Config}) when is_atom(ExporterModule) ->
89
102
kind => Kind ,
90
103
reason => Reason ,
91
104
exporter => ExporterModule }, #{report_cb => fun ? MODULE :report_cb /1 }),
92
- undefined
105
+ error
93
106
end ;
94
107
{error , undef } when ExporterModule =:= opentelemetry_exporter ->
95
108
? LOG_WARNING (" OTLP exporter module `opentelemetry_exporter` not found. "
96
109
" Verify you have included the `opentelemetry_exporter` dependency." ,
97
110
[ExporterModule ]),
98
- undefined ;
111
+ error ;
99
112
{error , undef } ->
100
113
? LOG_WARNING (" Exporter module ~tp not found. Verify you have included "
101
114
" the dependency that contains the exporter module." , [ExporterModule ]),
102
- undefined ;
115
+ error ;
103
116
_ ->
104
117
% % same as the debug log above
105
118
% % without the stacktrace and at a higher level
@@ -108,22 +121,25 @@ init({ExporterModule, Config}) when is_atom(ExporterModule) ->
108
121
kind => Kind ,
109
122
reason => Reason ,
110
123
exporter => ExporterModule }, #{report_cb => fun ? MODULE :report_cb /1 }),
111
- undefined
124
+ error
112
125
end
113
126
end ;
114
- init (Exporter ) when Exporter =:= none ; Exporter =:= undefined ->
115
- undefined ;
127
+ init (Exporter ) when Exporter =:= none ; Exporter =:= undefined ; Exporter =:= ignore ->
128
+ ignore ;
116
129
init (ExporterModule ) when is_atom (ExporterModule ) ->
117
130
init ({ExporterModule , []}).
118
131
119
- export_traces (ExporterModule , SpansTid , Resource , Config ) ->
120
- ExporterModule :export (traces , SpansTid , Resource , Config ).
132
+ export_traces (ExporterModule , SpansTid , Resource , ExporterState ) ->
133
+ export (traces , ExporterModule , SpansTid , Resource , ExporterState ).
134
+
135
+ export_metrics (ExporterModule , MetricsTid , Resource , ExporterState ) ->
136
+ export (metrics , ExporterModule , MetricsTid , Resource , ExporterState ).
121
137
122
- export_metrics (ExporterModule , MetricsTid , Resource , Config ) ->
123
- ExporterModule : export (metrics , MetricsTid , Resource , Config ).
138
+ export_logs (ExporterModule , LogsTidAndHandlerConfig , Resource , ExporterState ) ->
139
+ export (logs , ExporterModule , LogsTidAndHandlerConfig , Resource , ExporterState ).
124
140
125
- export_logs ( ExporterModule , Batch , Resource , Config ) ->
126
- ExporterModule :export (logs , Batch , Resource , Config ).
141
+ export ( OtelSignal , ExporterModule , Tid , Resource , ExporterState ) ->
142
+ ExporterModule :export (OtelSignal , Tid , Resource , ExporterState ).
127
143
128
144
shutdown (undefined ) ->
129
145
ok ;
0 commit comments