Skip to content

feat: Remote Run Context#67

Merged
monoxgas merged 1 commit into
mainfrom
feat/remote-run-context
Jun 6, 2025
Merged

feat: Remote Run Context#67
monoxgas merged 1 commit into
mainfrom
feat/remote-run-context

Conversation

@monoxgas
Copy link
Copy Markdown
Contributor

@monoxgas monoxgas commented Jun 4, 2025

  • Add get_run_context and continue_run features.
  • Fix dependencies and some pre-commit stuff

Example:

import asyncio
import threading
import time
from concurrent.futures import ThreadPoolExecutor

import dreadnode

# Initialize with default settings
dreadnode.configure()

NAMES = ["Nick", "Will", "Brad", "Brian"]


@dreadnode.task()
async def say_hello(name: str) -> str:
    return f"Hello, {name}!"

def process_in_thread(name: str, run_context) -> str:
    """Simulates work happening in another thread/process"""
    # Continue the run from context
    with dreadnode.continue_run(run_context) as remote_run:
        # Log that we're in a remote context
        remote_run.log_param("thread_id", threading.get_ident())
        remote_run.log_param("processed_name", name)
        
        # Simulate some work
        asyncio.run(say_hello(name))
        
        # Log metrics from remote thread
        remote_run.log_metric("processing_time", 0.5)
        remote_run.log_metric("name_length", len(name))
        
        # Log output
        result = f"Processed {name} in thread {threading.get_ident()}"
        remote_run.log_output("thread_result", result)
        
        return result


# Start a new run
with dreadnode.run("distributed-test-run") as main_run:
    # Log initial parameters
    dreadnode.log_params(
        name_count=len(NAMES),
        test_type="distributed_context"
    )

    # Log inputs
    dreadnode.log_input("names", NAMES)

    # Run tasks in main thread
    greetings = [await say_hello(name) for name in NAMES[:2]]
    dreadnode.log_output("main_greetings", greetings)

    # Capture run context for distribution
    run_context = dreadnode.get_run_context()
    print(f"Captured context for run: {run_context['run_id']}")

    # Process remaining names in separate threads
    with ThreadPoolExecutor(max_workers=2) as executor:
        futures = [
            executor.submit(process_in_thread, name, run_context) 
            for name in NAMES[2:]
        ]
        
        # Wait for thread results
        thread_results = [future.result() for future in futures]
        
    # Log combined results in main run
    dreadnode.log_output("thread_results", thread_results)
    dreadnode.log_metric("total_processed", len(NAMES))

    print("Main run completed!")
    print(f"Thread results: {thread_results}")

Generated Summary:

  • Added new methods get_run_context and continue_run in the Dreadnode class.
  • Modified imports to include OpenTelemetry's propagate.
  • Updated Audio data type checks from isinstance with tuple to use bitwise OR syntax.
  • Removed deprecated py.typed file from the dreadnode/data_types/ directory.
  • Adjusted the handling of run configurations:
    • Changed condition from and to or in checking server, token, and local directory.
  • Updated project name description in the Dreadnode constructor docstring.
  • Introduced the RunContext type definition for better context management.
  • Adjusted the type of run_id in RunSpan constructor and added from_context class method for span creation.
  • Enhanced the RunSpan class to support remote context injection.
  • Minor typo fixes in docstrings and comments.
  • Updated pre-commit-config.yaml to add more ignored words for codespell and commented out unused hooks for ruff and mypy.
  • Potential impacts include improved run management and context propagation for distributed systems, enhancing traceability and performance in complex applications.

This summary was generated with ❤️ by rigging

@dreadnode-renovate-bot dreadnode-renovate-bot Bot added area/python Changes to Python package configuration and dependencies area/pre-commit Changes made to pre-commit hooks labels Jun 4, 2025
@monoxgas monoxgas requested a review from briangreunke June 4, 2025 23:06
@monoxgas monoxgas merged commit 91a03ab into main Jun 6, 2025
10 checks passed
@monoxgas monoxgas deleted the feat/remote-run-context branch June 6, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/pre-commit Changes made to pre-commit hooks area/python Changes to Python package configuration and dependencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant