Skip to content

Commit

Permalink
feat(otel): add instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vringar committed Jul 21, 2024
1 parent 9755231 commit fe6d3a2
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 189 deletions.
41 changes: 23 additions & 18 deletions demo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import argparse
import os
from pathlib import Path
from typing import Literal

import tranco
from honeycomb.opentelemetry import HoneycombOptions, configure_opentelemetry
from opentelemetry import trace

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


display_mode: Literal["native", "headless", "xvfb"] = "native"
if args.headless:
display_mode = "headless"
Expand Down Expand Up @@ -67,6 +69,7 @@
# manager_params.memory_watchdog = True
# manager_params.process_watchdog = True

_tracer = trace.get_tracer(__name__)

# Commands time out by default after 60 seconds
with TaskManager(
Expand All @@ -77,23 +80,25 @@
) as manager:
# Visits the sites
for index, site in enumerate(sites):

def callback(success: bool, val: str = site) -> None:
print(
f"CommandSequence for {val} ran {'successfully' if success else 'unsuccessfully'}"
with _tracer.start_as_current_span("command_issuing"):
span = trace.get_current_span()

def callback(success: bool, val: str = site) -> None:
print(
f"CommandSequence for {val} ran {'successfully' if success else 'unsuccessfully'}"
)

# Parallelize sites over all number of browsers set above.
command_sequence = CommandSequence(
site,
site_rank=index,
callback=callback,
)

# Parallelize sites over all number of browsers set above.
command_sequence = CommandSequence(
site,
site_rank=index,
callback=callback,
)

# Start by visiting the page
command_sequence.append_command(GetCommand(url=site, sleep=3), timeout=60)
# Have a look at custom_command.py to see how to implement your own command
command_sequence.append_command(LinkCountingCommand())
# Start by visiting the page
command_sequence.append_command(GetCommand(url=site, sleep=3), timeout=60)
# Have a look at custom_command.py to see how to implement your own command
command_sequence.append_command(LinkCountingCommand())

# Run commands across all browsers (simple parallelization)
manager.execute_command_sequence(command_sequence)
# Run commands across all browsers (simple parallelization)
manager.execute_command_sequence(command_sequence)
Loading

0 comments on commit fe6d3a2

Please sign in to comment.