Skip to content

Commit

Permalink
fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
evanh committed Jun 18, 2024
1 parent b824d63 commit bf2df47
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions scripts/send_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
PROJECTS = [1, 2, 3]
ORGANIZATION_ID = 1123
RECEIVED = datetime.datetime.now().timestamp()
CUSTOM_TAGS = [
CUSTOM_TAGS: list[tuple[str, Callable[[], Any]]] = [
("tag1", partial(random.randint, 0, 10)),
("tag2", lambda: str(uuid.uuid4())),
("tag3", partial(random.randint, 0, 100000)),
Expand All @@ -56,6 +56,8 @@ def get_transaction_name(project_id: int) -> str:
elif project_id == 3:
return "database_transaction"

raise ValueError(f"Unknown project_id: {project_id}")


ACTIONS = ["GET", "PUT", "POST", "DELETE"]
STATUS_CODES = ["200", "300", "400"]
Expand Down Expand Up @@ -178,7 +180,7 @@ def generate_span_branch(

to_split_or_not_to_split = random.random()
if span_count < 100 and to_split_or_not_to_split < 0.3:
subspans = []
subspans: list[Span] = []
subduration = 0
if project_id != 3 and to_split_or_not_to_split < 0.15:
if verbose:
Expand Down Expand Up @@ -233,7 +235,7 @@ def create_transaction(
trace_id: str,
project_id: int,
start_timestamp: datetime.datetime,
parent_span_id: str = None,
parent_span_id: str | None = None,
prefix: str = "",
add_datetimes: bool = False,
) -> tuple[list[dict[str, Any]], int]:
Expand Down Expand Up @@ -287,7 +289,7 @@ def producer(messages: list[Span], dryrun: bool, verbose: bool) -> None:
print(f"{i + 1} / {len(messages)}")
print(json.dumps(message))
if not dryrun:
producer.produce(
kafka_producer.produce(
Topic(name=(topic)),
KafkaPayload(
key=None, value=json.dumps(message).encode("utf-8"), headers=[]
Expand Down Expand Up @@ -392,14 +394,14 @@ def main(
add_datetimes: bool,
dryrun: bool,
verbose: bool,
):
) -> None:
to_close = None
if output == "stdout":
producer = write_to_stdout
elif output == "file":
if not file:
raise ValueError("--file/-f must be specified when using file output.")
producer, to_close = create_file_producer(file)
producer, to_close = create_file_producer(file) # type: ignore
elif output == "kafka":
if not kafka_host:
raise ValueError(
Expand All @@ -409,7 +411,7 @@ def main(
raise ValueError(
"--kafka-topic/-t must be specified when using kafka output."
)
producer, to_close = create_kafka_producer(kafka_host, kafka_topic)
producer, to_close = create_kafka_producer(kafka_host, kafka_topic) # type: ignore
else:
raise ValueError(f"Unknown output type: {output}")

Expand Down

0 comments on commit bf2df47

Please sign in to comment.