Skip to content

Commit

Permalink
Remove flag and include non-user-facing traces in response
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Dec 16, 2022
1 parent d58f331 commit 6b27b32
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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 {
Expand Down
10 changes: 3 additions & 7 deletions query-engine/query-engine/src/capture_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,10 @@ pub struct TraceCapturer {
}

impl TraceCapturer {
pub fn new(enable: bool) -> Option<Self> {
if !enable {
return None;
}

Some(Self {
pub fn new() -> Self {
Self {
traces: Default::default(),
})
}
}

pub async fn start_capturing(&self, trace_id: TraceId) {
Expand Down
40 changes: 18 additions & 22 deletions query-engine/query-engine/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Logger<'a> {
log_queries: bool,
telemetry_endpoint: Option<&'a str>,
metrics: Option<MetricRegistry>,
trace_capturer: Option<TraceCapturer>,
trace_capturer: TraceCapturer,
}

impl<'a> Logger<'a> {
Expand All @@ -37,7 +37,7 @@ impl<'a> Logger<'a> {
log_queries: false,
telemetry_endpoint: None,
metrics: None,
trace_capturer: None,
trace_capturer: TraceCapturer::new(),
}
}

Expand Down Expand Up @@ -69,8 +69,7 @@ impl<'a> Logger<'a> {
self.metrics = Some(metrics);
}

pub fn enable_trace_capturer(&mut self, capture_logs: bool) -> Option<TraceCapturer> {
self.trace_capturer = TraceCapturer::new(capture_logs);
pub fn trace_capturer(&self) -> TraceCapturer {
self.trace_capturer.clone()
}

Expand All @@ -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);
Expand All @@ -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(())
Expand Down
5 changes: 0 additions & 5 deletions query-engine/query-engine/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions query-engine/query-engine/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub async fn setup(opts: &PrismaOpt, install_logger: bool, metrics: Option<Metri
logger.telemetry_endpoint(&opts.open_telemetry_endpoint);
logger.enable_metrics(metrics.clone());

let trace_capturer = logger.enable_trace_capturer(opts.enable_traces_in_response);
let capturer = logger.trace_capturer();

if install_logger {
logger.install().unwrap();
Expand All @@ -75,9 +75,9 @@ pub async fn setup(opts: &PrismaOpt, install_logger: bool, metrics: Option<Metri
let enable_metrics = config.preview_features().contains(PreviewFeature::Metrics) || opts.dataproxy_metric_override;
let span = tracing::info_span!("prisma:engine:connect");

let cx = PrismaContext::builder(datamodel) // opts.enable_raw_queries, metrics, logs_capture)
let cx = PrismaContext::builder(datamodel)
.set_metrics(metrics)
.set_trace_capturer(trace_capturer)
.set_trace_capturer(Some(capturer))
.enable_raw_queries(opts.enable_raw_queries)
.build()
.instrument(span)
Expand Down
1 change: 0 additions & 1 deletion query-engine/query-engine/src/tests/dmmf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ fn test_dmmf_cli_command(schema: &str) -> 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,
};

Expand Down

0 comments on commit 6b27b32

Please sign in to comment.