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

2.7.0: TypeError: string indices must be integers #283

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

2.7.0: TypeError: string indices must be integers #283

michaelbrewer opened this issue Apr 5, 2021 · 4 comments
Assignees

Comments

@michaelbrewer
Copy link

michaelbrewer commented Apr 5, 2021

Originally logged here: aws-powertools/powertools-lambda-python#383

Caused by : #275

Proof of concept code using Powertools and Xray 2.7.0

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
@lupengamzn
Copy link
Contributor

Hey @michaelbrewer ,

This is because when sdk is serializing exception, it could be either an dict or str and the current version didn't take the later case into consideration. I've submitted a PR to fix this and the new release should be out soon.

@michaelbrewer
Copy link
Author

thanks @lupengamzn for looking into it

@michaelbrewer
Copy link
Author

@lupengamzn i see the PR has been merged, what is the timeline for the next release?

@lupengamzn
Copy link
Contributor

@michaelbrewer Python SDK 2.8.0 has been released: https://pypi.org/project/aws-xray-sdk/2.8.0/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants