Skip to content

Commit

Permalink
Remove common tags from event batch.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-feld committed Apr 17, 2020
1 parent 73de076 commit e8a5c37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
18 changes: 4 additions & 14 deletions src/newrelic_telemetry_sdk/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,10 @@ class SpanBatch(Batch):


class EventBatch(Batch):
"""Aggregates events, providing a record / flush interface.
"""Aggregates events, providing a record / flush interface."""

:param tags: (optional) A dictionary of tags to attach to all flushes.
:type tags: dict
"""

def __init__(self, tags=None):
super(EventBatch, self).__init__(tags)
if tags:
# Events are currently a flat structure, so there's no nesting of
# user attributes.
self._common = dict(tags)
def __init__(self):
super(EventBatch, self).__init__()

def flush(self):
"""Flush all items from the batch
Expand All @@ -92,7 +84,5 @@ def flush(self):
:returns: A tuple of (items,)
:rtype: tuple
"""
items, common = super(EventBatch, self).flush()
if common:
items = tuple(dict(common, **item) for item in items)
items, _ = super(EventBatch, self).flush()
return (items,)
18 changes: 0 additions & 18 deletions tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,3 @@ def test_batch_simple(batch_cls):
batch.record(item)

assert batch.flush()[0] == (item,)


@pytest.mark.parametrize("tags", (None, {"foo": "bar"}, {"boo": "baz"}))
def test_event_batch_common_tags(tags):
batch = EventBatch(tags)

expected = item = {"foo": "foo"}
if tags:
expected = dict(tags)
expected.update(item)

for _ in range(2):
batch.record(item)

result = batch.flush()
items = result[0]

assert items == (expected,)

0 comments on commit e8a5c37

Please sign in to comment.