Python SDK
Python SDK
A client plus a logging handler that needs no code changes.
Install
pip install logstreemimport os
from logstreem import Logstreem
client = Logstreem(
token=os.environ["LOGSTREEM_TOKEN"],
dataset="api-gateway-prod",
)
client.log({"level": "error", "service": "checkout", "status": 503, "latency": 3814})
result = client.query("""
['api-gateway-prod']
| where status >= 500
| summarize errors = count() by service
""")
for row in result.rows:
print(row["service"], row["errors"])
client.flush()Use extra=, not f-strings
logging.error(f"pool exhausted for {service}") gives you one unqueryable string. extra={"service": service} gives you a field you can group by. It is the same amount of typing.