feat: harden community production foundation through story 1.5

This commit is contained in:
2026-08-14 00:21:59 +03:00
parent c30461cc92
commit f6fc2e5c9b
161 changed files with 16758 additions and 2515 deletions
+21 -13
View File
@@ -11,7 +11,9 @@ use crank_metrics::{
ToolOutcome, record_cache_outcome, record_confirmation_outcome, record_idempotency_outcome,
record_limit_rejection,
};
use crank_trace::{ErrorCategory, Stage, StageOutcome};
use crank_trace::{
ErrorCategory, Stage, StageOutcome, set_parent_from_trace_context, trace_context_for_span,
};
use serde_json::{Map, Value, json};
use time::OffsetDateTime;
use tokio::sync::{OwnedSemaphorePermit, Semaphore};
@@ -242,11 +244,22 @@ impl RuntimeExecutor {
&self,
request: RuntimeExecutionRequest<'_>,
) -> Result<Value, RuntimeError> {
log_runtime_event("unary.execute", request.operation, request.request_context);
let runtime_span = Stage::RuntimeExecute.span();
if let Some(context) = request.request_context {
set_parent_from_trace_context(&runtime_span, &context.trace_context);
}
let generated_context = request.request_context.is_none().then(|| {
RuntimeRequestContext::new(
crank_core::RequestId::generate(),
trace_context_for_span(&runtime_span)
.unwrap_or_else(crank_core::TraceContext::generate),
)
});
let request_context = request.request_context.or(generated_context.as_ref());
log_runtime_event("unary.execute", request.operation, request_context);
let started_at = Instant::now();
let invocation_metrics =
ToolInvocationMetrics::start(metric_invocation_source(request.request_context));
let runtime_span = Stage::RuntimeExecute.span();
ToolInvocationMetrics::start(metric_invocation_source(request_context));
let result = async {
let _permit = self.acquire_unary_permit(request.operation)?;
let _inflight = InFlightGuard::runtime();
@@ -261,7 +274,7 @@ impl RuntimeExecutor {
request.operation,
request.input,
prepared_request,
request.request_context,
request_context,
)
.await
}
@@ -274,13 +287,8 @@ impl RuntimeExecutor {
Err(error) => (ToolOutcome::Error, runtime_error_kind(error)),
};
invocation_metrics.complete(outcome, error_kind);
self.record_metering(
request.operation,
request.request_context,
&result,
started_at,
)
.await;
self.record_metering(request.operation, request_context, &result, started_at)
.await;
result
}
@@ -829,7 +837,7 @@ fn log_runtime_event(
operation_id = operation.operation_id.as_str(),
protocol,
request_id = context.request_id.as_str(),
correlation_id = context.correlation_id.as_str(),
trace_id = context.trace_context.trace_id().as_str(),
"runtime execution"
);
} else {