-
Notifications
You must be signed in to change notification settings - Fork 105
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
Add support printing TID to logs #323
Conversation
Please update the docs accordingly. |
done |
@Superskyyy Is there any doc about introducing how to use the logger? |
Not about this particular feature, @CodePrometheus would you mind adding a small doc to this section (by adding a new subsection called something like ``printing traceID to logs". |
skywalking/loggings.py
Outdated
def getLogger(name=None): # noqa | ||
logger = logging.getLogger(name) | ||
ch = logging.StreamHandler() | ||
formatter = logging.Formatter('%(asctime)s %(name)s [pid:%(process)d] [%(threadName)s] [%(levelname)s] %(message)s') | ||
formatter = logging.Formatter('%(asctime)s %(name)s %(tid)s [pid:%(process)d] [%(threadName)s] [%(levelname)s] %(message)s') |
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.
This feature should be optional as consistent with the Java agent (see here), because not all users want tids in their logs. To achieve this behavior in Python, please introduce a new setting to control the insertion of tids and adding the additional filter.
@CodePrometheus Oh I just realized your understanding of this feature from conversation in #323 was not entirely accurate. Sorry, I should have pointed out earlier when you were confirming it. The place you put this code was wrong, |
Copy that, thanks for the reply, this is my negligence, please give me some time, I will improve this PR as soon as possible. |
No problem! I will be waiting patiently, take your time. Ping me for any help you need. |
@Superskyyy As this is a terminal output, we don't have CI to verify this. Could you review and test locally? |
@CodePrometheus Please fix CI. |
@Superskyyy Please recheck, and fix the main branch if needed. |
Yes, I have a fix coming, it is due to a upstream dependency bug in flask, I will hold the merge of this pr untill that one is fixed first. |
Thanks! The code LGTM, please regenerate the configuration documentation by running the checklist command below. I will test it locally tmr.
|
skywalking/log/sw_logging.py
Outdated
if config.agent_log_print_tid: | ||
record.tid = str(context.segment.related_traces[0]) |
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.
We add the tid
info to the record
only when agent_log_print_tid == true
, but what if I set SW_AGENT_LOG_REPORTER_LAYOUT='%(tid)s %(asctime)s [%(threadName)s] %(levelname)s %(name)s - %(message)s
but agent_log_print_tid == false
? The implementation looks unreasonable to me, we have two ways to modify the log layout which might be conflict with each other.
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.
@kezhenxu94 thanks for your comment, my opinion is:
- If and only if agent_log_print_tid=true, the agent will enable the ability to print traceId.
- When the user-defined layout has tid, but agent_log_print_tid=false, printing traceId is turned off, so I will determine whether the user's input already exists tid before changing the layout.
- Or emphasize in the document that when agent_log_print_tid=true, the layout will change accordingly.
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.
How about we make it more consistent with the Java agent, that is simply introducing the tid mechnism through the custom layout?
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.
How about we make it more consistent with the Java agent, that is simply introducing the tid mechnism through the custom layout?
This makes sense to me
CHANGELOG.md
Outdated
@@ -4,6 +4,7 @@ | |||
|
|||
- Feature: | |||
- Users now can specify the `SW_AGENT_ASYNCIO_ENHANCEMENT` environment variable to enable the performance enhancement with asyncio (#316) | |||
- Add support printing TID to logs (#323) |
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.
- Add support printing TID to logs (#323) | |
- Support printing Trace IDs (TID) to collected application logs (#323) |
|
||
## Print trace ID in your logs | ||
To print out the traceId in the logs, simply add `%(tid)s` to the `agent_log_reporter_layout`. |
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.
To print out the traceId in the logs, simply add `%(tid)s` to the `agent_log_reporter_layout`. | |
To print out the trace IDs in the logs, simply add `%(tid)s` to the `agent_log_reporter_layout`. |
skywalking/log/sw_logging.py
Outdated
@@ -75,6 +75,9 @@ def build_log_tags() -> LogTags: | |||
|
|||
context = get_context() | |||
|
|||
if 'tid' in layout: |
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.
Please check for the full %(tid)s instead of this, otherwise one may surpise you with something like tidewave.
Since tid is injected into the logging record, user could also utilize this to print out the tid in whatever channel they want other than only the reported logs to oap, this can be done using any formatter they use in their own application logic, this should be pointed out in the documentation. @CodePrometheus |
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.
LGTM
CHANGELOG.md
.