Skip to content

Commit 3a921ce

Browse files
Jeadielukekim
andauthored
enable task name override for non static span names (spiceai#5423)
Co-authored-by: Luke Kim <80174+lukekim@users.noreply.github.com>
1 parent 664e39e commit 3a921ce

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

crates/runtime/src/task_history/otel_exporter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl TaskHistoryExporter {
8383
} else {
8484
Some(span.parent_span_id.to_string().into())
8585
};
86-
let task: Arc<str> = span.name.into();
86+
let task: Arc<str> = extract_attr!(span, "task_override").unwrap_or(span.name.into());
8787
let input: Arc<str> = span
8888
.attributes
8989
.iter()

crates/runtime/src/tools/mcp/catalog.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const HEARTBEAT_INTERVAL_SECONDS: u64 = 30; // 30 seconds
3939
pub(crate) struct McpToolCatalog {
4040
client: Arc<RwLock<Box<dyn McpClientTrait>>>,
4141

42-
/// User defined name & description, not from underlying MCP.
42+
/// Spicepod defined name & description, not from underlying MCP.
4343
name: String,
4444
heartbeat_task: tokio::task::JoinHandle<()>,
4545
}
@@ -190,8 +190,11 @@ impl SpiceToolCatalog for McpToolCatalog {
190190
tools
191191
.into_iter()
192192
.map(|t| {
193-
Arc::new(McpToolWrapper::new(Arc::clone(&self.client), t))
194-
as Arc<dyn SpiceModelTool>
193+
Arc::new(McpToolWrapper::new(
194+
Arc::clone(&self.client),
195+
t,
196+
self.name.clone(),
197+
)) as Arc<dyn SpiceModelTool>
195198
})
196199
.collect()
197200
}
@@ -221,6 +224,7 @@ impl SpiceToolCatalog for McpToolCatalog {
221224
Some(Arc::new(McpToolWrapper::new(
222225
Arc::clone(&self.client),
223226
tool,
227+
self.name.clone(),
224228
)))
225229
}
226230
}

crates/runtime/src/tools/mcp/tool.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,22 @@ use super::{McpProxy, Result};
3131
pub struct McpToolWrapper {
3232
client: Arc<RwLock<Box<dyn McpClientTrait>>>,
3333
spec: McpTool,
34+
35+
/// Spicepod defined name, not from underlying MCP.
36+
server_name: String,
3437
}
3538

3639
impl McpToolWrapper {
37-
pub fn new(client: Arc<RwLock<Box<dyn McpClientTrait>>>, spec: McpTool) -> Self {
38-
Self { client, spec }
40+
pub fn new(
41+
client: Arc<RwLock<Box<dyn McpClientTrait>>>,
42+
spec: McpTool,
43+
server_name: String,
44+
) -> Self {
45+
Self {
46+
client,
47+
spec,
48+
server_name,
49+
}
3950
}
4051

4152
#[must_use]
@@ -68,6 +79,10 @@ impl SpiceModelTool for McpToolWrapper {
6879
_rt: Arc<Runtime>,
6980
) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
7081
let span: Span = tracing::span!(target: "task_history", tracing::Level::INFO, "tool_use::mcp", tool = self.name().to_string(), input = arg);
82+
span.in_scope(
83+
|| tracing::info!(target: "task_history", task_override = %format!("tool_use::{}/{}", self.server_name, self.spec.name), "labels"),
84+
);
85+
7186
let tool_use_result: Result<Value, Box<dyn std::error::Error + Send + Sync>> = async {
7287
let client = self.client.read().await;
7388

0 commit comments

Comments
 (0)