feat: Implemented observability layer and benchmarking

This commit is contained in:
2026-07-03 11:20:23 +05:30
parent 9713a12591
commit c9ec297a5f
7 changed files with 202 additions and 101 deletions

View File

@@ -0,0 +1,53 @@
import pytest
import asyncio
from app.core.observability import benchmark, time_it
def test_benchmark_context_manager(caplog):
import logging
with caplog.at_level(logging.INFO):
with benchmark("Test Task"):
# simulate work
pass
assert any(
"[BENCHMARK] Test Task completed in" in record.message
for record in caplog.records
)
def test_time_it_decorator_sync(caplog):
import logging
@time_it("Sync Helper")
def my_sync_fn(x, y):
return x + y
with caplog.at_level(logging.INFO):
res = my_sync_fn(10, 20)
assert res == 30
assert any(
"[BENCHMARK] Sync Helper completed in" in record.message
for record in caplog.records
)
@pytest.mark.asyncio
async def test_time_it_decorator_async(caplog):
import logging
@time_it("Async Helper")
async def my_async_fn():
await asyncio.sleep(0.01)
return "done"
with caplog.at_level(logging.INFO):
res = await my_async_fn()
assert res == "done"
assert any(
"[BENCHMARK] Async Helper completed in" in record.message
for record in caplog.records
)