PHP 8.2.30
Preview: metrics.py Size: 2.00 KB
/opt/hc_python/lib64/python3.12/site-packages/sentry_sdk/metrics.py

"""
NOTE: This file contains experimental code that may be changed or removed at any
time without prior notice.
"""

import time
from typing import Any, Optional, TYPE_CHECKING, Union

import sentry_sdk
from sentry_sdk.utils import safe_repr

if TYPE_CHECKING:
    from sentry_sdk._types import Metric, MetricType


def _capture_metric(
    name,  # type: str
    metric_type,  # type: MetricType
    value,  # type: float
    unit=None,  # type: Optional[str]
    attributes=None,  # type: Optional[dict[str, Any]]
):
    # type: (...) -> None
    client = sentry_sdk.get_client()

    attrs = {}  # type: dict[str, Union[str, bool, float, int]]
    if attributes:
        for k, v in attributes.items():
            attrs[k] = (
                v
                if (
                    isinstance(v, str)
                    or isinstance(v, int)
                    or isinstance(v, bool)
                    or isinstance(v, float)
                )
                else safe_repr(v)
            )

    metric = {
        "timestamp": time.time(),
        "trace_id": None,
        "span_id": None,
        "name": name,
        "type": metric_type,
        "value": float(value),
        "unit": unit,
        "attributes": attrs,
    }  # type: Metric

    client._capture_metric(metric)


def count(
    name,  # type: str
    value,  # type: float
    unit=None,  # type: Optional[str]
    attributes=None,  # type: Optional[dict[str, Any]]
):
    # type: (...) -> None
    _capture_metric(name, "counter", value, unit, attributes)


def gauge(
    name,  # type: str
    value,  # type: float
    unit=None,  # type: Optional[str]
    attributes=None,  # type: Optional[dict[str, Any]]
):
    # type: (...) -> None
    _capture_metric(name, "gauge", value, unit, attributes)


def distribution(
    name,  # type: str
    value,  # type: float
    unit=None,  # type: Optional[str]
    attributes=None,  # type: Optional[dict[str, Any]]
):
    # type: (...) -> None
    _capture_metric(name, "distribution", value, unit, attributes)

Directory Contents

Dirs: 5 × Files: 33

Name Size Perms Modified Actions
ai DIR
- drwxr-xr-x 2025-12-03 08:02:53
Edit Download
crons DIR
- drwxr-xr-x 2025-12-03 08:02:53
Edit Download
- drwxr-xr-x 2025-12-03 08:02:53
Edit Download
profiler DIR
- drwxr-xr-x 2025-12-03 08:02:53
Edit Download
- drwxr-xr-x 2025-12-03 08:02:53
Edit Download
14.92 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
3.04 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
41.11 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
52.47 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
1019 B lrw-r--r-- 2025-12-03 08:02:53
Edit Download
10.23 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
2.18 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
25.14 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
2.73 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
2.00 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
3.55 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
0 B lrw-r--r-- 2025-12-03 08:02:53
Edit Download
63.89 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
5.92 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
13.22 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
5.46 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
8.96 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
8.47 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
50.53 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
39.59 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
31.13 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
1.24 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
62.40 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
4.36 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
3.04 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
2.50 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
5.37 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
1.20 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
4.92 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
10.99 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
10.18 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
3.65 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download
1.38 KB lrw-r--r-- 2025-12-03 08:02:53
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).