Framework telemetry integrations (SDK)
The Rhesis Python SDK wires automatic tracing for some AI frameworks through small integration classes under sdk/src/rhesis/sdk/telemetry/integrations/. Each integration subclasses BaseIntegration and is registered in get_all_integrations() so auto_instrument() can discover it.
This page is for contributors who want to add or extend an integration the same way LangChain and LangGraph do today.
BaseIntegration contract
Defined in sdk/src/rhesis/sdk/telemetry/integrations/base.py:
| Piece | Role |
|---|---|
framework_name | Stable string key (for example "langchain") used in auto_instrument("…"). |
is_installed() | Return True when optional deps for that framework are importable. |
_create_callback() | Build the framework-specific callback, patch handle, or None if not applicable. |
enable() / disable() | Turn observation on or off; enable() should return False if the framework is not installed or setup fails. |
callback() | Return the live handler; the base implementation can call enable() if needed. |
enabled | Whether this integration is currently active. |
Reference implementations:
- LangChain —
sdk/src/rhesis/sdk/telemetry/integrations/langchain/integration.py: singleton,set_default_callback_manager, optional fallback registration,BaseTool.invoke/ainvokepatching viaToolPatchStateandensure_callback_in_config. - LangGraph —
sdk/src/rhesis/sdk/telemetry/integrations/langgraph.py: enables the same LangChain singleton callback, then patches compiled graph methods and setstracing_v2_callback_varwhen available (GraphPatchStateguards idempotent patching).
Public registration
- Implement a
get_integration()factory that returns a module-level singleton (see existing modules). - Add the integration to
get_all_integrations()insdk/src/rhesis/sdk/telemetry/integrations/__init__.py. - Export any helpers (for example
get_callback) from the framework package if users need manual wiring. - Add an optional dependency group in
sdk/pyproject.tomlif the integration needs extra packages. - Add tests under
tests/sdk/telemetry/integrations/(patch state resets, enable/disable, and at least one smoke path through the framework API).
Checklist for a new framework
- Subclass
BaseIntegrationwith a clearframework_name. - Implement
is_installed()with a narrowimportcheck. - Implement
_create_callback()(or overrideenable()if patching must happen before/after, like LangGraph). - Register in
get_all_integrations(). - Document user-facing behavior in Auto-Instrumentation when the feature is ready for end users.
- Avoid advertising
auto_instrument("…")for placeholders that still returnNonefrom_create_callback()— prefer@observein docs until the hook is real.
Manual callback pattern
LangChain exposes get_callback() for advanced injection when auto-patching does not run (custom wrappers). New integrations can follow the same idea: a small module-level helper that returns the active handler after enable() has succeeded.
Related code paths
- Global orchestration:
sdk/src/rhesis/sdk/telemetry/observer.py(auto_instrument,disable_auto_instrument). - LangChain callback and agent/heuristic logic:
sdk/src/rhesis/sdk/telemetry/integrations/langchain/callback.py,extractors.py.