Skip to content

honeyhive.tracer.core

Core HoneyHive tracer implementation with dynamic composition.

This module provides the main HoneyHiveTracer class composed from multiple mixins using dynamic inheritance patterns. It maintains full backward compatibility while providing a clean, modular architecture.

NoOpSpan

No-op span implementation for graceful degradation.

This class provides a safe default span that implements the same interface as a real span but performs no operations. This follows OpenTelemetry best practices for error handling - never return None, always return a usable object.

Source code in src/honeyhive/tracer/core/base.py
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
class NoOpSpan:
    """No-op span implementation for graceful degradation.

    This class provides a safe default span that implements the same interface
    as a real span but performs no operations. This follows OpenTelemetry best
    practices for error handling - never return None, always return a usable object.
    """

    def __init__(self) -> None:
        """Initialize no-op span with safe defaults."""
        self.kind = SpanKind.INTERNAL
        self._attributes: Dict[str, Any] = {}

    def set_attribute(self, key: str, value: Any) -> None:
        """Set attribute (no-op)."""

    def set_attributes(self, attributes: Dict[str, Any]) -> None:
        """Set multiple attributes (no-op)."""

    def add_event(
        self,
        name: str,
        attributes: Optional[Dict[str, Any]] = None,
        timestamp: Optional[int] = None,
    ) -> None:
        """Add event (no-op)."""

    def record_exception(
        self,
        exception: Exception,
        attributes: Optional[Dict[str, Any]] = None,
        timestamp: Optional[int] = None,
        escaped: bool = False,
    ) -> None:
        """Record exception (no-op)."""

    def set_status(self, status: Any, description: Optional[str] = None) -> None:
        """Set status (no-op)."""

    def update_name(self, name: str) -> None:
        """Update name (no-op)."""

    def end(self, end_time: Optional[int] = None) -> None:
        """End span (no-op)."""

    def is_recording(self) -> bool:
        """Check if span is recording (always False for no-op)."""
        return False

    def get_span_context(self) -> Any:
        """Get span context (returns invalid context)."""
        return INVALID_SPAN_CONTEXT

kind instance-attribute

kind = INTERNAL

set_attribute

set_attribute(key: str, value: Any) -> None

Set attribute (no-op).

Source code in src/honeyhive/tracer/core/base.py
63
64
def set_attribute(self, key: str, value: Any) -> None:
    """Set attribute (no-op)."""

set_attributes

set_attributes(attributes: Dict[str, Any]) -> None

Set multiple attributes (no-op).

Source code in src/honeyhive/tracer/core/base.py
66
67
def set_attributes(self, attributes: Dict[str, Any]) -> None:
    """Set multiple attributes (no-op)."""

add_event

add_event(
    name: str,
    attributes: Optional[Dict[str, Any]] = None,
    timestamp: Optional[int] = None,
) -> None

Add event (no-op).

Source code in src/honeyhive/tracer/core/base.py
69
70
71
72
73
74
75
def add_event(
    self,
    name: str,
    attributes: Optional[Dict[str, Any]] = None,
    timestamp: Optional[int] = None,
) -> None:
    """Add event (no-op)."""

record_exception

record_exception(
    exception: Exception,
    attributes: Optional[Dict[str, Any]] = None,
    timestamp: Optional[int] = None,
    escaped: bool = False,
) -> None

Record exception (no-op).

Source code in src/honeyhive/tracer/core/base.py
77
78
79
80
81
82
83
84
def record_exception(
    self,
    exception: Exception,
    attributes: Optional[Dict[str, Any]] = None,
    timestamp: Optional[int] = None,
    escaped: bool = False,
) -> None:
    """Record exception (no-op)."""

set_status

set_status(
    status: Any, description: Optional[str] = None
) -> None

Set status (no-op).

Source code in src/honeyhive/tracer/core/base.py
86
87
def set_status(self, status: Any, description: Optional[str] = None) -> None:
    """Set status (no-op)."""

update_name

update_name(name: str) -> None

Update name (no-op).

Source code in src/honeyhive/tracer/core/base.py
89
90
def update_name(self, name: str) -> None:
    """Update name (no-op)."""

end

end(end_time: Optional[int] = None) -> None

End span (no-op).

Source code in src/honeyhive/tracer/core/base.py
92
93
def end(self, end_time: Optional[int] = None) -> None:
    """End span (no-op)."""

is_recording

is_recording() -> bool

Check if span is recording (always False for no-op).

Source code in src/honeyhive/tracer/core/base.py
95
96
97
def is_recording(self) -> bool:
    """Check if span is recording (always False for no-op)."""
    return False

get_span_context

get_span_context() -> Any

Get span context (returns invalid context).

Source code in src/honeyhive/tracer/core/base.py
 99
100
101
def get_span_context(self) -> Any:
    """Get span context (returns invalid context)."""
    return INVALID_SPAN_CONTEXT

HoneyHiveTracer

Bases: HoneyHiveTracerBase, TracerOperationsMixin, TracerContextMixin

HoneyHive OpenTelemetry tracer with dynamic multi-instance architecture.

This tracer class is composed from multiple mixins using dynamic inheritance, providing a comprehensive tracing solution with flexible configuration, robust error handling, and multi-instance support.

The class combines: - HoneyHiveTracerBase: Core initialization and configuration - TracerOperationsMixin: Span creation and event management - TracerContextMixin: Context and baggage management

All operations use dynamic logic for flexible parameter handling, automatic error recovery, and graceful degradation.

Example

config = TracerConfig(api_key="...", project="...", verbose=True) tracer = HoneyHiveTracer(config=config)

Backwards compatible approach

tracer = HoneyHiveTracer(api_key="...", project="...", verbose=True)

Dynamic span creation

with tracer.start_span("operation") as span: ... span.set_attribute("key", "value")

Dynamic event creation

event_id = tracer.create_event( ... event_name="my_event", ... event_type="tool", ... inputs={"input": "data"}, ... outputs={"output": "result"} ... )

Source code in src/honeyhive/tracer/core/tracer.py
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
class HoneyHiveTracer(HoneyHiveTracerBase, TracerOperationsMixin, TracerContextMixin):
    """HoneyHive OpenTelemetry tracer with dynamic multi-instance architecture.

    This tracer class is composed from multiple mixins using dynamic inheritance,
    providing a comprehensive tracing solution with flexible configuration,
    robust error handling, and multi-instance support.

    The class combines:
    - HoneyHiveTracerBase: Core initialization and configuration
    - TracerOperationsMixin: Span creation and event management
    - TracerContextMixin: Context and baggage management

    All operations use dynamic logic for flexible parameter handling,
    automatic error recovery, and graceful degradation.

    Example:
        >>> # New Pydantic config approach (recommended)
        >>> config = TracerConfig(api_key="...", project="...", verbose=True)
        >>> tracer = HoneyHiveTracer(config=config)
        >>>
        >>> # Backwards compatible approach
        >>> tracer = HoneyHiveTracer(api_key="...", project="...", verbose=True)

        >>> # Dynamic span creation
        >>> with tracer.start_span("operation") as span:
        ...     span.set_attribute("key", "value")

        >>> # Dynamic event creation
        >>> event_id = tracer.create_event(
        ...     event_name="my_event",
        ...     event_type="tool",
        ...     inputs={"input": "data"},
        ...     outputs={"output": "result"}
        ... )
    """

    # Explicit implementation to satisfy ABC requirements
    # The TracerContextMixin provides the actual implementation
    def get_baggage(self, key: str) -> Optional[str]:
        """Get baggage value by key.

        Delegates to TracerContextMixin implementation.

        Args:
            key: The baggage key to retrieve

        Returns:
            Baggage value or None if not found
        """
        return TracerContextMixin.get_baggage(self, key)

    def flush(self, timeout_millis: float = 30000) -> bool:
        """Flush tracer data. Alias for force_flush().

        Args:
            timeout_millis: Timeout in milliseconds (default 30000)

        Returns:
            True if flush successful, False otherwise
        """
        return self.force_flush(timeout_millis)

    @classmethod
    def flush_all(cls, timeout_millis: float = 30000) -> bool:
        """Flush all active tracer instances.

        This is a convenience class method that flushes all active tracers.

        Args:
            timeout_millis: Timeout in milliseconds (default 30000)

        Returns:
            True if all flushes successful, False otherwise
        """
        from honeyhive.tracer.lifecycle.flush import force_flush_tracer

        # Get current tracer from context if available
        try:
            from honeyhive.tracer.processing.context import get_current_tracer

            current = get_current_tracer()
            if current:
                return force_flush_tracer(current, timeout_millis)
        except Exception:
            pass
        return True

    def __repr__(self) -> str:
        """Dynamic string representation of tracer instance."""
        return (
            f"HoneyHiveTracer("
            f"project={self.project_name!r}, "
            f"source={self.source_environment!r}, "
            f"initialized={self.is_initialized}, "
            f"test_mode={self.is_test_mode})"
        )

get_baggage

get_baggage(key: str) -> Optional[str]

Get baggage value by key.

Delegates to TracerContextMixin implementation.

Parameters:

Name Type Description Default
key str

The baggage key to retrieve

required

Returns:

Type Description
Optional[str]

Baggage value or None if not found

Source code in src/honeyhive/tracer/core/tracer.py
53
54
55
56
57
58
59
60
61
62
63
64
def get_baggage(self, key: str) -> Optional[str]:
    """Get baggage value by key.

    Delegates to TracerContextMixin implementation.

    Args:
        key: The baggage key to retrieve

    Returns:
        Baggage value or None if not found
    """
    return TracerContextMixin.get_baggage(self, key)

flush

flush(timeout_millis: float = 30000) -> bool

Flush tracer data. Alias for force_flush().

Parameters:

Name Type Description Default
timeout_millis float

Timeout in milliseconds (default 30000)

30000

Returns:

Type Description
bool

True if flush successful, False otherwise

Source code in src/honeyhive/tracer/core/tracer.py
66
67
68
69
70
71
72
73
74
75
def flush(self, timeout_millis: float = 30000) -> bool:
    """Flush tracer data. Alias for force_flush().

    Args:
        timeout_millis: Timeout in milliseconds (default 30000)

    Returns:
        True if flush successful, False otherwise
    """
    return self.force_flush(timeout_millis)

flush_all classmethod

flush_all(timeout_millis: float = 30000) -> bool

Flush all active tracer instances.

This is a convenience class method that flushes all active tracers.

Parameters:

Name Type Description Default
timeout_millis float

Timeout in milliseconds (default 30000)

30000

Returns:

Type Description
bool

True if all flushes successful, False otherwise

Source code in src/honeyhive/tracer/core/tracer.py
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
@classmethod
def flush_all(cls, timeout_millis: float = 30000) -> bool:
    """Flush all active tracer instances.

    This is a convenience class method that flushes all active tracers.

    Args:
        timeout_millis: Timeout in milliseconds (default 30000)

    Returns:
        True if all flushes successful, False otherwise
    """
    from honeyhive.tracer.lifecycle.flush import force_flush_tracer

    # Get current tracer from context if available
    try:
        from honeyhive.tracer.processing.context import get_current_tracer

        current = get_current_tracer()
        if current:
            return force_flush_tracer(current, timeout_millis)
    except Exception:
        pass
    return True