feat: add tracing logger

This commit is contained in:
Kasper Juul Hermansen 2023-05-02 20:10:43 +02:00
parent 91097868dc
commit f670989a46
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
4 changed files with 26 additions and 5 deletions

14
Cargo.lock generated
View File

@ -1172,6 +1172,7 @@ dependencies = [
"opentelemetry-semantic-conventions",
"thiserror",
"thrift",
"tokio",
]
[[package]]
@ -1217,6 +1218,8 @@ dependencies = [
"percent-encoding",
"rand",
"thiserror",
"tokio",
"tokio-stream",
]
[[package]]
@ -1813,6 +1816,17 @@ dependencies = [
"webpki",
]
[[package]]
name = "tokio-stream"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842"
dependencies = [
"futures-core",
"pin-project-lite",
"tokio",
]
[[package]]
name = "tokio-util"
version = "0.7.8"

View File

@ -29,7 +29,8 @@ tracing-subscriber = { version = "0.3.17", features = [
tracing-opentelemetry = { version = "0.18.0" }
opentelemetry = { version = "0.18.0", default-features = false, features = [
"trace",
"rt-tokio",
] }
opentelemetry-jaeger = "0.17.0"
opentelemetry-jaeger = { version = "0.17.0", features = ["rt-tokio"] }
thiserror = "1.0.40"

View File

@ -7,14 +7,20 @@ use dagger_core::engine::Engine as DaggerEngine;
use crate::errors::ConnectError;
use crate::gen::Query;
use crate::logging::StdLogger;
use crate::logging::{StdLogger, TracingLogger};
use crate::querybuilder::query;
pub type DaggerConn = Arc<Query>;
pub async fn connect() -> Result<DaggerConn, ConnectError> {
let cfg = if cfg!(feature = "otel") {
let cfg = Config::new(None, None, None, None, Some(Arc::new(StdLogger::default())));
let cfg = Config::new(
None,
None,
None,
None,
Some(Arc::new(TracingLogger::default())),
);
#[cfg(feature = "otel")]
crate::logging::otel_logging().map_err(ConnectError::FailedToInstallOtelTracer)?;

View File

@ -61,13 +61,13 @@ impl Default for TracingLogger {
impl Logger for TracingLogger {
fn stdout(&self, output: &str) -> eyre::Result<()> {
tracing::info!(output = output, "dagger-sdk");
tracing::info!(output = output, "dagger_sdk");
Ok(())
}
fn stderr(&self, output: &str) -> eyre::Result<()> {
tracing::warn!(output = output, "dagger-sdk");
tracing::warn!(output = output, "dagger_sdk");
Ok(())
}