Skip to content

ccproxy.plugins.request_tracer

ccproxy.plugins.request_tracer

Request Tracer plugin for request tracing.

RequestTracerConfig

Bases: BaseModel

Unified configuration for request tracing.

Combines structured JSON tracing (from core_tracer) and raw HTTP logging (from raw_http_logger) into a single configuration.

get_json_log_dir

get_json_log_dir()

Get directory for structured JSON logs.

Source code in ccproxy/plugins/request_tracer/config.py
def get_json_log_dir(self) -> str:
    """Get directory for structured JSON logs."""
    return self.request_log_dir or self.log_dir

get_raw_log_dir

get_raw_log_dir()

Get directory for raw HTTP logs.

Source code in ccproxy/plugins/request_tracer/config.py
def get_raw_log_dir(self) -> str:
    """Get directory for raw HTTP logs."""
    return self.raw_log_dir or self.log_dir

should_trace_path

should_trace_path(path)

Check if a path should be traced based on include/exclude rules.

Source code in ccproxy/plugins/request_tracer/config.py
def should_trace_path(self, path: str) -> bool:
    """Check if a path should be traced based on include/exclude rules."""
    # First check exclude_paths (takes precedence)
    if any(path.startswith(exclude) for exclude in self.exclude_paths):
        return False

    # Then check include_paths (if specified, only log included paths)
    if self.include_paths:
        return any(path.startswith(include) for include in self.include_paths)

    # Default: trace all paths not explicitly excluded
    return True

RequestTracerHook

RequestTracerHook(config=None)

Bases: Hook

Simplified hook-based request tracer implementation.

This hook only handles REQUEST_* events since HTTP_* events are now handled by the core HTTPTracerHook. This eliminates duplication and follows the single responsibility principle.

The plugin now focuses purely on request lifecycle logging without attempting to capture HTTP request/response bodies.

Parameters:

Name Type Description Default
config RequestTracerConfig | None

Request tracer configuration

None
Source code in ccproxy/plugins/request_tracer/hook.py
def __init__(
    self,
    config: RequestTracerConfig | None = None,
) -> None:
    """Initialize the request tracer hook.

    Args:
        config: Request tracer configuration
    """
    self.config = config or RequestTracerConfig()

    # Storage for streaming chunks per request
    self._streaming_chunks: dict[str, list[bytes]] = {}
    self._streaming_metadata: dict[str, dict[str, Any]] = {}

    logger.debug(
        "request_tracer_hook_initialized",
        enabled=self.config.enabled,
    )