-
Notifications
You must be signed in to change notification settings - Fork 482
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
Simplified self-diagnostics example #2274
Merged
cijothomas
merged 2 commits into
open-telemetry:main
from
cijothomas:cijothomas/selfdiag-simplifired
Nov 5, 2024
Merged
Changes from all commits
Commits
Show all changes
2 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 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 was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,93 +1,28 @@ | ||
# Basic OpenTelemetry metrics example with custom error handler: | ||
|
||
This example shows how to setup the custom error handler for self-diagnostics. | ||
|
||
## Custom Error Handling: | ||
|
||
A custom error handler is set up to capture and record errors using the `tracing` crate's `error!` macro. These errors are then exported to a collector using the `opentelemetry-appender-tracing` crate, which utilizes the OTLP log exporter over `HTTP/protobuf`. As a result, any errors generated by the configured OTLP metrics pipeline are funneled through this custom error handler for proper recording and export. | ||
This example shows how to self-diagnose OpenTelemetry by enabling its internal | ||
logs. OpenTelemetry crates publish internal logs when "internal-logs" feature is | ||
enabled. This feature is enabled by default. Internal logs are published using | ||
`tracing` events, and hence, a `tracing` subscriber must be configured without | ||
which the logs are simply discarded. | ||
|
||
## Filtering logs from external dependencies of OTLP Exporter: | ||
|
||
The example configures a tracing `filter` to restrict logs from external crates (`hyper`, `tonic`, and `reqwest`) used by the OTLP Exporter to the `error` level. This helps prevent an infinite loop of log generation when these crates emit logs that are picked up by the tracing subscriber. | ||
|
||
## Ensure that the internally generated errors are logged only once: | ||
|
||
By using a hashset to track seen errors, the custom error handler ensures that the same error is not logged multiple times. This is particularly useful for handling scenarios where continuous error logging might occur, such as when the OpenTelemetry collector is not running. | ||
|
||
|
||
## Usage | ||
|
||
### `docker-compose` | ||
|
||
By default runs against the `otel/opentelemetry-collector:latest` image, and uses `reqwest-client` | ||
as the http client, using http as the transport. | ||
|
||
```shell | ||
docker-compose up | ||
``` | ||
|
||
In another terminal run the application `cargo run` | ||
|
||
The docker-compose terminal will display logs, traces, metrics. | ||
|
||
Press Ctrl+C to stop the collector, and then tear it down: | ||
|
||
```shell | ||
docker-compose down | ||
``` | ||
|
||
### Manual | ||
|
||
If you don't want to use `docker-compose`, you can manually run the `otel/opentelemetry-collector` container | ||
and inspect the logs to see traces being transferred. | ||
|
||
On Unix based systems use: | ||
|
||
```shell | ||
# From the current directory, run `opentelemetry-collector` | ||
docker run --rm -it -p 4318:4318 -v $(pwd):/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml | ||
``` | ||
|
||
On Windows use: | ||
|
||
```shell | ||
# From the current directory, run `opentelemetry-collector` | ||
docker run --rm -it -p 4318:4318 -v "%cd%":/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml | ||
``` | ||
|
||
Run the app which exports logs, metrics and traces via OTLP to the collector | ||
|
||
```shell | ||
cargo run | ||
``` | ||
|
||
### Output: | ||
|
||
- If the docker instance for collector is running, below error should be logged into the container. There won't be any logs from the `hyper`, `reqwest` and `tonic` crates. | ||
``` | ||
otel-collector-1 | 2024-06-05T17:09:46.926Z info LogExporter {"kind": "exporter", "data_type": "logs", "name": "logging", "resource logs": 1, "log records": 1} | ||
otel-collector-1 | 2024-06-05T17:09:46.926Z info ResourceLog #0 | ||
otel-collector-1 | Resource SchemaURL: | ||
otel-collector-1 | Resource attributes: | ||
otel-collector-1 | -> telemetry.sdk.name: Str(opentelemetry) | ||
otel-collector-1 | -> telemetry.sdk.version: Str(0.23.0) | ||
otel-collector-1 | -> telemetry.sdk.language: Str(rust) | ||
otel-collector-1 | -> service.name: Str(unknown_service) | ||
otel-collector-1 | ScopeLogs #0 | ||
otel-collector-1 | ScopeLogs SchemaURL: | ||
otel-collector-1 | InstrumentationScope opentelemetry-appender-tracing 0.4.0 | ||
otel-collector-1 | LogRecord #0 | ||
otel-collector-1 | ObservedTimestamp: 2024-06-05 17:09:45.931951161 +0000 UTC | ||
otel-collector-1 | Timestamp: 1970-01-01 00:00:00 +0000 UTC | ||
otel-collector-1 | SeverityText: ERROR | ||
otel-collector-1 | SeverityNumber: Error(17) | ||
otel-collector-1 | Body: Str(OpenTelemetry metrics error occurred: Metrics error: Warning: Maximum data points for metric stream exceeded. Entry added to overflow. Subsequent overflows to same metric until next collect will not be logged.) | ||
otel-collector-1 | Attributes: | ||
otel-collector-1 | -> name: Str(event examples/self-diagnostics/src/main.rs:42) | ||
otel-collector-1 | Trace ID: | ||
otel-collector-1 | Span ID: | ||
otel-collector-1 | Flags: 0 | ||
otel-collector-1 | {"kind": "exporter", "data_type": "logs", "name": "logging"} | ||
``` | ||
|
||
- The SDK will keep trying to upload metrics at regular intervals if the collector's Docker instance is down. To avoid a logging loop, internal errors like 'Connection refused' will be attempted to be logged only once. | ||
The example configures a tracing `filter` to restrict logs from external crates | ||
(`hyper`, `tonic`, and `reqwest` etc.) used by the OTLP Exporter to the `error` | ||
level. This helps prevent an infinite loop of log generation when these crates | ||
emit logs that are picked up by the tracing subscriber. This is only a | ||
workaround until [the root | ||
issue](https://github.com/open-telemetry/opentelemetry-rust/issues/761) is | ||
resolved. | ||
|
||
## Filtering logs to be send to OpenTelemetry itself | ||
|
||
If you use [OpenTelemetry Tracing | ||
Appender](../../opentelemetry-appender-tracing/README.md) to send `tracing` logs | ||
to OpenTelemetry, then enabling OpenTelemetry internal logs can also cause | ||
infinite, recursive logging. You can filter out all OpenTelemetry internal logs | ||
from being sent to [OpenTelemetry Tracing | ||
Appender](../../opentelemetry-appender-tracing/README.md) using a filter, like | ||
"add_directive("opentelemetry=off".parse().unwrap())" being done for tracing's | ||
`FmtSubscriber`. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.
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.
we can remove this filter if none of these transport dependencies are used in the example.
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.
let me move it to the otlp examples, so when users face this issue, they have something to easily refer to, to mitigate the infinite logs problem.
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.
will add this shortly in a follow up PR.