File tree 2 files changed +17
-0
lines changed 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 2
2
import os
3
3
import binascii
4
4
import time
5
+ import string
5
6
6
7
import jsonpickle
7
8
13
14
14
15
log = logging .getLogger (__name__ )
15
16
17
+ # List of valid characters found at http://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html
18
+ _valid_name_characters = string .ascii_letters + string .digits + '_.:/%&#=+\-@ '
19
+
16
20
17
21
class Entity (object ):
18
22
"""
19
23
The parent class for segment/subsegment. It holds common properties
20
24
and methods on segment and subsegment.
21
25
"""
26
+
22
27
def __init__ (self , name ):
23
28
24
29
# required attributes
25
30
self .id = self ._generate_random_id ()
26
31
self .name = name
32
+ self .name = '' .join ([c for c in name if c in _valid_name_characters ])
27
33
self .start_time = time .time ()
28
34
self .parent_id = None
29
35
36
+ if self .name != name :
37
+ log .warning ("Removing Segment/Subsugment Name invalid characters." )
38
+
30
39
# sampling
31
40
self .sampled = True
32
41
Original file line number Diff line number Diff line change @@ -57,3 +57,11 @@ def test_structure_intact():
57
57
subsegment .close ()
58
58
segment .close ()
59
59
assert segment .ready_to_send ()
60
+
61
+
62
+ def test_invalid_entity_name ():
63
+ segment = DummySegment ('DummySegment() Test?' )
64
+ subsegment = DummySubsegment (segment , 'Dummy*Sub!segment$' )
65
+
66
+ assert segment .name == 'DummySegment Test'
67
+ assert subsegment .name == 'DummySubsegment'
You can’t perform that action at this time.
0 commit comments