|
1 | 1 | import time |
2 | | - |
3 | 2 | import unittest |
4 | 3 | import opentracing |
| 4 | +from uuid import UUID |
| 5 | +from instana.util import to_json |
5 | 6 | from instana.singletons import tracer |
6 | 7 |
|
7 | 8 |
|
@@ -144,3 +145,44 @@ def test_span_kind(self): |
144 | 145 |
|
145 | 146 | span = spans[4] |
146 | 147 | self.assertEqual(3, span.k) |
| 148 | + |
| 149 | + def test_bad_tag_values(self): |
| 150 | + with tracer.start_active_span('test') as scope: |
| 151 | + # Set a UUID class as a tag |
| 152 | + # If unchecked, this causes a json.dumps error: "ValueError: Circular reference detected" |
| 153 | + scope.span.set_tag('uuid', UUID(bytes=b'\x12\x34\x56\x78'*4)) |
| 154 | + # Arbitrarily setting an instance of some class |
| 155 | + scope.span.set_tag('tracer', tracer) |
| 156 | + scope.span.set_tag('none', None) |
| 157 | + scope.span.set_tag('mylist', [1, 2, 3]) |
| 158 | + |
| 159 | + |
| 160 | + spans = tracer.recorder.queued_spans() |
| 161 | + assert len(spans) == 1 |
| 162 | + |
| 163 | + test_span = spans[0] |
| 164 | + assert(test_span) |
| 165 | + assert(len(test_span.data['sdk']['custom']['tags']) == 4) |
| 166 | + assert(test_span.data['sdk']['custom']['tags']['uuid'] == '12345678-1234-5678-1234-567812345678') |
| 167 | + assert(test_span.data['sdk']['custom']['tags']['tracer']) |
| 168 | + assert(test_span.data['sdk']['custom']['tags']['none'] == 'None') |
| 169 | + assert(test_span.data['sdk']['custom']['tags']['mylist'] == [1, 2, 3]) |
| 170 | + |
| 171 | + json_data = to_json(test_span) |
| 172 | + assert(json_data) |
| 173 | + |
| 174 | + def test_bad_tag_names(self): |
| 175 | + with tracer.start_active_span('test') as scope: |
| 176 | + # Tag names (keys) must be strings |
| 177 | + scope.span.set_tag(1234567890, 'This should not get set') |
| 178 | + |
| 179 | + spans = tracer.recorder.queued_spans() |
| 180 | + assert len(spans) == 1 |
| 181 | + |
| 182 | + test_span = spans[0] |
| 183 | + assert(test_span) |
| 184 | + assert(len(test_span.data['sdk']['custom']['tags']) == 0) |
| 185 | + |
| 186 | + json_data = to_json(test_span) |
| 187 | + assert(json_data) |
| 188 | + |
0 commit comments