def new_event(request): org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) group = Group( id=1, project=project, message='This is an example event.', level=logging.ERROR, ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data('python'), ) rule = Rule(label="An example rule") interface_list = [] for interface in event.interfaces.itervalues(): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) preview = MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.html', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), 'project_label': project.name, }, ) return render_to_response('sentry/debug/mail/preview.html', { 'preview': preview, })
def new_event(request): platform = request.GET.get("platform", "python") org = Organization(id=1, slug="example", name="Example") team = Team(id=1, slug="example", name="Example", organization=org) project = Project(id=1, slug="example", name="Example", team=team, organization=org) group = Group(id=1, project=project, message="This is an example event.", level=logging.ERROR) event = Event(id=1, project=project, group=group, message=group.message, data=load_data(platform)) rule = Rule(label="An example rule") interface_list = [] for interface in event.interfaces.itervalues(): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template="sentry/emails/error.html", text_template="sentry/emails/error.html", context={ "rule": rule, "group": group, "event": event, "link": "http://example.com/link", "interfaces": interface_list, "tags": event.get_tags(), "project_label": project.name, "tags": [("logger", "javascript"), ("environment", "prod"), ("level", "error"), ("device", "Other")], }, ).render()
def get(self, request): org = Organization(id=1, slug="organization", name="My Company") team = Team(id=1, slug="team", name="My Team", organization=org) project = Project(id=1, organization=org, team=team, slug="project", name="My Project") group = Group( id=1, project=project, message="This is an example event.", last_seen=datetime(2016, 6, 13, 3, 8, 24, tzinfo=timezone.utc), first_seen=datetime(2016, 6, 13, 3, 8, 24, tzinfo=timezone.utc), ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data("python"), datetime=datetime(2016, 6, 13, 3, 8, 24, tzinfo=timezone.utc), ) activity = Activity(group=event.group, project=event.project, **self.get_activity(request, event)) return render_to_response( "sentry/debug/mail/preview.html", {"preview": ActivityMailPreview(activity), "format": request.GET.get("format")}, )
def test_one_issue(self): with self.feature('organizations:sentry10'): self.init_snuba() event_data = load_data('python') event_data['event_id'] = 'd964fdbd649a4cf8bfc35d18082b6b0e' event_data['timestamp'] = 1452683305 event = self.store_event( project_id=self.project.id, data=event_data, assert_no_errors=False ) event.group.update( first_seen=datetime(2018, 1, 12, 3, 8, 25, tzinfo=timezone.utc), last_seen=datetime(2018, 1, 13, 3, 8, 25, tzinfo=timezone.utc), ) GroupAssignee.objects.create( user=self.user, group=event.group, project=self.project, ) OrganizationOnboardingTask.objects.create_or_update( organization_id=self.project.organization_id, task=OnboardingTask.FIRST_EVENT, status=OnboardingTaskStatus.COMPLETE, ) self.project.update(first_event=timezone.now()) self.browser.get(self.path) self.browser.wait_until_not('.loading-indicator') self.browser.wait_until('[data-test-id] figure') self.browser.snapshot('org dash one issue')
def get(self, request): org = Organization( id=1, slug='organization', name='My Company', ) project = Project( id=1, organization=org, slug='project', name='My Project', ) group = next( make_group_generator( get_random(request), project, ), ) data = dict(load_data('python')) data['message'] = group.message data.pop('logentry', None) event_manager = EventManager(data) event_manager.normalize() data = event_manager.get_data() event_type = event_manager.get_event_type() group.message = event_manager.get_search_message() group.data = { 'type': event_type.key, 'metadata': event_type.get_metadata(data), } event = Event( id=1, project=project, message=event_manager.get_search_message(), group=group, datetime=datetime(2016, 6, 13, 3, 8, 24, tzinfo=timezone.utc), data=event_manager.get_data() ) activity = Activity( group=event.group, project=event.project, **self.get_activity(request, event) ) return render_to_response( 'sentry/debug/mail/preview.html', { 'preview': ActivityMailPreview(request, activity), 'format': request.GET.get('format'), } )
def new_note(request): org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) group = Group( id=1, project=project, message='This is an example event.', ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data('python'), ) note = Activity( group=event.group, event=event, project=event.project, type=Activity.NOTE, user=request.user, data={'text': 'This is an example note!'}, ) preview = MailPreview( html_template='sentry/emails/activity/note.html', text_template='sentry/emails/activity/note.txt', context={ 'data': note.data, 'author': note.user, 'date': note.datetime, 'group': group, 'link': group.get_absolute_url(), }, ) return render_to_response('sentry/debug/mail/preview.html', { 'preview': preview, })
def assigned(request): org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) group = Group( id=1, project=project, message='This is an example event.', ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data('python'), ) assigned = Activity( group=event.group, event=event, project=event.project, type=Activity.ASSIGNED, user=request.user, data={'text': 'This is an example note!'}, ) return MailPreview( html_template='sentry/emails/activity/assigned.html', text_template='sentry/emails/activity/assigned.txt', context={ 'data': assigned.data, 'author': assigned.user, 'date': assigned.datetime, 'group': group, 'link': group.get_absolute_url(), }, ).render()
def create_sample_event(self, platform, default=None, sample_name=None): event_data = load_data(platform, default=default, sample_name=sample_name) event_data['event_id'] = 'd964fdbd649a4cf8bfc35d18082b6b0e' event = self.store_event( data=event_data, project_id=self.project.id, assert_no_errors=False, ) event.datetime = datetime(2017, 9, 6, 0, 0) event.save() event.group.update( first_seen=datetime(2015, 8, 13, 3, 8, 25, tzinfo=timezone.utc), last_seen=datetime(2016, 1, 13, 3, 8, 25, tzinfo=timezone.utc), ) return event
def get(self, request): org = Organization( id=1, slug='organization', name='My Company', ) team = Team( id=1, slug='team', name='My Team', organization=org, ) project = Project( id=1, organization=org, team=team, slug='project', name='My Project', ) group = next( make_group_generator( get_random(request), project, ), ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data('python'), datetime=datetime(2016, 6, 13, 3, 8, 24, tzinfo=timezone.utc), ) activity = Activity( group=event.group, project=event.project, **self.get_activity(request, event) ) return render_to_response( 'sentry/debug/mail/preview.html', { 'preview': ActivityMailPreview(request, activity), 'format': request.GET.get('format'), } )
def new_event(request): platform = request.GET.get('platform', 'python') org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) group = Group( id=1, project=project, message='This is an example event.', level=logging.ERROR, ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data(platform), ) rule = Rule(label="An example rule") interface_list = [] for interface in event.interfaces.itervalues(): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.html', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), 'project_label': project.name, 'tags': [ ('logger', 'javascript'), ('environment', 'prod'), ('level', 'error'), ('device', 'Other') ] }, ).render()
def create_error(self, platform, trace_id, span_id, project_id, timestamp): data = load_data(platform, timestamp=timestamp) if "contexts" not in data: data["contexts"] = {} data["contexts"]["trace"] = {"type": "trace", "trace_id": trace_id, "span_id": span_id} return self.store_event(data, project_id=project_id)
def test_transaction_vitals_filtering(self, mock_now): mock_now.return_value = before_now().replace(tzinfo=pytz.utc) vitals_path = u"/organizations/{}/performance/summary/vitals/?{}".format( self.org.slug, urlencode({ "transaction": "/country_by_code/", "project": self.project.id, "dataFilter": "exclude_outliers", }), ) # Create transactions for seconds in range(3): event_data = load_data("transaction", timestamp=before_now(minutes=2)) event_data["contexts"]["trace"]["op"] = "pageload" event_data["contexts"]["trace"]["id"] = ("c" * 31) + hex(seconds)[2:] event_data["event_id"] = ("c" * 31) + hex(seconds)[2:] event_data["measurements"]["fp"]["value"] = seconds * 10 event_data["measurements"]["fcp"]["value"] = seconds * 10 event_data["measurements"]["lcp"]["value"] = seconds * 10 event_data["measurements"]["fid"]["value"] = seconds * 10 event_data["measurements"]["cls"]["value"] = seconds / 10.0 self.store_event(data=event_data, project_id=self.project.id) # add anchor point event_data = load_data("transaction", timestamp=before_now(minutes=1)) event_data["contexts"]["trace"]["op"] = "pageload" event_data["contexts"]["trace"]["id"] = "a" * 32 event_data["event_id"] = "a" * 32 event_data["measurements"]["fp"]["value"] = 3000 event_data["measurements"]["fcp"]["value"] = 3000 event_data["measurements"]["lcp"]["value"] = 3000 event_data["measurements"]["fid"]["value"] = 3000 event_data["measurements"]["cls"]["value"] = 0.3 self.store_event(data=event_data, project_id=self.project.id) # add outlier event_data = load_data("transaction", timestamp=before_now(minutes=1)) event_data["contexts"]["trace"]["op"] = "pageload" event_data["contexts"]["trace"]["id"] = "b" * 32 event_data["event_id"] = "b" * 32 event_data["measurements"]["fp"]["value"] = 3000000000 event_data["measurements"]["fcp"]["value"] = 3000000000 event_data["measurements"]["lcp"]["value"] = 3000000000 event_data["measurements"]["fid"]["value"] = 3000000000 event_data["measurements"]["cls"]["value"] = 3000000000 self.store_event(data=event_data, project_id=self.project.id) self.wait_for_event_count(self.project.id, 5) with self.feature(FEATURE_NAMES): self.browser.get(vitals_path) self.page.wait_until_loaded() self.browser.snapshot("real user monitoring - exclude outliers") self.browser.element( xpath="//button//span[contains(text(), 'Exclude Outliers')]" ).click() self.browser.element( xpath="//li//span[contains(text(), 'View All')]").click() self.page.wait_until_loaded() self.browser.snapshot("real user monitoring - view all data")
def generate_transaction(trace=None, span=None): start_datetime = before_now(minutes=1, milliseconds=500) end_datetime = before_now(minutes=1) event_data = load_data( "transaction", timestamp=end_datetime, start_timestamp=start_datetime, trace=trace, span=span, ) event_data.update({"event_id": "a" * 32}) # generate and build up span tree reference_span = event_data["spans"][0] parent_span_id = reference_span["parent_span_id"] span_tree_blueprint = { "a": {}, "b": { "bb": { "bbb": { "bbbb": "bbbbb" } } }, "c": {}, "d": {}, "e": {}, } time_offsets = { "a": (timedelta(), timedelta(milliseconds=10)), "b": (timedelta(milliseconds=120), timedelta(milliseconds=250)), "bb": (timedelta(milliseconds=130), timedelta(milliseconds=10)), "bbb": (timedelta(milliseconds=140), timedelta(milliseconds=10)), "bbbb": (timedelta(milliseconds=150), timedelta(milliseconds=10)), "bbbbb": (timedelta(milliseconds=160), timedelta(milliseconds=90)), "c": (timedelta(milliseconds=260), timedelta(milliseconds=100)), "d": (timedelta(milliseconds=375), timedelta(milliseconds=50)), "e": (timedelta(milliseconds=400), timedelta(milliseconds=100)), } def build_span_tree(span_tree, spans, parent_span_id): for span_id, child in sorted(span_tree.items(), key=lambda item: item[0]): span = copy.deepcopy(reference_span) # non-leaf node span span["parent_span_id"] = parent_span_id.ljust(16, "0") span["span_id"] = span_id.ljust(16, "0") (start_delta, span_length) = time_offsets.get(span_id, (timedelta(), timedelta())) span_start_time = start_datetime + start_delta span["start_timestamp"] = timestamp_format(span_start_time) span["timestamp"] = timestamp_format(span_start_time + span_length) spans.append(span) if isinstance(child, dict): spans = build_span_tree(child, spans, span_id) elif isinstance(child, str): parent_span_id = span_id span_id = child span = copy.deepcopy(reference_span) # leaf node span span["parent_span_id"] = parent_span_id.ljust(16, "0") span["span_id"] = span_id.ljust(16, "0") (start_delta, span_length) = time_offsets.get(span_id, (timedelta(), timedelta())) span_start_time = start_datetime + start_delta span["start_timestamp"] = timestamp_format(span_start_time) span["timestamp"] = timestamp_format(span_start_time + span_length) spans.append(span) return spans event_data["spans"] = build_span_tree(span_tree_blueprint, [], parent_span_id) return event_data
def __build_transaction_event(self): manager = EventManager(load_data("transaction")) manager.normalize() return manager.save(self.project.id)
def setUp(self): super(OrganizationEventsStatsTopNEvents, self).setUp() self.login_as(user=self.user) self.day_ago = before_now(days=1).replace(hour=10, minute=0, second=0, microsecond=0) self.project = self.create_project() self.project2 = self.create_project() self.user2 = self.create_user() transaction_data = load_data("transaction") transaction_data["start_timestamp"] = iso_format(self.day_ago + timedelta(minutes=2)) transaction_data["timestamp"] = iso_format(self.day_ago + timedelta(minutes=4)) self.event_data = [ { "data": { "message": "poof", "timestamp": iso_format(self.day_ago + timedelta(minutes=2)), "user": {"email": self.user.email}, "fingerprint": ["group1"], }, "project": self.project2, "count": 7, }, { "data": { "message": "voof", "timestamp": iso_format(self.day_ago + timedelta(hours=1, minutes=2)), "fingerprint": ["group2"], "user": {"email": self.user2.email}, }, "project": self.project2, "count": 6, }, { "data": { "message": "very bad", "timestamp": iso_format(self.day_ago + timedelta(minutes=2)), "fingerprint": ["group3"], "user": {"email": "*****@*****.**"}, }, "project": self.project, "count": 5, }, { "data": { "message": "oh no", "timestamp": iso_format(self.day_ago + timedelta(minutes=2)), "fingerprint": ["group4"], "user": {"email": "*****@*****.**"}, }, "project": self.project, "count": 4, }, {"data": transaction_data, "project": self.project, "count": 3}, # Not in the top 5 { "data": { "message": "sorta bad", "timestamp": iso_format(self.day_ago + timedelta(minutes=2)), "fingerprint": ["group5"], "user": {"email": "*****@*****.**"}, }, "project": self.project, "count": 2, }, { "data": { "message": "not so bad", "timestamp": iso_format(self.day_ago + timedelta(minutes=2)), "fingerprint": ["group6"], "user": {"email": "*****@*****.**"}, }, "project": self.project, "count": 1, }, ] self.events = [] for index, event_data in enumerate(self.event_data): data = event_data["data"].copy() for i in range(event_data["count"]): data["event_id"] = "{}{}".format(index, i) * 16 event = self.store_event(data, project_id=event_data["project"].id) self.events.append(event) self.transaction = self.events[4] self.url = reverse( "sentry-api-0-organization-events-stats", kwargs={"organization_slug": self.project.organization.slug}, )
def alert(request): platform = request.GET.get('platform', 'python') org = Organization( id=1, slug='example', name='Example', ) project = Project( id=1, slug='example', name='Example', organization=org, ) random = get_random(request) group = next(make_group_generator(random, project), ) data = dict(load_data(platform)) data['message'] = group.message data['event_id'] = '44f1419e73884cd2b45c79918f4b6dc4' data.pop('logentry', None) data['environment'] = 'prod' data['tags'] = [('logger', 'javascript'), ('environment', 'prod'), ('level', 'error'), ('device', 'Other')] event_manager = EventManager(data) event_manager.normalize() event = event_manager.save(project.id) event_type = event_manager.get_event_type() group.message = event_manager.get_search_message() group.data = { 'type': event_type.key, 'metadata': event_type.get_metadata(), } rule = Rule(label="An example rule") interface_list = [] for interface in six.itervalues(event.interfaces): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.txt', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), 'project_label': project.slug, 'commits': [{ # TODO(dcramer): change to use serializer "repository": { "status": "active", "name": "Example Repo", "url": "https://github.com/example/example", "dateCreated": "2018-02-28T23:39:22.402Z", "provider": { "id": "github", "name": "GitHub" }, "id": "1" }, "score": 2, "subject": "feat: Do something to raven/base.py", "message": "feat: Do something to raven/base.py\naptent vivamus vehicula tempus volutpat hac tortor", "id": "1b17483ffc4a10609e7921ee21a8567bfe0ed006", "shortId": "1b17483", "author": { "username": "******", "isManaged": False, "lastActive": "2018-03-01T18:25:28.149Z", "id": "1", "isActive": True, "has2fa": False, "name": "*****@*****.**", "avatarUrl": "https://secure.gravatar.com/avatar/51567a4f786cd8a2c41c513b592de9f9?s=32&d=mm", "dateJoined": "2018-02-27T22:04:32.847Z", "emails": [{ "is_verified": False, "id": "1", "email": "*****@*****.**" }], "avatar": { "avatarUuid": None, "avatarType": "letter_avatar" }, "lastLogin": "******", "email": "*****@*****.**" } }], }, ).render(request)
def digest(request): random = get_random(request) # TODO: Refactor all of these into something more manageable. org = Organization( id=1, slug='example', name='Example Organization', ) team = Team( id=1, slug='example', name='Example Team', organization=org, ) project = Project( id=1, slug='example', name='Example Project', team=team, organization=org, ) rules = {i: Rule( id=i, project=project, label="Rule #%s" % (i,), ) for i in range(1, random.randint(2, 4))} state = { 'project': project, 'groups': {}, 'rules': rules, 'event_counts': {}, 'user_counts': {}, } records = [] event_sequence = itertools.count(1) group_generator = make_group_generator(random, project) for i in range(random.randint(1, 30)): group = next(group_generator) state['groups'][group.id] = group offset = timedelta(seconds=0) for i in range(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) event = Event( id=next(event_sequence), event_id=uuid.uuid4().hex, project=project, group=group, message=group.message, data=load_data('python'), datetime=to_datetime( random.randint( to_timestamp(group.first_seen), to_timestamp(group.last_seen), ), ) ) records.append( Record( event.event_id, Notification( event, random.sample(state['rules'], random.randint(1, len(state['rules']))), ), to_timestamp(event.datetime), ) ) state['event_counts'][group.id] = random.randint(10, 1e4) state['user_counts'][group.id] = random.randint(10, 1e4) digest = build_digest(project, records, state) start, end, counts = get_digest_metadata(digest) return MailPreview( html_template='sentry/emails/digests/body.html', text_template='sentry/emails/digests/body.txt', context={ 'project': project, 'counts': counts, 'digest': digest, 'start': start, 'end': end, }, ).render(request)
def digest(request): seed = request.GET.get('seed', str(time.time())) logger.debug('Using random seed value: %s') random = Random(seed) now = datetime.utcnow().replace(tzinfo=pytz.utc) # TODO: Refactor all of these into something more manageable. org = Organization( id=1, slug='example', name='Example Organization', ) team = Team( id=1, slug='example', name='Example Team', organization=org, ) project = Project( id=1, slug='example', name='Example Project', team=team, organization=org, ) rules = {i: Rule( id=i, project=project, label="Rule #%s" % (i,), ) for i in xrange(1, random.randint(2, 4))} state = { 'project': project, 'groups': {}, 'rules': rules, 'event_counts': {}, 'user_counts': {}, } records = [] group_sequence = itertools.count(1) event_sequence = itertools.count(1) for i in xrange(random.randint(1, 30)): group_id = next(group_sequence) group = state['groups'][group_id] = Group( id=group_id, project=project, message='This is example event #%s' % (group_id,), culprit='widget.foo in bar', ) offset = timedelta(seconds=0) for i in xrange(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) event = Event( id=next(event_sequence), event_id=uuid.uuid4().hex, project=project, group=group, message=group.message, data=load_data('python'), datetime=now - offset, ) records.append( Record( event.event_id, Notification( event, random.sample(state['rules'], random.randint(1, len(state['rules']))), ), to_timestamp(event.datetime), ) ) state['event_counts'][group_id] = random.randint(10, 1e4) state['user_counts'][group_id] = random.randint(10, 1e4) digest = build_digest(project, records, state) # TODO(tkaemming): This duplication from ``MailPlugin.notify_digest`` is a code smell counts = Counter() for rule, groups in digest.iteritems(): counts.update(groups.keys()) return MailPreview( html_template='sentry/emails/digests/body.html', text_template='sentry/emails/digests/body.txt', context={ 'project': project, 'counts': counts, 'digest': digest, }, ).render()
def setUp(self): super().setUp() self.min_ago = iso_format(before_now(minutes=1)) self.data = load_data("transaction")
def alert(request): platform = request.GET.get('platform', 'python') org = Organization( id=1, slug='example', name='Example', ) project = Project( id=1, slug='example', name='Example', organization=org, ) random = get_random(request) group = next( make_group_generator(random, project), ) event = Event( id=1, event_id='44f1419e73884cd2b45c79918f4b6dc4', project=project, group=group, message=group.message, data=load_data(platform), datetime=to_datetime( random.randint( to_timestamp(group.first_seen), to_timestamp(group.last_seen), ), ), ) rule = Rule(label="An example rule") interface_list = [] for interface in six.itervalues(event.interfaces): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.txt', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), 'project_label': project.slug, 'tags': [ ('logger', 'javascript'), ('environment', 'prod'), ('level', 'error'), ('device', 'Other') ], 'commits': [{ # TODO(dcramer): change to use serializer "repository": {"status": "active", "name": "Example Repo", "url": "https://github.com/example/example", "dateCreated": "2018-02-28T23:39:22.402Z", "provider": {"id": "github", "name": "GitHub"}, "id": "1"}, "score": 2, "subject": "feat: Do something to raven/base.py", "message": "feat: Do something to raven/base.py\naptent vivamus vehicula tempus volutpat hac tortor", "id": "1b17483ffc4a10609e7921ee21a8567bfe0ed006", "shortId": "1b17483", "author": {"username": "******", "isManaged": False, "lastActive": "2018-03-01T18:25:28.149Z", "id": "1", "isActive": True, "has2fa": False, "name": "*****@*****.**", "avatarUrl": "https://secure.gravatar.com/avatar/51567a4f786cd8a2c41c513b592de9f9?s=32&d=mm", "dateJoined": "2018-02-27T22:04:32.847Z", "emails": [{"is_verified": False, "id": "1", "email": "*****@*****.**"}], "avatar": {"avatarUuid": None, "avatarType": "letter_avatar"}, "lastLogin": "******", "email": "*****@*****.**"} }], }, ).render(request)
def digest(request): random = get_random(request) # TODO: Refactor all of these into something more manageable. org = Organization(id=1, slug="example", name="Example Organization") project = Project(id=1, slug="example", name="Example Project", organization=org) rules = { i: Rule(id=i, project=project, label="Rule #%s" % (i,)) for i in range(1, random.randint(2, 4)) } state = { "project": project, "groups": {}, "rules": rules, "event_counts": {}, "user_counts": {}, } records = [] event_sequence = itertools.count(1) group_generator = make_group_generator(random, project) for i in range(random.randint(1, 30)): group = next(group_generator) state["groups"][group.id] = group offset = timedelta(seconds=0) for i in range(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) event = Event( id=next(event_sequence), event_id=uuid.uuid4().hex, project=project, group=group, message=group.message, data=load_data("python"), datetime=to_datetime( random.randint(to_timestamp(group.first_seen), to_timestamp(group.last_seen)) ), ) records.append( Record( event.event_id, Notification( event, random.sample(state["rules"], random.randint(1, len(state["rules"]))) ), to_timestamp(event.datetime), ) ) state["event_counts"][group.id] = random.randint(10, 1e4) state["user_counts"][group.id] = random.randint(10, 1e4) digest = build_digest(project, records, state) start, end, counts = get_digest_metadata(digest) context = { "project": project, "counts": counts, "digest": digest, "start": start, "end": end, "referrer": "digest_email", } add_unsubscribe_link(context) return MailPreview( html_template="sentry/emails/digests/body.html", text_template="sentry/emails/digests/body.txt", context=context, ).render(request)
def alert(request): platform = request.GET.get("platform", "python") org = Organization(id=1, slug="example", name="Example") project = Project(id=1, slug="example", name="Example", organization=org) random = get_random(request) group = next(make_group_generator(random, project)) data = dict(load_data(platform)) data["message"] = group.message data["event_id"] = "44f1419e73884cd2b45c79918f4b6dc4" data.pop("logentry", None) data["environment"] = "prod" data["tags"] = [ ("logger", "javascript"), ("environment", "prod"), ("level", "error"), ("device", "Other"), ] event_manager = EventManager(data) event_manager.normalize() data = event_manager.get_data() event = event_manager.save(project.id) # Prevent Percy screenshot from constantly changing event.datetime = datetime(2017, 9, 6, 0, 0) try: event.save() except IntegrityError: pass event_type = event_manager.get_event_type() group.message = event_manager.get_search_message() group.data = { "type": event_type.key, "metadata": event_type.get_metadata(data) } rule = Rule(label="An example rule") interface_list = [] for interface in six.itervalues(event.interfaces): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template="sentry/emails/error.html", text_template="sentry/emails/error.txt", context={ "rule": rule, "group": group, "event": event, "link": "http://example.com/link", "interfaces": interface_list, "tags": event.tags, "project_label": project.slug, "commits": [{ # TODO(dcramer): change to use serializer "repository": { "status": "active", "name": "Example Repo", "url": "https://github.com/example/example", "dateCreated": "2018-02-28T23:39:22.402Z", "provider": { "id": "github", "name": "GitHub" }, "id": "1", }, "score": 2, "subject": "feat: Do something to raven/base.py", "message": "feat: Do something to raven/base.py\naptent vivamus vehicula tempus volutpat hac tortor", "id": "1b17483ffc4a10609e7921ee21a8567bfe0ed006", "shortId": "1b17483", "author": { "username": "******", "isManaged": False, "lastActive": "2018-03-01T18:25:28.149Z", "id": "1", "isActive": True, "has2fa": False, "name": "*****@*****.**", "avatarUrl": "https://secure.gravatar.com/avatar/51567a4f786cd8a2c41c513b592de9f9?s=32&d=mm", "dateJoined": "2018-02-27T22:04:32.847Z", "emails": [{ "is_verified": False, "id": "1", "email": "*****@*****.**" }], "avatar": { "avatarUuid": None, "avatarType": "letter_avatar" }, "lastLogin": "******", "email": "*****@*****.**", }, }], }, ).render(request)
def setUp(self): super().setUp() self.min_ago = iso_format(before_now(minutes=1)) self.data = load_data("transaction") self.features["organizations:performance-use-snql"] = True
def digest(request): seed = request.GET.get('seed', str(time.time())) logger.debug('Using random seed value: %s') random = Random(seed) now = datetime.utcnow().replace(tzinfo=pytz.utc) # TODO: Refactor all of these into something more manageable. org = Organization( id=1, slug='example', name='Example Organization', ) team = Team( id=1, slug='example', name='Example Team', organization=org, ) project = Project( id=1, slug='example', name='Example Project', team=team, organization=org, ) rules = {i: Rule( id=i, project=project, label="Rule #%s" % (i,), ) for i in xrange(1, random.randint(2, 4))} state = { 'project': project, 'groups': {}, 'rules': rules, 'event_counts': {}, 'user_counts': {}, } records = [] group_sequence = itertools.count(1) event_sequence = itertools.count(1) for i in xrange(random.randint(1, 30)): group_id = next(group_sequence) culprit = '{module} in {function}'.format( module='.'.join( ''.join(random.sample(WORDS, random.randint(1, int(random.paretovariate(2.2))))) for word in xrange(1, 4) ), function=random.choice(WORDS) ) group = state['groups'][group_id] = Group( id=group_id, project=project, message=words(int(random.weibullvariate(8, 4)), common=False), culprit=culprit, level=random.choice(LOG_LEVELS.keys()), ) offset = timedelta(seconds=0) for i in xrange(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) event = Event( id=next(event_sequence), event_id=uuid.uuid4().hex, project=project, group=group, message=group.message, data=load_data('python'), datetime=now - offset, ) records.append( Record( event.event_id, Notification( event, random.sample(state['rules'], random.randint(1, len(state['rules']))), ), to_timestamp(event.datetime), ) ) state['event_counts'][group_id] = random.randint(10, 1e4) state['user_counts'][group_id] = random.randint(10, 1e4) digest = build_digest(project, records, state) start, end, counts = get_digest_metadata(digest) return MailPreview( html_template='sentry/emails/digests/body.html', text_template='sentry/emails/digests/body.txt', context={ 'project': project, 'counts': counts, 'digest': digest, 'start': start, 'end': end, }, ).render()
def test_onboarding_complete(self): now = timezone.now() user = self.create_user(email="*****@*****.**") project = self.create_project(first_event=now) second_project = self.create_project(first_event=now) second_event = self.store_event( data={ "platform": "python", "message": "python error message" }, project_id=second_project.id, ) event = self.store_event( data={ "event_id": "a" * 32, "platform": "javascript", "timestamp": iso_format(before_now(minutes=1)), "tags": { "sentry:release": "e1b5d1900526feaf20fe2bc9cad83d392136030a", "sentry:user": "******", }, "user": { "ip_address": "0.0.0.0", "id": "41656", "email": "*****@*****.**" }, "exception": { "values": [{ "stacktrace": { "frames": [{ "data": { "sourcemap": "https://media.sentry.io/_static/29e365f8b0d923bc123e8afa38d890c3/sentry/dist/vendor.js.map" } }] }, "type": "TypeError", }] }, }, project_id=project.id, ) event_data = load_data("transaction") min_ago = iso_format(before_now(minutes=1)) event_data.update({"start_timestamp": min_ago, "timestamp": min_ago}) transaction = self.store_event(data=event_data, project_id=project.id) first_event_received.send(project=project, event=transaction, sender=type(project)) first_transaction_received.send(project=project, event=transaction, sender=type(project)) member = self.create_member(organization=self.organization, teams=[self.team], user=user) event_processed.send(project=project, event=event, sender=type(project)) project_created.send(project=project, user=user, sender=type(project)) project_created.send(project=second_project, user=user, sender=type(second_project)) first_event_received.send(project=project, event=event, sender=type(project)) first_event_received.send(project=second_project, event=second_event, sender=type(second_project)) member_joined.send(member=member, organization=self.organization, sender=type(member)) plugin_enabled.send( plugin=IssueTrackingPlugin(), project=project, user=user, sender=type(IssueTrackingPlugin), ) issue_tracker_used.send( plugin=IssueTrackingPlugin(), project=project, user=user, sender=type(IssueTrackingPlugin), ) alert_rule_created.send( rule=Rule(id=1), project=self.project, user=self.user, rule_type="issue", sender=type(Rule), is_api_token=False, ) assert (OrganizationOption.objects.filter( organization=self.organization, key="onboarding:complete").count() == 1)
def create_event(self, **kwargs): if "span_id" not in kwargs: kwargs["span_id"] = "a" * 16 if "start_timestamp" not in kwargs: kwargs["start_timestamp"] = self.min_ago if "timestamp" not in kwargs: kwargs["timestamp"] = self.min_ago + timedelta(seconds=8) if "trace_context" not in kwargs: # should appear for all of the pXX metrics kwargs["trace_context"] = { "op": "http.server", "hash": "ab" * 8, "exclusive_time": 4.0, } if "spans" not in kwargs: kwargs["spans"] = [ # should appear for the sum metric { "same_process_as_parent": True, "parent_span_id": "a" * 16, "span_id": x * 16, "start_timestamp": iso_format(self.min_ago + timedelta(seconds=1)), "timestamp": iso_format(self.min_ago + timedelta(seconds=4)), "op": "django.middleware", "description": "middleware span", "hash": "cd" * 8, "exclusive_time": 3.0, } for x in ["b", "c"] ] + [ # should appear for the count metric { "same_process_as_parent": True, "parent_span_id": "a" * 16, "span_id": x * 16, "start_timestamp": iso_format(self.min_ago + timedelta(seconds=4)), "timestamp": iso_format(self.min_ago + timedelta(seconds=5)), "op": "django.view", "description": "view span", "hash": "ef" * 8, "exclusive_time": 1.0, } for x in ["d", "e", "f"] ] data = load_data("transaction", **kwargs) data["transaction"] = "root transaction" return self.store_event(data, project_id=self.project.id)
def test_transaction_event_empty_spans(self): event_data = load_data("transaction") event_data["spans"] = [] event = self.store_event(data=event_data, project_id=self.project.id) result = serialize(event) assert result["entries"][0]["type"] == "spans"
def alert(request): platform = request.GET.get("platform", "python") org = Organization(id=1, slug="example", name="Example") project = Project(id=1, slug="example", name="Example", organization=org) random = get_random(request) group = next(make_group_generator(random, project)) data = dict(load_data(platform)) data["message"] = group.message data["event_id"] = "44f1419e73884cd2b45c79918f4b6dc4" data.pop("logentry", None) data["environment"] = "prod" data["tags"] = [ ("logger", "javascript"), ("environment", "prod"), ("level", "error"), ("device", "Other"), ] event_manager = EventManager(data) event_manager.normalize() data = event_manager.get_data() event = event_manager.save(project.id) # Prevent CI screenshot from constantly changing event.data["timestamp"] = 1504656000.0 # datetime(2017, 9, 6, 0, 0) event_type = get_event_type(event.data) group.message = event.search_message group.data = { "type": event_type.key, "metadata": event_type.get_metadata(data) } rule = Rule(id=1, label="An example rule") # XXX: this interface_list code needs to be the same as in # src/sentry/mail/adapter.py interface_list = [] for interface in event.interfaces.values(): body = interface.to_email_html(event) if not body: continue text_body = interface.to_string(event) interface_list.append( (interface.get_title(), mark_safe(body), text_body)) return MailPreview( html_template="sentry/emails/error.html", text_template="sentry/emails/error.txt", context={ "rule": rule, "rules": get_rules([rule], org, project), "group": group, "event": event, "timezone": pytz.timezone("Europe/Vienna"), # http://testserver/organizations/example/issues/<issue-id>/?referrer=alert_email # &alert_type=email&alert_timestamp=<ts>&alert_rule_id=1 "link": get_group_settings_link(group, None, get_rules([rule], org, project), 1337), "interfaces": interface_list, "tags": event.tags, "project_label": project.slug, "alert_status_page_enabled": features.has("organizations:alert-rule-status-page", org), "commits": [{ # TODO(dcramer): change to use serializer "repository": { "status": "active", "name": "Example Repo", "url": "https://github.com/example/example", "dateCreated": "2018-02-28T23:39:22.402Z", "provider": { "id": "github", "name": "GitHub" }, "id": "1", }, "score": 2, "subject": "feat: Do something to raven/base.py", "message": "feat: Do something to raven/base.py\naptent vivamus vehicula tempus volutpat hac tortor", "id": "1b17483ffc4a10609e7921ee21a8567bfe0ed006", "shortId": "1b17483", "author": { "username": "******", "isManaged": False, "lastActive": "2018-03-01T18:25:28.149Z", "id": "1", "isActive": True, "has2fa": False, "name": "*****@*****.**", "avatarUrl": "https://secure.gravatar.com/avatar/51567a4f786cd8a2c41c513b592de9f9?s=32&d=mm", "dateJoined": "2018-02-27T22:04:32.847Z", "emails": [{ "is_verified": False, "id": "1", "email": "*****@*****.**" }], "avatar": { "avatarUuid": None, "avatarType": "letter_avatar" }, "lastLogin": "******", "email": "*****@*****.**", }, }], }, ).render(request)
def digest(request): seed = request.GET.get("seed", str(time.time())) logger.debug("Using random seed value: %s") random = Random(seed) now = datetime.utcnow().replace(tzinfo=pytz.utc) # TODO: Refactor all of these into something more manageable. org = Organization(id=1, slug="example", name="Example Organization") team = Team(id=1, slug="example", name="Example Team", organization=org) project = Project(id=1, slug="example", name="Example Project", team=team, organization=org) rules = {i: Rule(id=i, project=project, label="Rule #%s" % (i,)) for i in xrange(1, random.randint(2, 4))} state = {"project": project, "groups": {}, "rules": rules, "event_counts": {}, "user_counts": {}} records = [] group_sequence = itertools.count(1) event_sequence = itertools.count(1) for i in xrange(random.randint(1, 30)): group_id = next(group_sequence) culprit = "{module} in {function}".format( module=".".join( "".join(random.sample(WORDS, random.randint(1, int(random.paretovariate(2.2))))) for word in xrange(1, 4) ), function=random.choice(WORDS), ) group = state["groups"][group_id] = Group( id=group_id, project=project, message=words(int(random.weibullvariate(8, 4)), common=False), culprit=culprit, level=random.choice(LOG_LEVELS.keys()), ) offset = timedelta(seconds=0) for i in xrange(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) event = Event( id=next(event_sequence), event_id=uuid.uuid4().hex, project=project, group=group, message=group.message, data=load_data("python"), datetime=now - offset, ) records.append( Record( event.event_id, Notification(event, random.sample(state["rules"], random.randint(1, len(state["rules"])))), to_timestamp(event.datetime), ) ) state["event_counts"][group_id] = random.randint(10, 1e4) state["user_counts"][group_id] = random.randint(10, 1e4) digest = build_digest(project, records, state) start, end, counts = get_digest_metadata(digest) return MailPreview( html_template="sentry/emails/digests/body.html", text_template="sentry/emails/digests/body.txt", context={"project": project, "counts": counts, "digest": digest, "start": start, "end": end}, ).render()
def new_event(request): platform = request.GET.get('platform', 'python') org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) random = get_random(request) group = next( make_group_generator(random, project), ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data(platform), datetime=to_datetime( random.randint( to_timestamp(group.first_seen), to_timestamp(group.last_seen), ), ), ) rule = Rule(label="An example rule") interface_list = [] for interface in six.itervalues(event.interfaces): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.txt', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), 'project_label': project.name, 'tags': [ ('logger', 'javascript'), ('environment', 'prod'), ('level', 'error'), ('device', 'Other') ] }, ).render(request)
def alert(request): platform = request.GET.get('platform', 'python') org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) random = get_random(request) group = next( make_group_generator(random, project), ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data(platform), datetime=to_datetime( random.randint( to_timestamp(group.first_seen), to_timestamp(group.last_seen), ), ), ) rule = Rule(label="An example rule") interface_list = [] for interface in six.itervalues(event.interfaces): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.txt', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), 'project_label': project.name, 'tags': [ ('logger', 'javascript'), ('environment', 'prod'), ('level', 'error'), ('device', 'Other') ] }, ).render(request)
def digest(request): random = get_random(request) # TODO: Refactor all of these into something more manageable. org = Organization(id=1, slug="example", name="Example Organization") project = Project(id=1, slug="example", name="Example Project", organization=org) rules = { i: Rule(id=i, project=project, label="Rule #%s" % (i, )) for i in range(1, random.randint(2, 4)) } state = { "project": project, "groups": {}, "rules": rules, "event_counts": {}, "user_counts": {}, } records = [] group_generator = make_group_generator(random, project) for i in range(random.randint(1, 30)): group = next(group_generator) state["groups"][group.id] = group offset = timedelta(seconds=0) for i in range(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) data = dict(load_data("python")) data["message"] = group.message data.pop("logentry", None) event_manager = EventManager(data) event_manager.normalize() data = event_manager.get_data() timestamp = to_datetime( random.randint(to_timestamp(group.first_seen), to_timestamp(group.last_seen))) event = SnubaEvent({ "event_id": uuid.uuid4().hex, "project_id": project.id, "group_id": group.id, "message": group.message, "data": data.data, "timestamp": timestamp.strftime("%Y-%m-%dT%H:%M:%S"), }) event.group = group records.append( Record( event.event_id, Notification( event, random.sample(state["rules"], random.randint(1, len(state["rules"])))), to_timestamp(event.datetime), )) state["event_counts"][group.id] = random.randint(10, 1e4) state["user_counts"][group.id] = random.randint(10, 1e4) digest = build_digest(project, records, state) start, end, counts = get_digest_metadata(digest) context = { "project": project, "counts": counts, "digest": digest, "start": start, "end": end, "referrer": "digest_email", } add_unsubscribe_link(context) return MailPreview( html_template="sentry/emails/digests/body.html", text_template="sentry/emails/digests/body.txt", context=context, ).render(request)
def digest(request): random = get_random(request) # TODO: Refactor all of these into something more manageable. org = Organization( id=1, slug='example', name='Example Organization', ) team = Team( id=1, slug='example', name='Example Team', organization=org, ) project = Project( id=1, slug='example', name='Example Project', team=team, organization=org, ) rules = {i: Rule( id=i, project=project, label="Rule #%s" % (i,), ) for i in range(1, random.randint(2, 4))} state = { 'project': project, 'groups': {}, 'rules': rules, 'event_counts': {}, 'user_counts': {}, } records = [] event_sequence = itertools.count(1) group_generator = make_group_generator(random, project) for i in range(random.randint(1, 30)): group = next(group_generator) state['groups'][group.id] = group offset = timedelta(seconds=0) for i in range(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) event = Event( id=next(event_sequence), event_id=uuid.uuid4().hex, project=project, group=group, message=group.message, data=load_data('python'), datetime=to_datetime( random.randint( to_timestamp(group.first_seen), to_timestamp(group.last_seen), ), ) ) records.append( Record( event.event_id, Notification( event, random.sample(state['rules'], random.randint(1, len(state['rules']))), ), to_timestamp(event.datetime), ) ) state['event_counts'][group.id] = random.randint(10, 1e4) state['user_counts'][group.id] = random.randint(10, 1e4) digest = build_digest(project, records, state) start, end, counts = get_digest_metadata(digest) context = { 'project': project, 'counts': counts, 'digest': digest, 'start': start, 'end': end, } add_unsubscribe_link(context) return MailPreview( html_template='sentry/emails/digests/body.html', text_template='sentry/emails/digests/body.txt', context=context, ).render(request)
def generate_transaction(): event_data = load_data("transaction") event_data.update({"event_id": "a" * 32}) # set timestamps start_datetime = before_now(minutes=1) end_datetime = start_datetime + timedelta(milliseconds=500) def generate_timestamp(date_time): return time.mktime( date_time.utctimetuple()) + date_time.microsecond / 1e6 event_data["start_timestamp"] = generate_timestamp(start_datetime) event_data["timestamp"] = generate_timestamp(end_datetime) # generate and build up span tree reference_span = event_data["spans"][0] parent_span_id = reference_span["parent_span_id"] span_tree_blueprint = { "a": {}, "b": { "bb": { "bbb": { "bbbb": "bbbbb" } } }, "c": {}, "d": {}, "e": {}, } time_offsets = { "a": (timedelta(), timedelta(milliseconds=10)), "b": (timedelta(milliseconds=120), timedelta(milliseconds=250)), "bb": (timedelta(milliseconds=130), timedelta(milliseconds=10)), "bbb": (timedelta(milliseconds=140), timedelta(milliseconds=10)), "bbbb": (timedelta(milliseconds=150), timedelta(milliseconds=10)), "bbbbb": (timedelta(milliseconds=160), timedelta(milliseconds=90)), "c": (timedelta(milliseconds=260), timedelta(milliseconds=100)), "d": (timedelta(milliseconds=375), timedelta(milliseconds=50)), "e": (timedelta(milliseconds=400), timedelta(milliseconds=100)), } def build_span_tree(span_tree, spans, parent_span_id): for span_id, child in span_tree.items(): span = copy.deepcopy(reference_span) # non-leaf node span span["parent_span_id"] = parent_span_id.ljust(16, "0") span["span_id"] = span_id.ljust(16, "0") (start_delta, span_length) = time_offsets.get(span_id, (timedelta(), timedelta())) span_start_time = start_datetime + start_delta span["start_timestamp"] = generate_timestamp(span_start_time) span["timestamp"] = generate_timestamp(span_start_time + span_length) spans.append(span) if isinstance(child, dict): spans = build_span_tree(child, spans, span_id) elif isinstance(child, six.string_types): parent_span_id = span_id span_id = child span = copy.deepcopy(reference_span) # leaf node span span["parent_span_id"] = parent_span_id.ljust(16, "0") span["span_id"] = span_id.ljust(16, "0") (start_delta, span_length) = time_offsets.get(span_id, (timedelta(), timedelta())) span_start_time = start_datetime + start_delta span["start_timestamp"] = generate_timestamp(span_start_time) span["timestamp"] = generate_timestamp(span_start_time + span_length) spans.append(span) return spans event_data["spans"] = build_span_tree(span_tree_blueprint, [], parent_span_id) return event_data
def digest(request): seed = request.GET.get('seed', str(time.time())) logger.debug('Using random seed value: %s') random = Random(seed) now = datetime.utcnow().replace(tzinfo=pytz.utc) # TODO: Refactor all of these into something more manageable. org = Organization( id=1, slug='example', name='Example Organization', ) team = Team( id=1, slug='example', name='Example Team', organization=org, ) project = Project( id=1, slug='example', name='Example Project', team=team, organization=org, ) state = { 'project': project, 'groups': {}, 'rules': { 1: Rule(id=1, project=project, label="First Rule"), 2: Rule(id=2, project=project, label="Second Rule"), 3: Rule(id=3, project=project, label="Third Rule"), }, 'event_counts': {}, 'user_counts': {}, } records = [] group_sequence = itertools.count(1) event_sequence = itertools.count(1) for i in xrange(random.randint(1, 4)): group_id = next(group_sequence) group = state['groups'][group_id] = Group( id=group_id, project=project, message='This is example event #%s' % (group_id,), ) offset = timedelta(seconds=0) for i in xrange(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) event = Event( id=next(event_sequence), event_id=uuid.uuid4().hex, project=project, group=group, message=group.message, data=load_data('python'), datetime=now - offset, ) records.append( Record( event.event_id, Notification( event, random.sample(state['rules'], random.randint(1, len(state['rules']))), ), to_timestamp(event.datetime), ) ) state['event_counts'][group_id] = random.randint(10, 1e4) state['user_counts'][group_id] = random.randint(10, 1e4) digest = build_digest(project, records, state) return MailPreview( html_template='sentry/emails/digests/body.html', text_template='sentry/emails/digests/body.txt', context={ 'project': project, 'digest': digest, }, ).render()
def setUp(self): super(OrganizationEventsHistogramEndpointTest, self).setUp() self.min_ago = iso_format(before_now(minutes=1)) self.data = load_data("transaction")
def setUp(self): super().setUp() self.min_ago = iso_format(before_now(minutes=1)) self.two_min_ago = iso_format(before_now(minutes=2)) self.transaction_data = load_data("transaction", timestamp=before_now(minutes=1))
def digest(request): random = get_random(request) # TODO: Refactor all of these into something more manageable. org = Organization(id=1, slug="example", name="Example Organization") project = Project(id=1, slug="example", name="Example Project", organization=org) rules = { i: Rule(id=i, project=project, label=f"Rule #{i}") for i in range(1, random.randint(2, 4)) } state = { "project": project, "groups": {}, "rules": rules, "event_counts": {}, "user_counts": {}, } records = [] group_generator = make_group_generator(random, project) for i in range(random.randint(1, 30)): group = next(group_generator) state["groups"][group.id] = group offset = timedelta(seconds=0) for i in range(random.randint(1, 10)): offset += timedelta(seconds=random.random() * 120) data = dict(load_data("python")) data["message"] = group.message data.pop("logentry", None) event_manager = EventManager(data) event_manager.normalize() data = event_manager.get_data() data["timestamp"] = random.randint(to_timestamp(group.first_seen), to_timestamp(group.last_seen)) event = eventstore.create_event(event_id=uuid.uuid4().hex, group_id=group.id, project_id=project.id, data=data.data) records.append( Record( event.event_id, Notification( event, random.sample(list(state["rules"].keys()), random.randint(1, len(state["rules"]))), ), to_timestamp(event.datetime), )) state["event_counts"][group.id] = random.randint(10, 1e4) state["user_counts"][group.id] = random.randint(10, 1e4) digest = build_digest(project, records, state)[0] start, end, counts = get_digest_metadata(digest) context = { "project": project, "counts": counts, "digest": digest, "start": start, "end": end, "referrer": "digest_email", "alert_status_page_enabled": features.has("organizations:alert-rule-status-page", org), "rules_details": {rule.id: rule for rule in get_rules(rules.values(), org, project)}, } add_unsubscribe_link(context) return MailPreview( html_template="sentry/emails/digests/body.html", text_template="sentry/emails/digests/body.txt", context=context, ).render(request)
def test_with_error_event(self): self.load_trace() root_event_id = self.root_event.event_id current_transaction_event = self.gen1_events[0].event_id start, _ = self.get_start_end(1000) error_data = load_data( "javascript", timestamp=start, ) error_data["contexts"]["trace"] = { "type": "trace", "trace_id": self.trace_id, "span_id": self.gen1_span_ids[0], } error_data["tags"] = [["transaction", "/transaction/gen1-0"]] error = self.store_event(error_data, project_id=self.gen1_project.id) def assertions(response): assert response.status_code == 200, response.content assert len(response.data) == 3 events = {item["event_id"]: item for item in response.data} assert root_event_id in events event = events[root_event_id] assert event["generation"] == 0 assert event["parent_event_id"] is None assert event["parent_span_id"] is None assert len(event["errors"]) == 0 assert current_transaction_event in events event = events[current_transaction_event] assert event["generation"] == 1 assert event["parent_event_id"] == root_event_id assert event["parent_span_id"] == self.root_span_ids[0] assert len(event["errors"]) == 1 assert event["errors"][0]["event_id"] == error.event_id assert event["errors"][0]["issue_id"] == error.group_id with self.feature(self.FEATURES): response = self.client.get( self.url, data={ "event_id": error.event_id, "project": -1 }, format="json", ) assertions(response) with self.feature(self.FEATURES): response = self.client.get( self.url, data={ "event_id": current_transaction_event, "project": -1 }, format="json", ) assertions(response)
def setUp(self): super().setUp() self.min_ago = iso_format(before_now(minutes=1)) self.two_min_ago = iso_format(before_now(minutes=2)) self.project1 = self.create_project() self.project2 = self.create_project() self.event1 = self.store_event( data={ "event_id": "a" * 32, "type": "default", "platform": "python", "fingerprint": ["group1"], "timestamp": self.two_min_ago, "tags": { "foo": "1" }, }, project_id=self.project1.id, ) self.event2 = self.store_event( data={ "event_id": "b" * 32, "type": "default", "platform": "python", "fingerprint": ["group1"], "timestamp": self.min_ago, "tags": { "foo": "1" }, }, project_id=self.project2.id, ) self.event3 = self.store_event( data={ "event_id": "c" * 32, "type": "default", "platform": "python", "fingerprint": ["group2"], "timestamp": self.min_ago, "tags": { "foo": "1" }, }, project_id=self.project2.id, ) event_data = load_data("transaction") event_data["timestamp"] = iso_format(before_now(minutes=1)) event_data["start_timestamp"] = iso_format( before_now(minutes=1, seconds=1)) event_data["event_id"] = "d" * 32 self.transaction_event = self.store_event(data=event_data, project_id=self.project2.id) event_data_2 = load_data("transaction") event_data_2["timestamp"] = iso_format(before_now(seconds=30)) event_data_2["start_timestamp"] = iso_format(before_now(seconds=31)) event_data_2["event_id"] = "e" * 32 self.transaction_event_2 = self.store_event( data=event_data_2, project_id=self.project2.id) self.eventstore = SnubaEventStorage()
def new_event(request): platform = request.GET.get('platform', 'python') org = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=org, ) project = Project( id=1, slug='example', name='Example', team=team, organization=org, ) group = Group( id=1, project=project, message='This is an example event.', level=logging.ERROR, ) event = Event( id=1, project=project, group=group, message=group.message, data=load_data(platform), ) rule = Rule(label="An example rule") interface_list = [] for interface in event.interfaces.itervalues(): body = interface.to_email_html(event) if not body: continue interface_list.append((interface.get_title(), mark_safe(body))) return MailPreview( html_template='sentry/emails/error.html', text_template='sentry/emails/error.html', context={ 'rule': rule, 'group': group, 'event': event, 'link': 'http://example.com/link', 'interfaces': interface_list, 'tags': event.get_tags(), 'project_label': project.name, 'tags': [('logger', 'javascript'), ('environment', 'prod'), ('level', 'error'), ('device', 'Other')] }, ).render()
def create_issue(self): event_data = load_data("javascript") event_data["timestamp"] = iso_format(before_now(minutes=1)) event_data["tags"] = {"url": "http://example.org/path?key=value"} return self.store_event(data=event_data, project_id=self.project.id)