1
1
import uuid
2
2
from typing import Type , Optional
3
3
import time
4
- import http .client
5
4
6
5
from lumigo_tracer .parsers .utils import (
7
6
safe_split_get ,
@@ -35,9 +34,7 @@ class Parser:
35
34
def parse_request (self , parse_params : HttpRequest ) -> dict :
36
35
if Configuration .verbose and parse_params and not should_scrub_domain (parse_params .host ):
37
36
additional_info = {
38
- "headers" : prepare_large_data (
39
- dict (parse_params .headers .items () if parse_params .headers else {})
40
- ),
37
+ "headers" : prepare_large_data (parse_params .headers ),
41
38
"body" : prepare_large_data (parse_params .body ),
42
39
"method" : parse_params .method ,
43
40
"uri" : parse_params .uri ,
@@ -60,12 +57,10 @@ def parse_request(self, parse_params: HttpRequest) -> dict:
60
57
"started" : int (time .time () * 1000 ),
61
58
}
62
59
63
- def parse_response (
64
- self , url : str , status_code : int , headers : Optional [http .client .HTTPMessage ], body : bytes
65
- ) -> dict :
60
+ def parse_response (self , url : str , status_code : int , headers : dict , body : bytes ) -> dict :
66
61
if Configuration .verbose and not should_scrub_domain (url ):
67
62
additional_info = {
68
- "headers" : prepare_large_data (dict ( headers . items () if headers else {}) ),
63
+ "headers" : prepare_large_data (headers ),
69
64
"body" : prepare_large_data (body ),
70
65
"statusCode" : status_code ,
71
66
}
@@ -85,7 +80,7 @@ class ServerlessAWSParser(Parser):
85
80
86
81
def parse_response (self , url : str , status_code : int , headers , body : bytes ) -> dict :
87
82
additional_info = {}
88
- message_id = headers .get ("x-amzn-RequestId " )
83
+ message_id = headers .get ("x-amzn-requestid " )
89
84
if message_id and self .should_add_message_id :
90
85
additional_info ["info" ] = {"messageId" : message_id }
91
86
span_id = headers .get ("x-amzn-requestid" ) or headers .get ("x-amz-requestid" )
@@ -100,7 +95,7 @@ class DynamoParser(ServerlessAWSParser):
100
95
should_add_message_id = False
101
96
102
97
def parse_request (self , parse_params : HttpRequest ) -> dict :
103
- target : str = str ( parse_params .headers .get ("x-amz-target" , "" )) # type: ignore
98
+ target : str = parse_params .headers .get ("x-amz-target" , "" )
104
99
return recursive_json_join (
105
100
{
106
101
"info" : {
@@ -139,10 +134,8 @@ class LambdaParser(ServerlessAWSParser):
139
134
def parse_request (self , parse_params : HttpRequest ) -> dict :
140
135
return recursive_json_join (
141
136
{
142
- "name" : safe_split_get (
143
- str (parse_params .headers .get ("path" , "" )), "/" , 3 # type: ignore
144
- ),
145
- "invocationType" : parse_params .headers .get ("x-amz-invocation-type" ), # type: ignore
137
+ "name" : safe_split_get (str (parse_params .headers .get ("path" , "" )), "/" , 3 ),
138
+ "invocationType" : parse_params .headers .get ("x-amz-invocation-type" ),
146
139
},
147
140
super ().parse_request (parse_params ),
148
141
)
@@ -223,16 +216,16 @@ class ApiGatewayV2Parser(ServerlessAWSParser):
223
216
# API-GW V1 covered by ServerlessAWSParser
224
217
225
218
def parse_response (self , url : str , status_code : int , headers , body : bytes ) -> dict :
226
- aws_request_id = headers .get ("x-amzn-RequestId " )
227
- apigw_request_id = headers .get ("Apigw-Requestid " )
219
+ aws_request_id = headers .get ("x-amzn-requestid " )
220
+ apigw_request_id = headers .get ("apigw-requestid " )
228
221
message_id = aws_request_id or apigw_request_id
229
222
return recursive_json_join (
230
223
{"info" : {"messageId" : message_id }},
231
224
super ().parse_response (url , status_code , headers , body ),
232
225
)
233
226
234
227
235
- def get_parser (url : str , headers : Optional [http . client . HTTPMessage ] = None ) -> Type [Parser ]:
228
+ def get_parser (url : str , headers : Optional [dict ] = None ) -> Type [Parser ]:
236
229
service = safe_split_get (url , "." , 0 )
237
230
if service == "dynamodb" :
238
231
return DynamoParser
@@ -249,6 +242,6 @@ def get_parser(url: str, headers: Optional[http.client.HTTPMessage] = None) -> T
249
242
return SqsParser
250
243
elif "execute-api" in url :
251
244
return ApiGatewayV2Parser
252
- elif url .endswith ("amazonaws.com" ) or (headers and headers .get ("x-amzn-RequestId " )):
245
+ elif url .endswith ("amazonaws.com" ) or (headers and headers .get ("x-amzn-requestid " )):
253
246
return ServerlessAWSParser
254
247
return Parser
0 commit comments