Skip to content

invoke_agent_span with propagate=True does not propagate agent_name and agent_id to children spans #55

@benedict-khoo-sap

Description

@benedict-khoo-sap

Describe the Bug

I tried instrumenting a langgraph agent with invoke_agent_span and propagate=True and I see a span appearing in CLS with the agent ID and name I provided. However, that same agent (in a single invocation) also produced a span with an agent name of LangGraph and a different agent ID. I expected all the children spans of my invoke_agent_span to inherit the same agent ID and name (because propagate=True).

Steps to Reproduce

  1. Clone https://github.tools.sap/Montana-AI-Singapore/a2a-server-samples
  2. Check out branch instrumentation-agent-id
  3. cd appfnd-langgraph-basic
  4. Copy .env.example and fill up the credentials with a valid AI Core and CLS instance
  5. uv run app to start the server
  6. Invoke the agent. Example curl request
curl --request POST \
  --url http://localhost:10000/v1/message:stream \
  --header 'content-type: application/json' \
  --data '{
  "message": {
    "messageId": "a52d542b-06cb-4e9a-b36e-15ee6cb7eee4",
    "role": "ROLE_USER",
    "content": [
      {
        "text": "5 USD to SGD"
      }
    ]
  }
}'
  1. Go to your CLS dashboard -> Dev Tools and use the OpenSearch query (fill up the service name)
GET otel-v1-apm-span-*/_search
{
  "size": 1000,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
             "serviceName": "<WHATEVER_YOU_FILLED_APPFND_CONHOS_APP_NAME_WITH>"
          }
        }
     ]
    }}
    ,
    "sort": [
      { "startTime": { "order": "desc" } }
    ]
}
  1. See Expected Behavior

Expected Behavior

In the search result from the repro steps,

  • Look for "span.attributes.gen_ai@operation@name": "invoke_agent". There should be 3 spans.
  • I expect to see all invoke_agent spans have span.attributes.gen_ai@agent@id with the agent_id value I provided (f268d3fd-096f-4ebc-b7ed-6fc03dfb3dde if you used the value in .env.example). Instead, I see only 2 instances: one with the value I set and another with a different ID. 1 of the invoke_agent spans is missing its span.attributes.gen_ai@agent@id field.
  • I expect to see all invoke_agent spans have "span.attributes.gen_ai@agent@name" with the agent_name value I provided (currency-agent-local if you used the value in .env.example). Instead, I see 1 instance of currency-agent-local (as expected) and 2 instances of Langgraph.

Screenshots

No response

Used Versions

  • Python version via python --version: 3.12
  • SAP Cloud SDK for Python version: sap-cloud-sdk~=0.6.1

See pyproject.toml in the example for version details

Code Examples

# Your code here

Stack Trace

No response

Log File

Log file ...

Affected Development Phase

Development

Impact

Impaired

Timeline

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions