Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Set explicit bucket boundaries (#17759)
Przemysław Łada9bc1b1134cc3
diff --git a/saleor/core/telemetry/__init__.py b/saleor/core/telemetry/__init__.pyindex c43b7c9cf2..369e94ad6c 100644--- a/saleor/core/telemetry/__init__.py+++ b/saleor/core/telemetry/__init__.py@@ -4,7 +4,7 @@ from typing import Anyfrom django.conf import settingsfrom opentelemetry.util.types import Attributes-from .metric import Meter, MeterProxy, MetricType+from .metric import DEFAULT_DURATION_BUCKETS, Meter, MeterProxy, MetricTypefrom .trace import Link, SpanKind, Tracer, TracerProxyfrom .utils import (Scope,@@ -63,4 +63,5 @@ __all__ = ["TelemetryTaskContext","task_with_telemetry_context","get_task_context",+ "DEFAULT_DURATION_BUCKETS",]diff --git a/saleor/core/telemetry/metric.py b/saleor/core/telemetry/metric.pyindex 3d20558767..9aff1f5b8b 100644--- a/saleor/core/telemetry/metric.py+++ b/saleor/core/telemetry/metric.py@@ -31,6 +31,26 @@ class MetricType(Enum):HISTOGRAM = "histogram"+DEFAULT_DURATION_BUCKETS = [+ 0.01, # 10ms+ 0.025, # 25ms+ 0.05, # 50ms+ 0.1, # 100ms+ 0.2, # 200ms+ 0.3, # 300ms+ 0.4, # 400ms+ 0.6, # 600ms+ 0.8, # 800ms+ 1, # 1s+ 1.5, # 1.5s+ 2.5, # 2.5s+ 4, # 4s+ 7, # 7s+ 18, # 18s+ 30, # 30s+]++def get_instrument_method(instrument: Synchronous,) -> Callable[[Amount, Attributes], None]:diff --git a/saleor/graphql/metrics.py b/saleor/graphql/metrics.pyindex 8bd4ebbbda..c09fbadd7d 100644--- a/saleor/graphql/metrics.py+++ b/saleor/graphql/metrics.py@@ -4,7 +4,14 @@ from opentelemetry.semconv._incubating.attributes import graphql_attributesfrom opentelemetry.semconv.attributes import error_attributesfrom opentelemetry.util.types import AttributeValue-from ..core.telemetry import MetricType, Scope, Unit, meter, saleor_attributes+from ..core.telemetry import (+ DEFAULT_DURATION_BUCKETS,+ MetricType,+ Scope,+ Unit,+ meter,+ saleor_attributes,+)# Initialize metricsMETRIC_GRAPHQL_QUERY_COUNT = meter.create_metric(@@ -21,14 +28,34 @@ METRIC_GRAPHQL_QUERY_DURATION = meter.create_metric(type=MetricType.HISTOGRAM,unit=Unit.SECOND,description="Duration of GraphQL queries.",+ bucket_boundaries=DEFAULT_DURATION_BUCKETS,)+QUERY_COST_BUCKETS = [+ 0,+ 5,+ 10,+ 25,+ 50,+ 100,+ 250,+ 500,+ 1000,+ 2000,+ 5000,+ 10000,+ 15000,+ 20000,+ 30000,+ 50000,+]METRIC_GRAPHQL_QUERY_COST = meter.create_metric("saleor.graphql.operation.cost",scope=Scope.SERVICE,type=MetricType.HISTOGRAM,unit=Unit.COST,description="Cost of GraphQL queries.",+ bucket_boundaries=QUERY_COST_BUCKETS,)METRIC_REQUEST_COUNT = meter.create_metric(@@ -45,6 +72,7 @@ METRIC_REQUEST_DURATION = meter.create_metric(type=MetricType.HISTOGRAM,unit=Unit.SECOND,description="Duration of API requests.",+ bucket_boundaries=DEFAULT_DURATION_BUCKETS,)diff --git a/saleor/webhook/transport/metrics.py b/saleor/webhook/transport/metrics.pyindex 744b61c856..0f94d1a1cb 100644--- a/saleor/webhook/transport/metrics.py+++ b/saleor/webhook/transport/metrics.py@@ -3,7 +3,7 @@ from urllib.parse import urlparsefrom opentelemetry.semconv.attributes import error_attributes, server_attributesfrom ...core.models import EventDeliveryStatus-from ...core.telemetry import MetricType, Scope, Unit, meter+from ...core.telemetry import DEFAULT_DURATION_BUCKETS, MetricType, Scope, Unit, meterfrom .utils import WebhookResponse# Initialize metrics@@ -20,13 +20,34 @@ METRIC_EXTERNAL_REQUEST_DURATION = meter.create_metric(type=MetricType.HISTOGRAM,unit=Unit.SECOND,description="Duration of webhook event delivery.",+ bucket_boundaries=DEFAULT_DURATION_BUCKETS,)++BODY_SIZE_BUCKETS = [+ 0, # 0B+ 100, # 100B+ 500, # 500B+ 1000, # 1KB+ 2000, # 2KB+ 4000, # 4KB+ 8000, # 8KB+ 16000, # 16KB+ 32000, # 32KB+ 64000, # 64KB+ 128000, # 128KB+ 256000, # 256KB+ 512000, # 512KB+ 1048576, # 1MB+ 2097152, # 2MB+ 4194304, # 4MB+]METRIC_EXTERNAL_REQUEST_BODY_SIZE = meter.create_metric("saleor.external_request.body.size",scope=Scope.SERVICE,type=MetricType.HISTOGRAM,unit=Unit.BYTE,description="Size of webhook event payloads.",+ bucket_boundaries=BODY_SIZE_BUCKETS,)