def test_get_group_backfill_attributes(self): now = datetime.utcnow().replace(microsecond=0, tzinfo=timezone.utc) assert get_group_backfill_attributes( get_caches(), Group( active_at=now, first_seen=now, last_seen=now, platform="javascript", message="Hello from JavaScript", level=logging.INFO, score=Group.calculate_score(3, now), logger="javascript", times_seen=1, first_release=None, culprit="", data={ "type": "default", "last_received": to_timestamp(now), "metadata": {} }, ), [ self.store_event( data={ "platform": "python", "message": "Hello from Python", "timestamp": iso_format(now - timedelta(hours=1)), "type": "default", "level": "debug", "tags": { "logger": "java" }, }, project_id=self.project.id, ), self.store_event( data={ "platform": "java", "message": "Hello from Java", "timestamp": iso_format(now - timedelta(hours=2)), "type": "default", "level": "debug", "tags": { "logger": "java" }, }, project_id=self.project.id, ), ], ) == { "active_at": now - timedelta(hours=2), "first_seen": now - timedelta(hours=2), "platform": "java", "score": Group.calculate_score(3, now), "logger": "java", "times_seen": 3, "first_release": None, }
def test_get_group_backfill_attributes(self): now = datetime(2017, 5, 3, 6, 6, 6, tzinfo=pytz.utc) assert get_group_backfill_attributes( get_caches(), Group( active_at=now, first_seen=now, last_seen=now, platform='javascript', message='Hello from JavaScript', level=logging.INFO, score=Group.calculate_score(3, now), logger='javascript', times_seen=1, first_release=None, culprit='', data={ 'type': 'default', 'last_received': to_timestamp(now), 'metadata': {}, }, ), [ Event( platform='python', message='Hello from Python', datetime=now - timedelta(hours=1), data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'error'], ['logger', 'python'], ], }, ), Event( platform='java', message='Hello from Java', datetime=now - timedelta(hours=2), data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'debug'], ['logger', 'java'], ], }, ), ], ) == { 'active_at': now - timedelta(hours=2), 'first_seen': now - timedelta(hours=2), 'platform': 'java', 'score': Group.calculate_score(3, now), 'logger': 'java', 'times_seen': 3, 'first_release': None, }
def test_get_group_backfill_attributes(self): now = datetime(2017, 5, 3, 6, 6, 6, tzinfo=pytz.utc) assert get_group_backfill_attributes( get_caches(), Group( active_at=now, first_seen=now, last_seen=now, platform="javascript", message="Hello from JavaScript", level=logging.INFO, score=Group.calculate_score(3, now), logger="javascript", times_seen=1, first_release=None, culprit="", data={ "type": "default", "last_received": to_timestamp(now), "metadata": {} }, ), [ Event( platform="python", message="Hello from Python", datetime=now - timedelta(hours=1), data={ "type": "default", "metadata": {}, "tags": [["level", "error"], ["logger", "python"]], }, ), Event( platform="java", message="Hello from Java", datetime=now - timedelta(hours=2), data={ "type": "default", "metadata": {}, "tags": [["level", "debug"], ["logger", "java"]], }, ), ], ) == { "active_at": now - timedelta(hours=2), "first_seen": now - timedelta(hours=2), "platform": "java", "score": Group.calculate_score(3, now), "logger": "java", "times_seen": 3, "first_release": None, }
def test_get_group_creation_attributes(self): now = datetime.utcnow().replace(microsecond=0, tzinfo=timezone.utc) e1 = self.store_event( data={ "fingerprint": ["group1"], "platform": "javascript", "message": "Hello from JavaScript", "type": "default", "level": "info", "tags": {"logger": "javascript"}, "timestamp": iso_format(now), }, project_id=self.project.id, ) e2 = self.store_event( data={ "fingerprint": ["group1"], "platform": "python", "message": "Hello from Python", "type": "default", "level": "error", "tags": {"logger": "python"}, "timestamp": iso_format(now), }, project_id=self.project.id, ) e3 = self.store_event( data={ "fingerprint": ["group1"], "platform": "java", "message": "Hello from Java", "type": "default", "level": "debug", "tags": {"logger": "java"}, "timestamp": iso_format(now), }, project_id=self.project.id, ) events = [e1, e2, e3] assert get_group_creation_attributes(get_caches(), events) == { "active_at": now, "first_seen": now, "last_seen": now, "platform": "java", "message": "Hello from JavaScript", "level": logging.INFO, "score": Group.calculate_score(3, now), "logger": "java", "times_seen": 3, "first_release": None, "culprit": "", "data": { "type": "default", "last_received": e1.data["received"], "metadata": {"title": "Hello from JavaScript"}, }, }
def test_get_group_creation_attributes(self): now = datetime(2017, 5, 3, 6, 6, 6, tzinfo=pytz.utc) events = [ Event( platform="javascript", message="Hello from JavaScript", datetime=now, data={ "type": "default", "metadata": {}, "tags": [["level", "info"], ["logger", "javascript"]], }, ), Event( platform="python", message="Hello from Python", datetime=now - timedelta(hours=1), data={ "type": "default", "metadata": {}, "tags": [["level", "error"], ["logger", "python"]], }, ), Event( platform="java", message="Hello from Java", datetime=now - timedelta(hours=2), data={ "type": "default", "metadata": {}, "tags": [["level", "debug"], ["logger", "java"]], }, ), ] assert get_group_creation_attributes(get_caches(), events) == { "active_at": now - timedelta(hours=2), "first_seen": now - timedelta(hours=2), "last_seen": now, "platform": "java", "message": "Hello from JavaScript", "level": logging.INFO, "score": Group.calculate_score(3, now), "logger": "java", "times_seen": 3, "first_release": None, "culprit": "", "data": { "type": "default", "last_received": to_timestamp(now), "metadata": {} }, }
def test_get_group_creation_attributes(self): now = datetime(2017, 5, 3, 6, 6, 6, tzinfo=pytz.utc) events = [ Event( platform='javascript', message='Hello from JavaScript', datetime=now, data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'info'], ['logger', 'javascript'], ], }, ), Event( platform='python', message='Hello from Python', datetime=now - timedelta(hours=1), data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'error'], ['logger', 'python'], ], }, ), Event( platform='java', message='Hello from Java', datetime=now - timedelta(hours=2), data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'debug'], ['logger', 'java'], ], }, ), ] assert get_group_creation_attributes( get_caches(), events, ) == { 'active_at': now - timedelta(hours=2), 'first_seen': now - timedelta(hours=2), 'last_seen': now, 'platform': 'java', 'message': 'Hello from JavaScript', 'level': logging.INFO, 'score': Group.calculate_score(3, now), 'logger': 'java', 'times_seen': 3, 'first_release': None, 'culprit': '', 'data': { 'type': 'default', 'last_received': to_timestamp(now), 'metadata': {}, }, }
lambda caches, data, event: event.platform, "logger": lambda caches, data, event: event.get_tag("logger") or DEFAULT_LOGGER_NAME, "first_seen": lambda caches, data, event: event.datetime, "active_at": lambda caches, data, event: event.datetime, "first_release": lambda caches, data, event: caches["Release"] (caches["Project"] (event.project_id).organization_id, event.get_tag("sentry:release")) if event.get_tag("sentry:release") else data.get("first_release", None), "times_seen": lambda caches, data, event: data["times_seen"] + 1, "score": lambda caches, data, event: Group.calculate_score(data["times_seen"] + 1, data["last_seen"]), } def get_group_creation_attributes(caches, events): latest_event = events[0] return reduce( lambda data, event: merge_mappings([ data, { name: f(caches, data, event) for name, f in backfill_fields.items() } ]), events, {name: f(latest_event)
'logger': lambda caches, data, event: event.get_tag('logger') or DEFAULT_LOGGER_NAME, 'first_seen': lambda caches, data, event: event.datetime, 'active_at': lambda caches, data, event: event.datetime, 'first_release': lambda caches, data, event: caches['Release']( caches['Project'](event.project_id).organization_id, event.get_tag('sentry:release'), ) if event.get_tag('sentry:release') else data.get('first_release', None), 'times_seen': lambda caches, data, event: data['times_seen'] + 1, 'score': lambda caches, data, event: Group.calculate_score( data['times_seen'] + 1, data['last_seen'], ), } def get_group_creation_attributes(caches, events): latest_event = events[0] return reduce( lambda data, event: merge_mappings([ data, { name: f(caches, data, event) for name, f in backfill_fields.items() }, ]), events,
'times_seen': lambda event: 0, } backfill_fields = { 'platform': lambda caches, data, event: event.platform, 'logger': lambda caches, data, event: event.get_tag('logger') or DEFAULT_LOGGER_NAME, 'first_seen': lambda caches, data, event: event.datetime, 'active_at': lambda caches, data, event: event.datetime, 'first_release': lambda caches, data, event: caches['Release']( caches['Project'](event.project_id).organization_id, event.get_tag('sentry:release'), ) if event.get_tag('sentry:release') else data.get('first_release', None), 'times_seen': lambda caches, data, event: data['times_seen'] + 1, 'score': lambda caches, data, event: Group.calculate_score( data['times_seen'] + 1, data['last_seen'], ), } def get_group_creation_attributes(caches, events): latest_event = events[0] return reduce( lambda data, event: merge_mappings([ data, {name: f(caches, data, event) for name, f in backfill_fields.items()}, ]), events, {name: f(latest_event) for name, f in initial_fields.items()}, )