Skip to content

Commit

Permalink
fix: avoid param use opentelemetry-otlp type for decoupling
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Aug 2, 2024
1 parent 1672729 commit 9ec5292
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/tisonkun/logforth"
rust-version = "1.71.0"
version = "0.7.0"
version = "0.7.1"

[package.metadata.docs.rs]
all-features = true
Expand Down
2 changes: 1 addition & 1 deletion src/append/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::layout::Layout;
#[cfg(feature = "fastrace")]
mod fastrace;
#[cfg(feature = "opentelemetry")]
mod opentelemetry;
pub mod opentelemetry;
#[cfg(feature = "rolling_file")]
pub mod rolling_file;
mod stdio;
Expand Down
16 changes: 12 additions & 4 deletions src/append/opentelemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ use opentelemetry_sdk::logs::LoggerProvider;

use crate::append::Append;

#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum OpentelemetryWireProtocol {
Grpc,
HttpBinary,
HttpJson,
}

#[derive(Debug)]
pub struct OpentelemetryLog {
name: String,
Expand All @@ -41,30 +49,30 @@ impl OpentelemetryLog {
name: impl Into<String>,
category: impl Into<String>,
otlp_endpoint: impl Into<String>,
protocol: Protocol,
protocol: OpentelemetryWireProtocol,
) -> Result<Self, opentelemetry::logs::LogError> {
let name = name.into();
let category = category.into();
let otlp_endpoint = otlp_endpoint.into();

let exporter = match protocol {
Protocol::Grpc => opentelemetry_otlp::new_exporter()
OpentelemetryWireProtocol::Grpc => opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(otlp_endpoint)
.with_protocol(Protocol::Grpc)
.with_timeout(Duration::from_secs(
opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT,
))
.build_log_exporter(),
Protocol::HttpBinary => opentelemetry_otlp::new_exporter()
OpentelemetryWireProtocol::HttpBinary => opentelemetry_otlp::new_exporter()
.http()
.with_endpoint(otlp_endpoint)
.with_protocol(Protocol::HttpBinary)
.with_timeout(Duration::from_secs(
opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT,
))
.build_log_exporter(),
Protocol::HttpJson => opentelemetry_otlp::new_exporter()
OpentelemetryWireProtocol::HttpJson => opentelemetry_otlp::new_exporter()
.http()
.with_endpoint(otlp_endpoint)
.with_protocol(Protocol::HttpJson)
Expand Down

0 comments on commit 9ec5292

Please sign in to comment.