Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xray: TypeError: string indices must be integers #383

Closed
michaelbrewer opened this issue Apr 5, 2021 · 2 comments
Closed

Xray: TypeError: string indices must be integers #383

michaelbrewer opened this issue Apr 5, 2021 · 2 comments
Labels
bug-upstream Something isn't working in an upstream dependency

Comments

@michaelbrewer
Copy link
Contributor

michaelbrewer commented Apr 5, 2021

Xray PR to fix this: aws/aws-xray-sdk-python#284

Proof of concept code:

import json
from aws_lambda_powertools import Tracer
import boto3

tracer = Tracer()

@tracer.capture_method
def my_method():
    sts = boto3.client("sts")
    sts.get_caller_identity()
    raise RuntimeError("Error happens!")

@tracer.capture_lambda_handler
def lambda_handler(event, context):
    my_method()
    return {"statusCode": 200, "body": json.dumps({"hello": "world"})}

Logs

[ERROR]	2021-04-05T05:33:00.732Z	8a4d5027-4faa-4f4f-8d08-df63b7ea72ed	Failed to serialize ## lambda_handler
Traceback (most recent call last):
  File "/var/task/aws_lambda_powertools/tracing/tracer.py", line 313, in decorate
    response = lambda_handler(event, context, **kwargs)
  File "/var/task/app.py", line 17, in lambda_handler
    my_method()
  File "/var/task/aws_lambda_powertools/tracing/tracer.py", line 612, in decorate
    response = method(*args, **kwargs)
  File "/var/task/app.py", line 12, in my_method
    raise RuntimeError("Error happens!")
RuntimeError: Error happens!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/task/aws_xray_sdk/core/models/entity.py", line 263, in serialize
    return json.dumps(self.to_dict(), default=str)
  File "/var/task/aws_xray_sdk/core/models/subsegment.py", line 157, in to_dict
    subsegment_dict = super(Subsegment, self).to_dict()
  File "/var/task/aws_xray_sdk/core/models/entity.py", line 284, in to_dict
    entity_dict[key]['working_directory'] = self.cause['working_directory']
TypeError: string indices must be integers

Xray screenshot:

Screen Shot 2021-04-04 at 10 32 12 PM

Xray screenshot without @tracer.capture_method :

Screen Shot 2021-04-04 at 10 31 01 PM

@michaelbrewer michaelbrewer added bug Something isn't working triage Pending triage from maintainers labels Apr 5, 2021
@michaelbrewer michaelbrewer changed the title @tracer.capture_method or middleware and xray does not handle errors Xray: TypeError: string indices must be integers Apr 5, 2021
@heitorlessa
Copy link
Contributor

hey @michaelbrewer - I can't reproduce this using the latest version, however I remember X-Ray SDK team changed the serialization from jsonpickle to their own, and this line tells there's an issue with the new implementation

 File "/var/task/aws_xray_sdk/core/models/subsegment.py", line 157, in to_dict

Could you open up an issue upstream with them?

It's a regression only available in the develop branch. Lambda Powertools 1.13.0 doesn't have this issue as it uses X-Ray SDK 2.6.0

I'll lock to 2.6.0 in the meantime as we near 1.14.0 release this week.

@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Apr 9, 2021
@heitorlessa heitorlessa added area/tracer bug-upstream Something isn't working in an upstream dependency and removed bug Something isn't working labels Apr 19, 2021
@heitorlessa
Copy link
Contributor

I've subscribed to the upstream issue pending PR merge so I can revert the dependency pinning to the working version of X-Ray SDK. For now, I am closing this issue as 1.14.0 uses a previous working version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-upstream Something isn't working in an upstream dependency
Projects
Development

No branches or pull requests

2 participants