Skip to content

feat(telemetry): Preserve user-provided span names - #319

Open
pradystar wants to merge 2 commits into
mainfrom
feat/SAO-17270-span-names
Open

pradystar wants to merge 2 commits into
mainfrom
feat/SAO-17270-span-names

Conversation

@pradystar

Copy link
Copy Markdown
Collaborator

Export explicit names supplied through Logger, @log, and supported native handlers as splunk_ao.span.name. Preserve the original OTLP span name and GenAI operation attributes. This PR also removes the opt-in normalization mode and its duplicate splunk_ao.* aliases for standard GenAI attributes.

Design document · SAO-17270

@opikalova opikalova left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This review was generated by the Astra agent (claude-opus-5-5). It may contain mistakes.

Verdict: request_changes — LangChain exports framework defaults and inherited metadata as user display names. Removed wire attributes have no changelog entry.

Addressed before this review

  • The PR removed splunk_ao.system, splunk_ao.llm.time_to_first_token_ns and the normalization switch without a changelog entry. Not addressed: HEAD is still 93e32f6, and CHANGELOG.md has no Removed entry. Raised again in this review.
  • LangChain exported unnamed runnable defaults (RunnableSequence, RunnableParallel<...>, lambda function names, LangGraph) as splunk_ao.span.name. Not addressed: HEAD is still 93e32f6. Confirmed again and raised in this review.

General Comments

  • 🟠 major (documentation): This PR removes wire attributes and a config switch. CHANGELOG.md does not record any of them. This concern was raised in an earlier unposted round against this same commit, and it is still open.

Removed items:

  • splunk_ao.system = "splunk_ao_python". The old normalize_attributes_for_export set it before the if not enabled check, so every export carried it by default. This includes caller-owned OTel such as A2A. The updated assertions in tests/test_otel_native_paths.py:307 and splunk-ao-a2a/tests/test_splunk_ao_compatibility.py:79 confirm the change.
  • splunk_ao.llm.time_to_first_token_ns. set_llm_attributes always emitted it. src/splunk_ao/converter/attribute_mapping.py:355 now emits only the seconds value.
  • The SPLUNK_AO_DEV_ENABLE_ATTRIBUTE_NORMALIZATION switch. tests/test_span_transform.py:128 shows it now has no effect.

The description says only "duplicate splunk_ao.* aliases for standard GenAI attributes" are removed. splunk_ao.system is an SDK marker, not an alias. The nanosecond TTFT value was emitted without normalization.

Please answer these questions:

  1. Does any backend, dashboard or detector read splunk_ao.system to find SDK spans?
  2. Does any consumer read the integer nanosecond TTFT value?

If nothing reads them, add a ### Removed entry to CHANGELOG.md for both attributes and the switch. AGENTS.md requires a changelog update when public behaviour changes. If something reads them, keep them.

  • 🟡 minor (question): The description says names from "supported native handlers" are exported. The ADK integration is not wired.

splunk-ao-adk/src/splunk_ao_adk/span_manager.py:42-200 calls start_node without _otel_display_name. So ADK agent spans never get splunk_ao.span.name, although LlmAgent(name=...) is user-supplied. ADK names such as agent_run [{name}] are formatted, so they need a separate raw-name source.

Is ADK out of scope for SAO-17270? If yes, state that in the description and the changelog entry. If no, pass the raw agent name as _otel_display_name in span_manager.py.

Follow-ups

Suggested follow-up work that could be tracked as Jira tickets:

  • src/splunk_ao/handlers/langchain/middleware.py:266-290: wrap_tool_call and awrap_tool_call read request.tool_call["name"] a second time after _prepare_tool_call_params already reads it. Return the raw name from _prepare_tool_call_params instead. Then one place handles a missing or non-dict tool_call.

Skills and MCP tools used

  • Skills: none
  • MCP tools: none

Comment on lines +76 to +82
callback_name = kwargs.get("name")
class_reference = options.get("id")
if isinstance(class_reference, list) and class_reference and callback_name == class_reference[-1]:
callback_name = None
if node_type == "tool" and not callback_name:
callback_name = options.get("name")
return callback_name if isinstance(callback_name, str) else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 major (bug): Unnamed LangChain runnables export framework defaults as user display names. An earlier unposted round raised this against this commit, and it is still present.

langchain-core always passes name=config.get("run_name") or self.get_name() to on_chain_start. Composite runnables pass serialized=None (langchain_core/runnables/base.py:3426-3428). With no id, the check on line 78 never clears the name.

I ran ChatPromptTemplate | RunnableLambda(f) | RunnableParallel(a=...) with no run_name through this helper. The results were:

  • RunnableSequence -> "RunnableSequence"
  • f -> "f"
  • RunnableParallel<a> -> "RunnableParallel<a>"
  • inner RunnableLambda -> "RunnableLambda"
  • ChatPromptTemplate -> None (correct)

An uncompiled LangGraph root has the default name "LangGraph" and behaves the same way. As a result, almost every LCEL or LangGraph trace gets a splunk_ao.span.name that the user did not supply. The f case also conflicts with @log, which treats func.__name__ as not explicit (src/splunk_ao/decorator.py:632-634).

Possible fixes:

  1. Drop the chain name when serialized is None. This is simple, but it loses real run_name values on composite runnables.
  2. Also reject generated forms: names that start with Runnable, and "LangGraph". This is more precise, but it is a heuristic list.
  3. Use only sources that are explicit by construction: a root run_name detected at the call site, metadata["langgraph_node"], and the tool serialized["name"].

Add a chain-callback regression test that passes the name kwarg the way langchain-core does.

🤖 Generated by the Astra agent

Comment on lines +72 to +75
metadata = kwargs.get("metadata")
configured_name = metadata.get("name") if isinstance(metadata, dict) else None
if isinstance(configured_name, str) and configured_name.strip():
return configured_name

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 major (bug): metadata["name"] is inherited by every descendant run, so one root name becomes the display name of every span in the tree.

LangChain merges parent config["metadata"] into each child config. I ran prompt | RunnableLambda(...) | search_tool with config={"metadata": {"name": "Checkout"}}. The helper returned "Checkout" for RunnableSequence, ChatPromptTemplate, RunnableLambda, and the search tool. LLM and retriever callbacks get the same inherited metadata.

Because metadata wins over every other source on line 74, explicit tool names are also hidden.

Fix options:

  1. Use metadata["name"] only for a run with no parent_run_id. Pass parent_run_id into _get_display_name from each callback.
  2. Use it only when it differs from the parent node's inherited value.

Add a test with a nested run and inherited metadata.

🤖 Generated by the Astra agent

Comment thread tests/test_langchain.py
assert child.parent == root.context
assert child.name == "execute_tool search"
assert child.attributes["splunk_ao.span.name"] == "search"
assert "splunk_ao.span.name" not in root.attributes

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 minor (testing): This test calls on_chain_start without the name kwarg. Real langchain-core always passes name=run_name or get_name(). So the assertion passes here but fails for every real unnamed RunnableSequence root.

Other new paths have no display-name test. I searched tests/ for splunk_ao.span.name and _otel_display_name. Only test_langchain.py, test_logger_otel_egress.py, test_openai.py and test_span_transform.py match. These paths have no coverage:

  • LangChain chain, LLM, chat and retriever callbacks, sync and async
  • SplunkAOMiddleware.wrap_tool_call and awrap_tool_call
  • CrewAI crew, agent, task and tool events
  • OpenAI Agents owned root and incremental spans
  • add_agent_span and add_control_span

Add tests that pass framework kwargs in the shape the framework really sends. Cover both named and unnamed cases.

🤖 Generated by the Astra agent

@opikalova
opikalova requested a review from etserend November 20, 2026 15:17

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants