-
Notifications
You must be signed in to change notification settings - Fork 524
Add simple processor to integration test #2522
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 2 commits into
open-telemetry:main
from
cijothomas:cijothomas/int-test-simple
Jan 17, 2025
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 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 |
---|---|---|
|
@@ -9,7 +9,7 @@ use opentelemetry_sdk::{logs as sdklogs, Resource}; | |
use std::fs::File; | ||
use std::io::Read; | ||
|
||
fn init_logs() -> Result<sdklogs::LoggerProvider> { | ||
fn init_logs(is_simple: bool) -> Result<sdklogs::LoggerProvider> { | ||
let exporter_builder = LogExporter::builder(); | ||
#[cfg(feature = "tonic-client")] | ||
let exporter_builder = exporter_builder.with_tonic(); | ||
|
@@ -23,14 +23,22 @@ fn init_logs() -> Result<sdklogs::LoggerProvider> { | |
|
||
let exporter = exporter_builder.build()?; | ||
|
||
Ok(LoggerProvider::builder() | ||
.with_batch_exporter(exporter) | ||
let mut logger_provider_builder = LoggerProvider::builder(); | ||
if is_simple { | ||
logger_provider_builder = logger_provider_builder.with_simple_exporter(exporter) | ||
} else { | ||
logger_provider_builder = logger_provider_builder.with_batch_exporter(exporter) | ||
}; | ||
|
||
let logger_provider = logger_provider_builder | ||
.with_resource( | ||
Resource::builder_empty() | ||
.with_service_name("logs-integration-test") | ||
.build(), | ||
) | ||
.build()) | ||
.build(); | ||
|
||
Ok(logger_provider) | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -99,7 +107,7 @@ mod logtests { | |
use crate::{assert_logs_results, init_logs}; | ||
test_utils::start_collector_container().await?; | ||
|
||
let logger_provider = init_logs().unwrap(); | ||
let logger_provider = init_logs(false).unwrap(); | ||
let layer = OpenTelemetryTracingBridge::new(&logger_provider); | ||
let subscriber = tracing_subscriber::registry().with(layer); | ||
// generate a random uuid and store it to expected guid | ||
|
@@ -115,6 +123,49 @@ mod logtests { | |
Ok(()) | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)] | ||
#[cfg(any(feature = "tonic-client"))] | ||
pub async fn logs_simple_tokio_multi_thread() -> Result<()> { | ||
logs_simple_tokio_helper().await | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
#[cfg(any(feature = "tonic-client"))] | ||
pub async fn logs_simple_tokio_multi_with_one_worker() -> Result<()> { | ||
logs_simple_tokio_helper().await | ||
} | ||
|
||
// Ignored, to be investigated | ||
#[ignore] | ||
#[tokio::test(flavor = "current_thread")] | ||
#[cfg(any(feature = "tonic-client"))] | ||
pub async fn logs_simple_tokio_current() -> Result<()> { | ||
logs_simple_tokio_helper().await | ||
} | ||
|
||
async fn logs_simple_tokio_helper() -> Result<()> { | ||
use crate::{assert_logs_results, init_logs}; | ||
test_utils::start_collector_container().await?; | ||
|
||
let logger_provider = init_logs(true).unwrap(); | ||
let layer = OpenTelemetryTracingBridge::new(&logger_provider); | ||
let subscriber = tracing_subscriber::registry().with(layer); | ||
info!("Tracing initialized"); | ||
// generate a random uuid and store it to expected guid | ||
let expected_uuid = Uuid::new_v4().to_string(); | ||
{ | ||
let _guard = tracing::subscriber::set_default(subscriber); | ||
info!("Tracing subscriber initialized"); | ||
info!(target: "my-target", uuid = expected_uuid, "hello from {}. My price is {}.", "banana", 2.99); | ||
info!("Log emitted"); | ||
} | ||
|
||
let _ = logger_provider.shutdown(); | ||
tokio::time::sleep(Duration::from_secs(5)).await; | ||
assert_logs_results(test_utils::LOGS_FILE, expected_uuid.as_str())?; | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] | ||
pub fn logs_batch_non_tokio_main() -> Result<()> { | ||
|
@@ -130,7 +181,38 @@ mod logtests { | |
let logger_provider = rt.block_on(async { | ||
// While we're here setup our collector container too, as this needs tokio to run | ||
test_utils::start_collector_container().await?; | ||
init_logs() | ||
init_logs(false) | ||
})?; | ||
let layer = layer::OpenTelemetryTracingBridge::new(&logger_provider); | ||
let subscriber = tracing_subscriber::registry().with(layer); | ||
// generate a random uuid and store it to expected guid | ||
let expected_uuid = Uuid::new_v4().to_string(); | ||
{ | ||
let _guard = tracing::subscriber::set_default(subscriber); | ||
info!(target: "my-target", uuid = expected_uuid, "hello from {}. My price is {}.", "banana", 2.99); | ||
} | ||
|
||
let _ = logger_provider.shutdown(); | ||
std::thread::sleep(Duration::from_secs(5)); | ||
assert_logs_results(test_utils::LOGS_FILE, expected_uuid.as_str())?; | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] | ||
pub fn logs_simple_non_tokio_main() -> Result<()> { | ||
logs_simple_non_tokio_helper() | ||
} | ||
|
||
fn logs_simple_non_tokio_helper() -> Result<()> { | ||
// Initialize the logger provider inside a tokio runtime | ||
// as this allows tonic client to capture the runtime, | ||
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. for reqwest-blocking, this can work without outside tokio too, will add a test to cover that also in a follow up PR. |
||
// but actual export occurs from the main non-tokio thread. | ||
let rt = tokio::runtime::Runtime::new()?; | ||
let logger_provider = rt.block_on(async { | ||
// While we're here setup our collector container too, as this needs tokio to run | ||
test_utils::start_collector_container().await?; | ||
init_logs(true) | ||
})?; | ||
let layer = layer::OpenTelemetryTracingBridge::new(&logger_provider); | ||
let subscriber = tracing_subscriber::registry().with(layer); | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.