Add --fresh-trace and --tag params to send_json/stress_test

This commit is contained in:
Klaas van Schelven
2025-02-27 14:04:52 +01:00
parent 5f1d5832d1
commit 0aa067eb9b
2 changed files with 47 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import io
import uuid
import brotli
import random
import time
import json
@@ -24,6 +25,8 @@ class Command(BaseCommand):
parser.add_argument("--valid-only", action="store_true")
parser.add_argument("--fresh-id", action="store_true")
parser.add_argument("--fresh-timestamp", action="store_true")
parser.add_argument("--fresh-trace", action="store_true")
parser.add_argument("--tag", nargs="*", action="append")
parser.add_argument("--compress", action="store", choices=["gzip", "deflate", "br"], default=None)
parser.add_argument("--use-envelope", action="store_true")
parser.add_argument(
@@ -102,6 +105,27 @@ class Command(BaseCommand):
if options["fresh_id"]:
data["event_id"] = uuid.uuid4().hex
if options["fresh_trace"]:
if "contexts" not in data:
data["contexts"] = {}
if "trace" not in data["contexts"]:
data["contexts"]["trace"] = {}
# https://develop.sentry.dev/sdk/data-model/event-payloads/span/#attributes
# > A random hex string with a length of 16 characters. [which is 8 bytes]
data["contexts"]["trace"]["span_id"] = random.getrandbits(64).to_bytes(8, byteorder='big').hex()
# > A random hex string with a length of 32 characters. [which is 16 bytes]
data["contexts"]["trace"]["trace_id"] = random.getrandbits(128).to_bytes(16, byteorder='big').hex()
if options["tag"]:
if "tags" not in data:
data["tags"] = {}
for tag in options["tag"]:
tag = tag[0] # it's a list of lists... how to prevent this is not immediately clear
k, v = tag.split(":", 1)
data["tags"][k] = v
if options["valid_only"] and not self.is_valid(data, identifier):
return False

View File

@@ -25,6 +25,8 @@ class Command(BaseCommand):
parser.add_argument("--dsn", nargs="+", action="extend")
parser.add_argument("--fresh-id", action="store_true")
parser.add_argument("--fresh-timestamp", action="store_true")
parser.add_argument("--fresh-trace", action="store_true")
parser.add_argument("--tag", nargs="*", action="append")
parser.add_argument("--compress", action="store", choices=["gzip", "deflate", "br"], default=None)
parser.add_argument("--use-envelope", action="store_true")
parser.add_argument("--random-type", action="store_true", default=False) # generate random exception type
@@ -89,6 +91,27 @@ class Command(BaseCommand):
if options["fresh_id"]:
data["event_id"] = uuid.uuid4().hex
if options["fresh_trace"]:
if "contexts" not in data:
data["contexts"] = {}
if "trace" not in data["contexts"]:
data["contexts"]["trace"] = {}
# https://develop.sentry.dev/sdk/data-model/event-payloads/span/#attributes
# > A random hex string with a length of 16 characters. [which is 8 bytes]
data["contexts"]["trace"]["span_id"] = random.getrandbits(64).to_bytes(8, byteorder='big').hex()
# > A random hex string with a length of 32 characters. [which is 16 bytes]
data["contexts"]["trace"]["trace_id"] = random.getrandbits(128).to_bytes(16, byteorder='big').hex()
if options["tag"]:
if "tags" not in data:
data["tags"] = {}
for tag in options["tag"]:
tag = tag[0] # it's a list of lists... how to prevent this is not immediately clear
k, v = tag.split(":", 1)
data["tags"][k] = v
if options["random_type"]:
# avoids numbers in the type because I imagine numbers may at some point be ignored in the grouping.
into_chars = lambda i: "".join([chr(ord("A") + int(c)) for c in str(i)]) # noqa