33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""Create one known trace, then print the trace ID for Grafana Explore."""
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
from secrets import token_hex
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "tests"))
|
|
from client import Client
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--base-url", default="http://localhost:8080")
|
|
args = parser.parse_args()
|
|
client = Client(args.base_url)
|
|
actor, peer, _, chat = client.bootstrap()
|
|
trace_id = token_hex(16)
|
|
parent = token_hex(8)
|
|
image = (ROOT / "tests/fixtures/sample.png").read_bytes()
|
|
upload = client.call("POST", f"/api/v1/chats/{chat['id']}/attachments?filename=trace.png", 202,
|
|
raw=image, actor=actor, headers={"Content-Type": "image/png",
|
|
"traceparent": f"00-{trace_id}-{parent}-01"}, schema="Attachment")
|
|
ready = client.wait_ready(peer, upload["json"])
|
|
print(json.dumps({"trace_id": trace_id, "request_id": upload["headers"]["X-Request-Id"],
|
|
"status": ready["status"]}, indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|