Beispiel #1
0
    def test_roundtrip(self):
        '''Verify that we can successfully roundtrip (marshal and unmarshal)'''
        trace_fields = {
            "traceflags": _TEST_TRACE_FLAGS,
            "tracestate": _TEST_TRACESTATE
        }

        pc = PropagationContext(_TEST_TRACE_ID, _TEST_PARENT_ID, trace_fields)

        traceparent_header = w3c.marshal_traceparent(pc)
        tracestate_header = w3c.marshal_tracestate(pc)

        # Make sure marshalled headers are as we expect.
        self.assertEquals(_TEST_TRACEPARENT_HEADER, traceparent_header)
        self.assertEquals(_TEST_TRACESTATE_HEADER, tracestate_header)

        new_trace_id, new_parent_id, new_trace_flags = w3c.unmarshal_traceparent(
            traceparent_header)
        new_tracestate = w3c.unmarshal_tracestate(tracestate_header)

        # Check round-trip values are the same as start values.
        self.assertEquals(_TEST_TRACE_ID, new_trace_id)
        self.assertEquals(_TEST_PARENT_ID, new_parent_id)
        self.assertEquals(_TEST_TRACE_FLAGS, new_trace_flags)
        self.assertEquals(_TEST_TRACESTATE, new_tracestate)
Beispiel #2
0
 def test_generates_correct_header(self):
     trace_id = "bloop"
     parent_id = "scoop"
     trace_fields = {"key": "value"}
     pc = PropagationContext(
         trace_id, parent_id, trace_fields)
     headers = hc.http_trace_propagation_hook(pc)
     self.assertIn('X-Honeycomb-Trace', headers)
     self.assertEquals(headers['X-Honeycomb-Trace'],
                       "1;trace_id=bloop,parent_id=scoop,context=eyJrZXkiOiAidmFsdWUifQ==")
Beispiel #3
0
 def test_generates_correct_headers(self):
     pc = PropagationContext(_TEST_TRACE_ID, _TEST_PARENT_ID, {
         "traceflags": _TEST_TRACE_FLAGS,
         "tracestate": _TEST_TRACESTATE
     })
     headers = w3c.http_trace_propagation_hook(pc)
     self.assertIn('traceparent', headers)
     self.assertIn('tracestate', headers)
     self.assertEquals(headers['traceparent'], _TEST_TRACEPARENT_HEADER)
     self.assertEquals(headers['tracestate'], _TEST_TRACESTATE_HEADER)
 def test_roundtrip(self):
     '''Verify that we can successfully roundtrip (marshal and unmarshal)'''
     trace_id = "bloop"
     parent_id = "scoop"
     trace_fields = {"key": "value"}
     pc = PropagationContext(trace_id, parent_id, trace_fields)
     header = hc.marshal_propagation_context(pc)
     new_trace_id, new_parent_id, new_trace_fields = hc.unmarshal_propagation_context(
         header)
     self.assertEqual(trace_id, new_trace_id)
     self.assertEqual(parent_id, new_parent_id)
     self.assertEqual(trace_fields, new_trace_fields)
Beispiel #5
0
def http_trace_parser_hook(request):
    '''
    Retrieves the honeycomb propagation context out of the request.
    request must implement the beeline.propagation.Request abstract base class
    '''
    trace_header = request.header('X-Honeycomb-Trace')
    if trace_header:
        try:
            trace_id, parent_id, context, dataset = unmarshal_propagation_context_with_dataset(
                trace_header)
            return PropagationContext(trace_id, parent_id, context, dataset)
        except Exception as e:
            beeline.internal.log(
                'error attempting to extract trace context: %s',
                beeline.internal.stringify_exception(e))
    return None
Beispiel #6
0
def http_trace_parser_hook(request):
    '''
    Retrieves the w3c propagation context out of the request.
    request must implement the beeline.propagation.Request abstract base class
    '''
    traceparent_header = request.header('traceparent')
    if not traceparent_header:
        return None
    tracestate_header = request.header('tracestate')

    trace_id = None
    parent_id = None
    try:
        trace_id, parent_id, trace_flags = unmarshal_traceparent(
            traceparent_header)
        tracestate = unmarshal_tracestate(tracestate_header)
        trace_fields = {}
        trace_fields['traceflags'] = trace_flags
        trace_fields['tracestate'] = tracestate
        return PropagationContext(trace_id, parent_id, trace_fields)
    except Exception as e:
        beeline.internal.log('error attempting to extract w3c trace: %s',
                             beeline.internal.stringify_exception(e))
    return None
Beispiel #7
0
 def test_defaults_trace_flags_to_sampled(self):
     pc = PropagationContext(_TEST_TRACE_ID, _TEST_PARENT_ID)
     headers = w3c.http_trace_propagation_hook(pc)
     self.assertIn('traceparent', headers)
     self.assertEqual(headers['traceparent'],
                      _TEST_TRACEPARENT_HEADER_DEFAULT_TRACEFLAGS)