Skip to content

Commit

Permalink
Move inmemory exporter for logs to diff namespace (#2538)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Jan 23, 2025
1 parent 5935cca commit fdf4a63
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion opentelemetry-appender-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ mod tests {
use super::OpenTelemetryLogBridge;

use opentelemetry::{logs::AnyValue, StringValue};
use opentelemetry_sdk::{logs::LoggerProvider, testing::logs::InMemoryLogExporter};
use opentelemetry_sdk::{logs::InMemoryLogExporter, logs::LoggerProvider};

use log::Log;

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-appender-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ mod tests {
use opentelemetry::trace::TracerProvider as _;
use opentelemetry::trace::{TraceContextExt, TraceFlags, Tracer};
use opentelemetry::{logs::AnyValue, Key};
use opentelemetry_sdk::logs::InMemoryLogExporter;
use opentelemetry_sdk::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogRecord, LogResult, LoggerProvider};
use opentelemetry_sdk::testing::logs::InMemoryLogExporter;
use opentelemetry_sdk::trace::{Sampler, TracerProvider};
use tracing::{error, warn};
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
Expand Down
13 changes: 10 additions & 3 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,26 @@ hardcoded limit of 2000 and no ability to change it. This feature will be
re-introduced in a future date, along with the ability to change the cardinality
limit.


- *Breaking* (Affects custom Exporter authors only) Moved `ExportError` trait from `opentelemetry::export::ExportError` to `opentelemetry_sdk::ExportError`
- *Breaking (Affects custom SpanExporter, SpanProcessor authors only)*: Rename namespaces
- *Breaking (Affects custom SpanExporter, SpanProcessor authors only)*: Rename namespaces for Span exporter structs/traits
before:
`opentelemetry_sdk::export::spans::{ExportResult, SpanData, SpanExporter};`
now:
`opentelemetry_sdk::logs::{ExportResult, SpanData, SpanExporter};`
`opentelemetry_sdk::spans::{ExportResult, SpanData, SpanExporter};`

- *Breaking (Affects custom LogExporter, LogProcessor authors only)*: Rename namespaces
- *Breaking (Affects custom LogExporter, LogProcessor authors only)*: Rename namespaces for Log exporter structs/traits.
before:
`opentelemetry_sdk::export::logs::{ExportResult, LogBatch, LogExporter};`
now:
`opentelemetry_sdk::logs::{ExportResult, LogBatch, LogExporter};`

- *Breaking*: Rename namespaces for InMemoryExporters. (The module is still under "testing" feature flag)
before:
`opentelemetry_sdk::testing::logs::{InMemoryLogExporter, InMemoryLogExporterBuilder};`
now:
`opentelemetry_sdk::logs::{InMemoryLogExporter, InMemoryLogExporterBuilder};`

## 0.27.1

Released 2024-Nov-27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::{Arc, Mutex};
/// ```no_run
///# use opentelemetry_sdk::logs::{BatchLogProcessor, LoggerProvider};
///# use opentelemetry_sdk::runtime;
///# use opentelemetry_sdk::testing::logs::InMemoryLogExporter;
///# use opentelemetry_sdk::logs::InMemoryLogExporter;
///
///# #[tokio::main]
///# async fn main() {
Expand Down Expand Up @@ -72,7 +72,7 @@ pub struct LogDataWithResource {
/// # Example
///
/// ```no_run
///# use opentelemetry_sdk::testing::logs::{InMemoryLogExporter, InMemoryLogExporterBuilder};
///# use opentelemetry_sdk::logs::{InMemoryLogExporter, InMemoryLogExporterBuilder};
///# use opentelemetry_sdk::logs::{BatchLogProcessor, LoggerProvider};
///# use opentelemetry_sdk::runtime;
///
Expand Down Expand Up @@ -139,7 +139,7 @@ impl InMemoryLogExporter {
/// # Example
///
/// ```
/// use opentelemetry_sdk::testing::logs::{InMemoryLogExporter, InMemoryLogExporterBuilder};
/// use opentelemetry_sdk::logs::{InMemoryLogExporter, InMemoryLogExporterBuilder};
///
/// let exporter = InMemoryLogExporterBuilder::default().build();
/// let emitted_logs = exporter.get_emitted_logs().unwrap();
Expand All @@ -164,7 +164,7 @@ impl InMemoryLogExporter {
/// # Example
///
/// ```
/// use opentelemetry_sdk::testing::logs::{InMemoryLogExporter, InMemoryLogExporterBuilder};
/// use opentelemetry_sdk::logs::{InMemoryLogExporter, InMemoryLogExporterBuilder};
///
/// let exporter = InMemoryLogExporterBuilder::default().build();
/// exporter.reset();
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/logs/log_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ impl opentelemetry::logs::Logger for Logger {
#[cfg(test)]
mod tests {
use crate::{
logs::InMemoryLogExporter,
resource::{
SERVICE_NAME, TELEMETRY_SDK_LANGUAGE, TELEMETRY_SDK_NAME, TELEMETRY_SDK_VERSION,
},
testing::logs::InMemoryLogExporter,
trace::TracerProvider,
Resource,
};
Expand Down
9 changes: 4 additions & 5 deletions opentelemetry-sdk/src/logs/log_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub trait LogProcessor: Send + Sync + Debug {
/// ```rust
/// use opentelemetry_sdk::logs::{SimpleLogProcessor, LoggerProvider, LogExporter};
/// use opentelemetry::global;
/// use opentelemetry_sdk::testing::logs::InMemoryLogExporter;
/// use opentelemetry_sdk::logs::InMemoryLogExporter;
///
/// let exporter = InMemoryLogExporter::default(); // Replace with an actual exporter
/// let provider = LoggerProvider::builder()
Expand Down Expand Up @@ -246,7 +246,7 @@ type LogsData = Box<(LogRecord, InstrumentationScope)>;
/// use opentelemetry_sdk::logs::{BatchLogProcessor, BatchConfigBuilder, LoggerProvider};
/// use opentelemetry::global;
/// use std::time::Duration;
/// use opentelemetry_sdk::testing::logs::InMemoryLogExporter;
/// use opentelemetry_sdk::logs::InMemoryLogExporter;
///
/// let exporter = InMemoryLogExporter::default(); // Replace with an actual exporter
/// let processor = BatchLogProcessor::builder(exporter)
Expand Down Expand Up @@ -818,16 +818,15 @@ mod tests {
};
use crate::logs::LogResult;
use crate::logs::{LogBatch, LogExporter, LogRecord};
use crate::testing::logs::InMemoryLogExporterBuilder;
use crate::{
logs::{
log_processor::{
OTEL_BLRP_EXPORT_TIMEOUT_DEFAULT, OTEL_BLRP_MAX_EXPORT_BATCH_SIZE_DEFAULT,
OTEL_BLRP_MAX_QUEUE_SIZE_DEFAULT, OTEL_BLRP_SCHEDULE_DELAY_DEFAULT,
},
BatchConfig, BatchConfigBuilder, LogProcessor, LoggerProvider, SimpleLogProcessor,
BatchConfig, BatchConfigBuilder, InMemoryLogExporter, InMemoryLogExporterBuilder,
LogProcessor, LoggerProvider, SimpleLogProcessor,
},
testing::logs::InMemoryLogExporter,
Resource,
};
use opentelemetry::logs::AnyValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,20 @@ mod tests {
OTEL_BLRP_SCHEDULE_DELAY,
};
use crate::logs::log_processor_with_async_runtime::BatchLogProcessor;
use crate::logs::InMemoryLogExporterBuilder;
use crate::logs::LogRecord;
use crate::logs::LogResult;
use crate::logs::{LogBatch, LogExporter};
use crate::runtime;
use crate::testing::logs::InMemoryLogExporterBuilder;
use crate::{
logs::{
log_processor::{
OTEL_BLRP_EXPORT_TIMEOUT_DEFAULT, OTEL_BLRP_MAX_EXPORT_BATCH_SIZE_DEFAULT,
OTEL_BLRP_MAX_QUEUE_SIZE_DEFAULT, OTEL_BLRP_SCHEDULE_DELAY_DEFAULT,
},
BatchConfig, BatchConfigBuilder, LogProcessor, LoggerProvider, SimpleLogProcessor,
BatchConfig, BatchConfigBuilder, InMemoryLogExporter, LogProcessor, LoggerProvider,
SimpleLogProcessor,
},
testing::logs::InMemoryLogExporter,
Resource,
};
use opentelemetry::logs::AnyValue;
Expand Down
9 changes: 8 additions & 1 deletion opentelemetry-sdk/src/logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ mod log_emitter;
mod log_processor;
pub(crate) mod record;

/// In-Memory log exporter for testing purpose.
#[cfg(any(feature = "testing", test))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "testing", test))))]
pub mod in_memory_exporter;
#[cfg(any(feature = "testing", test))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "testing", test))))]
pub use in_memory_exporter::{InMemoryLogExporter, InMemoryLogExporterBuilder};

pub use error::{LogError, LogResult};
pub use export::{ExportResult, LogBatch, LogExporter};
pub use log_emitter::{Builder, Logger, LoggerProvider};
Expand All @@ -21,7 +29,6 @@ pub mod log_processor_with_async_runtime;
#[cfg(all(test, feature = "testing"))]
mod tests {
use super::*;
use crate::testing::logs::InMemoryLogExporter;
use crate::Resource;
use opentelemetry::logs::LogRecord;
use opentelemetry::logs::{Logger, LoggerProvider as _, Severity};
Expand Down
6 changes: 0 additions & 6 deletions opentelemetry-sdk/src/testing/logs/mod.rs

This file was deleted.

3 changes: 0 additions & 3 deletions opentelemetry-sdk/src/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ pub mod trace;

#[cfg(all(feature = "testing", feature = "metrics"))]
pub mod metrics;

#[cfg(all(feature = "testing", feature = "logs"))]
pub mod logs;

0 comments on commit fdf4a63

Please sign in to comment.