Skip to content

Commit fe6d3a2

Browse files
committed
feat(otel): add instrumentation
1 parent 9755231 commit fe6d3a2

File tree

5 files changed

+266
-189
lines changed

5 files changed

+266
-189
lines changed

demo.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import argparse
2+
import os
23
from pathlib import Path
34
from typing import Literal
45

56
import tranco
7+
from honeycomb.opentelemetry import HoneycombOptions, configure_opentelemetry
8+
from opentelemetry import trace
69

710
from custom_command import LinkCountingCommand
811
from openwpm.command_sequence import CommandSequence
@@ -29,7 +32,6 @@
2932
latest_list = t.list()
3033
sites = ["http://" + x for x in latest_list.top(10)]
3134

32-
3335
display_mode: Literal["native", "headless", "xvfb"] = "native"
3436
if args.headless:
3537
display_mode = "headless"
@@ -67,6 +69,7 @@
6769
# manager_params.memory_watchdog = True
6870
# manager_params.process_watchdog = True
6971

72+
_tracer = trace.get_tracer(__name__)
7073

7174
# Commands time out by default after 60 seconds
7275
with TaskManager(
@@ -77,23 +80,25 @@
7780
) as manager:
7881
# Visits the sites
7982
for index, site in enumerate(sites):
80-
81-
def callback(success: bool, val: str = site) -> None:
82-
print(
83-
f"CommandSequence for {val} ran {'successfully' if success else 'unsuccessfully'}"
83+
with _tracer.start_as_current_span("command_issuing"):
84+
span = trace.get_current_span()
85+
86+
def callback(success: bool, val: str = site) -> None:
87+
print(
88+
f"CommandSequence for {val} ran {'successfully' if success else 'unsuccessfully'}"
89+
)
90+
91+
# Parallelize sites over all number of browsers set above.
92+
command_sequence = CommandSequence(
93+
site,
94+
site_rank=index,
95+
callback=callback,
8496
)
8597

86-
# Parallelize sites over all number of browsers set above.
87-
command_sequence = CommandSequence(
88-
site,
89-
site_rank=index,
90-
callback=callback,
91-
)
92-
93-
# Start by visiting the page
94-
command_sequence.append_command(GetCommand(url=site, sleep=3), timeout=60)
95-
# Have a look at custom_command.py to see how to implement your own command
96-
command_sequence.append_command(LinkCountingCommand())
98+
# Start by visiting the page
99+
command_sequence.append_command(GetCommand(url=site, sleep=3), timeout=60)
100+
# Have a look at custom_command.py to see how to implement your own command
101+
command_sequence.append_command(LinkCountingCommand())
97102

98-
# Run commands across all browsers (simple parallelization)
99-
manager.execute_command_sequence(command_sequence)
103+
# Run commands across all browsers (simple parallelization)
104+
manager.execute_command_sequence(command_sequence)

0 commit comments

Comments
 (0)