diff --git a/src/sentry/sentry_metrics/metrics_interface.py b/src/sentry/sentry_metrics/metrics_interface.py new file mode 100644 index 0000000000000..fbca6050d4cf8 --- /dev/null +++ b/src/sentry/sentry_metrics/metrics_interface.py @@ -0,0 +1,64 @@ +from abc import ABC, abstractmethod +from typing import Mapping, Optional, Sequence, Union + +from sentry.sentry_metrics.use_case_id_registry import UseCaseID + + +class GenericMetricsBackend(ABC): + @abstractmethod + def counter( + self, + use_case_id: UseCaseID, + org_id: int, + project_id: int, + metric_name: str, + value: Union[int, float], + unit: Optional[str], + tags: Mapping[str, str], + ) -> None: + + """ + Used for emitting a counter metric for internal use cases only. + Ensure that the use_case_id passed in has been registered + in the UseCaseID enum. + """ + + raise NotImplementedError() + + @abstractmethod + def set( + self, + use_case_id: UseCaseID, + org_id: int, + project_id: int, + metric_name: str, + value: Sequence[int], + unit: Optional[str], + tags: Mapping[str, str], + ) -> None: + + """ + Used for emitting a set metric for internal use cases only. Can support + a sequence of values. Ensure that the use_case_id passed in has + been registered in the UseCaseID enum. + """ + raise NotImplementedError() + + @abstractmethod + def distribution( + self, + use_case_id: UseCaseID, + org_id: int, + project_id: int, + metric_name: str, + value: Sequence[Union[int, float]], + unit: Optional[str], + tags: Mapping[str, str], + ) -> None: + + """ + Used for emitting a distribution metric for internal use cases only. Can + support a sequence of values. Ensure that the use_case_id passed in + has been registered in the UseCaseID enum. + """ + raise NotImplementedError() diff --git a/src/sentry/sentry_metrics/use_case_id_registry.py b/src/sentry/sentry_metrics/use_case_id_registry.py new file mode 100644 index 0000000000000..619c59417401b --- /dev/null +++ b/src/sentry/sentry_metrics/use_case_id_registry.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +from enum import Enum +from typing import Mapping + +from sentry.sentry_metrics.configuration import UseCaseKey + + +class UseCaseID(Enum): + TRANSACTIONS = "transactions" + SESSIONS = "sessions" + + +# UseCaseKey will be renamed to MetricPathKey +METRIC_PATH_MAPPING: Mapping[UseCaseID, UseCaseKey] = { + UseCaseID.SESSIONS: UseCaseKey.RELEASE_HEALTH, + UseCaseID.TRANSACTIONS: UseCaseKey.PERFORMANCE, +} + + +def get_metric_path_from_usecase(use_case: UseCaseID) -> UseCaseKey: + return METRIC_PATH_MAPPING[use_case]