예제 #1
0
	def test_set_parent_id(self):
		traceparent = BaseTraceparent()
		traceparent.set_parent_id(None)
		traceparent.set_parent_id(b'\xff\xff\xff\xff\xff\xff\xff\xff')
		self.assertRaises(ValueError, lambda: traceparent.set_parent_id('fffffffffffffff'))
		traceparent.set_parent_id('ffffffffffffffff')
		self.assertRaises(ValueError, lambda: traceparent.set_parent_id('fffffffffffffffff'))
예제 #2
0
    def test_span_id_limit(self):
        traceparent = BaseTraceparent(span_id=b'\0\0\0\0\0\0\0\0')
        self.assertEqual(traceparent.span_id, b'\0\0\0\0\0\0\0\0')

        self.assertRaises(ValueError,
                          lambda: BaseTraceparent(span_id=b'\0\0\0\0\0\0\0'))
        self.assertRaises(
            ValueError, lambda: BaseTraceparent(span_id=b'\0\0\0\0\0\0\0\0\0'))
예제 #3
0
    def test_version_limit(self):
        traceparent = BaseTraceparent(version=0)
        self.assertEqual(traceparent.version, 0)

        traceparent = BaseTraceparent(version=254)
        self.assertEqual(traceparent.version, 254)

        self.assertRaises(ValueError, lambda: BaseTraceparent(version=-1))
        self.assertRaises(ValueError, lambda: BaseTraceparent(version=255))
예제 #4
0
	def test_trace_flags_limit(self):
		traceparent = BaseTraceparent(trace_flags = 0)
		self.assertEqual(traceparent.trace_flags, 0)

		traceparent = BaseTraceparent(trace_flags = 0xff)
		self.assertEqual(traceparent.trace_flags, 0xff)

		self.assertRaises(ValueError, lambda: BaseTraceparent(trace_flags = -1))
		self.assertRaises(ValueError, lambda: BaseTraceparent(trace_flags = 0xff + 1))
예제 #5
0
 def test_ctor_default(self):
     traceparent = BaseTraceparent()
     self.assertEqual(traceparent.version, 0)
     self.assertEqual(traceparent.trace_id,
                      b'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0')
     self.assertEqual(traceparent.span_id, b'\0\0\0\0\0\0\0\0')
     self.assertEqual(traceparent.trace_flags, 0)
        def do_POST(self):
            self.send_response(200)
            arguments = json.loads(
                str(self.rfile.read(int(self.headers['Content-Length'])),
                    'ascii'))

            traceparent = None
            tracestate = Tracestate()

            try:
                temp_traceparent = BaseTraceparent.from_string(
                    self.get_header('traceparent'))
                if temp_traceparent.version == 0:
                    if temp_traceparent._residue:
                        raise ValueError('illegal traceparent format')
                traceparent = Traceparent(0, temp_traceparent.trace_id,
                                          temp_traceparent.span_id,
                                          temp_traceparent.trace_flags)
            except ValueError:
                pass

            if traceparent is None:
                traceparent = Traceparent()
            else:
                try:
                    header = self.get_header('tracestate', commaSeparated=True)
                    if header is not None:
                        tracestate = Tracestate(header)
                except ValueError:
                    # if tracestate is malformed, reuse the traceparent instead of restart the trace
                    # traceparent = Traceparent()
                    pass

            for item in arguments:
                headers = {}
                headers['traceparent'] = str(
                    Traceparent(0, traceparent.trace_id, None,
                                traceparent.trace_flags))
                if tracestate.is_valid():
                    headers['tracestate'] = str(tracestate)
                request = Request(method='POST',
                                  url=item['url'],
                                  headers=headers,
                                  data=bytes(json.dumps(item['arguments']),
                                             'ascii'))
                with self.opener_director.open(
                        request, timeout=self.timeout) as response:
                    pass
            self.end_headers()
예제 #7
0
    def test_from_string(self):
        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-1234567890123456-00')
        traceparent = BaseTraceparent.from_string(
            '01-12345678901234567890123456789012-1234567890123456-00')
        traceparent = BaseTraceparent.from_string(
            '02-12345678901234567890123456789012-1234567890123456-00')
        traceparent = BaseTraceparent.from_string(
            'cc-12345678901234567890123456789012-1234567890123456-00')
        self.assertRaises(
            ValueError, lambda: BaseTraceparent.from_string(
                'ff-12345678901234567890123456789012-1234567890123456-00'))

        traceparent = BaseTraceparent.from_string(
            '00-00000000000000000000000000000000-1234567890123456-00')
        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-1234567890123456-00')
        traceparent = BaseTraceparent.from_string(
            '00-ffffffffffffffffffffffffffffffff-1234567890123456-00')

        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-0000000000000000-00')
        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-1234567890123456-00')
        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-ffffffffffffffff-00')

        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-1234567890123456-00')
        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-1234567890123456-01')
        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-1234567890123456-02')
        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-1234567890123456-03')
        traceparent = BaseTraceparent.from_string(
            '00-12345678901234567890123456789012-1234567890123456-ff')

        self.assertRaises(
            ValueError, lambda: BaseTraceparent.from_string(
                '0-12345678901234567890123456789012-1234567890123456-00'))
        self.assertRaises(
            ValueError, lambda: BaseTraceparent.from_string(
                '000-12345678901234567890123456789012-1234567890123456-00'))
        self.assertRaises(
            ValueError, lambda: BaseTraceparent.from_string(
                '00-1234567890123456789012345678901-1234567890123456-00'))
        self.assertRaises(
            ValueError, lambda: BaseTraceparent.from_string(
                '00-123456789012345678901234567890123-1234567890123456-00'))
        self.assertRaises(
            ValueError, lambda: BaseTraceparent.from_string(
                '00-12345678901234567890123456789012-123456789012345-00'))
        self.assertRaises(
            ValueError, lambda: BaseTraceparent.from_string(
                '00-12345678901234567890123456789012-12345678901234567-00'))
예제 #8
0
 def test_ctor_with_variadic_arguments(self):
     traceparent = BaseTraceparent(0, None, None, 0, 'foo', 'bar', 'baz')
예제 #9
0
 def test_ctor(self):
     self.assertRaises(ValueError, lambda: BaseTraceparent(version=0xff))
예제 #10
0
 def test_str(self):
     string = '12-12345678901234567890123456789012-1234567890123456-ff'
     traceparent = BaseTraceparent.from_string(
         '12-12345678901234567890123456789012-1234567890123456-ff')
     self.assertEqual(str(traceparent), string)
예제 #11
0
 def test_repr(self):
     string = '12-12345678901234567890123456789012-1234567890123456-ff'
     traceparent = BaseTraceparent.from_string(
         '12-12345678901234567890123456789012-1234567890123456-ff')
     self.assertEqual(repr(traceparent),
                      'BaseTraceparent({})'.format(repr(string)))