10000 fix(telemetry): fix agent span start and end when using Agent.stream_async() by awsarron · Pull Request #119 · strands-agents/sdk-python · GitHub
[go: up one dir, main page]

Skip to content

fix(telemetry): fix agent span start and end when using Agent.stream_async() #119

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

Merged
merged 2 commits into from
May 26, 2025

Conversation

awsarron
Copy link
Member

Description

Fix agent span start and end when using Agent.stream_async()

Related Issues

#118

Documentation PR

N/A

Type of Change

  • Bug fix

Testing

#!/usr/bin/env python

import asyncio
import logging
import os
from strands import Agent, tool
from strands_tools import calculator, http_request, image_reader

logging.getLogger("strands.telemetry.tracer").setLevel(logging.DEBUG)
logging.basicConfig(
    format="%(levelname)s | %(name)s | %(message)s",
    handlers=[logging.StreamHandler()]
)

os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://us.cloud.langfuse.com/api/public/otel"
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = "Authorization=Basic <REDACTED>"

agent = Agent(
    system_prompt="You are a helpful assistant that provides concise responses.",
    tools=[http_request, calculator, image_reader],
    trace_attributes={
        "session.id": "abc-1234",
        "user.id": "user-email-example@domain.com",
        "langfuse.tags": [
            "Agent-SDK",
            "Okatank-Project",
            "Observability-Tags",
        ]
    },
    callback_handler=None,
)

async def process_streaming_response():
    agent_stream = agent.stream_async("\u30d5\u30a9\u30fc Describe the image at /Users/arron/strands-samples/01-getting-started/00-first-agent/images/architecture.png")
    async for event in agent_stream:
        print(event)

# Run the agent
asyncio.run(process_streaming_response())

Checklist

  • I have read the CONTRIBUTING document
  • I have added tests that prove my fix is effective or my feature works
  • [-] I have updated the documentation accordingly
  • [-] I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@awsarron awsarron merged commit bd60f90 into strands-agents:main May 26, 2025
10 checks passed
@awsarron awsarron deleted the fix-telemetry-stream-async branch May 26, 2025 17:06
awsarron added a commit to awsarron/sdk-python that referenced this pull request May 26, 2025
awsarron added a commit that referenced this pull request May 26, 2025
* models - openai - argument none (#97)

* docs(readme): add open PRs badge + link to samples repo + change 'Docs' to 'Documentation' (#100)

* docs(readme): add logo (#101)

* docs(readme): add logo, title, badges, links to other repos, standardize headings (#102)

* style(readme): use dark logo for clearer visibility when system is using light color scheme (#104)

* fix(readme): use logo that changes color automatically depending on user's color preference scheme (#105)

* feat(handlers): add reasoning text to callback handler and related tests (#109)

* feat(handlers): add reasoning text to callback handler and related tests

* feat(handlers): removed redundant comment in .gitignore file

* feat(handlers): Updated reasoningText type as (Optional[str]

* feat: Add dynamic system prompt override functionality (#108)

* Modularizing Event Loop (#106)

* fix(telemetry): fix agent span start and end when using Agent.stream_async() (#119)

* feat: Update SlidingWindowConversationManager (#120)

* v0.1.5

---------

Co-authored-by: Patrick Gray <pgrayy@amazon.com>
Co-authored-by: Gokhan (Joe) Gultekin <joseph.gueltekin@gmail.com>
Co-authored-by: Shubham Raut <shubhamrao12321@gmail.com>
Co-authored-by: fede-dash <fede.kamelhar@doordash.com>
Co-authored-by: Nick Clegg <nac542@gmail.com>
@Unshure Unshure mentioned this pull request May 27, 2025
3 tasks
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
0