@@ -25,7 +25,6 @@ if Code.ensure_loaded?(:telemetry) do
25
25
## Options
26
26
27
27
- `:metadata` - additional metadata passed to telemetry events
28
- - `:prefix` - prefix for telemetry events. Defaults to `:tesla`
29
28
30
29
## Telemetry Events
31
30
@@ -92,10 +91,9 @@ if Code.ensure_loaded?(:telemetry) do
92
91
@ impl Tesla.Middleware
93
92
def call ( env , next , opts ) do
94
93
metadata = opts [ :metadata ] || % { }
95
- prefix = opts [ :prefix ] || :tesla
96
94
start_time = System . monotonic_time ( )
97
95
98
- emit_start ( prefix , Map . merge ( metadata , % { env: env } ) )
96
+ emit_start ( Map . merge ( metadata , % { env: env } ) )
99
97
100
98
try do
101
99
Tesla . run ( env , next )
@@ -105,7 +103,6 @@ if Code.ensure_loaded?(:telemetry) do
105
103
duration = System . monotonic_time ( ) - start_time
106
104
107
105
emit_exception (
108
- prefix ,
109
106
duration ,
110
107
Map . merge ( metadata , % { env: env , kind: kind , reason: reason , stacktrace: stacktrace } )
111
108
)
@@ -115,56 +112,56 @@ if Code.ensure_loaded?(:telemetry) do
115
112
{ :ok , env } = result ->
116
113
duration = System . monotonic_time ( ) - start_time
117
114
118
- emit_stop ( prefix , duration , Map . merge ( metadata , % { env: env } ) )
119
- emit_legacy_event ( prefix , duration , result )
115
+ emit_stop ( duration , Map . merge ( metadata , % { env: env } ) )
116
+ emit_legacy_event ( duration , result )
120
117
121
118
result
122
119
123
120
{ :error , reason } = result ->
124
121
duration = System . monotonic_time ( ) - start_time
125
122
126
- emit_stop ( prefix , duration , Map . merge ( metadata , % { env: env , error: reason } ) )
127
- emit_legacy_event ( prefix , duration , result )
123
+ emit_stop ( duration , Map . merge ( metadata , % { env: env , error: reason } ) )
124
+ emit_legacy_event ( duration , result )
128
125
129
126
result
130
127
end
131
128
end
132
129
133
- defp emit_start ( prefix , metadata ) do
130
+ defp emit_start ( metadata ) do
134
131
:telemetry . execute (
135
- [ prefix , :request , :start ] ,
132
+ [ :tesla , :request , :start ] ,
136
133
% { system_time: System . system_time ( ) } ,
137
134
metadata
138
135
)
139
136
end
140
137
141
- defp emit_stop ( prefix , duration , metadata ) do
138
+ defp emit_stop ( duration , metadata ) do
142
139
:telemetry . execute (
143
- [ prefix , :request , :stop ] ,
140
+ [ :tesla , :request , :stop ] ,
144
141
% { duration: duration } ,
145
142
metadata
146
143
)
147
144
end
148
145
149
146
if @ disable_legacy_event do
150
- defp emit_legacy_event ( _prefix , _duration , _result ) do
147
+ defp emit_legacy_event ( _duration , _result ) do
151
148
:ok
152
149
end
153
150
else
154
- defp emit_legacy_event ( prefix , duration , result ) do
151
+ defp emit_legacy_event ( duration , result ) do
155
152
duration = System . convert_time_unit ( duration , :native , :microsecond )
156
153
157
154
:telemetry . execute (
158
- [ prefix , :request ] ,
155
+ [ :tesla , :request ] ,
159
156
% { request_time: duration } ,
160
157
% { result: result }
161
158
)
162
159
end
163
160
end
164
161
165
- defp emit_exception ( prefix , duration , metadata ) do
162
+ defp emit_exception ( duration , metadata ) do
166
163
:telemetry . execute (
167
- [ prefix , :request , :exception ] ,
164
+ [ :tesla , :request , :exception ] ,
168
165
% { duration: duration } ,
169
166
metadata
170
167
)
0 commit comments