import os
import urllib.request
import json
def ingest(entries: list) -> None:
body = json.dumps(entries).encode()
req = urllib.request.Request(
"https://api.streamlogia.com/v1/ingest",
data=body,
headers={
"Authorization": f"Bearer {os.environ['LOGINGESTOR_API_KEY']}",
"Content-Type": "application/json",
},
method="POST",
)
with urllib.request.urlopen(req, timeout=5) as resp:
if resp.status >= 400:
raise RuntimeError(f"ingest failed with status {resp.status}")
ingest([{
"projectId": os.environ["LOGINGESTOR_PROJECT_ID"],
"level": "INFO",
"message": "Hello, Streamlogia!",
"source": "my-service",
"timestamp": "2024-01-01T00:00:00Z",
"tags": [],
"meta": {},
}])