You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Lambda function that gets called and it executes a lot of HTTP requests. I'm trying to speed those up through aiohttp. Ultimately I want 1 log entry per http request and 1 log for the actual lambda invocation. I'm running into problems with the metric logger decorating an async method.
Traceback (most recent call last):\n File \"/var/task/index.py\", line 174, in process_requests\n code = await send_request(request, context, session)\n File \"/var/task/aws_embedded_metrics/metric_scope/__init__.py\", line 34, in wrapper\n await logger.flush()\n File \"/var/task/aws_embedded_metrics/logger/metrics_logger.py\", line 47, in flush\n sink.accept(self.context)\n File \"/var/task/aws_embedded_metrics/sinks/stdout_sink.py\", line 25, in accept\n for serialized_content in self.serializer.serialize(context):\n File \"/var/task/aws_embedded_metrics/serializers/log_serializer.py\", line 106, in serialize\n event_batches.append(json.dumps(current_body))\n File \"/var/lang/lib/python3.9/json/__init__.py\", line 231, in dumps\n return _default_encoder.encode(obj)\n File \"/var/lang/lib/python3.9/json/encoder.py\", line 199, in encode\n chunks = self.iterencode(o, _one_shot=True)\n File \"/var/lang/lib/python3.9/json/encoder.py\", line 257, in iterencode\n return _iterencode(o, 0)\n File \"/var/lang/lib/python3.9/json/encoder.py\", line 179, in default\n raise TypeError(f'Object of type {o.__class__.__name__} '\nTypeError: Object of type method is not JSON serializable\n"
asyncdefprocess_requests(event, context, metrics):
""" Sets up the aiohttp client and iterates all of the requests through the session """tracebacks= []
errors= []
asyncwithaiohttp.ClientSession() assession:
forrequestinevent["requests"]:
forxinrange(0, request["iterations"]):
try:
code=awaitsend_request(request, context, session)
exceptExceptionase:
errors.append(str(e))
tracebacks.append(traceback.format_exc())
metrics.set_property("Errors", errors)
metrics.set_property("Tracebacks", tracebacks)
returnNone
This works when I process the HTTP requests synchronously, I get a log for each time send_request is called and once for the overall handler execution. Is there a way I can use the metrics logger and get the same outcome with aiohttp/asyncio?
The text was updated successfully, but these errors were encountered:
I have a Lambda function that gets called and it executes a lot of HTTP requests. I'm trying to speed those up through
aiohttp
. Ultimately I want 1 log entry per http request and 1 log for the actual lambda invocation. I'm running into problems with the metric logger decorating an async method.This is a basic version of my handler:
The process_requests method:
And finally, the send_request method:
This works when I process the HTTP requests synchronously, I get a log for each time
send_request
is called and once for the overall handler execution. Is there a way I can use the metrics logger and get the same outcome with aiohttp/asyncio?The text was updated successfully, but these errors were encountered: