Skip to content

ccproxy.core.plugins.hooks.implementations

ccproxy.core.plugins.hooks.implementations

Built-in hook implementations for CCProxy.

This module contains standard hook implementations for common use cases: - MetricsHook: Prometheus metrics collection - LoggingHook: Structured logging - AnalyticsHook: Analytics data collection - AccessLoggingHook: Access logging (replaces AccessLogMiddleware) - ContentLoggingHook: Content logging for hooks-based logging - StreamingCaptureHook: Streaming response capture - HTTPTracerHook: Core HTTP request/response tracing

HTTPTracerHook

HTTPTracerHook(
    json_formatter=None, raw_formatter=None, enabled=True
)

Bases: Hook

Core hook for tracing all HTTP requests and responses.

This hook captures HTTP_REQUEST, HTTP_RESPONSE, and HTTP_ERROR events for both client-side (CCProxy → providers) and server-side (client → CCProxy) HTTP traffic. It uses injected formatters for consistent logging.

Parameters:

Name Type Description Default
json_formatter Any

JSONFormatter instance for structured logging

None
raw_formatter Any

RawHTTPFormatter instance for raw HTTP logging

None
enabled bool

Whether the hook is enabled

True
Source code in ccproxy/core/plugins/hooks/implementations/http_tracer.py
def __init__(
    self,
    json_formatter: Any = None,
    raw_formatter: Any = None,
    enabled: bool = True,
) -> None:
    """Initialize the HTTP tracer hook.

    Args:
        json_formatter: JSONFormatter instance for structured logging
        raw_formatter: RawHTTPFormatter instance for raw HTTP logging
        enabled: Whether the hook is enabled
    """
    self.enabled = enabled
    self.json_formatter = json_formatter
    self.raw_formatter = raw_formatter

    if self.enabled:
        logger.debug(
            "core_http_tracer_hook_initialized",
            json_logs=json_formatter is not None,
            raw_http=raw_formatter is not None,
        )