Skip to content

Filter invalid characters from annotation key names; raise warning if found #22

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

Merged
merged 5 commits into from
Feb 20, 2018

Conversation

tay-bird
Copy link
Contributor

Fixes #18

I took the approach of stripping invalid characters from annotation key names and raising a warning, rather than exiting the function.

docs/basic.rst Outdated
@@ -51,7 +51,8 @@ You can add annotations and metadata to an active segment/subsegment.
Annotations are simple key-value pairs that are indexed for use with
`filter expressions <http://docs.aws.amazon.com/xray/latest/devguide/xray-console-filters.html>`_.
Use annotations to record data that you want to use to group traces in the console,
or when calling the GetTraceSummaries API.
or when calling the GetTraceSummaries API. Annotation keys may only use ASCII letters and the underscore(_)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably replace "may" with "should" as user needs to understand invalid keys are dropped, per RFC2119. Also ASCII digits are missing here.

@@ -140,7 +141,12 @@ def put_annotation(self, key, value):
log.warning("ignoring unsupported annotation value type %s.", type(value))
return

self.annotations[key] = value
sanitized_key = ''.join([c for c in key if c in _valid_annotation_key_characters])
Copy link
Contributor

Choose a reason for hiding this comment

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

Annotation key is difference to entity name. User can have 100 lines of code adding annotations to a single entity. Under worst case this could result in 100 times of string concatenation, which adds a lot of overhead.

Invalid key is a user error and the key should be dropped until the author explicit fix it using valid characters.

@haotianw465
Copy link
Contributor

Thank you for the PR and we really appreciate it. I have left some comments and would expect this can be merged very soon.

@tay-bird
Copy link
Contributor Author

tay-bird commented Feb 19, 2018 via email

@tay-bird
Copy link
Contributor Author

@haotianw465 revisions made.

@haotianw465
Copy link
Contributor

It looks all good. Sorry that I forgot to mention if you could add two line check on this unit test https://github.com/aws/aws-xray-sdk-python/blob/master/tests/test_trace_entities.py#L47 to cover the new key dropping logic. Thanks.

@tay-bird
Copy link
Contributor Author

tay-bird commented Feb 19, 2018 via email

@tay-bird
Copy link
Contributor Author

@haotianw465 test updated!

@haotianw465 haotianw465 merged commit f8b65f1 into aws:master Feb 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants