Skip to content

Commit fee9dbe

Browse files
committed
feat: remove env var auto-reads, hardcode flush interval to 60s, rename internal param
1 parent 6a1974d commit fee9dbe

4 files changed

Lines changed: 8 additions & 11 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ app.add_middleware(
5555
ApiForgeMiddleware,
5656
db_path=".apiforge.db",
5757
dashboard_port=4242, # set to 0 to disable
58-
flush_interval=60_000, # aggregate and flush every 60s (ms)
5958
env="production",
6059
release="v1.4.0", # enables release regression detection
6160
service="user-service",

apiforgepy/__init__.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""
1616

1717
import atexit
18-
import os
1918

2019
from .aggregator import Aggregator
2120
from .database import ApiForgeDatabase
@@ -39,9 +38,8 @@ class ApiForgeMiddleware(_Base):
3938
api_key: Cloud mode: project API key starting with 'af_'.
4039
db_path: Local mode: SQLite file path. Default: '.apiforge.db'.
4140
dashboard_port: Local mode: dashboard port. 0 = disabled. Default: 4242.
42-
flush_interval: Aggregation flush interval in ms. Default: 60 000.
43-
env: Environment label. Default: ENV env var or 'production'.
44-
release: Release tag. Default: APP_VERSION env var.
41+
env: Environment label. Default: 'production'.
42+
release: Release tag. Default: None.
4543
service: Service name. Default: 'default'.
4644
sampling: Sample rate 0.0–1.0. Default: 1.0.
4745
ignore_paths: Paths to exclude. Default: ['/favicon.ico'].
@@ -55,12 +53,12 @@ def __init__(
5553
api_key: str | None = None,
5654
db_path: str = ".apiforge.db",
5755
dashboard_port: int = 4242,
58-
flush_interval: int = 60_000,
5956
env: str | None = None,
6057
release: str | None = None,
6158
service: str = "default",
6259
sampling: float = 1.0,
6360
ignore_paths: list[str] = None,
61+
_flush_interval: int = 60_000, # internal — not part of the public API
6462
):
6563
is_cloud = bool(cloud_url and api_key)
6664

@@ -69,8 +67,8 @@ def __init__(
6967

7068
config = {
7169
"mode": "cloud" if is_cloud else "local",
72-
"env": env or os.environ.get("ENV", "production"),
73-
"release": release or os.environ.get("APP_VERSION"),
70+
"env": env or "production",
71+
"release": release,
7472
"service": service,
7573
"sampling": sampling,
7674
"ignore_paths": ignore_paths or ["/favicon.ico"],
@@ -88,7 +86,7 @@ def __init__(
8886
transport = LocalTransport(self._db)
8987
config["store_routes"] = self._db.upsert_known_routes
9088

91-
aggregator = Aggregator(transport, flush_interval)
89+
aggregator = Aggregator(transport, _flush_interval)
9290
aggregator.start()
9391

9492
if not is_cloud and dashboard_port:

tests/test_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def make_app(db_path=":memory:", sampling=1.0, ignore_paths=None):
1111
ApiForgeMiddleware,
1212
db_path=db_path,
1313
dashboard_port=0,
14-
flush_interval=999_999,
14+
_flush_interval=999_999,
1515
sampling=sampling,
1616
ignore_paths=ignore_paths or [],
1717
)

tests/test_smoke.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def make_app(db_path=":memory:"):
1111
ApiForgeMiddleware,
1212
db_path=db_path,
1313
dashboard_port=0,
14-
flush_interval=999_999,
14+
_flush_interval=999_999,
1515
)
1616

1717
@app.get("/health")

0 commit comments

Comments
 (0)