Skip to content

[BUG] OTEL context not passed from Agent to Agent #489

@jonesaws

Description

@jonesaws

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.0.0

Python Version

3.12.4

Operating System

macOS 15.5

Installation Method

pip

Steps to Reproduce

Using a simple requirements.txt:

strands-agents[otel]>=0.1.0

And a basic python file:

import os
from strands import Agent, tool
from strands.telemetry import StrandsTelemetry

# Set up OpenTelemetry environment variables
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "http://localhost:4318"

# Set up basic logging
logging.basicConfig(level=logging.INFO, format="%(levelname)s | %(name)s | %(message)s")
logging.getLogger("strands").setLevel(logging.DEBUG)

strands_telemetry = StrandsTelemetry()
strands_telemetry.setup_otlp_exporter()

# Define the child agent as a tool
@tool
def child_agent(query: str) -> str:
    """
    A child agent that processes specific tasks delegated by the parent agent.
    
    Args:
        query: The task or question to process
        
    Returns:
        Processed result as a string
    """
    # Create a specialized child agent
    agent = Agent(
        system_prompt="""You are a helpful child agent. 
        Your job is to assist the parent agent by providing detailed information and analysis.
        Always be thorough and precise in your responses."""
    )
    result = agent(query)
    return str(result)

# Simple CLI interface with integrated parent agent
if __name__ == "__main__":
    print("Simple Strands Parent-Child Agent Demo")
    print("Type 'exit' to quit")
    
    # Create the parent agent with the child agent as a tool
    parent_agent = Agent(
        system_prompt="""You are a parent agent that delegates tasks to a child agent.
        Use the child_agent tool when you need detailed information or analysis.
        Synthesize the information from the child agent into your final response.""",
        tools=[child_agent]
    )
    
    while True:
        user_input = input("\nEnter your query: ")
        if user_input.lower() == 'exit':
            break
            
        try:
            response = parent_agent(user_input)
            print(f"\nResponse: {response}")
        except Exception as e:
            print(f"Error: {str(e)}")

Reviewing traces shows that there is no parent emitted, so the siblings do not get related in tooling (in my case Jaeger).

Expected Behavior

OTEL visualisation tooling should show the entire trace, with the events from the child agent showing under the parent agent.

Actual Behavior

Events do not get related in tooling. Example emitted traces are as follows:

{
    "name": "Model invoke",
    "context": {
        "trace_id": "0x7cf7751ee1c4653242b7fc4f9f8ef87b",
        "span_id": "0xbdf3af588db20374",
        "trace_state": "[]"
    },
    "kind": "SpanKind.CLIENT",
    "parent_id": "0x378f694c49fa6724",
    "start_time": "2025-07-17T10:25:32.990367Z",
    "end_time": "2025-07-17T10:25:37.160431Z",
    "status": {
        "status_code": "OK"
    },
    "attributes": {
        "gen_ai.event.start_time": "2025-07-17T10:25:32.990369+00:00",
        "gen_ai.system": "strands-agents",
        "gen_ai.operation.name": "chat",
        "gen_ai.request.model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
        "gen_ai.event.end_time": "2025-07-17T10:25:37.160300+00:00",
        "gen_ai.usage.prompt_tokens": 478,
        "gen_ai.usage.input_tokens": 478,
        "gen_ai.usage.completion_tokens": 106,
        "gen_ai.usage.output_tokens": 106,
        "gen_ai.usage.total_tokens": 584
    },
    "events": [
        {
            "name": "gen_ai.user.message",
            "timestamp": "2025-07-17T10:25:32.990396Z",
            "attributes": {
                "content": "[{\"text\": \"is the ChildAgent working?\"}]"
            }
        },
        {
            "name": "gen_ai.choice",
            "timestamp": "2025-07-17T10:25:37.160277Z",
            "attributes": {
                "finish_reason": "tool_use",
                "message": "[{\"text\": \"I'd be happy to check if the ChildAgent is working properly. I can do this by sending a simple test query to the child agent and seeing if it responds correctly.\"}, {\"toolUse\": {\"toolUseId\": \"tooluse_iU3WUffATFCnBv8PCP6I0Q\", \"name\": \"child_agent\", \"input\": {\"query\": \"Hello, are you functioning properly? Please confirm that you're receiving and processing this message.\"}}}]"
            }
        }
    ],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.33.1",
            "service.name": "strands-agents",
            "service.version": "0.2.1"
        },
        "schema_url": ""
    }
}

{
    "name": "Model invoke",
    "context": {
        "trace_id": "0xa2faf1bf8ba57f1fa33dc8304d700668",
        "span_id": "0x298560abc561ed38",
        "trace_state": "[]"
    },
    "kind": "SpanKind.CLIENT",
    "parent_id": "0xf95f042d9cd5201b",
    "start_time": "2025-07-17T10:25:37.714615Z",
    "end_time": "2025-07-17T10:25:39.878535Z",
    "status": {
        "status_code": "OK"
    },
    "attributes": {
        "gen_ai.event.start_time": "2025-07-17T10:25:37.714616+00:00",
        "gen_ai.system": "strands-agents",
        "gen_ai.operation.name": "chat",
        "gen_ai.request.model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
        "gen_ai.event.end_time": "2025-07-17T10:25:39.878354+00:00",
        "gen_ai.usage.prompt_tokens": 62,
        "gen_ai.usage.input_tokens": 62,
        "gen_ai.usage.completion_tokens": 53,
        "gen_ai.usage.output_tokens": 53,
        "gen_ai.usage.total_tokens": 115
    },
    "events": [
        {
            "name": "gen_ai.user.message",
            "timestamp": "2025-07-17T10:25:37.714629Z",
            "attributes": {
                "content": "[{\"text\": \"Hello, are you functioning properly? Please confirm that you're receiving and processing this message.\"}]"
            }
        },
        {
            "name": "gen_ai.choice",
            "timestamp": "2025-07-17T10:25:39.878275Z",
            "attributes": {
                "finish_reason": "end_turn",
                "message": "[{\"text\": \"I'm functioning properly and I can confirm that I'm receiving and processing your message. As a helpful child agent, I'm ready to provide detailed information and analysis to assist the parent agent with whatever task is needed. How can I help you today?\"}]"
            }
        }
    ],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.33.1",
            "service.name": "strands-agents",
            "service.version": "0.2.1"
        },
        "schema_url": ""
    }
}
{
    "name": "Cycle fca857e2-fcaf-49bd-980f-1fe18ade1d17",
    "context": {
        "trace_id": "0xa2faf1bf8ba57f1fa33dc8304d700668",
        "span_id": "0xf95f042d9cd5201b",
        "trace_state": "[]"
    },
    "kind": "SpanKind.INTERNAL",
    "parent_id": "0x9bb6fe868d422dbb",
    "start_time": "2025-07-17T10:25:37.714565Z",
    "end_time": "2025-07-17T10:25:39.889124Z",
    "status": {
        "status_code": "OK"
    },
    "attributes": {
        "gen_ai.event.start_time": "2025-07-17T10:25:37.714566+00:00",
        "event_loop.cycle_id": "fca857e2-fcaf-49bd-980f-1fe18ade1d17",
        "gen_ai.event.end_time": "2025-07-17T10:25:39.889078+00:00"
    },
    "events": [
        {
            "name": "gen_ai.user.message",
            "timestamp": "2025-07-17T10:25:37.714590Z",
            "attributes": {
                "content": "[{\"text\": \"Hello, are you functioning properly? Please confirm that you're receiving and processing this message.\"}]"
            }
        },
        {
            "name": "gen_ai.choice",
            "timestamp": "2025-07-17T10:25:39.889064Z",
            "attributes": {
                "message": "[{\"text\": \"I'm functioning properly and I can confirm that I'm receiving and processing your message. As a helpful child agent, I'm ready to provide detailed information and analysis to assist the parent agent with whatever task is needed. How can I help you today?\"}]"
            }
        }
    ],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.33.1",
            "service.name": "strands-agents",
            "service.version": "0.2.1"
        },
        "schema_url": ""
    }
}

{
    "name": "invoke_agent Strands Agents",
    "context": {
        "trace_id": "0xa2faf1bf8ba57f1fa33dc8304d700668",
        "span_id": "0x9bb6fe868d422dbb",
        "trace_state": "[]"
    },
    "kind": "SpanKind.CLIENT",
    "parent_id": null,
    "start_time": "2025-07-17T10:25:37.714435Z",
    "end_time": "2025-07-17T10:25:39.902323Z",
    "status": {
        "status_code": "OK"
    },
    "attributes": {
        "gen_ai.event.start_time": "2025-07-17T10:25:37.714439+00:00",
        "gen_ai.system": "strands-agents",
        "gen_ai.agent.name": "Strands Agents",
        "gen_ai.operation.name": "invoke_agent",
        "gen_ai.request.model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
        "system_prompt": "You are a helpful child agent. \n        Your job is to assist the parent agent by providing detailed information and analysis.\n        Always be thorough and precise in your responses.",
        "gen_ai.event.end_time": "2025-07-17T10:25:39.902277+00:00",
        "gen_ai.usage.prompt_tokens": 62,
        "gen_ai.usage.completion_tokens": 53,
        "gen_ai.usage.input_tokens": 62,
        "gen_ai.usage.output_tokens": 53,
        "gen_ai.usage.total_tokens": 115
    },
    "events": [
        {
            "name": "gen_ai.user.message",
            "timestamp": "2025-07-17T10:25:37.714469Z",
            "attributes": {
                "content": "Hello, are you functioning properly? Please confirm that you're receiving and processing this message."
            }
        },
        {
            "name": "gen_ai.choice",
            "timestamp": "2025-07-17T10:25:39.902263Z",
            "attributes": {
                "message": "I'm functioning properly and I can confirm that I'm receiving and processing your message. As a helpful child agent, I'm ready to provide detailed information and analysis to assist the parent agent with whatever task is needed. How can I help you today?\n",
                "finish_reason": "end_turn"
            }
        }
    ],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.33.1",
            "service.name": "strands-agents",
            "service.version": "0.2.1"
        },
        "schema_url": ""
    }
}
{
    "name": "Tool: child_agent",
    "context": {
        "trace_id": "0x7cf7751ee1c4653242b7fc4f9f8ef87b",
        "span_id": "0x2786e5cd3d7d9638",
        "trace_state": "[]"
    },
    "kind": "SpanKind.INTERNAL",
    "parent_id": "0x378f694c49fa6724",
    "start_time": "2025-07-17T10:25:37.205271Z",
    "end_time": "2025-07-17T10:25:39.911305Z",
    "status": {
        "status_code": "OK"
    },
    "attributes": {
        "gen_ai.event.start_time": "2025-07-17T10:25:37.205274+00:00",
        "gen_ai.operation.name": "execute_tool",
        "gen_ai.system": "strands-agents",
        "gen_ai.tool.name": "child_agent",
        "gen_ai.tool.call.id": "tooluse_iU3WUffATFCnBv8PCP6I0Q",
        "gen_ai.event.end_time": "2025-07-17T10:25:39.911282+00:00",
        "tool.status": "success"
    },
    "events": [
        {
            "name": "gen_ai.tool.message",
            "timestamp": "2025-07-17T10:25:37.205321Z",
            "attributes": {
                "role": "tool",
                "content": "{\"query\": \"Hello, are you functioning properly? Please confirm that you're receiving and processing this message.\"}",
                "id": "tooluse_iU3WUffATFCnBv8PCP6I0Q"
            }
        },
        {
            "name": "gen_ai.choice",
            "timestamp": "2025-07-17T10:25:39.911275Z",
            "attributes": {
                "message": "[{\"text\": \"I'm functioning properly and I can confirm that I'm receiving and processing your message. As a helpful child agent, I'm ready to provide detailed information and analysis to assist the parent agent with whatever task is needed. How can I help you today?\\n\"}]",
                "id": "tooluse_iU3WUffATFCnBv8PCP6I0Q"
            }
        }
    ],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.33.1",
            "service.name": "strands-agents",
            "service.version": "0.2.1"
        },
        "schema_url": ""
    }
}
{
    "name": "Cycle cd0ce784-724d-48fc-9b8c-3cd618f9dbdc",
    "context": {
        "trace_id": "0x7cf7751ee1c4653242b7fc4f9f8ef87b",
        "span_id": "0x378f694c49fa6724",
        "trace_state": "[]"
    },
    "kind": "SpanKind.INTERNAL",
    "parent_id": "0xeb4a32a53e398304",
    "start_time": "2025-07-17T10:25:32.990244Z",
    "end_time": "2025-07-17T10:25:39.917613Z",
    "status": {
        "status_code": "OK"
    },
    "attributes": {
        "gen_ai.event.start_time": "2025-07-17T10:25:32.990248+00:00",
        "event_loop.cycle_id": "cd0ce784-724d-48fc-9b8c-3cd618f9dbdc",
        "gen_ai.event.end_time": "2025-07-17T10:25:39.917589+00:00"
    },
    "events": [
        {
            "name": "gen_ai.user.message",
            "timestamp": "2025-07-17T10:25:32.990297Z",
            "attributes": {
                "content": "[{\"text\": \"is the ChildAgent working?\"}]"
            }
        },
        {
            "name": "gen_ai.choice",
            "timestamp": "2025-07-17T10:25:39.917570Z",
            "attributes": {
                "message": "[{\"text\": \"I'd be happy to check if the ChildAgent is working properly. I can do this by sending a simple test query to the child agent and seeing if it responds correctly.\"}, {\"toolUse\": {\"toolUseId\": \"tooluse_iU3WUffATFCnBv8PCP6I0Q\", \"name\": \"child_agent\", \"input\": {\"query\": \"Hello, are you functioning properly? Please confirm that you're receiving and processing this message.\"}}}]",
                "tool.result": "[{\"toolResult\": {\"toolUseId\": \"tooluse_iU3WUffATFCnBv8PCP6I0Q\", \"status\": \"success\", \"content\": [{\"text\": \"I'm functioning properly and I can confirm that I'm receiving and processing your message. As a helpful child agent, I'm ready to provide detailed information and analysis to assist the parent agent with whatever task is needed. How can I help you today?\\n\"}]}}]"
            }
        }
    ],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.33.1",
            "service.name": "strands-agents",
            "service.version": "0.2.1"
        },
        "schema_url": ""
    }
}

Additional Context

No response

Possible Solution

No response

Related Issues

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