Skip to content

Commit 186eeed

Browse files
jordanhunt22Convex, Inc.
authored andcommitted
[Tracing] Add support for push_config (#24543)
Rewired the `http` endpoint tracing to capture the entire request execution + added support to trace `push_config` requests. GitOrigin-RevId: c62edbfa24650c5763077079d2540a10c9acee0c
1 parent 2e086b3 commit 186eeed

File tree

15 files changed

+44
-20
lines changed

15 files changed

+44
-20
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/application/src/application_function_runner/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
12751275
}
12761276
}
12771277

1278+
#[minitrace::trace]
12781279
pub async fn build_deps(
12791280
&self,
12801281
deps: Vec<NodeDependency>,
@@ -1298,6 +1299,7 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
12981299
)
12991300
}
13001301

1302+
#[minitrace::trace]
13011303
pub async fn analyze(
13021304
&self,
13031305
udf_config: UdfConfig,
@@ -1401,6 +1403,7 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
14011403
Ok(Ok(result))
14021404
}
14031405

1406+
#[minitrace::trace]
14041407
async fn validate_cron_jobs(
14051408
&self,
14061409
modules: &BTreeMap<CanonicalizedModulePath, AnalyzedModule>,

crates/application/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,7 @@ impl<RT: Runtime> Application<RT> {
15981598
Ok(schema)
15991599
}
16001600

1601+
#[minitrace::trace]
16011602
pub async fn get_evaluated_auth_config(
16021603
runner: Arc<ApplicationFunctionRunner<RT>>,
16031604
tx: &mut Transaction<RT>,
@@ -1701,6 +1702,7 @@ impl<RT: Runtime> Application<RT> {
17011702
.await
17021703
}
17031704

1705+
#[minitrace::trace]
17041706
async fn _apply_config(
17051707
runner: Arc<ApplicationFunctionRunner<RT>>,
17061708
tx: &mut Transaction<RT>,
@@ -2006,6 +2008,7 @@ impl<RT: Runtime> Application<RT> {
20062008
})
20072009
}
20082010

2011+
#[minitrace::trace]
20092012
pub async fn build_external_node_deps(
20102013
&self,
20112014
deps: Vec<NodeDependency>,
@@ -2042,6 +2045,7 @@ impl<RT: Runtime> Application<RT> {
20422045
Ok((id, pkg))
20432046
}
20442047

2048+
#[minitrace::trace]
20452049
async fn _upload_external_deps_package(
20462050
&self,
20472051
external_deps_package: ExternalDepsPackage,

crates/common/src/http/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use http::{
6969
use hyper::server::conn::AddrIncoming;
7070
use itertools::Itertools;
7171
use maplit::btreemap;
72+
use minitrace::future::FutureExt;
7273
use prometheus::TextEncoder;
7374
use sentry::integrations::tower as sentry_tower;
7475
use serde::{
@@ -715,26 +716,27 @@ pub async fn stats_middleware<RM: RouteMapper>(
715716
) -> Result<impl IntoResponse, HttpResponseError> {
716717
let start = Instant::now();
717718
let method = req.method().clone();
718-
719-
let resp = next.run(req).await;
720-
721-
let client_version_s = client_version.to_string();
722719
// tag with the route. 404s lack matched query path - and the
723720
// uri is generally unhelpful for metrics aggregation, so leave it out there.
724721
let route = matched_path
725722
.map(|r| r.as_str().to_owned())
726723
.unwrap_or("unknown".to_owned());
727724

728-
let route = route_metric_mapper.map_route(route);
725+
// Configure tracing
726+
let root = {
727+
let mut rng = rand::thread_rng();
728+
get_sampled_span(
729+
route.as_str(),
730+
&mut rng,
731+
btreemap!["request_id".to_owned() => request_id.to_string()],
732+
)
733+
};
729734

730-
// Configure tracing.
731-
let mut rng = rand::thread_rng();
732-
let root = get_sampled_span(
733-
route.as_str(),
734-
&mut rng,
735-
btreemap!["request_id".to_owned() => request_id.to_string()],
736-
);
737-
let _guard = root.set_local_parent();
735+
let resp = next.run(req).in_span(root).await;
736+
737+
let client_version_s = client_version.to_string();
738+
739+
let route = route_metric_mapper.map_route(route);
738740

739741
// Add the request_id to sentry
740742
sentry::configure_scope(|scope| scope.set_tag("request_id", request_id.clone()));

crates/database/src/transaction_index.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ impl TransactionIndex {
126126
/// streamed from the database.
127127
/// The returned vec may be larger or smaller than `max_size` depending on
128128
/// pending writes.
129-
#[minitrace::trace]
130129
async fn range_no_deps(
131130
&mut self,
132131
ranges: BTreeMap<BatchKey, RangeRequest>,
@@ -250,6 +249,7 @@ impl TransactionIndex {
250249
results
251250
}
252251

252+
#[minitrace::trace]
253253
pub async fn search(
254254
&mut self,
255255
reads: &mut TransactionReadSet,
@@ -411,6 +411,7 @@ impl TransactionIndex {
411411
.context("batch_key missing")?
412412
}
413413

414+
#[minitrace::trace]
414415
pub async fn preload_index_range(
415416
&mut self,
416417
reads: &mut TransactionReadSet,
@@ -748,6 +749,7 @@ impl SearchIndexManagerSnapshot {
748749
.clone()
749750
}
750751

752+
#[minitrace::trace]
751753
pub async fn search_with_compiled_query(
752754
&self,
753755
index: &Index,

crates/indexing/src/backend_in_memory_indexes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ impl DatabaseIndexSnapshot {
424424
}
425425

426426
/// Query the given index at the snapshot.
427-
#[minitrace::trace]
428427
pub async fn range_batch(
429428
&mut self,
430429
range_requests: BTreeMap<BatchKey, RangeRequest>,

crates/isolate/src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ use keybroker::{
8888
KeyBroker,
8989
};
9090
use minitrace::{
91+
collector::SpanContext,
9192
full_name,
9293
future::FutureExt as _,
9394
};
@@ -790,6 +791,7 @@ impl<RT: Runtime> IsolateClient<RT> {
790791
}
791792

792793
/// Analyze a set of user-defined modules.
794+
#[minitrace::trace]
793795
pub async fn analyze(
794796
&self,
795797
udf_config: UdfConfig,
@@ -809,12 +811,10 @@ impl<RT: Runtime> IsolateClient<RT> {
809811
udf_config,
810812
environment_variables,
811813
};
812-
// TODO(jordan): this is an incomplete state. eventually we will expand to trace
813-
// other requests besides udfs
814814
self.send_request(Request::new(
815815
self.instance_name.clone(),
816816
request,
817-
EncodedSpan::empty(),
817+
EncodedSpan::from_parent(SpanContext::current_local_parent()),
818818
))?;
819819
Self::receive_response(rx).await?.map_err(|e| {
820820
if e.is_overloaded() {

crates/isolate/src/environment/udf/async_syscall.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ pub struct DatabaseSyscallsV1<RT: Runtime> {
452452
}
453453

454454
impl<RT: Runtime> DatabaseSyscallsV1<RT> {
455-
#[convex_macro::instrument_future]
456455
#[minitrace::trace]
456+
#[convex_macro::instrument_future]
457457
async fn get_batch(
458458
env: &mut DatabaseUdfEnvironment<RT>,
459459
batch_args: Vec<JsonValue>,
@@ -840,6 +840,7 @@ impl<RT: Runtime> DatabaseSyscallsShared<RT> {
840840
))
841841
}
842842

843+
#[minitrace::trace]
843844
async fn queryPage(
844845
env: &mut DatabaseUdfEnvironment<RT>,
845846
args: JsonValue,

crates/local_backend/src/deploy_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ pub async fn push_config(
377377
Ok(Json(EmptyResponse {}))
378378
}
379379

380+
#[minitrace::trace]
380381
pub async fn push_config_handler(
381382
application: &Application<ProdRuntime>,
382383
config: ConfigJson,
@@ -478,6 +479,7 @@ pub async fn push_config_handler(
478479
))
479480
}
480481

482+
#[minitrace::trace]
481483
async fn analyze_modules_with_auth_config(
482484
application: &Application<ProdRuntime>,
483485
udf_config: UdfConfig,

crates/model/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ humansize = { workspace = true }
2323
keybroker = { path = "../keybroker" }
2424
maplit = { workspace = true }
2525
metrics = { path = "../metrics" }
26+
minitrace = { workspace = true }
2627
openidconnect = { workspace = true }
2728
pb = { path = "../pb" }
2829
proptest = { workspace = true, optional = true }
@@ -50,7 +51,9 @@ proptest = { workspace = true }
5051
proptest-derive = { workspace = true }
5152
runtime = { path = "../runtime", features = ["testing"] }
5253
storage = { path = "../storage" }
53-
sync_types = { package = "convex_sync_types", path = "../convex/sync_types", features = ["testing"] }
54+
sync_types = { package = "convex_sync_types", path = "../convex/sync_types", features = [
55+
"testing",
56+
] }
5457
value = { path = "../value", features = ["testing"] }
5558

5659
[features]

0 commit comments

Comments
 (0)