-
Notifications
You must be signed in to change notification settings - Fork 522
Update OTLP examples to use opentelemetry-appender-tracing, with filtering of the events from specific crates. #1798
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
Merged
cijothomas
merged 4 commits into
open-telemetry:main
from
lalitb:tracing-appender-examples
May 22, 2024
Merged
Changes from all commits
Commits
Show all changes
4 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
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 | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,3 @@ | ||||||
use log::{info, Level}; | ||||||
use once_cell::sync::Lazy; | ||||||
use opentelemetry::global; | ||||||
use opentelemetry::logs::LogError; | ||||||
|
@@ -8,11 +7,14 @@ use opentelemetry::{ | |||||
trace::{TraceContextExt, Tracer}, | ||||||
Key, KeyValue, | ||||||
}; | ||||||
use opentelemetry_appender_log::OpenTelemetryLogBridge; | ||||||
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; | ||||||
use opentelemetry_otlp::{ExportConfig, WithExportConfig}; | ||||||
use opentelemetry_sdk::logs::Config; | ||||||
use opentelemetry_sdk::{runtime, trace as sdktrace, Resource}; | ||||||
use std::error::Error; | ||||||
use tracing::info; | ||||||
use tracing_subscriber::prelude::*; | ||||||
use tracing_subscriber::EnvFilter; | ||||||
|
||||||
static RESOURCE: Lazy<Resource> = Lazy::new(|| { | ||||||
Resource::new(vec![KeyValue::new( | ||||||
|
@@ -91,9 +93,21 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> { | |||||
let logger_provider = init_logs().unwrap(); | ||||||
|
||||||
// Create a new OpenTelemetryLogBridge using the above LoggerProvider. | ||||||
let otel_log_appender = OpenTelemetryLogBridge::new(&logger_provider); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
log::set_boxed_logger(Box::new(otel_log_appender)).unwrap(); | ||||||
log::set_max_level(Level::Info.to_level_filter()); | ||||||
let layer = OpenTelemetryTracingBridge::new(&logger_provider); | ||||||
|
||||||
// add a tracing filter to filter the events generated from the crates used by opentelemetry-otlp | ||||||
// Below filter level means: | ||||||
// - Logs at `info` level and above are allowed by default. | ||||||
// - Only `error` level logs from `hyper`, `tonic`, and `reqwest` crates are allowed. | ||||||
let filter = EnvFilter::new("info") | ||||||
.add_directive("hyper=error".parse().unwrap()) | ||||||
.add_directive("tonic=error".parse().unwrap()) | ||||||
.add_directive("reqwest=error".parse().unwrap()); | ||||||
|
||||||
tracing_subscriber::registry() | ||||||
.with(filter) | ||||||
.with(layer) | ||||||
.init(); | ||||||
|
||||||
let common_scope_attributes = vec![KeyValue::new("scope-key", "scope-value")]; | ||||||
let tracer = global::tracer_provider() | ||||||
|
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.
please add a link to the tracking issue, and also warn that, the events from this layer will be filtered for this layer irrespective of if they occur inside OTLP Exporting or not, potentially leading to blind spots.