Skip to content

Commit

Permalink
Add eventType to reports (#272)
Browse files Browse the repository at this point in the history
Closes #270
  • Loading branch information
kolanos committed Nov 8, 2018
1 parent 9cb04d6 commit b984537
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions iopipe/context.py
Expand Up @@ -86,6 +86,12 @@ def error(self, error):
self.instance.run_hooks("post:report")
raise error

def event_type(self, event_Type):
if self.instance.report is None:
return

self.instance.report.report["eventType"] = event_Type

def register(self, name, value, force=False):
if not hasattr(self, name) or force:
setattr(self, name, value)
Expand Down
1 change: 1 addition & 0 deletions iopipe/contrib/eventinfo/event_types.py
Expand Up @@ -204,6 +204,7 @@ def metrics_for_event_type(event, context):
if event_type.has_required_keys():
context.iopipe.label("@iopipe/plugin-event-info")
context.iopipe.label("@iopipe/aws-%s" % event_type.slug)
context.iopipe.event_type("aws-%s" % event_type.slug)
event_info = event_type.collect()
[context.iopipe.metric(k, v) for k, v in event_info.items()]
break
12 changes: 12 additions & 0 deletions tests/contrib/eventinfo/test_plugin.py
Expand Up @@ -27,6 +27,9 @@ def test__eventinfo_plugin__apigw(
assert len(event_type) == 1
assert event_type[0]["s"] == "apiGateway"

assert "eventType" in iopipe.report.report
assert iopipe.report.report["eventType"] == "aws-api-gateway"


@mock.patch("iopipe.report.send_report", autospec=True)
def test__eventinfo_plugin__cloudfront(
Expand All @@ -49,6 +52,9 @@ def test__eventinfo_plugin__cloudfront(
assert len(event_type) == 1
assert event_type[0]["s"] == "cloudFront"

assert "eventType" in iopipe.report.report
assert iopipe.report.report["eventType"] == "aws-cloud-front"


@mock.patch("iopipe.report.send_report", autospec=True)
def test__eventinfo_plugin__kinesis(
Expand All @@ -71,6 +77,9 @@ def test__eventinfo_plugin__kinesis(
assert len(event_type) == 1
assert event_type[0]["s"] == "kinesis"

assert "eventType" in iopipe.report.report
assert iopipe.report.report["eventType"] == "aws-kinesis"


@mock.patch("iopipe.report.send_report", autospec=True)
def test__eventinfo_plugin__scheduled(
Expand All @@ -93,6 +102,9 @@ def test__eventinfo_plugin__scheduled(
assert len(event_type) == 1
assert event_type[0]["s"] == "scheduled"

assert "eventType" in iopipe.report.report
assert iopipe.report.report["eventType"] == "aws-scheduled"


def test__eventinfo_plugin__enabled(monkeypatch):
monkeypatch.setattr(os, "environ", {"IOPIPE_EVENT_INFO_ENABLED": "true"})
Expand Down

0 comments on commit b984537

Please sign in to comment.