[WIP] feat(deepagents): add instrumentation plugin#190
Open
123liuziming wants to merge 3 commits into
Open
Conversation
|
observability_dev_agent seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new loongsuite-instrumentation-deepagents package to instrument the deepagents framework with ENTRY span creation, span enrichment, and GenAI metrics emission.
Changes:
- Introduces a
DeepAgentsInstrumentorthat wrapsdeepagents.graph.create_deep_agent, installs a LangChain callback enricher, and registers a metrics SpanProcessor. - Adds internal helpers for extracting metadata/messages and for generating ENTRY spans + metrics.
- Adds a dedicated test suite plus packaging/docs (pyproject, README) and registers the package in the instrumentation index.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/src/opentelemetry/instrumentation/deepagents/init.py | New instrumentor wiring ENTRY patch, enricher, and metrics processor |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/src/opentelemetry/instrumentation/deepagents/internal/_entry_patch.py | Wraps create_deep_agent and graph methods to create/manage ENTRY spans |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/src/opentelemetry/instrumentation/deepagents/internal/_enricher.py | LangChain callback handler + callback-manager patch to enrich active spans |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/src/opentelemetry/instrumentation/deepagents/internal/_metrics_processor.py | SpanProcessor that emits GenAI metrics from finished spans |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/src/opentelemetry/instrumentation/deepagents/internal/_utils.py | Shared helpers for metadata/version detection and message conversion |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/src/opentelemetry/instrumentation/deepagents/internal/_attributes.py | Centralized constants for attributes, span kinds, and metric names |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/src/opentelemetry/instrumentation/deepagents/package.py | Declares supported deepagents versions and metrics support |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/src/opentelemetry/instrumentation/deepagents/version.py | Declares package version for distribution |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/src/opentelemetry/instrumentation/deepagents/internal/init.py | Internal package init |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/tests/conftest.py | Test fixtures for tracing/metrics providers and env setup |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/tests/test_entry_patch.py | Tests ENTRY patch wrapping behavior and span attributes |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/tests/test_enricher.py | Tests span enrichment from callback handler |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/tests/test_metrics.py | Tests metrics processor behavior and warnings |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/pyproject.toml | New distributable project config + dependencies |
| instrumentation-loongsuite/loongsuite-instrumentation-deepagents/README.md | Package documentation and local install instructions |
| instrumentation-loongsuite/README.md | Adds deepagents instrumentation to the index table |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+72
to
+84
| async def on_chain_start_async( | ||
| self, | ||
| serialized: dict[str, Any], | ||
| inputs: dict[str, Any], | ||
| *, | ||
| run_id: Any, | ||
| parent_run_id: Any | None = None, | ||
| tags: list[str] | None = None, | ||
| metadata: dict[str, Any] | None = None, | ||
| **kwargs: Any, | ||
| ) -> Any: | ||
| del serialized, inputs, run_id, parent_run_id, tags, kwargs | ||
| self._enrich_agent_or_chain(metadata or {}) |
Comment on lines
+100
to
+112
| async def on_tool_start_async( | ||
| self, | ||
| serialized: dict[str, Any], | ||
| input_str: str, | ||
| *, | ||
| run_id: Any, | ||
| parent_run_id: Any | None = None, | ||
| tags: list[str] | None = None, | ||
| metadata: dict[str, Any] | None = None, | ||
| **kwargs: Any, | ||
| ) -> Any: | ||
| del input_str, run_id, parent_run_id, tags, metadata | ||
| self._enrich_tool(serialized, kwargs) |
Comment on lines
+77
to
+80
| labels = { | ||
| "spanKind": str(span_kind), | ||
| "modelName": _model_name(attributes), | ||
| } |
Comment on lines
+103
to
+107
| usage_labels = { | ||
| "spanKind": SPAN_KIND_LLM, | ||
| "modelName": labels["modelName"], | ||
| "usageType": usage_type, | ||
| } |
| ) | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
| _processors_by_provider_id: dict[int, "DeepAgentMetricsSpanProcessor"] = {} |
Comment on lines
+140
to
+145
| provider_id = id(tracer_provider) | ||
| if provider_id in _processors_by_provider_id: | ||
| return | ||
| processor = DeepAgentMetricsSpanProcessor(meter_provider=meter_provider) | ||
| tracer_provider.add_span_processor(processor) | ||
| _processors_by_provider_id[provider_id] = processor |
Comment on lines
+21
to
+24
| ## Local Install | ||
|
|
||
| Install the shared GenAI utility from the same source tree first, then install | ||
| the dependent LangChain, LangGraph, and deepagents instrumentations: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.