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

Improve SubSegment Naming #32

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, name):
self.parent_id = None

if self.name != name:
log.warning("Removing Segment/Subsugment Name invalid characters.")
log.warning("Removing Segment/Subsugment Name invalid characters from {}.".format(name))

# sampling
self.sampled = True
Expand Down
9 changes: 7 additions & 2 deletions aws_xray_sdk/ext/sqlalchemy/util/decerators.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import re
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.ext.util import strip_url
from aws_xray_sdk.core.models.entity import _valid_name_characters
from future.standard_library import install_aliases
install_aliases()
from urllib.parse import urlparse, uses_netloc



def decorate_all_functions(function_decorator):
def decorator(cls):
for c in cls.__bases__:
Expand Down Expand Up @@ -46,7 +47,11 @@ def wrapper(*args, **kw):
sql = None
if sql is not None:
if getattr(c._local, 'entities', None) is not None:
subsegment = xray_recorder.begin_subsegment(sql['url'], namespace='remote')
# Strip URL of ? and following text
sub_name = strip_url(sql['url'])
# Ensure url has a valid characters.
sub_name = ''.join([c for c in sub_name if c in _valid_name_characters])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate to https://github.com/aws/aws-xray-sdk-python/blob/master/aws_xray_sdk/core/models/entity.py#L33. IMO when we see a warning on invalid characters we fix from its source, like the strip_url here. But we should not deliberately skip the log warning by placing sub_name = ''.join([c for c in sub_name if c in _valid_name_characters]) everywhere.

Otherwise it looks fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without that code, we would still end up logging warnings for certain SQL URLs. For example 'échéanciers' is a valid name or a database in postgres, but would be stripped to 'chanciers' for x-ray... I left this code to prevent the warnings as the sqlalchemy plugin is setting this, so it is not in users control.. If you want it removed I will, let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with special casing the sql subsegment name. I will create a follow up issue for further write an utility module that strips unicode for patchers that might capture unicode as subsegment name.

subsegment = xray_recorder.begin_subsegment(sub_name, namespace='remote')
else:
subsegment = None
res = func(*args, **kw)
Expand Down