From 6b27b32dc1691b7ab37209e8a83a525533f04fa7 Mon Sep 17 00:00:00 2001 From: Miguel Fernandez Date: Fri, 16 Dec 2022 16:57:58 +0100 Subject: [PATCH] Remove flag and include non-user-facing traces in response --- Makefile | 2 +- .../query-tests-setup/src/runner/binary.rs | 8 +--- .../query-engine/src/capture_tracer.rs | 10 ++--- query-engine/query-engine/src/logger.rs | 40 +++++++++---------- query-engine/query-engine/src/opt.rs | 5 --- query-engine/query-engine/src/state.rs | 6 +-- query-engine/query-engine/src/tests/dmmf.rs | 1 - 7 files changed, 26 insertions(+), 46 deletions(-) diff --git a/Makefile b/Makefile index b8863d7ec66f..489de641bac6 100644 --- a/Makefile +++ b/Makefile @@ -207,7 +207,7 @@ validate: cargo run --bin test-cli -- validate-datamodel dev_datamodel.prisma qe: - cargo run --bin query-engine -- --enable-playground --enable-raw-queries --enable-metrics --enable-open-telemetry --enable-traces-in-response + cargo run --bin query-engine -- --enable-playground --enable-raw-queries --enable-metrics --enable-open-telemetry qe-dmmf: cargo run --bin query-engine -- cli dmmf > dmmf.json diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/runner/binary.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/runner/binary.rs index 2f049182a03b..2b7b82590ccd 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/runner/binary.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/runner/binary.rs @@ -16,13 +16,7 @@ pub struct BinaryRunner { #[async_trait::async_trait] impl RunnerInterface for BinaryRunner { async fn load(datamodel: String, connector_tag: ConnectorTag, metrics: MetricRegistry) -> TestResult { - let opts = PrismaOpt::from_list(&[ - "binary", - "--enable-raw-queries", - "--enable-traces-in-response", - "--datamodel", - &datamodel, - ]); + let opts = PrismaOpt::from_list(&["binary", "--enable-raw-queries", "--datamodel", &datamodel]); let state = setup(&opts, false, Some(metrics)).await.unwrap(); Ok(BinaryRunner { diff --git a/query-engine/query-engine/src/capture_tracer.rs b/query-engine/query-engine/src/capture_tracer.rs index 4ee582f32d96..144b73bb9785 100644 --- a/query-engine/query-engine/src/capture_tracer.rs +++ b/query-engine/query-engine/src/capture_tracer.rs @@ -97,14 +97,10 @@ pub struct TraceCapturer { } impl TraceCapturer { - pub fn new(enable: bool) -> Option { - if !enable { - return None; - } - - Some(Self { + pub fn new() -> Self { + Self { traces: Default::default(), - }) + } } pub async fn start_capturing(&self, trace_id: TraceId) { diff --git a/query-engine/query-engine/src/logger.rs b/query-engine/query-engine/src/logger.rs index 0608520dca37..18b1c9f54054 100644 --- a/query-engine/query-engine/src/logger.rs +++ b/query-engine/query-engine/src/logger.rs @@ -24,7 +24,7 @@ pub struct Logger<'a> { log_queries: bool, telemetry_endpoint: Option<&'a str>, metrics: Option, - trace_capturer: Option, + trace_capturer: TraceCapturer, } impl<'a> Logger<'a> { @@ -37,7 +37,7 @@ impl<'a> Logger<'a> { log_queries: false, telemetry_endpoint: None, metrics: None, - trace_capturer: None, + trace_capturer: TraceCapturer::new(), } } @@ -69,8 +69,7 @@ impl<'a> Logger<'a> { self.metrics = Some(metrics); } - pub fn enable_trace_capturer(&mut self, capture_logs: bool) -> Option { - self.trace_capturer = TraceCapturer::new(capture_logs); + pub fn trace_capturer(&self) -> TraceCapturer { self.trace_capturer.clone() } @@ -79,23 +78,6 @@ impl<'a> Logger<'a> { /// lifetime of the service. pub fn install(self) -> LoggerResult<()> { let filter = create_env_filter(self.log_queries); - - let telemetry = if self.enable_telemetry { - let tracer = create_otel_tracer(self.service_name, self.telemetry_endpoint); - let mut telemetry = tracing_opentelemetry::layer().with_tracer(tracer); - - if let Some(exporter) = self.trace_capturer { - let tracer = crate::capture_tracer::new_pipeline().install(exporter); - telemetry = telemetry.with_tracer(tracer); - } - - let is_user_trace = filter_fn(is_user_facing_trace_filter); - let telemetry = telemetry.with_filter(is_user_trace); - Some(telemetry) - } else { - None - }; - let fmt_layer = match self.log_format { LogFormat::Text => { let fmt_layer = tracing_subscriber::fmt::layer().with_filter(filter); @@ -107,10 +89,24 @@ impl<'a> Logger<'a> { } }; + let otel_layer = if self.enable_telemetry { + let otel = create_otel_tracer(self.service_name, self.telemetry_endpoint); + let otel_layer = tracing_opentelemetry::layer() + .with_tracer(otel) + .with_filter(filter_fn(is_user_facing_trace_filter)); + Some(otel_layer) + } else { + None + }; + + let capture = crate::capture_tracer::new_pipeline().install(self.trace_capturer()); + let capture_layer = tracing_opentelemetry::layer().with_tracer(capture); + let subscriber = tracing_subscriber::registry() .with(fmt_layer) .with(self.metrics) - .with(telemetry); + .with(otel_layer) + .with(capture_layer); subscriber::set_global_default(subscriber)?; Ok(()) diff --git a/query-engine/query-engine/src/opt.rs b/query-engine/query-engine/src/opt.rs index da2e1896fe6e..77591d81097b 100644 --- a/query-engine/query-engine/src/opt.rs +++ b/query-engine/query-engine/src/opt.rs @@ -102,11 +102,6 @@ pub struct PrismaOpt { /// Enable OpenTelemetry streaming from requests. #[structopt(long)] pub enable_open_telemetry: bool, - - #[structopt(long)] - /// Enable tracer to capture logs and return in the response - pub enable_traces_in_response: bool, - /// The url to the OpenTelemetry collector. /// Enabling this will send the OpenTelemtry tracing to a collector /// and not via our custom stdout tracer diff --git a/query-engine/query-engine/src/state.rs b/query-engine/query-engine/src/state.rs index bc5e7ae53279..3db72bbfc248 100644 --- a/query-engine/query-engine/src/state.rs +++ b/query-engine/query-engine/src/state.rs @@ -58,7 +58,7 @@ pub async fn setup(opts: &PrismaOpt, install_logger: bool, metrics: Option PrismaResult<()> { subcommand: Some(Subcommand::Cli(CliOpt::Dmmf)), enable_open_telemetry: false, open_telemetry_endpoint: String::new(), - enable_traces_in_response: false, dataproxy_metric_override: false, };