|
7 | 7 | from sentry.testutils.helpers.datetime import before_now
|
8 | 8 |
|
9 | 9 |
|
10 |
| -class ProjectEventDetailsTest(APITestCase, SnubaTestCase, OurLogTestCase, SpanTestCase): |
| 10 | +class ProjectTraceItemDetailsEndpointTest(APITestCase, SnubaTestCase, OurLogTestCase, SpanTestCase): |
11 | 11 | def setUp(self):
|
12 | 12 | super().setUp()
|
13 | 13 | self.login_as(user=self.user)
|
@@ -38,47 +38,27 @@ def do_request(self, event_type: str, item_id: str, features=None):
|
38 | 38 | )
|
39 | 39 |
|
40 | 40 | def test_simple(self):
|
41 |
| - logs = [ |
42 |
| - self.create_ourlog( |
43 |
| - { |
44 |
| - "body": "foo", |
45 |
| - "trace_id": self.trace_uuid, |
| 41 | + log = self.create_ourlog( |
| 42 | + { |
| 43 | + "body": "foo", |
| 44 | + "trace_id": self.trace_uuid, |
| 45 | + }, |
| 46 | + attributes={ |
| 47 | + "str_attr": { |
| 48 | + "string_value": "1", |
46 | 49 | },
|
47 |
| - attributes={ |
48 |
| - "str_attr": { |
49 |
| - "string_value": "1", |
50 |
| - }, |
51 |
| - "int_attr": {"int_value": 2}, |
52 |
| - "float_attr": { |
53 |
| - "double_value": 3.0, |
54 |
| - }, |
55 |
| - "bool_attr": { |
56 |
| - "bool_value": True, |
57 |
| - }, |
| 50 | + "int_attr": {"int_value": 2}, |
| 51 | + "float_attr": { |
| 52 | + "double_value": 3.0, |
| 53 | + }, |
| 54 | + "bool_attr": { |
| 55 | + "bool_value": True, |
58 | 56 | },
|
59 |
| - timestamp=self.one_min_ago, |
60 |
| - ), |
61 |
| - ] |
62 |
| - self.store_ourlogs(logs) |
63 |
| - item_list_url = reverse( |
64 |
| - "sentry-api-0-organization-events", |
65 |
| - kwargs={ |
66 |
| - "organization_id_or_slug": self.project.organization.slug, |
67 | 57 | },
|
| 58 | + timestamp=self.one_min_ago, |
68 | 59 | )
|
69 |
| - with self.feature(self.features): |
70 |
| - item_list_response = self.client.get( |
71 |
| - item_list_url, |
72 |
| - { |
73 |
| - "field": ["message", "sentry.item_id", "sentry.trace_id"], |
74 |
| - "query": "", |
75 |
| - "orderby": "sentry.item_id", |
76 |
| - "project": self.project.id, |
77 |
| - "dataset": "ourlogs", |
78 |
| - }, |
79 |
| - ) |
80 |
| - assert item_list_response.data is not None |
81 |
| - item_id = item_list_response.data["data"][0]["sentry.item_id"] |
| 60 | + self.store_ourlogs([log]) |
| 61 | + item_id = uuid.UUID(bytes=bytes(reversed(log.item_id))).hex |
82 | 62 |
|
83 | 63 | trace_details_response = self.do_request("logs", item_id)
|
84 | 64 |
|
@@ -113,47 +93,27 @@ def test_simple(self):
|
113 | 93 | )
|
114 | 94 |
|
115 | 95 | def test_simple_using_logs_item_type(self):
|
116 |
| - logs = [ |
117 |
| - self.create_ourlog( |
118 |
| - { |
119 |
| - "body": "foo", |
120 |
| - "trace_id": self.trace_uuid, |
| 96 | + log = self.create_ourlog( |
| 97 | + { |
| 98 | + "body": "foo", |
| 99 | + "trace_id": self.trace_uuid, |
| 100 | + }, |
| 101 | + attributes={ |
| 102 | + "str_attr": { |
| 103 | + "string_value": "1", |
121 | 104 | },
|
122 |
| - attributes={ |
123 |
| - "str_attr": { |
124 |
| - "string_value": "1", |
125 |
| - }, |
126 |
| - "int_attr": {"int_value": 2}, |
127 |
| - "float_attr": { |
128 |
| - "double_value": 3.0, |
129 |
| - }, |
130 |
| - "bool_attr": { |
131 |
| - "bool_value": True, |
132 |
| - }, |
| 105 | + "int_attr": {"int_value": 2}, |
| 106 | + "float_attr": { |
| 107 | + "double_value": 3.0, |
| 108 | + }, |
| 109 | + "bool_attr": { |
| 110 | + "bool_value": True, |
133 | 111 | },
|
134 |
| - timestamp=self.one_min_ago, |
135 |
| - ), |
136 |
| - ] |
137 |
| - self.store_ourlogs(logs) |
138 |
| - item_list_url = reverse( |
139 |
| - "sentry-api-0-organization-events", |
140 |
| - kwargs={ |
141 |
| - "organization_id_or_slug": self.project.organization.slug, |
142 | 112 | },
|
| 113 | + timestamp=self.one_min_ago, |
143 | 114 | )
|
144 |
| - with self.feature(self.features): |
145 |
| - item_list_response = self.client.get( |
146 |
| - item_list_url, |
147 |
| - { |
148 |
| - "field": ["message", "sentry.item_id", "sentry.trace_id"], |
149 |
| - "query": "", |
150 |
| - "orderby": "sentry.item_id", |
151 |
| - "project": self.project.id, |
152 |
| - "dataset": "ourlogs", |
153 |
| - }, |
154 |
| - ) |
155 |
| - assert item_list_response.data is not None |
156 |
| - item_id = item_list_response.data["data"][0]["sentry.item_id"] |
| 115 | + self.store_ourlogs([log]) |
| 116 | + item_id = uuid.UUID(bytes=bytes(reversed(log.item_id))).hex |
157 | 117 |
|
158 | 118 | trace_details_response = self.do_request("logs", item_id)
|
159 | 119 |
|
@@ -325,49 +285,29 @@ def test_simple_using_spans_item_type_with_sentry_conventions(self):
|
325 | 285 | )
|
326 | 286 |
|
327 | 287 | def test_logs_with_a_meta_key(self):
|
328 |
| - logs = [ |
329 |
| - self.create_ourlog( |
330 |
| - { |
331 |
| - "body": "[Filtered]", |
332 |
| - "trace_id": self.trace_uuid, |
| 288 | + log = self.create_ourlog( |
| 289 | + { |
| 290 | + "body": "[Filtered]", |
| 291 | + "trace_id": self.trace_uuid, |
| 292 | + }, |
| 293 | + attributes={ |
| 294 | + "str_attr": { |
| 295 | + "string_value": "1", |
333 | 296 | },
|
334 |
| - attributes={ |
335 |
| - "str_attr": { |
336 |
| - "string_value": "1", |
337 |
| - }, |
338 |
| - "sentry._meta.fields.attributes.sentry.body": '{"length": 300, "reason": "value too long"}', |
339 |
| - "sentry._meta.fields.attributes.float_attr": '{"unit": "float"}', |
340 |
| - "int_attr": {"int_value": 2}, |
341 |
| - "float_attr": { |
342 |
| - "double_value": 3.0, |
343 |
| - }, |
344 |
| - "bool_attr": { |
345 |
| - "bool_value": True, |
346 |
| - }, |
| 297 | + "sentry._meta.fields.attributes.sentry.body": '{"length": 300, "reason": "value too long"}', |
| 298 | + "sentry._meta.fields.attributes.float_attr": '{"unit": "float"}', |
| 299 | + "int_attr": {"int_value": 2}, |
| 300 | + "float_attr": { |
| 301 | + "double_value": 3.0, |
| 302 | + }, |
| 303 | + "bool_attr": { |
| 304 | + "bool_value": True, |
347 | 305 | },
|
348 |
| - timestamp=self.one_min_ago, |
349 |
| - ), |
350 |
| - ] |
351 |
| - self.store_ourlogs(logs) |
352 |
| - item_list_url = reverse( |
353 |
| - "sentry-api-0-organization-events", |
354 |
| - kwargs={ |
355 |
| - "organization_id_or_slug": self.project.organization.slug, |
356 | 306 | },
|
| 307 | + timestamp=self.one_min_ago, |
357 | 308 | )
|
358 |
| - with self.feature(self.features): |
359 |
| - item_list_response = self.client.get( |
360 |
| - item_list_url, |
361 |
| - { |
362 |
| - "field": ["message", "sentry.item_id", "sentry.trace_id"], |
363 |
| - "query": "", |
364 |
| - "orderby": "sentry.item_id", |
365 |
| - "project": self.project.id, |
366 |
| - "dataset": "ourlogs", |
367 |
| - }, |
368 |
| - ) |
369 |
| - assert item_list_response.data is not None |
370 |
| - item_id = item_list_response.data["data"][0]["sentry.item_id"] |
| 309 | + self.store_ourlogs([log]) |
| 310 | + item_id = uuid.UUID(bytes=bytes(reversed(log.item_id))).hex |
371 | 311 |
|
372 | 312 | trace_details_response = self.do_request("logs", item_id)
|
373 | 313 |
|
@@ -407,3 +347,49 @@ def test_logs_with_a_meta_key(self):
|
407 | 347 | ).isoformat()
|
408 | 348 | + "Z",
|
409 | 349 | }
|
| 350 | + |
| 351 | + def test_user_attributes_collide_with_sentry_attributes(self): |
| 352 | + log = self.create_ourlog( |
| 353 | + { |
| 354 | + "body": "foo", |
| 355 | + "trace_id": self.trace_uuid, |
| 356 | + }, |
| 357 | + attributes={"timestamp": "bar", "severity": "baz"}, |
| 358 | + timestamp=self.one_min_ago, |
| 359 | + ) |
| 360 | + |
| 361 | + self.store_ourlogs([log]) |
| 362 | + item_id = uuid.UUID(bytes=bytes(reversed(log.item_id))).hex |
| 363 | + |
| 364 | + trace_details_response = self.do_request("logs", item_id) |
| 365 | + assert trace_details_response.status_code == 200, trace_details_response.content |
| 366 | + |
| 367 | + timestamp_nanos = int(self.one_min_ago.timestamp() * 1_000_000_000) |
| 368 | + assert trace_details_response.data == { |
| 369 | + "attributes": [ |
| 370 | + {"name": "project_id", "type": "int", "value": str(self.project.id)}, |
| 371 | + {"name": "severity_number", "type": "int", "value": "0"}, |
| 372 | + { |
| 373 | + "name": "tags[sentry.timestamp_nanos,number]", |
| 374 | + "type": "int", |
| 375 | + "value": str(timestamp_nanos), |
| 376 | + }, |
| 377 | + { |
| 378 | + "name": "tags[sentry.timestamp_precise,number]", |
| 379 | + "type": "int", |
| 380 | + "value": str(timestamp_nanos), |
| 381 | + }, |
| 382 | + {"name": "message", "type": "str", "value": "foo"}, |
| 383 | + {"name": "severity", "type": "str", "value": "INFO"}, |
| 384 | + {"name": "tags[severity,string]", "type": "str", "value": "baz"}, |
| 385 | + {"name": "tags[timestamp,string]", "type": "str", "value": "bar"}, |
| 386 | + {"name": "trace", "type": "str", "value": self.trace_uuid}, |
| 387 | + ], |
| 388 | + "meta": {}, |
| 389 | + "itemId": item_id, |
| 390 | + "timestamp": self.one_min_ago.replace( |
| 391 | + microsecond=0, |
| 392 | + tzinfo=None, |
| 393 | + ).isoformat() |
| 394 | + + "Z", |
| 395 | + } |
0 commit comments