-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_generator.py
More file actions
36 lines (30 loc) · 944 Bytes
/
Copy pathlog_generator.py
File metadata and controls
36 lines (30 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
import json
import time
from datetime import datetime
log_ingestor_url = "http://localhost:3000/ingest-log"
def generate_log():
log = {
"level": "info",
"message": "Log entry",
"resourceId": "server-123",
"timestamp": datetime.utcnow().isoformat(),
"traceId": "abc-xyz-123",
"spanId": "span-456",
"commit": "5e5342f",
"metadata": {
"parentResourceId": "server-098"
}
}
return json.dumps(log)
log_count = 10
for _ in range(log_count):
log_entry = generate_log()
headers = {'Content-Type': 'application/json'}
try:
response = requests.post(log_ingestor_url, data=log_entry, headers=headers)
response.raise_for_status()
print(f"Log sent successfully: {response.text}")
except requests.exceptions.RequestException as e:
print(f"Failed to send log: {e}")
time.sleep(1)