-
Notifications
You must be signed in to change notification settings - Fork 421
Bug: Generates valid subsegment names that comply with X-Ray SDK restrictions #3981
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
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @loesak, thank you for bringing up this concern. Although I agree that we should ensure the generated subsegment names comply with the X-Ray specification, I wouldn't classify this as a bug since there's no loss of tracer or subsegment data. It's more of a warning propagated by the X-Ray SDK. I believe it's a good idea to add a sanitization method before creating the subsegment name. However, I would like to have opinions from other maintainers before making a final decision. @sthulb @rubenfonseca I'm reclassifying this issue as a feature request and adding labels until we reach a decision. Thank you |
Hi folks! I like this idea – I think adding sanitisation on things we generate to ensure it works as expected is a good idea. Are there any known issues with backwards compat. with this? |
The name is mostly relevant for the developer to understand the call structure and troubleshoot. I don't see the internals such as But overall, sanitising the method name according to X-Ray requirements is the right step. |
Agree, sanitising the method name can't hurt |
Thanks @am29d and @sthulb! I agree that removing these invalid characters -
I don't see any backwards compact @sthulb. X-Ray SDK already strips these characters from the subsegment name and generates a warning.
I agree that Hey @loesak, would you like to send a PR to sanitize the name before creating the subsegment? Your contribution would be greatly appreciated here! Thank you for your insights, @rubenfonseca, @am29d and @sthulb! |
Returning with some concerning findings that I'd like to discuss. Upon reviewing our tests, I've noticed that we're testing scenarios such as nested context managers, where the name may contain characters like While I agree that it's essential to avoid allowing these characters and we must sanitize them before sending to XRay SDK, I'm hesitant about potentially introducing a breaking change in our customers' CI pipelines. I'm considering adding labels to Powertools V3, with modifications planned for a major release. What do you think @am29d @rubenfonseca @sthulb? |
Nice customer obsession Leandro, well done! Normally I would agree that it could be a breaking change. However, consider the following:
With those things in mind, I would still consider this to be a bug fix rather than a breaking change |
Thank you for your concise and insightful points, @rubenfonseca. Sending a PR right now. |
|
Thank you for the quick turn around @leandrodamascena . Much appreciated. |
This is now released under 2.36.0 version! |
Expected Behaviour
When decorating a method with
tracer.capture_method
, it should generate names that are compatible with the AWS X-Ray Python SDK.Current Behaviour
In some circumstances, it generates subsegment names that are incompatible with the AWS X-Ray Python SDK. This will continually cause AWS X-Ray Python SDK to produce a WARNING log message.
Code snippet
OUTPUTS:
which is an invalid name for a segment and generates a warning.
Possible Solution
The name of the subsegment is taken from the method name using method_name = f"{method.module}.{method.qualname}" but does nothing to sanitize the result to make it compatible with AWS X-Ray or AWS X-Ray Python SDK.
AWS X-Ray docs say the name can be:
AWS X-Ray Python SDK strips the following characters:
From PEP 3155 - Qualified name for classes and functions
In our case, our segment is being affected by "A function’s local namespace is represented in that dotted path by a component named <locals>." where the "<" and ">" are invalid characters and raising a WARNING in our logs.
Add logic to sanitize the value of
method_name
to be compatible with AWS X-Ray or AWS X-Ray Python SDK by restricting the length to 200 characters and removing any invalid character.Steps to Reproduce
Create a locally defined function and decorate it with
@tracer.capture_method
and receive WARNING in logs.Powertools for AWS Lambda (Python) version
2.26.0
AWS Lambda function runtime
3.11
Packaging format used
PyPi
Debugging logs
No response
The text was updated successfully, but these errors were encountered: