o
    <‘ðis  ã                   @   s|   d dl mZmZ d dlmZmZmZ 	 G dd„ deƒZG dd„ deƒZdee	 fdd	„Z
dee	 fd
d„ZG dd„ dƒZdS )é    )ÚIntFlagÚauto)ÚListÚOptionalÚSequencec                   @   s:   e Zd ZdZeƒ Zeƒ Zeƒ Zeƒ Zeƒ Z	eƒ Z
eƒ ZdS )ÚMetricGroupz+Metric groups that can be enabled/disabled.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú
RESILIENCYÚCONNECTION_BASICÚCONNECTION_ADVANCEDÚCOMMANDÚCSCÚ	STREAMINGÚPUBSUB© r   r   úY/root/parts/websockify/install/lib/python3.10/site-packages/redis/observability/config.pyr      s    
r   c                   @   s   e Zd ZdZeƒ ZdS )ÚTelemetryOptionzTelemetry options to export.N)r   r	   r
   r   r   ÚMETRICSr   r   r   r   r      s    
r   Úreturnc                   C   ó   g d¢S )N)ç-Cëâ6?gü©ñÒMb0?çü©ñÒMb@?çü©ñÒMbP?g{®Gázd?ç{®Gázt?ç{®Gáz„?gš™™™™™™?çš™™™™™©?çš™™™™™¹?g      Ð?ç      à?é   g      @r   r   r   r   r   Ú"default_operation_duration_buckets   ó   r"   c                   C   r   )N)r   r   r   r   r   r   r   r    r!   é   é
   r   r   r   r   r   Údefault_histogram_buckets1   r#   r&   c                   @   sÐ   e Zd ZdZejZejej	B Z
ddddddeƒ eƒ eƒ eƒ f
deee  deee  deee  deee  ded	ed
ee dee dee dee fdd„Zdefdd„Zdedefdd„Zdefdd„ZdS )Ú
OTelConfiga‰  
    Configuration for OpenTelemetry observability in redis-py.

    This class manages all OTel-related settings including metrics, traces (future),
    and logs (future). Configuration can be provided via constructor parameters or
    environment variables (OTEL_* spec).

    Constructor parameters take precedence over environment variables.

    Args:
        enabled_telemetry: Enabled telemetry options to export (default: metrics). Traces and logs will be added
                           in future phases.
        metric_groups: Group of metrics that should be exported.
        include_commands: Explicit allowlist of commands to track
        exclude_commands: Blocklist of commands to track
        hide_pubsub_channel_names: If True, hide PubSub channel names in metrics (default: False)
        hide_stream_names: If True, hide stream names in streaming metrics (default: False)

    Note:
        Redis-py uses the global MeterProvider set by your application.
        Set it up before initializing observability:

            from opentelemetry import metrics
            from opentelemetry.sdk.metrics import MeterProvider
            from opentelemetry.sdk.metrics._internal.view import View
            from opentelemetry.sdk.metrics._internal.aggregation import ExplicitBucketHistogramAggregation

            # Configure histogram bucket boundaries via Views
            views = [
                View(
                    instrument_name="db.client.operation.duration",
                    aggregation=ExplicitBucketHistogramAggregation(
                        boundaries=[0.0001, 0.00025, 0.0005, 0.001, 0.0025, 0.005,
                                    0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5]
                    ),
                ),
                # Add more views for other histograms...
            ]

            provider = MeterProvider(views=views, metric_readers=[reader])
            metrics.set_meter_provider(provider)

            # Then initialize redis-py observability
            from redis.observability import get_observability_instance, OTelConfig
            otel = get_observability_instance()
            otel.init(OTelConfig())
    NFÚenabled_telemetryÚmetric_groupsÚinclude_commandsÚexclude_commandsÚhide_pubsub_channel_namesÚhide_stream_namesÚbuckets_operation_durationÚ"buckets_stream_processing_durationÚbuckets_connection_create_timeÚbuckets_connection_wait_timec                 C   s¶   |d u r	| j | _ntdƒ| _|D ]	}|  j|O  _q|d u r#| j| _ntdƒ| _|D ]	}|  j|O  _q*|r:t|ƒnd | _|rCt|ƒntƒ | _|| _	|| _
|| _|| _|	| _|
| _d S )Nr   )ÚDEFAULT_TELEMETRYr(   r   ÚDEFAULT_METRIC_GROUPSr)   r   Úsetr*   r+   r,   r-   r.   r/   r0   r1   )Úselfr(   r)   r*   r+   r,   r-   r.   r/   r0   r1   ÚoptionÚmetric_groupr   r   r   Ú__init__i   s$   




zOTelConfig.__init__r   c                 C   s
   t | jƒS )z.Check if any observability feature is enabled.)Úboolr(   ©r5   r   r   r   Ú
is_enabled   s   
zOTelConfig.is_enabledÚcommand_namec                 C   s&   |  ¡ }| jdur|| jv S || jvS )a  
        Determine if a command should be tracked based on include/exclude lists.

        Args:
            command_name: The Redis command name (e.g., 'GET', 'SET')

        Returns:
            True if the command should be tracked, False otherwise
        N)Úupperr*   r+   )r5   r<   Úcommand_upperr   r   r   Úshould_track_command¡   s   



zOTelConfig.should_track_commandc                 C   s   d| j › S )NzOTelConfig(enabled_telemetry=)r(   r:   r   r   r   Ú__repr__´   s   zOTelConfig.__repr__)r   r	   r
   r   r   r   r2   r   r   r   r3   r"   r&   r   r   Ústrr9   r   Úfloatr8   r;   r?   r@   r   r   r   r   r'   5   sT    0ì
ý
û
ù
ø
öõÿóÿðí
ì4r'   N)Úenumr   r   Útypingr   r   r   r   r   rB   r"   r&   r'   r   r   r   r   Ú<module>   s    