32
32
from werkzeug .exceptions import HTTPException
33
33
import logging
34
34
from jormungandr .new_relic import record_exception
35
+ from jormungandr .otlp import otlp_instance
36
+ from typing import Dict
35
37
36
38
__all__ = [
37
39
"RegionNotFound" ,
@@ -49,6 +51,10 @@ def format_error(code, message):
49
51
return error
50
52
51
53
54
+ def format_otlp_error (data ):
55
+ return {"error_id" : data ["error" ]["id" ], "error_message" : data ["error" ]["message" ]}
56
+
57
+
52
58
class RegionNotFound (HTTPException ):
53
59
def __init__ (self , region = None , lon = None , lat = None , object_id = None , custom_msg = None ):
54
60
super (RegionNotFound , self ).__init__ ()
@@ -76,6 +82,7 @@ def __init__(self, region=None, lon=None, lat=None, object_id=None, custom_msg=N
76
82
self .data = format_error ("unknown_object" , "Invalid id : {id}" .format (id = object_id ))
77
83
else :
78
84
self .data = format_error ("unknown_object" , "Unable to parse region" )
85
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
79
86
80
87
def __str__ (self ):
81
88
return repr (self .data ['message' ])
@@ -87,6 +94,7 @@ def __init__(self, region, path):
87
94
error = 'The region {} is dead' .format (region )
88
95
self .data = format_error ("dead_socket" , error )
89
96
self .code = 503
97
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
90
98
91
99
92
100
class ApiNotFound (HTTPException ):
@@ -95,6 +103,7 @@ def __init__(self, api):
95
103
error = 'The api {} doesn\' t exist' .format (api )
96
104
self .data = format_error ("unknown_object" , error )
97
105
self .code = 404
106
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
98
107
99
108
100
109
class UnknownObject (HTTPException ):
@@ -103,27 +112,31 @@ def __init__(self, msg):
103
112
error = 'The object {} doesn\' t exist' .format (msg )
104
113
self .data = format_error ("unknown_object" , error )
105
114
self .code = 404
115
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
106
116
107
117
108
118
class InvalidArguments (HTTPException ):
109
119
def __init__ (self , arg ):
110
120
super (InvalidArguments , self ).__init__ ()
111
121
self .data = format_error ("unknown_object" , "Invalid arguments " + arg )
112
122
self .code = 400
123
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
113
124
114
125
115
126
class UnableToParse (HTTPException ):
116
127
def __init__ (self , msg ):
117
128
super (UnableToParse , self ).__init__ ()
118
129
self .data = format_error ("unable_to_parse" , msg )
119
130
self .code = 400
131
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
120
132
121
133
122
134
class TechnicalError (HTTPException ):
123
135
def __init__ (self , msg ):
124
136
super (TechnicalError , self ).__init__ ()
125
137
self .data = format_error ("technical_error" , msg )
126
138
self .code = 500
139
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
127
140
128
141
129
142
# Only used by geovelo streetnetwork
@@ -132,27 +145,31 @@ def __init__(self, msg):
132
145
super (GeoveloTechnicalError , self ).__init__ ()
133
146
self .data = format_error ("technical_error" , msg )
134
147
self .code = 500
148
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
135
149
136
150
137
151
class HandimapTechnicalError (HTTPException ):
138
152
def __init__ (self , msg ):
139
153
super (HandimapTechnicalError , self ).__init__ ()
140
154
self .data = format_error ("technical_error" , msg )
141
155
self .code = 500
156
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
142
157
143
158
144
159
class AndyamoTechnicalError (HTTPException ):
145
160
def __init__ (self , msg ):
146
161
super (AndyamoTechnicalError , self ).__init__ ()
147
162
self .data = format_error ("technical_error" , msg )
148
163
self .code = 500
164
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
149
165
150
166
151
167
class ConfigException (Exception ):
152
168
def __init__ (self , arg ):
153
169
super (ConfigException , self ).__init__ (arg )
154
170
self .data = format_error ("config_exception" , "Invalid config " + arg )
155
171
self .code = 400
172
+ otlp_instance .record_exception (self , format_otlp_error (self .data ))
156
173
157
174
158
175
def log_exception (sender , exception , ** extra ):
@@ -166,9 +183,11 @@ def log_exception(sender, exception, **extra):
166
183
logger .debug (error )
167
184
if exception .code >= 500 :
168
185
record_exception ()
186
+ otlp_instance .record_exception (exception )
169
187
else :
170
188
logger .exception (error )
171
189
record_exception ()
190
+ otlp_instance .record_exception (exception )
172
191
173
192
174
193
class StatManagerError (RuntimeError ):
0 commit comments