Skip to content

Commit

Permalink
Add Resource validation to Log SDK test (#1748)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored May 12, 2024
1 parent bf20372 commit 2fcd65e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions opentelemetry-sdk/src/logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@ pub use record::{LogRecord, TraceContext};
mod tests {
use super::*;
use crate::testing::logs::InMemoryLogsExporter;
use crate::Resource;
use opentelemetry::logs::LogRecord;
use opentelemetry::logs::{Logger, LoggerProvider as _, Severity};
use opentelemetry::{logs::AnyValue, Key, KeyValue};
use std::borrow::Borrow;
use std::collections::HashMap;

#[test]
fn logging_sdk_test() {
// Arrange
let resource = Resource::new(vec![
KeyValue::new("k1", "v1"),
KeyValue::new("k2", "v2"),
KeyValue::new("k3", "v3"),
KeyValue::new("k4", "v4"),
]);
let exporter: InMemoryLogsExporter = InMemoryLogsExporter::default();
let logger_provider = LoggerProvider::builder()
.with_config(Config::default().with_resource(resource.clone()))
.with_log_processor(SimpleLogProcessor::new(Box::new(exporter.clone())))
.build();

Expand Down Expand Up @@ -85,6 +94,9 @@ mod tests {
AnyValue::String(format!("value{}", i).into())
)));
}

// validate Resource
assert_eq!(&resource, log.resource.borrow());
}

#[test]
Expand Down

0 comments on commit 2fcd65e

Please sign in to comment.