-
Notifications
You must be signed in to change notification settings - Fork 110
single doc for python logging #1891
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
Open
Calm-Rock
wants to merge
5
commits into
main
Choose a base branch
from
python-logs-docs-improvement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| --- | ||
| date: 2025-09-01 | ||
| title: Sending Python Logs | ||
| id: python-logs | ||
| hide_table_of_contents: true | ||
| --- | ||
|
|
||
| You can send Python logs to SigNoz using Auto instrumentation which is the fast, no code change way to send logs to SigNoz. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - A [auto-instrumented](https://signoz.io/docs/instrumentation/opentelemetry-python/#send-traces-directly-to-signoz-cloud) python application with logging implemented | ||
|
|
||
| ## Setup | ||
|
|
||
| ### Step 1: Instrument your application | ||
|
|
||
| Follow the steps in our [Python instrumentation document](https://signoz.io/docs/instrumentation/opentelemetry-python/#send-traces-directly-to-signoz-cloud) to auto-instrument your application. | ||
|
|
||
|
|
||
| ### Step 2: Run your application | ||
|
|
||
| Now, run your application with the following environment variables set: | ||
|
|
||
| ```bash | ||
| OTEL_SERVICE_NAME=<service_name> \ | ||
| OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.<region>.signoz.cloud:443" \ | ||
| OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key=<your-ingestion-key>" \ | ||
| OTEL_EXPORTER_OTLP_PROTOCOL=grpc \ | ||
| OTEL_TRACES_EXPORTER=otlp \ | ||
| OTEL_LOGS_EXPORTER=otlp \ | ||
| OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true \ | ||
| opentelemetry-instrument <your_run_command> | ||
| ``` | ||
|
|
||
| This attaches an OTLP log handler, injects trace context into each log record. This will allow you to correlate logs with traces. | ||
|
|
||
| - `OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED` when set to `true` will [attach the OTLP log handler](https://opentelemetry.io/docs/zero-code/python/configuration/#logging) to the root logger. That is what sends the logs out. | ||
|
|
||
|
|
||
| <figure data-zoomable align='center'> | ||
| <img src="/img/docs/traces-management/correlate-traces-with-logs.gif" alt="Correlated Logs and Traces"/> | ||
| <figcaption><i>Correlated Logs and Traces</i></figcaption> | ||
| </figure> | ||
|
|
||
|
|
||
| ## Python application on Kubernetes | ||
|
|
||
| If your application is running on Kubernetes, you can use the [k8s-infra-chart](https://signoz.io/docs/collection-agents/k8s/k8s-infra/install-k8s-infra/) to get your logs directly to SigNoz. | ||
|
|
||
| The chart has [presets.logsCollection.enabled](https://signoz.io/docs/collection-agents/k8s/k8s-infra/configure-k8s-infra/#3-container-log-collection) property to **true** which adds a `filelogreceiver`. This receiver is configured to read the files where Kubernetes | ||
| container runtime writes all containers console output **(/var/log/pods/*/*/*.log)**. | ||
|
|
||
| ### Parse attributes | ||
|
|
||
| Once you have the logs in SigNoz, you can parse different attributes from the log body using [Logs Pipelines](https://signoz.io/docs/logs-pipelines/introduction/). | ||
| Logs pipelines give you the ability to pre-process logs by providing you with a number of [log processors](https://signoz.io/docs/logs-pipelines/processors/). | ||
| Checkout [these guides](https://signoz.io/docs/category/guides/) to learn how you can use logs pipelines for different use-cases. | ||
|
|
||
| ## Fine Grained Control | ||
|
|
||
| If you need more control over your logging, you can use the OpenTelemetry Python SDK to manually instrument your application. It provides a handler that can be used to transport logs to any OTLP-compatible backend. | ||
|
|
||
| Here are some references to get you started with manual instrumentation: | ||
| - [Configure OTel logs SDK in Python](https://signoz.io/opentelemetry/logging-in-python/) part of implementing OTel in Python applications [series](https://signoz.io/opentelemetry/python-overview/) | ||
| - Official OpenTelemetry [SDK example for python](https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples/logs) logs | ||
| - OpenTelemetry [docs for python instrumentation](https://opentelemetry.io/docs/languages/python/instrumentation/#logs) logs section | ||
67 changes: 0 additions & 67 deletions
67
data/docs/userguide/collecting_application_logs_otel_sdk_python.mdx
This file was deleted.
Oops, something went wrong.
100 changes: 0 additions & 100 deletions
100
data/docs/userguide/python-logs-auto-instrumentation.mdx
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 prerequisite is not valid when user is on k8s and don't want to instrument app