Skip to content
Draft
34 changes: 24 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pydantic = [
{ version = "~=2.8", python = "<3.14" },
{ version = "~=2.12", python = ">=3.14" },
]
opentelemetry-exporter-prometheus = "0.55b1"

# This is for building the rust components during "poetry install", which
# currently ignores the `build-system.requires` directive (c.f.
Expand Down
6 changes: 2 additions & 4 deletions synapse/api/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
#
from typing import TYPE_CHECKING, Optional, Protocol

from prometheus_client import Histogram

from twisted.web.server import Request

from synapse.appservice import ApplicationService
from synapse.http.site import SynapseRequest
from synapse.metrics import SERVER_NAME_LABEL
from synapse.metrics import SERVER_NAME_LABEL, SynapseHistogram
from synapse.types import Requester

if TYPE_CHECKING:
Expand All @@ -36,7 +34,7 @@
GUEST_DEVICE_ID = "guest_device"


introspection_response_timer = Histogram(
introspection_response_timer = SynapseHistogram(
"synapse_api_auth_delegated_introspection_response",
"Time taken to get a response for an introspection request",
labelnames=["code", SERVER_NAME_LABEL],
Expand Down
12 changes: 5 additions & 7 deletions synapse/app/phone_stats_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
import sys
from typing import TYPE_CHECKING, Mapping, Sized

from prometheus_client import Gauge

from twisted.internet import defer

from synapse.metrics import SERVER_NAME_LABEL
from synapse.metrics import SERVER_NAME_LABEL, SynapseGauge
from synapse.types import JsonDict
from synapse.util.constants import (
MILLISECONDS_PER_SECOND,
Expand Down Expand Up @@ -57,22 +55,22 @@
_stats_process: list[tuple[int, "resource.struct_rusage"]] = []

# Gauges to expose monthly active user control metrics
current_mau_gauge = Gauge(
current_mau_gauge = SynapseGauge(
"synapse_admin_mau_current",
"Current MAU",
labelnames=[SERVER_NAME_LABEL],
)
current_mau_by_service_gauge = Gauge(
current_mau_by_service_gauge = SynapseGauge(
"synapse_admin_mau_current_mau_by_service",
"Current MAU by service",
labelnames=["app_service", SERVER_NAME_LABEL],
)
max_mau_gauge = Gauge(
max_mau_gauge = SynapseGauge(
"synapse_admin_mau_max",
"MAU Limit",
labelnames=[SERVER_NAME_LABEL],
)
registered_reserved_users_mau_gauge = Gauge(
registered_reserved_users_mau_gauge = SynapseGauge(
"synapse_admin_mau_registered_reserved_users",
"Registered users with reserved threepids",
labelnames=[SERVER_NAME_LABEL],
Expand Down
13 changes: 6 additions & 7 deletions synapse/appservice/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
Union,
)

from prometheus_client import Counter
from typing_extensions import ParamSpec, TypeGuard

from synapse.api.constants import EventTypes, Membership, ThirdPartyEntityKind
Expand All @@ -45,7 +44,7 @@
from synapse.events.utils import SerializeEventConfig, serialize_event
from synapse.http.client import SimpleHttpClient, is_unknown_endpoint
from synapse.logging import opentracing
from synapse.metrics import SERVER_NAME_LABEL
from synapse.metrics import SERVER_NAME_LABEL, SynapseCounter
from synapse.types import DeviceListUpdates, JsonDict, JsonMapping, ThirdPartyInstanceID
from synapse.util.caches.response_cache import ResponseCache

Expand All @@ -54,31 +53,31 @@

logger = logging.getLogger(__name__)

sent_transactions_counter = Counter(
sent_transactions_counter = SynapseCounter(
"synapse_appservice_api_sent_transactions",
"Number of /transactions/ requests sent",
labelnames=["service", SERVER_NAME_LABEL],
)

failed_transactions_counter = Counter(
failed_transactions_counter = SynapseCounter(
"synapse_appservice_api_failed_transactions",
"Number of /transactions/ requests that failed to send",
labelnames=["service", SERVER_NAME_LABEL],
)

sent_events_counter = Counter(
sent_events_counter = SynapseCounter(
"synapse_appservice_api_sent_events",
"Number of events sent to the AS",
labelnames=["service", SERVER_NAME_LABEL],
)

sent_ephemeral_counter = Counter(
sent_ephemeral_counter = SynapseCounter(
"synapse_appservice_api_sent_ephemeral",
"Number of ephemeral events sent to the AS",
labelnames=["service", SERVER_NAME_LABEL],
)

sent_todevice_counter = Counter(
sent_todevice_counter = SynapseCounter(
"synapse_appservice_api_sent_todevice",
"Number of todevice messages sent to the AS",
labelnames=["service", SERVER_NAME_LABEL],
Expand Down
5 changes: 2 additions & 3 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
)

import attr
from prometheus_client import Counter

from synapse.api.constants import Direction, EventContentFields, EventTypes, Membership
from synapse.api.errors import (
Expand Down Expand Up @@ -71,7 +70,7 @@
from synapse.http.client import is_unknown_endpoint
from synapse.http.types import QueryParams
from synapse.logging.opentracing import SynapseTags, log_kv, set_tag, tag_args, trace
from synapse.metrics import SERVER_NAME_LABEL
from synapse.metrics import SERVER_NAME_LABEL, SynapseCounter
from synapse.types import JsonDict, StrCollection, UserID, get_domain_from_id
from synapse.types.handlers.policy_server import RECOMMENDATION_OK, RECOMMENDATION_SPAM
from synapse.util.async_helpers import concurrently_execute
Expand All @@ -83,7 +82,7 @@

logger = logging.getLogger(__name__)

sent_queries_counter = Counter(
sent_queries_counter = SynapseCounter(
"synapse_federation_client_sent_queries", "", labelnames=["type", SERVER_NAME_LABEL]
)

Expand Down
19 changes: 11 additions & 8 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
Union,
)

from prometheus_client import Counter, Gauge, Histogram

from twisted.python import failure

from synapse.api.constants import (
Expand Down Expand Up @@ -79,7 +77,12 @@
tag_args,
trace,
)
from synapse.metrics import SERVER_NAME_LABEL
from synapse.metrics import (
SERVER_NAME_LABEL,
SynapseCounter,
SynapseGauge,
SynapseHistogram,
)
from synapse.metrics.background_process_metrics import wrap_as_background_process
from synapse.replication.http.federation import (
ReplicationFederationSendEduRestServlet,
Expand All @@ -102,27 +105,27 @@

logger = logging.getLogger(__name__)

received_pdus_counter = Counter(
received_pdus_counter = SynapseCounter(
"synapse_federation_server_received_pdus", "", labelnames=[SERVER_NAME_LABEL]
)

received_edus_counter = Counter(
received_edus_counter = SynapseCounter(
"synapse_federation_server_received_edus", "", labelnames=[SERVER_NAME_LABEL]
)

received_queries_counter = Counter(
received_queries_counter = SynapseCounter(
"synapse_federation_server_received_queries",
"",
labelnames=["type", SERVER_NAME_LABEL],
)

pdu_process_time = Histogram(
pdu_process_time = SynapseHistogram(
"synapse_federation_server_pdu_process_time",
"Time taken to process an event",
labelnames=[SERVER_NAME_LABEL],
)

last_pdu_ts_metric = Gauge(
last_pdu_ts_metric = SynapseGauge(
"synapse_federation_last_received_pdu_time",
"The timestamp of the last PDU which was successfully received from the given domain",
labelnames=("origin_server_name", SERVER_NAME_LABEL),
Expand Down
6 changes: 3 additions & 3 deletions synapse/federation/sender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
)

import attr
from prometheus_client import Counter

from twisted.internet import defer

Expand All @@ -160,6 +159,7 @@
from synapse.metrics import (
SERVER_NAME_LABEL,
LaterGauge,
SynapseCounter,
event_processing_loop_counter,
event_processing_loop_room_count,
events_processed_counter,
Expand All @@ -184,13 +184,13 @@

logger = logging.getLogger(__name__)

sent_pdus_destination_dist_count = Counter(
sent_pdus_destination_dist_count = SynapseCounter(
"synapse_federation_client_sent_pdu_destinations_count",
"Number of PDUs queued for sending to one or more destinations",
labelnames=[SERVER_NAME_LABEL],
)

sent_pdus_destination_dist_total = Counter(
sent_pdus_destination_dist_total = SynapseCounter(
"synapse_federation_client_sent_pdu_destinations",
"Total number of PDUs queued for sending across all destinations",
labelnames=[SERVER_NAME_LABEL],
Expand Down
7 changes: 3 additions & 4 deletions synapse/federation/sender/per_destination_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from typing import TYPE_CHECKING, Hashable, Iterable, Optional

import attr
from prometheus_client import Counter

from twisted.internet import defer

Expand All @@ -42,7 +41,7 @@
from synapse.handlers.presence import format_user_presence_state
from synapse.logging import issue9533_logger
from synapse.logging.opentracing import SynapseTags, set_tag
from synapse.metrics import SERVER_NAME_LABEL, sent_transactions_counter
from synapse.metrics import SERVER_NAME_LABEL, SynapseCounter, sent_transactions_counter
from synapse.types import JsonDict, ReadReceipt
from synapse.util.retryutils import NotRetryingDestination, get_retry_limiter
from synapse.visibility import filter_events_for_server
Expand All @@ -56,13 +55,13 @@
logger = logging.getLogger(__name__)


sent_edus_counter = Counter(
sent_edus_counter = SynapseCounter(
"synapse_federation_client_sent_edus",
"Total number of EDUs successfully sent",
labelnames=[SERVER_NAME_LABEL],
)

sent_edus_by_type = Counter(
sent_edus_by_type = SynapseCounter(
"synapse_federation_client_sent_edus_by_type",
"Number of sent EDUs successfully sent, by event type",
labelnames=["type", SERVER_NAME_LABEL],
Expand Down
6 changes: 2 additions & 4 deletions synapse/federation/sender/transaction_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import logging
from typing import TYPE_CHECKING

from prometheus_client import Gauge

from synapse.api.constants import EduTypes
from synapse.api.errors import HttpResponseException
from synapse.events import EventBase
Expand All @@ -34,7 +32,7 @@
tags,
whitelisted_homeserver,
)
from synapse.metrics import SERVER_NAME_LABEL
from synapse.metrics import SERVER_NAME_LABEL, SynapseGauge
from synapse.types import JsonDict
from synapse.util.json import json_decoder
from synapse.util.metrics import measure_func
Expand All @@ -45,7 +43,7 @@
logger = logging.getLogger(__name__)
issue_8631_logger = logging.getLogger("synapse.8631_debug")

last_pdu_ts_metric = Gauge(
last_pdu_ts_metric = SynapseGauge(
"synapse_federation_last_sent_pdu_time",
"The timestamp of the last PDU which was successfully sent to the given domain",
labelnames=("destination_server_name", SERVER_NAME_LABEL),
Expand Down
Loading
Loading