Skip to content
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

Merged
merged 7 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Feature:
- Users now can specify the `SW_AGENT_ASYNCIO_ENHANCEMENT` environment variable to enable the performance enhancement with asyncio (#316)
- Support printing Trace IDs (TID) to collected application logs (#323)

- Plugins:
- Add neo4j plugin.(#312)
Expand Down
8 changes: 7 additions & 1 deletion docs/en/setup/advanced/LogReporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ Will result in:
}
]
}
```
```

## Print trace ID in your logs
To print out the trace IDs in the logs, simply add `%(tid)s` to the `agent_log_reporter_layout`.

You can take advantage of this feature to print out the trace IDs on any channel you desire, not limited to reporting logs to OAP,
this can be achieved by using any formatter you prefer in your own application logic.
2 changes: 0 additions & 2 deletions skywalking/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def start(self) -> None:
logger.info(f'SkyWalking sync agent instance {config.agent_instance_name} starting in pid-{os.getpid()}.')

# Install log reporter core
# TODO - Add support for printing traceID/ context in logs
if config.agent_log_reporter_active:
from skywalking import log
log.install()
Expand Down Expand Up @@ -502,7 +501,6 @@ async def __start_event_loop_async(self) -> None:
self._finished = asyncio.Event()

# Install log reporter core
# TODO - Add support for printing traceID/ context in logs
if config.agent_log_reporter_active:
from skywalking import log
log.install()
Expand Down
3 changes: 3 additions & 0 deletions skywalking/log/sw_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def build_log_tags() -> LogTags:

context = get_context()

if '%(tid)s' in layout:
record.tid = str(context.segment.related_traces[0])

active_span_id = -1
primary_endpoint_name = ''

Expand Down