feat(ag2): add first-class instrumentation - #3379
Merged
Merged
Conversation
Contributor
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
lxingy3
marked this pull request as ready for review
July 12, 2026 04:34
Contributor
Author
|
Synced this branch with current Local validation passes on Python 3.14:
The PR is mergeable again and ready for review. |
- Restore the legacy SpanAttributes class on the autogen compat package - Track instrumentation ownership in the facade so uninstrument() no longer tears down instrumentation installed independently via AG2Instrumentor - Accept the legacy autogen/pyautogen distribution names in the dependency check so instrument() is not a silent no-op, and drop the facade's skip_dep_check bypass and dead instrumentation_dependencies - Bound the autogen instruments extra to <1.0.0 - Normalize string func_call arguments before delegating to execute_function - Record the chat span's output.value as the final message content and emit the root chat span as AGENT kind, matching the legacy instrumentor - Disable use_span's own exception recording to avoid duplicate exception events on error spans - Replace the custom _json_value serializer with the shared get_input_attributes/get_output_attributes helpers
Adds an examples directory matching the convention used by the other Python instrumentors. Two examples run without an LLM API key so the instrumentation can be verified against a local Phoenix instance immediately; the other two cover LLM-driven tool calling and the async agent paths.
Replaces the single tool-calling example with examples that follow the AG2 user guide: the quickstart agent driven by run(), LLM-driven tool calling, an AutoPattern group chat, sequential chats with carryover, and structured outputs. Each example sets its own Phoenix project through the openinference.project.name resource attribute so traces stay separated.
Calling execute_function directly left the TOOL span as its own trace root, which is not how tool calls appear in a real AG2 run. Executing the tool from a registered reply nests the TOOL span under generate_reply, matching the shape an LLM-driven tool call produces.
Adds module, class, and function docstrings covering what each wrapper traces and why the non-obvious paths exist: the alias-aware dependency check, the suppressed exception recording on use_span, and the string func_call normalization. Also drops the dependabot entry for the new package from this PR.
Restores the weekly pip update entry for the AG2 instrumentation package, matching the cooldown and ignore rules used by the other Python packages.
- Normalize a string func_call before the suppression check, so suppressing tracing no longer changes the call and crashes execute_function - Bind the caller's context to async wrapper coroutines: AG2 runs async tools from its sync reply path on a fresh thread, which orphaned the tool span and dropped its context attributes - Resolve tool parameter types with get_type_hints, which strips Annotated and resolves the string annotations PEP 563 produces; both cases previously reported useless type names - Leave output.value unset when a reply is None and fall back to the chat summary when the history is empty, instead of recording "None" or a repr - Build tool parameters defensively so unreadable annotations cannot break the wrapped call - Uninstrument the autogen facade whenever instrument() was called on it, so a matched pair still restores the patched methods when the AG2 entry point was loaded first - Run the autogen tox environments for ag2-only diffs, since the facade imports the ag2 package at module import time
Adds the standard collector blurb naming Phoenix, Arize AX, and Langfuse, the phoenix serve quickstart walkthrough, and the shared More Info links, keeping the AG2 version support note, span kind table, and examples pointer.
mikeldking
enabled auto-merge (squash)
August 7, 2026 13:52
mikeldking
approved these changes
Aug 7, 2026
mikeldking
left a comment
Contributor
There was a problem hiding this comment.
Appreciate the contribution!
Merged
satyadevai
pushed a commit
to latent-variable-17/openinference
that referenced
this pull request
Aug 17, 2026
Co-authored-by: Mikyo King <mikeldking@gmail.com>
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.
Closes #1332.
Summary
openinference-instrumentation-ag2package andopeninference.instrumentation.ag2APIopeninference-instrumentation-autogenas a compatibility package for the legacyautogendistributionInstrumentation behavior
Chat runs emit
CHAINspans, individual replies emitAGENTspans, and function execution emitsTOOLspans. The wrappers useBaseInstrumentorandOITracer, honor OpenTelemetry suppression, carry OpenInference context attributes, applyTraceConfigmasking, report tool failures, and restore all patched methods on uninstrumentation.Tool spans include normalized input parameter definitions; return annotations are excluded from
tool.parameters. Provider SDK instrumentors remain responsible for LLM spans.Compatibility
The deprecated
AutogenInstrumentorretains itsautogen>=0.5.0dependency check and delegates patching to the sameAG2Instrumentorsingleton. This keeps existing installations working without double-patching when both entry points are present.The AG2 package targets the pre-1.0
autogenAPI. AG2 1.0 uses an async middleware and event model and should be supported separately through that native interface.openinference-instrumentation-autogen-agentchatis unchanged.Validation
tox run -e py314-ci-ag2tox run -e py314-ci-ag2-latesttox run -e py314-ci-autogentox run -e py314-ci-autogen-latestAll four environments pass Ruff, strict mypy, wheel installation, and pytest. The compatibility environments exercise the real
autogen==0.5.0distribution and its latest release withoutag2installed.A local Phoenix 18.0.0 trace confirmed the
CHAIN -> AGENT -> TOOLhierarchy, successful tool input/output capture, and the normalized{"a":"int","b":"int"}parameter definition.Trace output
Phoenix 18.0.0 showing the

CHAIN -> AGENT -> TOOLhierarchy and normalized tool parameter metadata: