Viewing File: /opt/hc_python/lib/python3.12/site-packages/sentry_sdk/__pycache__/spotlight.cpython-312.pyc
�
_�*jf/ �
�� � d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m
Z
mZ d dlm
Z
d dlZe
rd dlmZmZmZmZmZ d dlmZ d dlmZmZ d dlmZ ej6 d� Zd Zd
Z G d� d� Z d d
lm Z d dl!m"Z"m#Z#m$Z$ d dl%m&Z& dZ'dZ(dZ)dZ*dZ+ e,d� e e-e+j] � e+j_ � � � D � � Z0 G d� de&� Z1 dd�Z3dd�Z4y# e2$ r dZ Y �w xY w)� N)�chain�product)�
TYPE_CHECKING)�Any�Callable�Dict�Optional�Self)�Envelope)�capture_internal_exceptions�env_to_bool)�logger� spotlightzhttp://localhost:8969/streamz(sentry_sdk.spotlight.SpotlightMiddlewarec �0 � e Zd ZdZdZdZdeddfd�Zd d�Zy)
�SpotlightClientaY
A client for sending envelopes to Sentry Spotlight.
Implements exponential backoff retry logic per the SDK spec:
- Logs error at least once when server is unreachable
- Does not log for every failed envelope
- Uses exponential backoff to avoid hammering an unavailable server
- Never blocks normal Sentry operation
g �?g N@�url�returnNc �t � || _ t j � | _ | j | _ d| _ y )N� )r �urllib3�PoolManager�http�INITIAL_RETRY_DELAY�_retry_delay�_last_error_time)�selfr s �C/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/spotlight.py�__init__zSpotlightClient.__init__0 s/ � �����'�'�)�� � �4�4���'*��� c � � | j dkD r1t j � | j z
}|| j k ry t j � }|j |� | j j | j |j � dddi�� }|j � | j | _ d| _ y # t $ rw}t j � | _ t | j dz | j � | _ t j d| j || j � Y d }~y d }~ww xY w) Nr �POST�Content-Typezapplication/x-sentry-envelope)r �body�method�headersr � zNFailed to send envelope to Spotlight at %s: %s. Will retry after %.1f seconds.)r �timer �io�BytesIO�serialize_intor �requestr �getvalue�closer � Exception�min�MAX_RETRY_DELAY�
sentry_logger�warning)r �envelope�time_since_errorr# �req�es r �capture_envelopez SpotlightClient.capture_envelope6 s � �� � �1�$�#�y�y�{�T�-B�-B�B���$�"3�"3�3���z�z�|������%� ��)�)�#�#��H�H��]�]�_��"�$C�� $� �C�
�I�I�K� $� 8� 8�D��$'�D�!���
�$(�I�I�K�D�!� !$�D�$5�$5��$9�4�;O�;O� P�D��
�!�!�1������!�!�
�
��
�s �'A!C � E �A-E�E )r3 r r N) �__name__�
__module__�__qualname__�__doc__r r0 �strr r7 � r r r r ! s, � �� ���O�+�C� +�D� +�$r r )�settings)�HttpRequest�HttpResponse�HttpResponseServerError)�MiddlewareMixinz/assets/main.jsz�<script>window.__spotlight = {{ initOptions: {{ sidecarUrl: '{spotlight_url}', fullPage: false }} }};</script>
<script type="module" crossorigin src="{spotlight_js_url}"></script>
z�<html><base href="{spotlight_url}">
<script>window.__spotlight = {{ initOptions: {{ fullPage: true, startFrom: "/errors/{event_id}" }}}};</script>
zcharset=r# c # �\ K � | ]$ }d j dj |� � �� �& y�w)z</{}>� N)�format�join)�.0�charss r � <genexpr>rI m s) � �� � )�P�E� ���r�w�w�u�~�&�P�s �*,c � � � e Zd ZU dZded<