Skip to content

Commit

Permalink
Add type safety checking in add_trace_field, bump version
Browse files Browse the repository at this point in the history
#96 added a string content check to the trace field name, but there were previously no checks to ensure that this value is in fact a string. Any customer using the beeline that picks up that patch and is using unusual types here could crash, so I added some type checking before bumping the version on this release.
  • Loading branch information
tredman committed Jan 23, 2020
1 parent 2d2b4c1 commit 70ad2e9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# beeline-python changelog

## 2.11.3 2020-01-23

Fixes

- Prevent duplicate `app.` prefixes in trace fields. [#96](https://github.com/honeycombio/beeline-python/pull/96)

## 2.11.2 2019-11-26

Fixes
Expand Down
10 changes: 9 additions & 1 deletion beeline/test_trace.py
Expand Up @@ -274,6 +274,10 @@ def test_add_trace_field_propagates(self):

tracer.add_trace_field('another', 'important_thing')
tracer.add_trace_field('wide', 'events_are_great')
# ensure we don't crash if non-string added here
tracer.add_trace_field(12345, 54321)
# ensure fields prefixed with app. don't get another prefix
tracer.add_trace_field('app.prefixes', 'there should only be 1')

span2 = tracer.start_span(context={'more': 'important_stuff'})
# should still have the root span as the first item in the stack
Expand All @@ -287,7 +291,9 @@ def test_add_trace_field_propagates(self):
self.assertEqual(span.trace_id, tracer._trace.id)
m_client.new_event.assert_called_once_with(data={
'app.another': 'important_thing',
'app.wide': 'events_are_great'
'app.wide': 'events_are_great',
'app.12345': 54321,
'app.prefixes': 'there should only be 1',
})
m_client.new_event.return_value.add.assert_has_calls([
call(data={'more': 'important_stuff'}),
Expand Down Expand Up @@ -315,6 +321,8 @@ def test_add_trace_field_propagates(self):
m_client.new_event.assert_called_once_with(data={
'app.wide': 'events_are_great',
'app.more': 'data!',
'app.12345': 54321,
'app.prefixes': 'there should only be 1',
})

def test_add_rollup_field_propagates(self):
Expand Down
6 changes: 5 additions & 1 deletion beeline/trace.py
Expand Up @@ -206,8 +206,12 @@ def add_rollup_field(self, name, value):
def add_trace_field(self, name, value):
# prefix with app to avoid key conflicts
# add the app prefix if it's missing
if not name.startswith("app."):

if (type(name) == str and not name.startswith("app.")) or type(name) != str:
key = "app.%s" % name
else:
key = name

# also add to current span
self.add_context_field(key, value)

Expand Down
2 changes: 1 addition & 1 deletion beeline/version.py
@@ -1 +1 @@
VERSION = '2.11.2'
VERSION = '2.11.3'
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@
setup(
python_requires='>=2.7',
name='honeycomb-beeline',
version='2.11.2',
version='2.11.3',
description='Honeycomb library for easy instrumentation',
url='https://github.com/honeycombio/beeline-python',
author='Honeycomb.io',
Expand Down

0 comments on commit 70ad2e9

Please sign in to comment.