-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Introduce logging context to Tangle #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
45fca00 to
c08c8f2
Compare
|
Thank you for this PR. I'm reviewing the changes and I think we might want to design this slightly differently. On the other hand, API requests might benefit from trace IDs so that all logging messages that are generated when processing a single API call can be filtered and grouped together. |
This sounds good to me. I will make some adjustments. Thanks! |
c08c8f2 to
e824f64
Compare
2bfcc23 to
4e7b1a3
Compare
The work has been re-designed. Here is a summary: Logging Context ImprovementsSummaryEnhanced the Tangle orchestrator logging to automatically include execution context (execution_id, container_execution_id) in all log messages, making it easier to trace and filter logs for specific executions. Changes Made1. Added Logging Context to Orchestrator (
|
Ark-kun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. This looks pretty good.
I've left some comments and approved it.
4e7b1a3 to
f684007
Compare
d6101f4 to
f0a7c32
Compare
| ) | ||
| session.commit() | ||
| finally: | ||
| duration_ms = int((time.monotonic_ns() - start_timestamp) / 1_000_000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Are you sure we no longer need to log processing times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I restored duration. It should have been removed yet. Maybe in the future when we have a replacement solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out
|
|
||
| # Set execution context for logging (includes container_execution_id) | ||
| # Get first execution_node_id for context (there may be multiple nodes using same container) | ||
| execution_nodes = running_container_execution.execution_nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that you're slightly changing the logic here by making SQL queries outside the try/except context. If an exception occurs, it will go up the stack.
You might want to swap try and with contexts.
Also, AFAIK, the code now always queries the ExecutionNodes DB table whereas before it would only do that when needed. This is likely not affecting perf too much but I'd like you to understand the changes you're making (basically, you add and extra DB query to extract more information from the DB for the purpose of logging it.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will review this area again. My editor during development of this portion was not behaving very well, telling me the code was wrong (showing warnings) and I remember it was difficult for me satisfy. Maybe, this lead to this difference in behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, AFAIK, the code now always queries the ExecutionNodes DB table whereas before it would only do that when needed. This is likely not affecting perf too much but I'd like you to understand the changes you're making (basically, you add and extra DB query to extract more information from the DB for the purpose of logging it.).
Thank you. I do understand this.
I'm curious, would you prefer to take any other approach such as passing metadata around differently to avoid a DB call? Open to any better ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pairing. I have implemented the changes we discussed:
- Singular
withblockwith contextual_logging.logging_context( container_execution_id=running_container_execution.id, execution_node_ids=execution_node_ids, ):
- Moving the execution_node_ids select we wrote above / outside the try catch
Also:
- Restored duration tracking
2aa126b to
c251f3d
Compare
**Changes:**
* Adds logging context helpers
* Add request middleware to generate unique request id and set it in the logging context around API requests
* Sets the x-tangle-request-id on the response for client consumption
c251f3d to
cc58b41
Compare
Issue
#67
Changes:
extrasparameterextrasparameter, or creating a new one if None)Test pipeline notes:
ytest,starlette,httpx(e.g.pip3 install ...)