@@ -125,6 +125,7 @@ class StackdriverExporter(base.Exporter):
125125 :class:`.SyncTransport`. The other option is
126126 :class:`.BackgroundThreadTransport`.
127127 """
128+
128129 def __init__ (self , client = None , project_id = None ,
129130 transport = sync .SyncTransport ):
130131 # The client will handle the case when project_id is None
@@ -187,7 +188,7 @@ def translate_to_stackdriver(self, trace):
187188 'startTime' : span .get ('startTime' ),
188189 'endTime' : span .get ('endTime' ),
189190 'spanId' : str (span .get ('spanId' )),
190- 'attributes' : span .get ('attributes' ),
191+ 'attributes' : self . map_attributes ( span .get ('attributes' ) ),
191192 'links' : span .get ('links' ),
192193 'status' : span .get ('status' ),
193194 'stackTrace' : span .get ('stackTrace' ),
@@ -204,3 +205,46 @@ def translate_to_stackdriver(self, trace):
204205
205206 spans = {'spans' : spans_list }
206207 return spans
208+
209+ def map_attributes (self , attribute_map ):
210+ if attribute_map is None :
211+ return attribute_map
212+
213+ for (key , value ) in attribute_map .items ():
214+ if (key != 'attributeMap' ):
215+ continue
216+ for attribute_key in list (value .keys ()):
217+ if (attribute_key in ATTRIBUTE_MAPPING ):
218+ new_key = ATTRIBUTE_MAPPING .get (attribute_key )
219+ value [new_key ] = value .pop (attribute_key )
220+
221+ return attribute_map
222+
223+
224+ ATTRIBUTE_MAPPING = {
225+ 'component' : '/component' ,
226+ 'error.message' : '/error/message' ,
227+ 'error.name' : '/error/name' ,
228+ 'http.client_city' : '/http/client_city' ,
229+ 'http.client_country' : '/http/client_country' ,
230+ 'http.client_protocol' : '/http/client_protocol' ,
231+ 'http.client_region' : '/http/client_region' ,
232+
233+ 'http.host' : '/http/host' ,
234+ 'http.method' : '/http/method' ,
235+
236+ 'http.redirected_url' : '/http/redirected_url' ,
237+ 'http.request_size' : '/http/request/size' ,
238+ 'http.response_size' : '/http/response/size' ,
239+
240+ 'http.status_code' : '/http/status_code' ,
241+ 'http.url' : '/http/url' ,
242+ 'http.user_agent' : '/http/user_agent' ,
243+
244+ 'pid' : '/pid' ,
245+ 'stacktrace' : '/stacktrace' ,
246+ 'tid' : '/tid' ,
247+
248+ 'grpc.host_port' : '/grpc/host_port' ,
249+ 'grpc.method' : '/grpc/method' ,
250+ }
0 commit comments