-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into global-error-handler-cleanup-logs-sdk
- Loading branch information
Showing
22 changed files
with
384 additions
and
151 deletions.
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 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 |
---|---|---|
|
@@ -208,17 +208,20 @@ const fn severity_of_level(level: &Level) -> Severity { | |
#[cfg(test)] | ||
mod tests { | ||
use crate::layer; | ||
use opentelemetry::logs::Severity; | ||
use async_trait::async_trait; | ||
use opentelemetry::logs::{LogResult, Severity}; | ||
use opentelemetry::trace::TracerProvider as _; | ||
use opentelemetry::trace::{TraceContextExt, TraceFlags, Tracer}; | ||
use opentelemetry::{logs::AnyValue, Key}; | ||
use opentelemetry_sdk::export::logs::{LogBatch, LogExporter}; | ||
use opentelemetry_sdk::logs::{LogRecord, LoggerProvider}; | ||
use opentelemetry_sdk::testing::logs::InMemoryLogsExporter; | ||
use opentelemetry_sdk::trace; | ||
use opentelemetry_sdk::trace::{Sampler, TracerProvider}; | ||
use tracing::error; | ||
use tracing::{error, warn}; | ||
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt; | ||
use tracing_subscriber::Layer; | ||
use tracing_subscriber::util::SubscriberInitExt; | ||
use tracing_subscriber::{EnvFilter, Layer}; | ||
|
||
pub fn attributes_contains(log_record: &LogRecord, key: &Key, value: &AnyValue) -> bool { | ||
log_record | ||
|
@@ -238,6 +241,70 @@ mod tests { | |
} | ||
|
||
// cargo test --features=testing | ||
|
||
#[derive(Clone, Debug, Default)] | ||
struct ReentrantLogExporter; | ||
|
||
#[async_trait] | ||
impl LogExporter for ReentrantLogExporter { | ||
async fn export(&mut self, _batch: LogBatch<'_>) -> LogResult<()> { | ||
// This will cause a deadlock as the export itself creates a log | ||
// while still within the lock of the SimpleLogProcessor. | ||
warn!(name: "my-event-name", target: "reentrant", event_id = 20, user_name = "otel", user_email = "[email protected]"); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[test] | ||
#[ignore = "See issue: https://github.com/open-telemetry/opentelemetry-rust/issues/1745"] | ||
fn simple_processor_deadlock() { | ||
let exporter: ReentrantLogExporter = ReentrantLogExporter; | ||
let logger_provider = LoggerProvider::builder() | ||
.with_simple_exporter(exporter.clone()) | ||
.build(); | ||
|
||
let layer = layer::OpenTelemetryTracingBridge::new(&logger_provider); | ||
|
||
// Setting subscriber as global as that is the only way to test this scenario. | ||
tracing_subscriber::registry().with(layer).init(); | ||
warn!(name: "my-event-name", target: "my-system", event_id = 20, user_name = "otel", user_email = "[email protected]"); | ||
} | ||
|
||
#[test] | ||
#[ignore = "While this test runs fine, this uses global subscriber and does not play well with other tests."] | ||
fn simple_processor_no_deadlock() { | ||
let exporter: ReentrantLogExporter = ReentrantLogExporter; | ||
let logger_provider = LoggerProvider::builder() | ||
.with_simple_exporter(exporter.clone()) | ||
.build(); | ||
|
||
let layer = layer::OpenTelemetryTracingBridge::new(&logger_provider); | ||
|
||
// This filter will prevent the deadlock as the reentrant log will be | ||
// ignored. | ||
let filter = EnvFilter::new("debug").add_directive("reentrant=error".parse().unwrap()); | ||
// Setting subscriber as global as that is the only way to test this scenario. | ||
tracing_subscriber::registry() | ||
.with(filter) | ||
.with(layer) | ||
.init(); | ||
warn!(name: "my-event-name", target: "my-system", event_id = 20, user_name = "otel", user_email = "[email protected]"); | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
#[ignore = "While this test runs fine, this uses global subscriber and does not play well with other tests."] | ||
async fn batch_processor_no_deadlock() { | ||
let exporter: ReentrantLogExporter = ReentrantLogExporter; | ||
let logger_provider = LoggerProvider::builder() | ||
.with_batch_exporter(exporter.clone(), opentelemetry_sdk::runtime::Tokio) | ||
.build(); | ||
|
||
let layer = layer::OpenTelemetryTracingBridge::new(&logger_provider); | ||
|
||
tracing_subscriber::registry().with(layer).init(); | ||
warn!(name: "my-event-name", target: "my-system", event_id = 20, user_name = "otel", user_email = "[email protected]"); | ||
} | ||
|
||
#[test] | ||
fn tracing_appender_standalone() { | ||
// Arrange | ||
|
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 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 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 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 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 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.