Skip to content

Commit 1b0082a

Browse files
jordanhunt22Convex, Inc.
authored andcommitted
[Tracing] Add support for V8 actions (#24441)
Adds support for `V8` actions + relevant `syscalls` This doesn't include tracing for other `async_ops` like fetches or storage gets GitOrigin-RevId: 508ad4db88053c90d9f995eb5aa002828cad9630
1 parent 3911922 commit 1b0082a

File tree

8 files changed

+48
-4
lines changed

8 files changed

+48
-4
lines changed

crates/application/src/application_function_runner/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ impl<RT: Runtime> FunctionRouter<RT> {
270270
Ok((tx, outcome))
271271
}
272272

273+
#[minitrace::trace]
273274
pub(crate) async fn execute_action(
274275
&self,
275276
tx: Transaction<RT>,
@@ -955,6 +956,7 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
955956
Ok((tx, mutation_outcome))
956957
}
957958

959+
#[minitrace::trace]
958960
pub async fn run_action(
959961
&self,
960962
request_id: RequestId,
@@ -1014,6 +1016,7 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
10141016

10151017
/// Runs the actions without logging to the UDF log. It is the caller
10161018
/// responsibility to log to the UDF log.
1019+
#[minitrace::trace]
10171020
pub async fn run_action_no_udf_log(
10181021
&self,
10191022
name: CanonicalizedUdfPath,
@@ -1055,6 +1058,7 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
10551058
}
10561059

10571060
/// Runs the action without any logging.
1061+
#[minitrace::trace]
10581062
async fn run_action_inner(
10591063
&self,
10601064
name: CanonicalizedUdfPath,
@@ -1665,6 +1669,7 @@ impl<RT: Runtime> ApplicationFunctionRunner<RT> {
16651669

16661670
#[async_trait]
16671671
impl<RT: Runtime> ActionCallbacks for ApplicationFunctionRunner<RT> {
1672+
#[minitrace::trace]
16681673
async fn execute_query(
16691674
&self,
16701675
identity: Identity,
@@ -1693,6 +1698,7 @@ impl<RT: Runtime> ActionCallbacks for ApplicationFunctionRunner<RT> {
16931698
Ok(FunctionResult { result })
16941699
}
16951700

1701+
#[minitrace::trace]
16961702
async fn execute_mutation(
16971703
&self,
16981704
identity: Identity,
@@ -1723,6 +1729,7 @@ impl<RT: Runtime> ActionCallbacks for ApplicationFunctionRunner<RT> {
17231729
Ok(FunctionResult { result })
17241730
}
17251731

1732+
#[minitrace::trace]
17261733
async fn execute_action(
17271734
&self,
17281735
identity: Identity,

crates/application/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ impl<RT: Runtime> Application<RT> {
964964
}
965965
}
966966

967+
#[minitrace::trace]
967968
pub async fn action_udf(
968969
&self,
969970
request_id: RequestId,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::{
3636
};
3737

3838
impl<RT: Runtime> TaskExecutor<RT> {
39+
#[minitrace::trace]
3940
pub async fn run_async_syscall(&self, name: String, args: JsonValue) -> anyhow::Result<String> {
4041
let start = self.rt.monotonic_now();
4142
let timer = async_syscall_timer(&name);

crates/isolate/src/environment/action/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use common::{
3535
LogLine,
3636
SystemLogMetadata,
3737
},
38+
minitrace_helpers::EncodedSpan,
3839
runtime::{
3940
Runtime,
4041
SpawnHandle,
@@ -61,6 +62,7 @@ use humansize::{
6162
};
6263
use itertools::Itertools;
6364
use keybroker::Identity;
65+
use minitrace::collector::SpanContext;
6466
use model::{
6567
environment_variables::types::{
6668
EnvVarName,
@@ -453,10 +455,12 @@ impl<RT: Runtime> ActionEnvironment<RT> {
453455
.unbounded_send(TaskRequest {
454456
task_id,
455457
variant: TaskRequestEnum::AsyncOp(AsyncOpRequest::SendStream { stream, stream_id }),
458+
parent_trace: EncodedSpan::from_parent(SpanContext::current_local_parent()),
456459
})
457460
.expect("TaskExecutor went away?");
458461
}
459462

463+
#[minitrace::trace]
460464
pub async fn run_action(
461465
mut self,
462466
isolate: &mut Isolate<RT>,
@@ -516,6 +520,7 @@ impl<RT: Runtime> ActionEnvironment<RT> {
516520
Ok(outcome)
517521
}
518522

523+
#[minitrace::trace]
519524
async fn run_action_inner(
520525
isolate: &mut RequestScope<'_, '_, RT, Self>,
521526
request_params: ActionRequestParams,
@@ -712,6 +717,7 @@ impl<RT: Runtime> ActionEnvironment<RT> {
712717
}
713718
}
714719

720+
#[minitrace::trace]
715721
async fn run_inner<'a, 'b: 'a, T, Fut>(
716722
scope: &mut ExecutionScope<'a, 'b, RT, Self>,
717723
handle: IsolateHandle,
@@ -1010,6 +1016,7 @@ impl<RT: Runtime> ActionEnvironment<RT> {
10101016
.unbounded_send(TaskRequest {
10111017
task_id,
10121018
variant: request,
1019+
parent_trace: EncodedSpan::from_parent(SpanContext::current_local_parent()),
10131020
})
10141021
.expect("TaskExecutor went away?");
10151022
Ok(())

crates/isolate/src/environment/action/task.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
//! Our action runtime runs "tasks" asynchronously, which either be
22
//! async syscalls or async ops.
33
4-
use common::runtime::{
5-
Runtime,
6-
UnixTimestamp,
4+
use common::{
5+
minitrace_helpers::EncodedSpan,
6+
runtime::{
7+
Runtime,
8+
UnixTimestamp,
9+
},
710
};
811
use deno_core::{
912
serde_v8,
@@ -30,6 +33,7 @@ use crate::{
3033
pub struct TaskRequest {
3134
pub task_id: TaskId,
3235
pub variant: TaskRequestEnum,
36+
pub parent_trace: EncodedSpan,
3337
}
3438

3539
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, derive_more::Display)]

crates/isolate/src/environment/action/task_executor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use common::{
88
execution_context::ExecutionContext,
99
http::fetch::FetchClient,
1010
knobs::MAX_CONCURRENT_ACTION_OPS,
11+
minitrace_helpers::initialize_root_from_parent,
1112
runtime::{
1213
Runtime,
1314
UnixTimestamp,
@@ -27,6 +28,7 @@ use keybroker::{
2728
Identity,
2829
KeyBroker,
2930
};
31+
use minitrace::future::FutureExt;
3032
use parking_lot::Mutex;
3133
use serde_json::Value as JsonValue;
3234
use usage_tracking::FunctionUsageTracker;
@@ -95,8 +97,9 @@ impl<RT: Runtime> TaskExecutor<RT> {
9597
},
9698
task_request = pending_tasks.next() => {
9799
if let Some(task_request) = task_request {
100+
let root = initialize_root_from_parent("TaskExecutor::execute_task", task_request.parent_trace.clone());
98101
self.task_order.push_running_task(&task_request);
99-
running_tasks.push(self.clone().run_async_task(task_request));
102+
running_tasks.push(self.clone().run_async_task(task_request).in_span(root));
100103
} else {
101104
requests_closed = true;
102105
}
@@ -105,6 +108,7 @@ impl<RT: Runtime> TaskExecutor<RT> {
105108
}
106109
}
107110

111+
#[minitrace::trace]
108112
async fn run_async_task(self, task_request: TaskRequest) -> TaskId {
109113
let task_id = task_request.task_id;
110114
let variant = match task_request.variant {

crates/pb/protos/backend.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ message ExecuteQueryRequest {
7373
common.PathAndArgs path_and_args = 3;
7474
optional bool block_logging = 5;
7575
optional common.ExecutionContext execution_context = 6;
76+
77+
// Encoded parent trace
78+
optional string encoded_parent_trace = 7;
7679
}
7780

7881
message ExecuteQueryResponse {
@@ -88,6 +91,9 @@ message ExecuteMutationRequest {
8891
common.PathAndArgs path_and_args = 3;
8992
optional bool block_logging = 5;
9093
optional common.ExecutionContext execution_context = 6;
94+
95+
// Encoded parent trace
96+
optional string encoded_parent_trace = 7;
9197
}
9298

9399
message ExecuteMutationResponse {
@@ -103,6 +109,9 @@ message ExecuteActionRequest {
103109
common.PathAndArgs path_and_args = 3;
104110
optional bool block_logging = 5;
105111
optional common.ExecutionContext execution_context = 6;
112+
113+
// Encoded parent trace
114+
optional string encoded_parent_trace = 7;
106115
}
107116

108117
message ExecuteActionResponse {

crates/sync/src/worker.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,16 @@ impl<RT: Runtime> SyncWorker<RT> {
499499
Some(id) => RequestId::new_for_ws_session(id, request_id),
500500
None => RequestId::new(),
501501
};
502+
let root = self.rt.with_rng(|rng| {
503+
get_sampled_span(
504+
"sync-worker/action",
505+
rng,
506+
btreemap! {
507+
"udf_type".into() => UdfType::Action.to_lowercase_string().into(),
508+
"udf_path".into() => udf_path.clone().into(),
509+
},
510+
)
511+
});
502512
let future = async move {
503513
let result = application
504514
.action_udf(
@@ -509,6 +519,7 @@ impl<RT: Runtime> SyncWorker<RT> {
509519
AllowedVisibility::PublicOnly,
510520
FunctionCaller::SyncWorker(client_version),
511521
)
522+
.in_span(root)
512523
.await?;
513524
let response = match result {
514525
Ok(udf_return) => ServerMessage::ActionResponse {

0 commit comments

Comments
 (0)