-
Notifications
You must be signed in to change notification settings - Fork 13
[Observability]Add agent frame observation extension #12
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
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9e32406
Add af extension
Jimh333 1038692
reformat
Jimh333 bf9c469
clean up unsused import
Jimh333 e6e3377
Clean up
Jimh333 708ba0c
reformat
Jimh333 2855393
uv run
Jimh333 42624c3
update setup versioning format
Jimh333 a38e4b2
add integration test for agent framework
Jimh333 9ca6926
Fix integration test
Jimh333 b704be7
format
Jimh333 a6acd1a
clean up
Jimh333 c2bd9de
change dependency version
Jimh333 a5a564f
update copyright
Jimh333 14d1634
move process logic to onstart
Jimh333 05f275c
Merge branch 'main' into user/jianhan/ob_af_extension
Jimh333 cc5b282
reformat
Jimh333 da1759a
add env setting info to readme
Jimh333 b379010
update readme
Jimh333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Empty file.
1 change: 1 addition & 0 deletions
1
...-agentframework/microsoft_agents_a365/observability/extensions/agentframework/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
JianH marked this conversation as resolved.
Outdated
|
||
34 changes: 34 additions & 0 deletions
34
...framework/microsoft_agents_a365/observability/extensions/agentframework/span_processor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
JianH marked this conversation as resolved.
Outdated
JianH marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Custom Span Processor | ||
|
|
||
| from opentelemetry.sdk.trace.export import SpanProcessor | ||
|
|
||
| from microsoft_agents_a365.observability.core.constants import ( | ||
| GEN_AI_OPERATION_NAME_KEY, | ||
| EXECUTE_TOOL_OPERATION_NAME, | ||
| GEN_AI_EVENT_CONTENT, | ||
| ) | ||
|
|
||
|
|
||
| class AgentFrameworkSpanProcessor(SpanProcessor): | ||
| """ | ||
| SpanProcessor for Agent Framework. | ||
| """ | ||
|
|
||
| TOOL_CALL_RESULT_TAG = "gen_ai.tool.call.result" | ||
|
JianH marked this conversation as resolved.
|
||
|
|
||
| def __init__(self, service_name: str | None = None): | ||
| self.service_name = service_name | ||
|
JianH marked this conversation as resolved.
|
||
| super().__init__() | ||
|
|
||
| def on_start(self, span, parent_context): | ||
| pass | ||
|
|
||
| def on_end(self, span): | ||
| if hasattr(span, "attributes"): | ||
| operation_name = span.attributes.get(GEN_AI_OPERATION_NAME_KEY) | ||
| if isinstance(operation_name, str) and operation_name == EXECUTE_TOOL_OPERATION_NAME: | ||
| tool_call_result = span.attributes.get(self.TOOL_CALL_RESULT_TAG) | ||
| if tool_call_result is not None: | ||
| span.set_attribute(GEN_AI_EVENT_CONTENT, tool_call_result) | ||
48 changes: 48 additions & 0 deletions
48
...ework/microsoft_agents_a365/observability/extensions/agentframework/trace_instrumentor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
JianH marked this conversation as resolved.
Outdated
JianH marked this conversation as resolved.
Outdated
|
||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Collection | ||
| from typing import Any | ||
|
|
||
| from microsoft_agents_a365.observability.core.config import get_tracer_provider, is_configured | ||
| from opentelemetry.instrumentation.instrumentor import BaseInstrumentor | ||
|
|
||
| from microsoft_agents_a365.observability.extensions.agentframework.span_processor import ( | ||
| AgentFrameworkSpanProcessor, | ||
| ) | ||
|
|
||
| # ----------------------------- | ||
| # 3) The Instrumentor class | ||
| # ----------------------------- | ||
| _instruments = ("semantic-kernel >= 1.0.0",) | ||
|
JianH marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| class AgentFrameworkInstrumentor(BaseInstrumentor): | ||
| """ | ||
| Instruments Agent Framework: | ||
| • Installs your custom OTel SpanProcessor | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| if not is_configured(): | ||
| raise RuntimeError( | ||
| "Agent365 (or your telemetry config) is not initialized. Configure it before instrumenting." | ||
| ) | ||
| super().__init__() | ||
|
|
||
| def instrumentation_dependencies(self) -> Collection[str]: | ||
| return _instruments | ||
|
|
||
| def _instrument(self, **kwargs: Any) -> None: | ||
| """ | ||
| kwargs (all optional): | ||
| """ | ||
|
|
||
| # Ensure we have an SDK TracerProvider | ||
| provider = get_tracer_provider() | ||
| self._processor = AgentFrameworkSpanProcessor() | ||
| provider.add_span_processor(self._processor) | ||
|
|
||
| def _uninstrument(self, **kwargs: Any) -> None: | ||
| pass | ||
75 changes: 75 additions & 0 deletions
75
libraries/microsoft-agents-a365-observability-extensions-agentframework/pyproject.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| [build-system] | ||
| requires = ["setuptools>=68", "wheel", "tzdata"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
| name = "microsoft-agents-a365-observability-extensions-agent-framework" | ||
| dynamic = ["version"] | ||
| authors = [ | ||
| { name = "Microsoft", email = "support@microsoft.com" }, | ||
| ] | ||
| description = "Agent Framework observability and tracing extensions for Microsoft Agents A365" | ||
| readme = "README.md" | ||
| requires-python = ">=3.11" | ||
| classifiers = [ | ||
| "Development Status :: 3 - Alpha", | ||
| "Intended Audience :: Developers", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Operating System :: OS Independent", | ||
| "Topic :: Software Development :: Libraries :: Python Modules", | ||
| "Topic :: Scientific/Engineering :: Artificial Intelligence", | ||
| "Topic :: System :: Monitoring", | ||
| ] | ||
| license = "MIT" | ||
| keywords = ["observability", "telemetry", "tracing", "opentelemetry", "agent-framework", "agents", "ai"] | ||
| dependencies = [ | ||
| "microsoft-agents-a365-observability-core >= 2025.10.16", | ||
|
JianH marked this conversation as resolved.
Outdated
|
||
| "opentelemetry-api >= 1.36.0", | ||
| "opentelemetry-sdk >= 1.36.0", | ||
| "opentelemetry-instrumentation >= 0.47b0", | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/microsoft/Agent365" | ||
| Repository = "https://github.com/microsoft/Agent365" | ||
| Issues = "https://github.com/microsoft/Agent365/issues" | ||
| Documentation = "https://github.com/microsoft/Agent365-python/tree/main/libraries/microsoft-agents-a365-observability-extensions-agentframework" | ||
|
|
||
| [project.optional-dependencies] | ||
| dev = [ | ||
| "pytest >= 7.0.0", | ||
| "pytest-asyncio >= 0.21.0", | ||
| "ruff >= 0.1.0", | ||
| "black >= 23.0.0", | ||
| "mypy >= 1.0.0", | ||
| ] | ||
| test = [ | ||
| "pytest >= 7.0.0", | ||
| "pytest-asyncio >= 0.21.0", | ||
| ] | ||
|
|
||
| [tool.setuptools.packages.find] | ||
| where = ["."] | ||
|
JianH marked this conversation as resolved.
|
||
|
|
||
| [tool.setuptools] | ||
| license-files = ["../../LICENSE"] | ||
| include-package-data = true | ||
|
|
||
| [tool.setuptools.package-data] | ||
| "*" = ["../../LICENSE"] | ||
|
|
||
| [tool.black] | ||
| line-length = 100 | ||
| target-version = ['py311'] | ||
|
|
||
| [tool.ruff] | ||
| line-length = 100 | ||
| target-version = "py311" | ||
|
|
||
| [tool.mypy] | ||
| python_version = "3.11" | ||
| strict = true | ||
| warn_return_any = true | ||
| warn_unused_configs = true | ||
13 changes: 13 additions & 0 deletions
13
libraries/microsoft-agents-a365-observability-extensions-agentframework/setup.py
|
JianH marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from os import environ | ||
| from setuptools import setup | ||
|
|
||
| # Get version from environment variable set by CI/CD | ||
| # This will be set by setuptools-git-versioning in the CI pipeline | ||
| package_version = environ.get("AGENT365_PYTHON_SDK_PACKAGE_VERSION", "0.0.0") | ||
|
|
||
| setup( | ||
| version=package_version, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.