Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 5a6869c

Browse files
authored
Merge pull request #33 from honeycombio/tredman.add_marshal_headers
[api] add marshal_trace_context to top-level API
2 parents d772fce + 402e701 commit 5a6869c

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

beeline/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,24 @@ def finish_span(span):
427427
if _GBL:
428428
_GBL.tracer_impl.finish_span(span=span)
429429

430+
def marshal_trace_context():
431+
'''
432+
Returns a serialized form of the current trace context (including the trace
433+
id and the current span), encoded as a string. You can use this to propagate
434+
trace context to other services.
435+
436+
Example:
437+
438+
```
439+
trace_context = beeline.marshal_trace_context()
440+
headers = {'X-Honeycomb-Trace': trace_context}
441+
requests.get("http://...", headers=headers)
442+
```
443+
'''
444+
if _GBL:
445+
return _GBL.tracer_impl.marshal_trace_context()
446+
447+
430448
def new_event(data=None, trace_name=''):
431449
''' DEPRECATED: Helper method that wraps `start_trace` and
432450
`start_span`. It is better to use these methods as it provides

beeline/middleware/awslambda/test_awslambda.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ def test_wrapper_works_no_init(self):
3434
''' ensure that the wrapper doesn't break anything if used before
3535
beeline.init is called
3636
'''
37-
@awslambda.beeline_wrapper
38-
def foo(event, context):
39-
return 1
37+
with patch('beeline.get_beeline') as p:
38+
p.return_value = None
39+
@awslambda.beeline_wrapper
40+
def foo(event, context):
41+
return 1
4042

41-
self.assertEqual(foo(None, None), 1)
43+
self.assertEqual(foo(None, None), 1)
4244

4345
def test_basic_instrumentation(self):
4446
''' ensure basic event fields get instrumented '''

beeline/test_beeline.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,9 @@ def test_start_trace_returns_value(self):
152152
self.m_gbl.tracer_impl.start_trace.return_value = 'wooimatrace'
153153
val = beeline.start_trace()
154154
self.assertEqual(val, 'wooimatrace')
155+
156+
def test_marshal_trace_context_returns_value(self):
157+
''' ensure the top-level definition of marshal_trace_context returns a value '''
158+
self.m_gbl.tracer_impl.marshal_trace_context.return_value = 'asdf'
159+
val = beeline.marshal_trace_context()
160+
self.assertEqual(val, 'asdf')

beeline/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '2.0.0'
1+
VERSION = '2.1.0'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
setup(
55
python_requires='>=2.7',
66
name='honeycomb-beeline',
7-
version='2.0.0',
7+
version='2.1.0',
88
description='Honeycomb library for easy instrumentation',
99
url='https://github.com/honeycombio/beeline-python',
1010
author='Honeycomb.io',

0 commit comments

Comments
 (0)