mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2024-11-29 10:12:27 +01:00
feat: with opentelemetry working
This commit is contained in:
parent
07d14450c8
commit
91097868dc
@ -1,5 +1,6 @@
|
||||
use rand::Rng;
|
||||
|
||||
#[tracing::instrument]
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect().await?;
|
||||
|
@ -1,8 +1,14 @@
|
||||
use dagger_sdk::HostDirectoryOpts;
|
||||
use opentelemetry::global;
|
||||
use tracing::Level;
|
||||
|
||||
#[tracing::instrument]
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect().await?;
|
||||
global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
|
||||
let span = tracing::span!(Level::INFO, "start main");
|
||||
let _enter = span.enter();
|
||||
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
"examples/build-the-application/app",
|
||||
@ -33,5 +39,9 @@ async fn main() -> eyre::Result<()> {
|
||||
|
||||
println!("build dir contents: \n {:?}", entries);
|
||||
|
||||
drop(_enter);
|
||||
|
||||
global::shutdown_tracer_provider(); // sending remaining spans
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -7,20 +7,14 @@ use dagger_core::engine::Engine as DaggerEngine;
|
||||
|
||||
use crate::errors::ConnectError;
|
||||
use crate::gen::Query;
|
||||
use crate::logging::{StdLogger, TracingLogger};
|
||||
use crate::logging::StdLogger;
|
||||
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(TracingLogger::default())),
|
||||
);
|
||||
let cfg = Config::new(None, None, None, None, Some(Arc::new(StdLogger::default())));
|
||||
|
||||
#[cfg(feature = "otel")]
|
||||
crate::logging::otel_logging().map_err(ConnectError::FailedToInstallOtelTracer)?;
|
||||
|
@ -11,9 +11,13 @@ pub fn otel_logging() -> eyre::Result<()> {
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::Registry;
|
||||
|
||||
std::env::set_var("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", "25");
|
||||
|
||||
let tracer = opentelemetry_jaeger::new_agent_pipeline()
|
||||
.with_service_name("dagger_sdk")
|
||||
.install_simple();
|
||||
.with_max_packet_size(9216)
|
||||
.with_auto_split_batch(true)
|
||||
.install_batch(opentelemetry::runtime::Tokio)?;
|
||||
|
||||
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
|
||||
|
||||
|
@ -2,6 +2,7 @@ use std::{collections::HashMap, ops::Add, sync::Arc};
|
||||
|
||||
use dagger_core::graphql_client::DynGraphQLClient;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::errors::{DaggerError, DaggerUnpackError};
|
||||
|
||||
@ -30,6 +31,7 @@ pub struct Selection {
|
||||
}
|
||||
|
||||
impl Selection {
|
||||
#[instrument(skip(self))]
|
||||
pub fn select_with_alias(&self, alias: &str, name: &str) -> Selection {
|
||||
Self {
|
||||
name: Some(name.to_string()),
|
||||
@ -39,6 +41,7 @@ impl Selection {
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
pub fn select(&self, name: &str) -> Selection {
|
||||
Self {
|
||||
name: Some(name.to_string()),
|
||||
@ -48,6 +51,7 @@ impl Selection {
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self, value))]
|
||||
pub fn arg<S>(&self, name: &str, value: S) -> Selection
|
||||
where
|
||||
S: Serialize,
|
||||
@ -70,6 +74,7 @@ impl Selection {
|
||||
s
|
||||
}
|
||||
|
||||
#[instrument(skip(self, value))]
|
||||
pub fn arg_enum<S>(&self, name: &str, value: S) -> Selection
|
||||
where
|
||||
S: Serialize,
|
||||
@ -93,6 +98,7 @@ impl Selection {
|
||||
s
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
pub fn build(&self) -> Result<String, DaggerError> {
|
||||
let mut fields = vec!["query".to_string()];
|
||||
|
||||
@ -118,14 +124,13 @@ impl Selection {
|
||||
Ok(fields.join("{") + &"}".repeat(fields.len() - 1))
|
||||
}
|
||||
|
||||
#[instrument(skip(self, gql_client))]
|
||||
pub async fn execute<D>(&self, gql_client: DynGraphQLClient) -> Result<D, DaggerError>
|
||||
where
|
||||
D: for<'de> Deserialize<'de>,
|
||||
{
|
||||
let query = self.build()?;
|
||||
|
||||
tracing::trace!(query = query.as_str(), "dagger-query");
|
||||
|
||||
let resp: Option<serde_json::Value> = match gql_client.query(&query).await {
|
||||
Ok(r) => r,
|
||||
Err(e) => return Err(DaggerError::Query(e)),
|
||||
@ -136,6 +141,7 @@ impl Selection {
|
||||
Ok(resp.unwrap())
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
fn path(&self) -> Vec<Selection> {
|
||||
let mut selections: Vec<Selection> = vec![];
|
||||
let mut cur = self;
|
||||
@ -152,6 +158,7 @@ impl Selection {
|
||||
selections
|
||||
}
|
||||
|
||||
#[instrument(skip(self, resp))]
|
||||
pub(crate) fn unpack_resp<D>(
|
||||
&self,
|
||||
resp: Option<serde_json::Value>,
|
||||
@ -165,6 +172,7 @@ impl Selection {
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self, r))]
|
||||
fn unpack_resp_value<D>(&self, r: serde_json::Value) -> Result<D, DaggerError>
|
||||
where
|
||||
D: for<'de> Deserialize<'de>,
|
||||
|
Loading…
Reference in New Issue
Block a user