unioslo / mreg-cli

Command Line Interface for Mreg
GNU General Public License v3.0
2 stars 7 forks source link

Use corrolation_id for logging across commands. #213

Closed terjekv closed 8 months ago

terjekv commented 8 months ago

This PR sets the corrolation-id sent to the mreg server per command, and the mreg server then logs it like this (well, for console view, it's less pretty otherwise (see https://github.com/unioslo/mreg/pull/515) for more information.

In short, this ensures that multiple requests performed by the same command will have the same correlation-id set by reg-cli, and this id is an uuidv4 plus the command issued (where spaces are substituted for _).

2024-02-21T11:55:44.797346Z [info     ]  • request          request_id=eda...3cc method=GET remote_ip=127.0.0.1 proxy_ip= path=/api/v1/hosts/foo.bar.com request_size=0 content= correlation_id=515a1d8d-4511-4cd0-8eb8-b0f34a59e544-host_info_foo.bar.com lineno=111 filename=logging_http.py func_name=log_request
2024-02-21T11:55:44.925721Z [info     ]  • updated          request_id=eda...3cc model=ExpiringToken id=7d4...b0e _str=7d4...b0e correlation_id=515a1d8d-4511-4cd0-8eb8-b0f34a59e544-host_info_foo.bar.com lineno=448 filename=signals.py func_name=_log_object_event
2024-02-21T11:55:44.937297Z [warning  ]  • response         request_id=eda...3cc user=test method=GET status_code=404 status_label=Not Found path=/api/v1/hosts/foo.bar.com content={"detail":"Not found."} run_time_ms=140.77 correlation_id=515a1d8d-4511-4cd0-8eb8-b0f34a59e544-host_info_foo.bar.com lineno=156 filename=logging_http.py func_name=log_response
2024-02-21T11:55:44.945056Z [info     ]  • request          request_id=26f...45d method=GET remote_ip=127.0.0.1 proxy_ip= path=/api/v1/hosts/ request_size=0 content= correlation_id=515a1d8d-4511-4cd0-8eb8-b0f34a59e544-host_info_foo.bar.com lineno=111 filename=logging_http.py func_name=log_request
2024-02-21T11:55:45.025543Z [info     ]  • updated          request_id=26f...45d model=ExpiringToken id=7d4...b0e _str=7d4...b0e correlation_id=515a1d8d-4511-4cd0-8eb8-b0f34a59e544-host_info_foo.bar.com lineno=448 filename=signals.py func_name=_log_object_event
2024-02-21T11:55:45.037113Z [info     ]  • response         request_id=26f...45d user=test method=GET status_code=200 status_label=OK path=/api/v1/hosts/ content={"count":0,"next":null,"previous":null,"results":[]} run_time_ms=92.24 correlation_id=515a1d8d-4511-4cd0-8eb8-b0f34a59e544-host_info_foo.bar.com lineno=156 filename=logging_http.py func_name=log_response