|
@@ -900,124 +900,195 @@ def create_mock_transactions(
|
|
|
time.sleep(0.05)
|
|
|
|
|
|
if load_performance_issues:
|
|
|
- print(f" > Loading performance issues data") # NOQA
|
|
|
- trace_id = uuid4().hex
|
|
|
- transaction_user = generate_user()
|
|
|
- frontend_root_span_id = uuid4().hex[:16]
|
|
|
-
|
|
|
- n_plus_one_db_current_offset = timestamp
|
|
|
- n_plus_one_db_duration = timedelta(milliseconds=100)
|
|
|
-
|
|
|
- parent_span_id = uuid4().hex[:16]
|
|
|
-
|
|
|
- source_span = {
|
|
|
- "timestamp": (timestamp + n_plus_one_db_duration).timestamp(),
|
|
|
- "start_timestamp": (timestamp + timedelta(milliseconds=10)).timestamp(),
|
|
|
- "description": "SELECT `books_book`.`id`, `books_book`.`title`, `books_book`.`author_id` FROM `books_book` ORDER BY `books_book`.`id` DESC LIMIT 10",
|
|
|
- "op": "db",
|
|
|
- "parent_span_id": parent_span_id,
|
|
|
- "span_id": uuid4().hex[:16],
|
|
|
- "hash": "858fea692d4d93e8",
|
|
|
- }
|
|
|
-
|
|
|
- def make_repeating_span(duration):
|
|
|
- nonlocal timestamp
|
|
|
- nonlocal n_plus_one_db_current_offset
|
|
|
- nonlocal n_plus_one_db_duration
|
|
|
- n_plus_one_db_duration += timedelta(milliseconds=duration) + timedelta(milliseconds=1)
|
|
|
- n_plus_one_db_current_offset = timestamp + n_plus_one_db_duration
|
|
|
- return {
|
|
|
- "timestamp": (
|
|
|
- n_plus_one_db_current_offset + timedelta(milliseconds=duration)
|
|
|
- ).timestamp(),
|
|
|
- "start_timestamp": (
|
|
|
- n_plus_one_db_current_offset + timedelta(milliseconds=1)
|
|
|
- ).timestamp(),
|
|
|
- "description": "SELECT `books_author`.`id`, `books_author`.`name` FROM `books_author` WHERE `books_author`.`id` = %s LIMIT 21",
|
|
|
+
|
|
|
+ def load_performance_issues():
|
|
|
+ print(f" > Loading performance issues data") # NOQA
|
|
|
+ print(f" > Loading n plus one issue") # NOQA
|
|
|
+ load_n_plus_one_issue()
|
|
|
+ time.sleep(1.0)
|
|
|
+ print(f" > Loading consecutive db issue") # NOQA
|
|
|
+ load_consecutive_db_issue()
|
|
|
+
|
|
|
+ def load_n_plus_one_issue():
|
|
|
+ trace_id = uuid4().hex
|
|
|
+ transaction_user = generate_user()
|
|
|
+ frontend_root_span_id = uuid4().hex[:16]
|
|
|
+
|
|
|
+ n_plus_one_db_current_offset = timestamp
|
|
|
+ n_plus_one_db_duration = timedelta(milliseconds=100)
|
|
|
+
|
|
|
+ parent_span_id = uuid4().hex[:16]
|
|
|
+
|
|
|
+ source_span = {
|
|
|
+ "timestamp": (timestamp + n_plus_one_db_duration).timestamp(),
|
|
|
+ "start_timestamp": (timestamp + timedelta(milliseconds=10)).timestamp(),
|
|
|
+ "description": "SELECT `books_book`.`id`, `books_book`.`title`, `books_book`.`author_id` FROM `books_book` ORDER BY `books_book`.`id` DESC LIMIT 10",
|
|
|
"op": "db",
|
|
|
- "span_id": uuid4().hex[:16],
|
|
|
"parent_span_id": parent_span_id,
|
|
|
- "hash": "63f1e89e6a073441",
|
|
|
+ "span_id": uuid4().hex[:16],
|
|
|
+ "hash": "858fea692d4d93e8",
|
|
|
}
|
|
|
|
|
|
- repeating_spans = [make_repeating_span(200) for _ in range(10)]
|
|
|
-
|
|
|
- parent_span = {
|
|
|
- "timestamp": (
|
|
|
- timestamp + n_plus_one_db_duration + timedelta(milliseconds=200)
|
|
|
- ).timestamp(),
|
|
|
- "start_timestamp": timestamp.timestamp(),
|
|
|
- "description": "new",
|
|
|
- "op": "django.view",
|
|
|
- "parent_span_id": uuid4().hex[:16],
|
|
|
- "span_id": parent_span_id,
|
|
|
- "hash": "0f43fb6f6e01ca52",
|
|
|
- }
|
|
|
-
|
|
|
- create_sample_event(
|
|
|
- project=backend_project,
|
|
|
- platform="transaction",
|
|
|
- transaction="/n_plus_one_db/backend/",
|
|
|
- event_id=uuid4().hex,
|
|
|
- user=transaction_user,
|
|
|
- timestamp=timestamp + n_plus_one_db_duration + timedelta(milliseconds=300),
|
|
|
- start_timestamp=timestamp,
|
|
|
- trace=trace_id,
|
|
|
- parent_span_id=frontend_root_span_id,
|
|
|
- spans=[
|
|
|
- parent_span,
|
|
|
- source_span,
|
|
|
- ]
|
|
|
- + repeating_spans,
|
|
|
- )
|
|
|
+ def make_repeating_span(duration):
|
|
|
+ nonlocal timestamp
|
|
|
+ nonlocal n_plus_one_db_current_offset
|
|
|
+ nonlocal n_plus_one_db_duration
|
|
|
+ n_plus_one_db_duration += timedelta(milliseconds=duration) + timedelta(
|
|
|
+ milliseconds=1
|
|
|
+ )
|
|
|
+ n_plus_one_db_current_offset = timestamp + n_plus_one_db_duration
|
|
|
+ return {
|
|
|
+ "timestamp": (
|
|
|
+ n_plus_one_db_current_offset + timedelta(milliseconds=duration)
|
|
|
+ ).timestamp(),
|
|
|
+ "start_timestamp": (
|
|
|
+ n_plus_one_db_current_offset + timedelta(milliseconds=1)
|
|
|
+ ).timestamp(),
|
|
|
+ "description": "SELECT `books_author`.`id`, `books_author`.`name` FROM `books_author` WHERE `books_author`.`id` = %s LIMIT 21",
|
|
|
+ "op": "db",
|
|
|
+ "span_id": uuid4().hex[:16],
|
|
|
+ "parent_span_id": parent_span_id,
|
|
|
+ "hash": "63f1e89e6a073441",
|
|
|
+ }
|
|
|
+
|
|
|
+ repeating_spans = [make_repeating_span(200) for _ in range(10)]
|
|
|
+
|
|
|
+ parent_span = {
|
|
|
+ "timestamp": (
|
|
|
+ timestamp + n_plus_one_db_duration + timedelta(milliseconds=200)
|
|
|
+ ).timestamp(),
|
|
|
+ "start_timestamp": timestamp.timestamp(),
|
|
|
+ "description": "new",
|
|
|
+ "op": "django.view",
|
|
|
+ "parent_span_id": uuid4().hex[:16],
|
|
|
+ "span_id": parent_span_id,
|
|
|
+ "hash": "0f43fb6f6e01ca52",
|
|
|
+ }
|
|
|
+
|
|
|
+ create_sample_event(
|
|
|
+ project=backend_project,
|
|
|
+ platform="transaction",
|
|
|
+ transaction="/n_plus_one_db/backend/",
|
|
|
+ event_id=uuid4().hex,
|
|
|
+ user=transaction_user,
|
|
|
+ timestamp=timestamp + n_plus_one_db_duration + timedelta(milliseconds=300),
|
|
|
+ start_timestamp=timestamp,
|
|
|
+ trace=trace_id,
|
|
|
+ parent_span_id=frontend_root_span_id,
|
|
|
+ spans=[
|
|
|
+ parent_span,
|
|
|
+ source_span,
|
|
|
+ ]
|
|
|
+ + repeating_spans,
|
|
|
+ )
|
|
|
+
|
|
|
+ time.sleep(1.0)
|
|
|
+
|
|
|
+ create_sample_event(
|
|
|
+ project=backend_project,
|
|
|
+ platform="transaction",
|
|
|
+ transaction="/file-io-main-thread/",
|
|
|
+ event_id=uuid4().hex,
|
|
|
+ user=transaction_user,
|
|
|
+ timestamp=timestamp + timedelta(milliseconds=300),
|
|
|
+ start_timestamp=timestamp,
|
|
|
+ trace=trace_id,
|
|
|
+ parent_span_id=frontend_root_span_id,
|
|
|
+ spans=[
|
|
|
+ parent_span,
|
|
|
+ {
|
|
|
+ "timestamp": (timestamp + timedelta(milliseconds=200)).timestamp(),
|
|
|
+ "start_timestamp": timestamp.timestamp(),
|
|
|
+ "description": "1669031858711_file.txt (4.0 kB)",
|
|
|
+ "op": "file.write",
|
|
|
+ "span_id": uuid4().hex[:16],
|
|
|
+ "parent_span_id": parent_span_id,
|
|
|
+ "status": "ok",
|
|
|
+ "data": {
|
|
|
+ "blocked_ui_thread": True,
|
|
|
+ "call_stack": [
|
|
|
+ {
|
|
|
+ "function": "onClick",
|
|
|
+ "in_app": True,
|
|
|
+ "lineno": 2,
|
|
|
+ "module": "io.sentry.samples.android.MainActivity$$ExternalSyntheticLambda6",
|
|
|
+ "native": False,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "filename": "MainActivity.java",
|
|
|
+ "function": "lambda$onCreate$5$io-sentry-samples-android-MainActivity",
|
|
|
+ "in_app": True,
|
|
|
+ "lineno": 93,
|
|
|
+ "module": "io.sentry.samples.android.MainActivity",
|
|
|
+ "native": False,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ "file.path": "/data/user/0/io.sentry.samples.android/files/1669031858711_file.txt",
|
|
|
+ "file.size": 4010,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ )
|
|
|
|
|
|
- time.sleep(1.0)
|
|
|
-
|
|
|
- create_sample_event(
|
|
|
- project=backend_project,
|
|
|
- platform="transaction",
|
|
|
- transaction="/file-io-main-thread/",
|
|
|
- event_id=uuid4().hex,
|
|
|
- user=transaction_user,
|
|
|
- timestamp=timestamp + timedelta(milliseconds=300),
|
|
|
- start_timestamp=timestamp,
|
|
|
- trace=trace_id,
|
|
|
- parent_span_id=frontend_root_span_id,
|
|
|
- spans=[
|
|
|
- parent_span,
|
|
|
+ def load_consecutive_db_issue():
|
|
|
+ transaction_user = generate_user()
|
|
|
+ trace_id = uuid4().hex
|
|
|
+ parent_span_id = uuid4().hex[:16]
|
|
|
+
|
|
|
+ parent_span = {
|
|
|
+ "timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
|
|
|
+ "start_timestamp": timestamp.timestamp(),
|
|
|
+ "description": "new",
|
|
|
+ "op": "django.view",
|
|
|
+ "parent_span_id": uuid4().hex[:16],
|
|
|
+ "span_id": parent_span_id,
|
|
|
+ "hash": "0f43fb6f6e01ca52",
|
|
|
+ }
|
|
|
+
|
|
|
+ spans = [
|
|
|
{
|
|
|
- "timestamp": (timestamp + timedelta(milliseconds=200)).timestamp(),
|
|
|
- "start_timestamp": timestamp.timestamp(),
|
|
|
- "description": "1669031858711_file.txt (4.0 kB)",
|
|
|
- "op": "file.write",
|
|
|
+ "timestamp": (timestamp + timedelta(milliseconds=1000)).timestamp(),
|
|
|
+ "start_timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
|
|
|
+ "description": "SELECT `customer`.`id` FROM `customers` WHERE `customer`.`name` = 'customerName'",
|
|
|
+ "op": "db",
|
|
|
+ "parent_span_id": parent_span_id,
|
|
|
"span_id": uuid4().hex[:16],
|
|
|
+ "hash": "858fea692d4d93e9",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "timestamp": (timestamp + timedelta(milliseconds=2000)).timestamp(),
|
|
|
+ "start_timestamp": (timestamp + timedelta(milliseconds=1000)).timestamp(),
|
|
|
+ "description": "SELECT COUNT(*) FROM `customers`",
|
|
|
+ "op": "db",
|
|
|
"parent_span_id": parent_span_id,
|
|
|
- "status": "ok",
|
|
|
- "data": {
|
|
|
- "blocked_ui_thread": True,
|
|
|
- "call_stack": [
|
|
|
- {
|
|
|
- "function": "onClick",
|
|
|
- "in_app": True,
|
|
|
- "lineno": 2,
|
|
|
- "module": "io.sentry.samples.android.MainActivity$$ExternalSyntheticLambda6",
|
|
|
- "native": False,
|
|
|
- },
|
|
|
- {
|
|
|
- "filename": "MainActivity.java",
|
|
|
- "function": "lambda$onCreate$5$io-sentry-samples-android-MainActivity",
|
|
|
- "in_app": True,
|
|
|
- "lineno": 93,
|
|
|
- "module": "io.sentry.samples.android.MainActivity",
|
|
|
- "native": False,
|
|
|
- },
|
|
|
- ],
|
|
|
- "file.path": "/data/user/0/io.sentry.samples.android/files/1669031858711_file.txt",
|
|
|
- "file.size": 4010,
|
|
|
- },
|
|
|
+ "span_id": uuid4().hex[:16],
|
|
|
+ "hash": "858fea692d4d93e7",
|
|
|
},
|
|
|
- ],
|
|
|
- )
|
|
|
+ {
|
|
|
+ "timestamp": (timestamp + timedelta(milliseconds=3000)).timestamp(),
|
|
|
+ "start_timestamp": (timestamp + timedelta(milliseconds=2000)).timestamp(),
|
|
|
+ "description": "SELECT COUNT(*) FROM `items`",
|
|
|
+ "op": "db",
|
|
|
+ "parent_span_id": parent_span_id,
|
|
|
+ "span_id": uuid4().hex[:16],
|
|
|
+ "hash": "858fea692d4d93e6",
|
|
|
+ },
|
|
|
+ ]
|
|
|
+
|
|
|
+ create_sample_event(
|
|
|
+ project=backend_project,
|
|
|
+ platform="transaction",
|
|
|
+ transaction="/consecutive-db/",
|
|
|
+ event_id=uuid4().hex,
|
|
|
+ user=transaction_user,
|
|
|
+ timestamp=timestamp + timedelta(milliseconds=300),
|
|
|
+ start_timestamp=timestamp,
|
|
|
+ trace=trace_id,
|
|
|
+ parent_span_id=parent_span_id,
|
|
|
+ spans=[parent_span] + spans,
|
|
|
+ )
|
|
|
+
|
|
|
+ load_performance_issues()
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|