-
Notifications
You must be signed in to change notification settings - Fork 5.1k
cookbook: add MLflow observability integration via OpenInference #6930
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 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2393aa
cookbook: add MLflow observability integration via OpenInference
ysolanky 71eb1a6
Merge branch 'main' into ysolanky/sdk-vs-agentos-deploy
kausmeows 7d78b12
Update cookbook/92_integrations/observability/mlflow_via_openinferenc…
kausmeows 7c23112
update
kausmeows 2b45eac
Merge branch 'main' into ysolanky/sdk-vs-agentos-deploy
kausmeows 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
There are no files selected for viewing
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
63 changes: 63 additions & 0 deletions
63
cookbook/92_integrations/observability/mlflow_via_openinference.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,63 @@ | ||
| """ | ||
| MLflow Via OpenInference | ||
| ======================== | ||
|
|
||
| Demonstrates instrumenting an Agno agent with OpenInference and sending traces to MLflow. | ||
|
|
||
| Requirements: | ||
| pip install mlflow opentelemetry-exporter-otlp-proto-http openinference-instrumentation-agno | ||
|
|
||
| Start MLflow with OTLP tracing enabled: | ||
| mlflow server --host 127.0.0.1 --port 5000 | ||
| """ | ||
|
|
||
| import asyncio | ||
| import os | ||
|
|
||
| from agno.agent import Agent | ||
| from agno.models.openai import OpenAIChat | ||
| from agno.tools.yfinance import YFinanceTools | ||
| from openinference.instrumentation.agno import AgnoInstrumentor | ||
| from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
| from opentelemetry.sdk.trace import TracerProvider | ||
| from opentelemetry.sdk.trace.export import SimpleSpanProcessor | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Setup | ||
| # --------------------------------------------------------------------------- | ||
| MLFLOW_TRACKING_URI = os.getenv("MLFLOW_TRACKING_URI", "http://127.0.0.1:5000") | ||
|
|
||
| endpoint = f"{MLFLOW_TRACKING_URI}/api/2.0/mlflow/traces" | ||
|
|
||
| tracer_provider = TracerProvider() | ||
| tracer_provider.add_span_processor( | ||
| SimpleSpanProcessor(OTLPSpanExporter(endpoint=endpoint)) | ||
| ) | ||
|
|
||
| # Start instrumenting agno | ||
| AgnoInstrumentor().instrument(tracer_provider=tracer_provider) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Create Agent | ||
| # --------------------------------------------------------------------------- | ||
| agent = Agent( | ||
| name="Stock Price Agent", | ||
| model=OpenAIChat(id="gpt-4o"), | ||
| tools=[YFinanceTools()], | ||
| instructions="You are a stock price agent. Answer questions in the style of a stock analyst.", | ||
| ) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Run Example | ||
| # --------------------------------------------------------------------------- | ||
| async def main() -> None: | ||
| await agent.aprint_response( | ||
| "What is the current price of Tesla? Then find the current price of NVIDIA", | ||
| stream=True, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) | ||
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.