Skip to content

Commit

Permalink
Install logger provider
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 committed Jul 26, 2023
1 parent ccb510f commit 701c1a0
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions opentelemetry-otlp/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ use std::{
time::Duration,
};

use opentelemetry_api::logs::{LogError, LoggerProvider};
use opentelemetry_api::{
global,
logs::{LogError, LoggerProvider},
};
use opentelemetry_sdk::{self, export::logs::LogData, logs::BatchMessage, runtime::RuntimeChannel};

impl OtlpPipeline {
Expand Down Expand Up @@ -419,11 +422,12 @@ impl OtlpLogPipeline {
self
}

/// Returns a [`Logger`] with the name `opentelemetry-otlp` and the
/// current crate version, using the configured log exporter.
/// Install the configured log exporter.
///
/// Returns a [`Logger`] with the name `opentelemetry-otlp` and the current crate version.
///
/// [`Logger`]: opentelemetry_sdk::logs::Logger
pub fn simple(self) -> Result<opentelemetry_sdk::logs::Logger, LogError> {
pub fn install_simple(self) -> Result<opentelemetry_sdk::logs::Logger, LogError> {

Check warning on line 430 in opentelemetry-otlp/src/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/logs.rs#L430

Added line #L430 was not covered by tests
Ok(build_simple_with_exporter(
self.exporter_builder
.ok_or(crate::Error::NoExporterBuilder)?
Expand All @@ -432,12 +436,13 @@ impl OtlpLogPipeline {
))
}

/// Returns a [`Logger`] with the name `opentelemetry-otlp` and the
/// current crate version, using the configured log exporter and a
/// batch log processor.
/// Install the configured log exporter and a batch span processor using the
/// specified runtime.
///
/// Returns a [`Logger`] with the name `opentelemetry-otlp` and the current crate version.
///
/// [`Logger`]: opentelemetry_sdk::logs::Logger
pub fn batch<R: RuntimeChannel<BatchMessage>>(
pub fn install_batch<R: RuntimeChannel<BatchMessage>>(

Check warning on line 445 in opentelemetry-otlp/src/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/logs.rs#L445

Added line #L445 was not covered by tests
self,
runtime: R,
) -> Result<opentelemetry_sdk::logs::Logger, LogError> {
Expand All @@ -461,12 +466,14 @@ fn build_simple_with_exporter(
provider_builder = provider_builder.with_config(config);
}
let provider = provider_builder.build();
provider.versioned_logger(
let logger = provider.versioned_logger(

Check warning on line 469 in opentelemetry-otlp/src/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/logs.rs#L469

Added line #L469 was not covered by tests
Cow::Borrowed("opentelemetry-otlp"),
Some(Cow::Borrowed(env!("CARGO_PKG_VERSION"))),
None,
None,
)
);
let _ = global::set_logger_provider(provider);
logger

Check warning on line 476 in opentelemetry-otlp/src/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/logs.rs#L474-L476

Added lines #L474 - L476 were not covered by tests
}

fn build_batch_with_exporter<R: RuntimeChannel<BatchMessage>>(
Expand All @@ -480,10 +487,12 @@ fn build_batch_with_exporter<R: RuntimeChannel<BatchMessage>>(
provider_builder = provider_builder.with_config(config);
}
let provider = provider_builder.build();
provider.versioned_logger(
let logger = provider.versioned_logger(

Check warning on line 490 in opentelemetry-otlp/src/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/logs.rs#L490

Added line #L490 was not covered by tests
Cow::Borrowed("opentelemetry-otlp"),
Some(Cow::Borrowed("CARGO_PKG_VERSION")),
None,
None,
)
);
let _ = global::set_logger_provider(provider);
logger

Check warning on line 497 in opentelemetry-otlp/src/logs.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/logs.rs#L495-L497

Added lines #L495 - L497 were not covered by tests
}

0 comments on commit 701c1a0

Please sign in to comment.