Skip to content

Commit

Permalink
Replace fastapi with Starlette
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanderlee committed Jan 8, 2024
1 parent b645ccb commit da344ce
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ keywords = ["prometheus", "instrumentation", "fastapi", "exporter", "metrics"]

[tool.poetry.dependencies]
python = ">= 3.7.0, < 4.0.0"
fastapi = ">= 0.38.1, < 1.0.0"
starlette = ">= 0.30.0, < 1.0.0"
prometheus-client = ">= 0.8.0, < 1.0.0"

[tool.poetry.group.dev.dependencies]
Expand Down
18 changes: 9 additions & 9 deletions src/prometheus_fastapi_instrumentator/instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from enum import Enum
from typing import Any, Awaitable, Callable, List, Optional, Sequence, Union, cast

from fastapi import FastAPI
from prometheus_client import (
CONTENT_TYPE_LATEST,
REGISTRY,
CollectorRegistry,
generate_latest,
multiprocess,
)
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import Response

Expand All @@ -40,7 +40,7 @@ def __init__(
inprogress_labels: bool = False,
registry: Union[CollectorRegistry, None] = None,
) -> None:
"""Create a Prometheus FastAPI Instrumentator.
"""Create a Prometheus Starlette Instrumentator.
Args:
should_group_status_codes (bool): Should status codes be grouped into
Expand All @@ -60,7 +60,7 @@ def __init__(
should_respect_env_var (bool): Should the instrumentator only work - for
example the methods `instrument()` and `expose()` - if a
certain environment variable is set to `true`? Usecase: A base
FastAPI app that is used by multiple distinct apps. The apps
Starlette app that is used by multiple distinct apps. The apps
only have to set the variable to be instrumented. Defaults to
`False`.
Expand Down Expand Up @@ -149,7 +149,7 @@ def __init__(

def instrument(
self,
app: FastAPI,
app: Starlette,
metric_namespace: str = "",
metric_subsystem: str = "",
should_only_respect_2xx_for_highr: bool = False,
Expand Down Expand Up @@ -183,10 +183,10 @@ def instrument(
The middleware iterates through all `instrumentations` and executes them.
Args:
app (FastAPI): FastAPI app instance.
app (Starlette): Starlette app instance.
Raises:
e: Only raised if FastAPI itself throws an exception.
e: Only raised if Starlette itself throws an exception.
Returns:
self: Instrumentator. Builder Pattern.
Expand Down Expand Up @@ -222,7 +222,7 @@ def instrument(

def expose(
self,
app: FastAPI,
app: Starlette,
should_gzip: bool = False,
endpoint: str = "/metrics",
include_in_schema: bool = True,
Expand All @@ -232,7 +232,7 @@ def expose(
"""Exposes endpoint for metrics.
Args:
app: FastAPI app instance. Endpoint will be added to this app.
app: Starlette app instance. Endpoint will be added to this app.
should_gzip: Should the endpoint return compressed data? It will
also check for `gzip` in the `Accept-Encoding` header.
Expand All @@ -247,7 +247,7 @@ def expose(
tags (List[str], optional): If you manage your routes with tags.
Defaults to None.
kwargs: Will be passed to FastAPI route annotation.
kwargs: Will be passed to Starlette route annotation.
Returns:
self: Instrumentator. Builder Pattern.
Expand Down
2 changes: 1 addition & 1 deletion src/prometheus_fastapi_instrumentator/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def latency(
buckets: Sequence[Union[float, str]] = Histogram.DEFAULT_BUCKETS,
registry: CollectorRegistry = REGISTRY,
) -> Optional[Callable[[Info], None]]:
"""Default metric for the Prometheus FastAPI Instrumentator.
"""Default metric for the Prometheus Starlette Instrumentator.
Args:
metric_name (str, optional): Name of the metric to be created. Must be
Expand Down
4 changes: 2 additions & 2 deletions src/prometheus_fastapi_instrumentator/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from timeit import default_timer
from typing import Awaitable, Callable, Optional, Sequence, Tuple, Union

from fastapi import FastAPI
from prometheus_client import REGISTRY, CollectorRegistry, Gauge
from starlette.applications import Starlette
from starlette.datastructures import Headers
from starlette.requests import Request
from starlette.responses import Response
Expand All @@ -19,7 +19,7 @@
class PrometheusInstrumentatorMiddleware:
def __init__(
self,
app: FastAPI,
app: Starlette,
*,
should_group_status_codes: bool = True,
should_ignore_untemplated: bool = False,
Expand Down

0 comments on commit da344ce

Please sign in to comment.