Repository navigation
fix: gate span content capture behind OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dbe104b
53bb292
5c2d260
b116d73
bf9b4e3
cf7de4e
57fffba
83bf0a7
ad8bea6
ab3bd45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import { | |
| isTraceEnabled, | ||
| markSeen, | ||
| modelRef, | ||
| redactErrorMessage, | ||
| resolveSubagentTraceContext, | ||
| setBoundedMap, | ||
| totalTokens, | ||
|
|
@@ -191,7 +192,7 @@ export function handleExecutionStarted(e: EventOf<"session.execution.started">, | |
| const parentCtx = isSubagent && totals?.parentID | ||
| ? resolveSubagentTraceContext(sessionID, totals.parentID, totals.agent, ctx) | ||
| : ctx.rootContext() | ||
| const promptText = pendingPrompt?.text ?? "" | ||
| const promptText = (pendingPrompt?.text ?? "").slice(0, 64_000) | ||
|
|
||
| const span = ctx.tracer.startSpan( | ||
| `${ctx.tracePrefix}session`, | ||
|
|
@@ -203,7 +204,7 @@ export function handleExecutionStarted(e: EventOf<"session.execution.started">, | |
| [AGENT_NAME]: totals?.agent ?? "unknown", | ||
| "agent.type": totals?.agentType ?? "primary", | ||
| "session.is_subagent": isSubagent, | ||
| ...(promptText | ||
| ...(promptText && ctx.captureContent | ||
| ? { | ||
| [INPUT_VALUE]: promptText, | ||
| [INPUT_MIME_TYPE]: MimeType.TEXT, | ||
|
|
@@ -258,8 +259,8 @@ export function handleExecutionEnded( | |
| } | ||
| if (outcome.type === "failed") { | ||
| const message = errorSummary(outcome.error) | ||
| span.setStatus({ code: SpanStatusCode.ERROR, message }) | ||
| span.setAttribute("error", message) | ||
| span.setStatus({ code: SpanStatusCode.ERROR, message: ctx.captureContent ? message : redactErrorMessage(message) }) | ||
| span.setAttribute("error", ctx.captureContent ? message : redactErrorMessage(message)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } else if (outcome.type === "interrupted") { | ||
| span.setAttribute("session.interrupted_reason", outcome.reason) | ||
| span.setStatus({ code: SpanStatusCode.OK }) | ||
|
|
@@ -273,6 +274,7 @@ export function handleExecutionEnded( | |
|
|
||
| if (outcome.type === "failed") { | ||
| const message = errorSummary(outcome.error) | ||
| const safeMessage = ctx.captureContent ? message : redactErrorMessage(message) | ||
| ctx.emitLog({ | ||
| severityNumber: SeverityNumber.ERROR, | ||
| severityText: "ERROR", | ||
|
|
@@ -282,12 +284,12 @@ export function handleExecutionEnded( | |
| attributes: { | ||
| "event.name": "session.error", | ||
| "session.id": sessionID, | ||
| error: message, | ||
| error: safeMessage, | ||
| ...agentAttrs(totals?.agent ?? "unknown", totals?.agentType ?? "unknown"), | ||
| ...ctx.commonAttrs, | ||
| }, | ||
| }) | ||
| void ctx.log("error", "otel: session.error", { sessionID, error: message }) | ||
| void ctx.log("error", "otel: session.error", { sessionID, error: safeMessage }) | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When content capture is enabled for a prompt longer than 64,000 characters,
handleExecutionStartedputs the entirependingPrompt.textintoinput.valueandllm.input_messages; unlikehandleStepStarted, this session-span path never slices it. This can still create an oversized span despite the new content limit, so cap the root prompt before attaching it.AGENTS.md reference: AGENTS.md:L61-L61
Useful? React with 👍 / 👎.