feat(otel): propagate session.id to spans and log records (#7490)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Adrian Cole
2026-03-16 13:06:31 +08:00
committed by GitHub
parent 10d597de3b
commit 2631095f20
20 changed files with 193 additions and 126 deletions
+8 -7
View File
@@ -7,6 +7,7 @@ use std::sync::Arc;
use anyhow::{anyhow, Context, Result};
use futures::stream::BoxStream;
use futures::{stream, FutureExt, Stream, StreamExt, TryStreamExt};
use tracing_futures::Instrument;
use uuid::Uuid;
use super::container::Container;
@@ -492,7 +493,7 @@ impl Agent {
}
/// Dispatch a single tool call to the appropriate client
#[instrument(skip(self, tool_call, request_id, session), fields(input, output, session_id = %session.id))]
#[instrument(skip(self, tool_call, request_id, cancellation_token, session), fields(input, output, session.id = %session.id))]
pub async fn dispatch_tool_call(
&self,
tool_call: CallToolRequestParams,
@@ -875,8 +876,8 @@ impl Agent {
}
#[instrument(
skip(self, user_message, session_config),
fields(user_message, trace_input)
skip(self, user_message, session_config, cancel_token),
fields(user_message, trace_input, session.id = %session_config.id)
)]
pub async fn reply(
&self,
@@ -1120,9 +1121,8 @@ impl Agent {
}
let working_dir = session.working_dir.clone();
Ok(Box::pin(async_stream::try_stream! {
let reply_stream_span = tracing::info_span!(target: "goose::agents::agent", "reply_stream");
let _stream_guard = reply_stream_span.enter();
let reply_stream_span = tracing::info_span!(target: "goose::agents::agent", "reply_stream", session.id = %session_config.id);
let inner = Box::pin(async_stream::try_stream! {
let mut turns_taken = 0u32;
let max_turns = session_config.max_turns.unwrap_or_else(|| {
Config::global()
@@ -1690,7 +1690,8 @@ impl Agent {
if !last_assistant_text.is_empty() {
tracing::info!(target: "goose::agents::agent", trace_output = last_assistant_text.as_str());
}
}))
}.instrument(reply_stream_span));
Ok(inner)
}
pub async fn extend_system_prompt(&self, key: String, instruction: String) {
+6 -2
View File
@@ -205,8 +205,12 @@ impl Agent {
Ok((tools, toolshim_tools, system_prompt))
}
/// Stream a response from the LLM provider.
/// Handles toolshim transformations if needed
// Don't add gen_ai.request.model here — provider.get_model_config()
// returns the wrong model for LeadWorkerProvider.
#[tracing::instrument(
skip(provider, session_id, system_prompt, messages, tools, toolshim_tools),
fields(session.id = %session_id)
)]
pub(crate) async fn stream_response_from_provider(
provider: Arc<dyn Provider>,
session_id: &str,