Answer: Use the `runInDevTraceSpan` function to wrap any section of code in a trace span, passing an operation type and optional attributes, then record input, output, attributes, and errors via the `metadata` object. Status: Confirmed Entry: tool/gemini-cli/troubleshooting/instrument-code-traces Revision: 1 Digest: sha256:1013349198fa1efa (changes whenever the content changes) Timeline: Created: 2026-11-13T03:18:44Z Last changed: 2026-11-13T03:18:44Z Last verified: 2026-11-20T12:53:23Z Next check: 2026-11-21T12:53:23Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of function | runInDevTraceSpan | [1] | 2026-11-20 import source | @google/gemini-cli-core | [1] | 2026-11-20 operation enum | GeminiCliOperation | [1] | 2026-11-20 metadata.input | metadata.input | [1] | 2026-11-20 metadata.output | metadata.output | [1] | 2026-11-20 metadata.attributes | metadata.attributes | [1] | 2026-11-20 metadata.error | metadata.error | [1] | 2026-11-20 Sources: [1] Google. "Local development guide". https://geminicli.com/docs/local-development.md Role: primary. Accessed: 2026-11-20T12:53:23Z Quote: "Use the `runInDevTraceSpan` function to wrap any section of code in a trace span." (Supports: function) Quote: "import { runInDevTraceSpan } from '@google/gemini-cli-core';" (Supports: import source) Quote: "`operation`: The operation type of the span, represented by the `GeminiCliOperation` enum." (Supports: operation enum) Quote: "`metadata.input`: (Optional) An object containing the input data for the traced operation." (Supports: metadata.input) Quote: "`metadata.output`: (Optional) An object containing the output data from the traced operation." (Supports: metadata.output) Quote: "`metadata.attributes`: (Optional) A record of custom attributes to add to the span." (Supports: metadata.attributes) Quote: "`metadata.error`: (Optional) An error object to record if the operation fails." (Supports: metadata.error) Published: 2026-10-16T02:36:07Z Snapshot SHA-256: 9e0238545439a95ea1a15136f7b5da2a10b6f54fded386cb636d102a1e8d8f2f (captured 2026-11-13T03:18:43Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. On this check the text of [1] was unchanged since 2026-11-13T03:18:44Z, so the values verified then were kept. Cross-check: not-available at 2026-11-20T12:53:23Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:53:23Z Last attempt: 2026-11-20T12:53:23Z Notes and limitations: Extracted automatically from a single official source (section "Instrument code with traces"). Related: https://latestn.com/tool/gemini-cli/troubleshooting/mcp-server-connection-issues How do I troubleshoot an MCP server that won't connect in Gemini CLI? https://latestn.com/tool/gemini-cli/troubleshooting/regenerate-model-responses How do I regenerate model responses for Gemini CLI integration tests? https://latestn.com/tool/gemini-cli/troubleshooting/run-integration-tests How do I run Gemini CLI integration tests? https://latestn.com/tool/gemini-cli/troubleshooting/fix-429-resource-exhausted Why am I getting an API error 429 Resource exhausted in Gemini CLI? https://latestn.com/tool/gemini-cli/troubleshooting/fix-named-user-subscription-error How do I fix the Gemini CLI authentication error about needing a named user on an organization's Gemini Code Assist Standard edition subscription? https://latestn.com/tool/gemini-cli/troubleshooting/headless-exit-codes What do the exit codes mean in Gemini CLI headless mode? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-13T03:18:44Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/gemini-cli/troubleshooting/instrument-code-traces/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/gemini-cli/troubleshooting/instrument-code-traces POST: https://latestn.com/dispute/tool/gemini-cli/troubleshooting/instrument-code-traces with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/gemini-cli/troubleshooting/instrument-code-traces?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I instrument code with traces in Gemini CLI? Revision 1, last verified 2026-11-20T12:53:23Z. https://latestn.com/tool/gemini-cli/troubleshooting/instrument-code-traces (accessed 2026-11-21T09:54:38Z). @misc{LatestN_tool_gemini_cli_troubleshooting_instrument_code_traces_r1, title = {How do I instrument code with traces in Gemini CLI?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/gemini-cli/troubleshooting/instrument-code-traces}}, note = {Revision 1; digest sha256:1013349198fa1efa; last verified 2026-11-20T12:53:23Z; accessed 2026-11-21T09:54:38Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/gemini-cli/troubleshooting/instrument-code-traces