Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.
TypeScript agent-harnessagent-harness-engineeringai-engineeringai-observabilityamd-gpuclaude-codeclickhousecodexcoding-agentcoding-agentscursorgenaigpu-monitoringllm-observabilityllmopsnvidia-smiobservabilityopen-sourceopenaiopentelemetry
[Feat]: Add OpenTelemetry Instrumentation for monitoring Phidata and Dynamiq Agents (#518)
Patcher2ace9d1f8a90
diff --git a/.gitignore b/.gitignoreindex d3eb8d9d..eaa48e58 100644--- a/.gitignore+++ b/.gitignore@@ -6,4 +6,4 @@ yala.ymlspeech.mp3venv/path/-__pycache__\ No newline at end of file+__pycache__/\ No newline at end of filediff --git a/docs/latest/integrations/dynamiq.mdx b/docs/latest/integrations/dynamiq.mdxnew file mode 100644index 00000000..d8337ccd--- /dev/null+++ b/docs/latest/integrations/dynamiq.mdx@@ -0,0 +1,75 @@+---+title: 'Monitor Dynamiq using OpenTelemetry'+sidebarTitle: 'Dynamiq'+---++<Frame>+ <img src="/images/docs-dynamiq-banner.gif" />+</Frame>++OpenLIT uses OpenTelemetry Auto-Instrumentation to help you monitor AI Agents built using Dynamiq. This includes tracking performance and operation stats.++Auto-instrumentation means you don't have to set up monitoring manually for different LLMs, frameworks, or databases. By simply adding OpenLIT in your application, all the necessary monitoring configurations are automatically set up.++## Get Started++<Steps>+ <Step title="Install OpenLIT">+ Open your command line or terminal and run:+ ```shell+ pip install openlit+ ```+ </Step>+ <Step title="Initialize OpenLIT in your Application">+ You can set up OpenLIT in your application using either function arguments directly in your code or by using environment variables.+ <Tabs>+ <Tab title="Setup using function arguments">++ Add the following two lines to your application code:++ ```python+ import openlit++ openlit.init(+ otlp_endpoint="YOUR_OTEL_ENDPOINT",+ )+ ```++ Replace:+ 1. `YOUR_OTEL_ENDPOINT` with the URL of your OpenTelemetry backend, such as `http://127.0.0.1:4318` if you are using OpenLIT and a local OTel Collector.+ </Tab>+ <Tab title="Setup using Environment Variables">++ Add the following two lines to your application code:++ ```python+ import openlit++ openlit.init()+ ```++ Then, configure the your OTLP endpoint using environment variable:+ ```shell+ export OTEL_EXPORTER_OTLP_ENDPOINT = "YOUR_OTEL_ENDPOINT"+ ```++ Replace:+ 1. `YOUR_OTEL_ENDPOINT` with the URL of your OpenTelemetry backend, such as `http://127.0.0.1:4318` if you are using OpenLIT and a local OTel Collector.+ </Tab>+ </Tabs>+ To send metrics and traces to other Observability tools, refer to the [Connections Guide](/latest/connections/intro).++ For more advanced configurations and application use cases, visit the [OpenLIT Python repository](https://github.com/openlit/openlit/tree/main/sdk/python).+ </Step>+</Steps>++---++<CardGroup cols={2}>+<Card title="Connections" href="/latest/connections/intro" icon='link'>+Connect to your existing Observablity Stack+</Card>+<Card title="SDK configuration" href="/latest/sdk-configuration" icon='file-code'>+Documentation of the configuration options for the OpenLIT SDK.+</Card>+</CardGroup>\ No newline at end of filediff --git a/docs/latest/integrations/introduction.mdx b/docs/latest/integrations/introduction.mdxindex d8aa72c7..6d1668c5 100644--- a/docs/latest/integrations/introduction.mdx+++ b/docs/latest/integrations/introduction.mdx@@ -769,6 +769,34 @@ Start integrating and monitoring your applications with OpenLIT effortlessly. Ch}></Card>+ <Card+ title="Phidata"+ href="/latest/integrations/phidata"+ iconType="duotone"+ icon={+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 210 210">+ <path d="M0 0 C2.37548919 -0.00202432 4.75097777 -0.00493873 7.12646484 -0.00869751 C12.08892777 -0.01310397 17.05122796 -0.00674393 22.01367188 0.00732422 C28.34818478 0.02441483 34.68231624 0.01456465 41.01681519 -0.00339317 C45.91726513 -0.01427638 50.81762586 -0.01076387 55.71807861 -0.0030098 C58.05267381 -0.00102033 60.38727732 -0.0034226 62.72186279 -0.01044846 C93.96762848 -0.08386426 93.96762848 -0.08386426 104.625 10.3984375 C115.47300686 21.46394826 113.06610471 39.59577161 113.0234375 53.7734375 C113.02546182 56.14892669 113.02837623 58.52441527 113.03213501 60.89990234 C113.03654147 65.86236527 113.03018143 70.82466546 113.01611328 75.78710938 C112.99902267 82.12162228 113.00887285 88.45575374 113.02683067 94.79025269 C113.03771388 99.69070263 113.03420137 104.59106336 113.0264473 109.49151611 C113.02445783 111.82611131 113.0268601 114.16071482 113.03388596 116.49530029 C113.10756015 147.85103677 113.10756015 147.85103677 102.625 158.3984375 C95.13636888 165.0261197 87.78639745 165.69707043 78.07104492 165.68896484 C76.91419693 165.69568207 75.75734894 165.70239929 74.56544495 165.70932007 C70.74540905 165.7283002 66.92554885 165.73222433 63.10546875 165.734375 C61.11782789 165.73917764 59.13018699 165.74398391 57.14254743 165.74929583 C50.89409093 165.76555604 44.64569202 165.770467 38.3972168 165.76904297 C31.96922095 165.7678424 25.54156132 165.78893246 19.1136505 165.8205303 C13.57966076 165.84675621 8.0457804 165.85740762 2.51172906 165.85613215 C-0.78675494 165.85562431 -4.08487425 165.86307099 -7.38331032 165.88248825 C-11.06677561 165.90214162 -14.74938141 165.89631157 -18.43286133 165.88427734 C-19.5131662 165.89551636 -20.59347107 165.90675537 -21.70651245 165.91833496 C-30.99879356 165.84141294 -38.04045874 163.32575775 -44.87890625 156.9453125 C-56.04141283 145.40392189 -53.81802269 127.83841798 -53.7734375 113.0234375 C-53.77546182 110.64794831 -53.77837623 108.27245973 -53.78213501 105.89697266 C-53.78654147 100.93450973 -53.78018143 95.97220954 -53.76611328 91.00976562 C-53.74902267 84.67525272 -53.75887285 78.34112126 -53.77683067 72.00662231 C-53.78771388 67.10617237 -53.78420137 62.20581164 -53.7764473 57.30535889 C-53.77445783 54.97076369 -53.7768601 52.63616018 -53.78388596 50.30157471 C-53.85730176 19.05580902 -53.85730176 19.05580902 -43.375 8.3984375 C-32.30948924 -2.44956936 -14.17766589 -0.04266721 0 0 Z M79.44140625 105.93359375 C77.01428811 109.22716697 76.91190135 111.78368503 76.5625 115.8359375 C75.76924154 124.81134504 75.76924154 124.81134504 72.625 128.3984375 C66.3506501 132.09348702 59.99559244 131.61151205 52.984375 131.19335938 C48.21835167 130.99493808 48.21835167 130.99493808 44.078125 133.20703125 C42.33716587 135.39427377 42.33716587 135.39427377 42.625 138.5234375 C43.31519307 141.43465661 43.31519307 141.43465661 45.30859375 142.53125 C54.88698174 146.11708834 66.71285737 144.76418957 75.9375 140.7109375 C82.56050428 136.97280011 85.59476348 132.23436771 88 125.0859375 C89.51978308 119.54319923 90.72394957 114.12396477 89.625 108.3984375 C88.0798843 105.68195173 88.0798843 105.68195173 85.625 104.3984375 C81.7255027 104.01501694 81.7255027 104.01501694 79.44140625 105.93359375 Z " fill="#FF4017" transform="translate(53.375,0.6015625)"/>+ </svg>+ }+ >+ </Card>+ <Card+ title="Dynamiq"+ href="/latest/integrations/dynamiq"+ iconType="duotone"+ icon={+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 210 210">+ <path d="M0 0 C66 0 132 0 200 0 C200 66 200 132 200 200 C134 200 68 200 0 200 C0 134 0 68 0 0 Z " fill="#000000" transform="translate(0,0)"/>+ <path d="M0 0 C10.55169288 2.89724449 20.89181437 6.23841491 31.23657227 9.80102539 C33.85200347 10.70109464 36.46980121 11.59402414 39.08789062 12.48632812 C40.75274653 13.05687643 42.4174655 13.62782448 44.08203125 14.19921875 C45.2552166 14.59919319 45.2552166 14.59919319 46.45210266 15.00724792 C51.88475764 16.88475764 51.88475764 16.88475764 53 18 C53.09381302 19.84118029 53.11743954 21.68597641 53.11352539 23.52954102 C53.11341209 25.30126427 53.11341209 25.30126427 53.11329651 27.10877991 C53.10813522 28.3941716 53.10297394 29.67956329 53.09765625 31.00390625 C53.0962413 32.31205795 53.09482635 33.62020966 53.09336853 34.96800232 C53.0895441 38.45162859 53.07971446 41.93521339 53.06866455 45.41882324 C53.05844882 48.97126708 53.05387056 52.52371759 53.04882812 56.07617188 C53.03809212 63.05079832 53.0210166 70.02539717 53 77 C50.94124711 76.3752346 48.88319679 75.74815382 46.82543945 75.12011719 C45.67928665 74.77116394 44.53313385 74.42221069 43.35224915 74.06268311 C38.88377177 72.64614895 34.53688744 70.99231469 30.1875 69.25 C27.485625 68.1775 24.78375 67.105 22 66 C22 75.57 22 85.14 22 95 C18.52657547 94.30531509 15.69654625 93.62712983 12.4375 92.43359375 C11.56802734 92.11664551 10.69855469 91.79969727 9.80273438 91.47314453 C8.87783203 91.13138184 7.95292969 90.78961914 7 90.4375 C6.03900391 90.0854248 5.07800781 89.73334961 4.08789062 89.37060547 C-3.67296036 86.51660694 -11.405184 83.58823154 -19.12109375 80.61499023 C-19.93707031 80.30118408 -20.75304687 79.98737793 -21.59375 79.6640625 C-22.30208984 79.39029785 -23.01042969 79.1165332 -23.74023438 78.83447266 C-26.47086371 77.82612228 -29.23851555 76.92049482 -32 76 C-32 56.86 -32 37.72 -32 18 C-25.91742171 19.35168406 -20.57472288 20.73802746 -14.875 23 C-13.54013573 23.52357783 -12.20420265 24.04443934 -10.8671875 24.5625 C-10.29081543 24.79066406 -9.71444336 25.01882812 -9.12060547 25.25390625 C-6.12555461 26.30765659 -3.05285283 27.12775633 0 28 C0 18.76 0 9.52 0 0 Z " fill="#F7F7F7" transform="translate(89,52)"/>+ <path d="M0 0 C0 12.54 0 25.08 0 38 C-4.07875969 37.32020672 -6.86134885 36.83062183 -10.5234375 35.37109375 C-11.71259766 34.90219727 -11.71259766 34.90219727 -12.92578125 34.42382812 C-13.73402344 34.09833984 -14.54226562 33.77285156 -15.375 33.4375 C-16.20644531 33.10814453 -17.03789063 32.77878906 -17.89453125 32.43945312 C-19.93178676 31.63157594 -21.9661887 30.81650915 -24 30 C-24 24.06 -24 18.12 -24 12 C-20.5668874 9.99212214 -17.12895516 7.99348479 -13.6875 6 C-12.71103516 5.42765625 -11.73457031 4.8553125 -10.72851562 4.265625 C-9.79072266 3.72421875 -8.85292969 3.1828125 -7.88671875 2.625 C-7.02264404 2.12226562 -6.15856934 1.61953125 -5.26831055 1.1015625 C-3 0 -3 0 0 0 Z " fill="#060606" transform="translate(135,80)"/>+ <path d="M0 0 C5.89517654 1.31003923 11.40555941 2.66590326 17.0625 4.625 C20.4965625 5.800625 20.4965625 5.800625 24 7 C24 12.61 24 18.22 24 24 C20.37523055 25.97958991 16.7501958 27.95869114 13.125 29.9375 C12.09246094 30.50146484 11.05992188 31.06542969 9.99609375 31.64648438 C8.51689453 32.45375977 8.51689453 32.45375977 7.0078125 33.27734375 C6.09660645 33.77484131 5.18540039 34.27233887 4.24658203 34.78491211 C2.84229533 35.54443557 1.42797676 36.28601162 0 37 C0 24.79 0 12.58 0 0 Z " fill="#040404" transform="translate(65,81)"/>+ <path d="M0 0 C0 7.26 0 14.52 0 22 C-8.99230769 19.75192308 -8.99230769 19.75192308 -13.234375 18.08984375 C-14.13800781 17.73986328 -15.04164062 17.38988281 -15.97265625 17.02929688 C-16.88917969 16.66900391 -17.80570313 16.30871094 -18.75 15.9375 C-20.59814695 15.21536789 -22.44707674 14.49523533 -24.296875 13.77734375 C-25.10479492 13.46015381 -25.91271484 13.14296387 -26.74511719 12.81616211 C-28.81675309 12.06632681 -30.85373125 11.48926819 -33 11 C-33 10.34 -33 9.68 -33 9 C-29.59533266 6.87934773 -26.14797052 4.84059007 -22.6875 2.8125 C-21.73037109 2.21501953 -20.77324219 1.61753906 -19.78710938 1.00195312 C-12.10314359 -3.42214839 -8.24401282 -3.220634 0 0 Z " fill="#050505" transform="translate(103,114)"/>+ <path d="M0 0 C4.51764803 0.75294134 8.21437511 1.62009825 12.4921875 3.06640625 C13.69101563 3.46923828 14.88984375 3.87207031 16.125 4.28710938 C17.3625 4.70798828 18.6 5.12886719 19.875 5.5625 C21.1482967 5.99195414 22.42173301 6.4209946 23.6953125 6.84960938 C26.79827113 7.89568255 29.8997474 8.94593952 33 10 C29.71509183 13.47575893 25.93107213 15.76583126 21.875 18.25 C21.153125 18.72179687 20.43125 19.19359375 19.6875 19.6796875 C14.88297208 22.60343937 11.62707575 23.4664012 6.04736328 22.58105469 C4 22 4 22 0 20 C0 13.4 0 6.8 0 0 Z " fill="#080808" transform="translate(96,63)"/>+ <path d="M0 0 C2.31 0.66 4.62 1.32 7 2 C7 6.62 7 11.24 7 16 C4.69 15.01 2.38 14.02 0 13 C0 8.71 0 4.42 0 0 Z " fill="#0D0D0D" transform="translate(96,91)"/>+ </svg>+ }+ >+ </Card></CardGroup>### GPUs@@ -795,41 +823,6 @@ Start integrating and monitoring your applications with OpenLIT effortlessly. Ch></Card></CardGroup>------| Integration | Type | Python SDK | Typescript SDK |-|--------|--------------|---------------------------|--------------------------|-| OpenAI | LLM | ✔️ | ✔️ |-| Anthropic | LLM | ✔️ | ✔️ |-| Ollama | LLM | ✔️ | ❌ |-| Cohere | LLM | ✔️ | ✔️ |-| GPT4All | LLM | ✔️ | ❌ |-| vLLM | LLM | ✔️ | ❌ |-| Azure OpenAI | LLM | ✔️ | ❌ |-| Azure AI Inference | LLM | ✔️ | ❌ |-| Google AI Studio | LLM | ✔️ | ❌ |-| GitHub Models | LLM | ✔️ | ❌ |-| NVIDIA NIM | LLM | ✔️ | ❌ |-| Mistral | LLM | ✔️ | ❌ |-| HuggingFace | LLM | ✔️ | ❌ |-| Amazon Bedrock | LLM | ✔️ | ❌ |-| Vertex AI | LLM | ✔️ | ❌ |-| Groq | LLM | ✔️ | ❌ |-| ElevenLabs | LLM | ✔️ | ❌ |-| OLA Krutrim | LLM | ✔️ | ❌ |-| ChromaDB | VectorDB | ✔️ | ❌ |-| Pinecone | VectorDB | ✔️ | ❌ |-| Qdrant | VectorDB | ✔️ | ❌ |-| Milvus | VectorDB | ✔️ | ❌ |-| LangChain | Framework | ✔️ | ❌ |-| LiteLLM | Framework | ✔️ | ❌ |-| LlamaIndex | Framework | ✔️ | ❌ |-| Haystack | Framework | ✔️ | ❌ |-| CrewAI | Framework | ✔️ | ❌ |-| DSPy | Framework | ✔️ | ❌ |-| EmbedChain | Framework | ✔️ | ❌ |-| NVIDIA GPUs | GPU | ✔️ | ❌ |-| AMD GPUs | GPU | ✔️ | ❌ |---diff --git a/docs/latest/integrations/phidata.mdx b/docs/latest/integrations/phidata.mdxnew file mode 100644index 00000000..8d6f7301--- /dev/null+++ b/docs/latest/integrations/phidata.mdx@@ -0,0 +1,75 @@+---+title: 'Monitor Phidata using OpenTelemetry'+sidebarTitle: 'Phidata'+---++<Frame>+ <img src="/images/docs-phidata-banner.gif" />+</Frame>++OpenLIT uses OpenTelemetry Auto-Instrumentation to help you monitor AI Agents built using Phidata. This includes tracking performance and operation stats.++Auto-instrumentation means you don't have to set up monitoring manually for different LLMs, frameworks, or databases. By simply adding OpenLIT in your application, all the necessary monitoring configurations are automatically set up.++## Get Started++<Steps>+ <Step title="Install OpenLIT">+ Open your command line or terminal and run:+ ```shell+ pip install openlit+ ```+ </Step>+ <Step title="Initialize OpenLIT in your Application">+ You can set up OpenLIT in your application using either function arguments directly in your code or by using environment variables.+ <Tabs>+ <Tab title="Setup using function arguments">++ Add the following two lines to your application code:++ ```python+ import openlit++ openlit.init(+ otlp_endpoint="YOUR_OTEL_ENDPOINT",+ )+ ```++ Replace:+ 1. `YOUR_OTEL_ENDPOINT` with the URL of your OpenTelemetry backend, such as `http://127.0.0.1:4318` if you are using OpenLIT and a local OTel Collector.+ </Tab>+ <Tab title="Setup using Environment Variables">++ Add the following two lines to your application code:++ ```python+ import openlit++ openlit.init()+ ```++ Then, configure the your OTLP endpoint using environment variable:+ ```shell+ export OTEL_EXPORTER_OTLP_ENDPOINT = "YOUR_OTEL_ENDPOINT"+ ```++ Replace:+ 1. `YOUR_OTEL_ENDPOINT` with the URL of your OpenTelemetry backend, such as `http://127.0.0.1:4318` if you are using OpenLIT and a local OTel Collector.+ </Tab>+ </Tabs>+ To send metrics and traces to other Observability tools, refer to the [Connections Guide](/latest/connections/intro).++ For more advanced configurations and application use cases, visit the [OpenLIT Python repository](https://github.com/openlit/openlit/tree/main/sdk/python).+ </Step>+</Steps>++---++<CardGroup cols={2}>+<Card title="Connections" href="/latest/connections/intro" icon='link'>+Connect to your existing Observablity Stack+</Card>+<Card title="SDK configuration" href="/latest/sdk-configuration" icon='file-code'>+Documentation of the configuration options for the OpenLIT SDK.+</Card>+</CardGroup>\ No newline at end of filediff --git a/docs/mint.json b/docs/mint.jsonindex c993da9e..42c6a328 100644--- a/docs/mint.json+++ b/docs/mint.json@@ -126,7 +126,9 @@"latest/integrations/ag2","latest/integrations/haystack","latest/integrations/embedchain",- "latest/integrations/guardrails"+ "latest/integrations/guardrails",+ "latest/integrations/phidata",+ "latest/integrations/dynamiq"]},{diff --git a/sdk/python/README.md b/sdk/python/README.mdindex f4e850be..512717af 100644--- a/sdk/python/README.md+++ b/sdk/python/README.md@@ -43,8 +43,8 @@ This project proudly follows and maintains the [Semantic Conventions](https://gi| [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | | [✅ CrewAI](https://docs.openlit.io/latest/integrations/crewai) | || [✅ Azure AI Inference](https://docs.openlit.io/latest/integrations/azure-ai-inference) | | [✅ DSPy](https://docs.openlit.io/latest/integrations/dspy) | || [✅ GitHub AI Models](https://docs.openlit.io/latest/integrations/github-models) | | [✅ AG2](https://docs.openlit.io/latest/integrations/ag2) | |-| [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | | | |-| [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | | | |+| [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | | [✅ Dynamiq](https://docs.openlit.io/latest/integrations/dynamiq) | |+| [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | | [✅ Phidata](https://docs.openlit.io/latest/integrations/phidata) | || [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | | | || [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | | | || [✅ ElevenLabs](https://docs.openlit.io/latest/integrations/elevenlabs) | | | |diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.tomlindex 8d74db8f..1fda8804 100644--- a/sdk/python/pyproject.toml+++ b/sdk/python/pyproject.toml@@ -1,6 +1,6 @@[tool.poetry]name = "openlit"-version = "1.31.0"+version = "1.31.1"description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"authors = ["OpenLIT"]repository = "https://github.com/openlit/openlit/tree/main/openlit/python"diff --git a/sdk/python/src/openlit/__init__.py b/sdk/python/src/openlit/__init__.pyindex 0f9c67f3..cca8d637 100644--- a/sdk/python/src/openlit/__init__.py+++ b/sdk/python/src/openlit/__init__.py@@ -49,6 +49,8 @@ from openlit.instrumentation.transformers import TransformersInstrumentorfrom openlit.instrumentation.litellm import LiteLLMInstrumentorfrom openlit.instrumentation.crewai import CrewAIInstrumentorfrom openlit.instrumentation.ag2 import AG2Instrumentor+from openlit.instrumentation.dynamiq import DynamiqInstrumentor+from openlit.instrumentation.phidata import PhidataInstrumentorfrom openlit.instrumentation.gpu import GPUInstrumentorimport openlit.guardimport openlit.evals@@ -236,6 +238,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en"ag2": "ag2","autogen": "autogen","pyautogen": "pyautogen",+ "dynamiq": "dynamiq",+ "phidata": "phi",}invalid_instrumentors = [@@ -318,6 +322,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en"ag2": AG2Instrumentor(),"autogen": AG2Instrumentor(),"pyautogen": AG2Instrumentor(),+ "dynamiq": DynamiqInstrumentor(),+ "phidata": PhidataInstrumentor(),}# Initialize and instrument only the enabled instrumentorsdiff --git a/sdk/python/src/openlit/instrumentation/dynamiq/__init__.py b/sdk/python/src/openlit/instrumentation/dynamiq/__init__.pynew file mode 100644index 00000000..baee93e7--- /dev/null+++ b/sdk/python/src/openlit/instrumentation/dynamiq/__init__.py@@ -0,0 +1,64 @@+# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code+"""Initializer of Auto Instrumentation of Dynamiq Functions"""++from typing import Collection+import importlib.metadata+from opentelemetry.instrumentation.instrumentor import BaseInstrumentor+from wrapt import wrap_function_wrapper++from openlit.instrumentation.dynamiq.dynamiq import (+ dynamiq_wrap+)++_instruments = ("dynamiq >= 0.4.0",)++class DynamiqInstrumentor(BaseInstrumentor):+ """+ An instrumentor for dynamiq's client library.+ """++ def instrumentation_dependencies(self) -> Collection[str]:+ return _instruments++ def _instrument(self, **kwargs):+ application_name = kwargs.get("application_name", "default_application")+ environment = kwargs.get("environment", "default_environment")+ tracer = kwargs.get("tracer")+ metrics = kwargs.get("metrics_dict")+ pricing_info = kwargs.get("pricing_info", {})+ trace_content = kwargs.get("trace_content", False)+ disable_metrics = kwargs.get("disable_metrics")+ version = importlib.metadata.version("dynamiq")++ wrap_function_wrapper(+ "dynamiq.nodes.agents.base",+ "Agent.run",+ dynamiq_wrap("dynamiq.agent_run", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )++ wrap_function_wrapper(+ "dynamiq",+ "Workflow.run",+ dynamiq_wrap("dynamiq.workflow_run", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )++ wrap_function_wrapper(+ "dynamiq.memory",+ "Memory.add",+ dynamiq_wrap("dynamiq.memory_add", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )++ wrap_function_wrapper(+ "dynamiq.memory",+ "Memory.search",+ dynamiq_wrap("dynamiq.memory_search", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )+++ def _uninstrument(self, **kwargs):+ # Proper uninstrumentation logic to revert patched methods+ passdiff --git a/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.py b/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.pynew file mode 100644index 00000000..4b3fe47f--- /dev/null+++ b/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.py@@ -0,0 +1,108 @@+# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument+"""+Module for monitoring Dynamiq calls.+"""++import logging+from opentelemetry.trace import SpanKind, Status, StatusCode+from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME+from openlit.__helpers import (+ handle_exception,+)+from openlit.semcov import SemanticConvetion++# Initialize logger for logging potential issues and operations+logger = logging.getLogger(__name__)++def dynamiq_wrap(gen_ai_endpoint, version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics):+ """+ Generates a telemetry wrapper for chat completions to collect metrics.++ Args:+ gen_ai_endpoint: Endpoint identifier for logging and tracing.+ version: Version of the monitoring package.+ environment: Deployment environment (e.g., production, staging).+ application_name: Name of the application using the dynamiq Agent.+ tracer: OpenTelemetry tracer for creating spans.+ pricing_info: Information used for calculating the cost of dynamiq usage.+ trace_content: Flag indicating whether to trace the actual content.++ Returns:+ A function that wraps the chat completions method to add telemetry.+ """++ def wrapper(wrapped, instance, args, kwargs):+ """+ Wraps the 'chat.completions' API call to add telemetry.++ This collects metrics such as execution time, cost, and token usage, and handles errors+ gracefully, adding details to the trace for observability.++ Args:+ wrapped: The original 'chat.completions' method to be wrapped.+ instance: The instance of the class where the original method is defined.+ args: Positional arguments for the 'chat.completions' method.+ kwargs: Keyword arguments for the 'chat.completions' method.++ Returns:+ The response from the original 'chat.completions' method.+ """++ # pylint: disable=line-too-long+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:+ response = wrapped(*args, **kwargs)++ try:+ # Set base span attribues+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,+ SemanticConvetion.GEN_AI_SYSTEM_DYNAMIQ)+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,+ SemanticConvetion.GEN_AI_TYPE_AGENT)+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,+ gen_ai_endpoint)+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,+ application_name)++ if gen_ai_endpoint == "dynamiq.agent_run":+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,+ getattr(instance, 'id', '') or '')+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,+ getattr(instance, 'name', '') or '')+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,+ getattr(getattr(instance, 'llm', None), 'model', '') or '')+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TYPE,+ str(getattr(instance, 'type', '')) or '')++ elif gen_ai_endpoint == "dynamiq.workflow_run":+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,+ getattr(instance, 'id', '') or '')+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,+ getattr(getattr(instance.flow, 'nodes', [None])[0], 'model', 'default_model'))++ elif gen_ai_endpoint == "dynamiq.memory_add":+ span.set_attribute(SemanticConvetion.DB_OPERATION,+ SemanticConvetion.DB_OPERATION_ADD)+ span.set_attribute(SemanticConvetion.DB_METADATA, str(kwargs.get('metadata', '')))++ elif gen_ai_endpoint == "dynamiq.memory_search":+ query_value = kwargs.get('query', '') or (args[0] if args else '')+ span.set_attribute(SemanticConvetion.DB_OPERATION,+ SemanticConvetion.DB_OPERATION_GET)+ span.set_attribute(SemanticConvetion.DB_FILTER, str(kwargs.get('filters', '')))+ span.set_attribute(SemanticConvetion.DB_STATEMENT, query_value)++ span.set_status(Status(StatusCode.OK))++ # Return original response+ return response++ except Exception as e:+ handle_exception(span, e)+ logger.error("Error in trace creation: %s", e)++ # Return original response+ return response++ return wrapperdiff --git a/sdk/python/src/openlit/instrumentation/phidata/__init__.py b/sdk/python/src/openlit/instrumentation/phidata/__init__.pynew file mode 100644index 00000000..03ee5657--- /dev/null+++ b/sdk/python/src/openlit/instrumentation/phidata/__init__.py@@ -0,0 +1,42 @@+# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code+"""Initializer of Auto Instrumentation of Phidata Functions"""++from typing import Collection+import importlib.metadata+from opentelemetry.instrumentation.instrumentor import BaseInstrumentor+from wrapt import wrap_function_wrapper++from openlit.instrumentation.phidata.phidata import (+ phidata_wrap+)++_instruments = ("phidata >= 2.5.32",)++class PhidataInstrumentor(BaseInstrumentor):+ """+ An instrumentor for Phidata's client library.+ """++ def instrumentation_dependencies(self) -> Collection[str]:+ return _instruments++ def _instrument(self, **kwargs):+ application_name = kwargs.get("application_name", "default_application")+ environment = kwargs.get("environment", "default_environment")+ tracer = kwargs.get("tracer")+ metrics = kwargs.get("metrics_dict")+ pricing_info = kwargs.get("pricing_info", {})+ trace_content = kwargs.get("trace_content", False)+ disable_metrics = kwargs.get("disable_metrics")+ version = importlib.metadata.version("phidata")++ wrap_function_wrapper(+ "phi.agent",+ "Agent.print_response",+ phidata_wrap("phidata.print_response", version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics),+ )++ def _uninstrument(self, **kwargs):+ # Proper uninstrumentation logic to revert patched methods+ passdiff --git a/sdk/python/src/openlit/instrumentation/phidata/phidata.py b/sdk/python/src/openlit/instrumentation/phidata/phidata.pynew file mode 100644index 00000000..d444161e--- /dev/null+++ b/sdk/python/src/openlit/instrumentation/phidata/phidata.py@@ -0,0 +1,98 @@+# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument+"""+Module for monitoring Phidata calls.+"""++import logging+from opentelemetry.trace import SpanKind, Status, StatusCode+from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME+from openlit.__helpers import (+ handle_exception,+)+from openlit.semcov import SemanticConvetion++# Initialize logger for logging potential issues and operations+logger = logging.getLogger(__name__)++def phidata_wrap(gen_ai_endpoint, version, environment, application_name,+ tracer, pricing_info, trace_content, metrics, disable_metrics):+ """+ Generates a telemetry wrapper for chat completions to collect metrics.++ Args:+ gen_ai_endpoint: Endpoint identifier for logging and tracing.+ version: Version of the monitoring package.+ environment: Deployment environment (e.g., production, staging).+ application_name: Name of the application using the Phidata Agent.+ tracer: OpenTelemetry tracer for creating spans.+ pricing_info: Information used for calculating the cost of Phidata usage.+ trace_content: Flag indicating whether to trace the actual content.++ Returns:+ A function that wraps the chat completions method to add telemetry.+ """++ def wrapper(wrapped, instance, args, kwargs):+ """+ Wraps the 'chat.completions' API call to add telemetry.++ This collects metrics such as execution time, cost, and token usage, and handles errors+ gracefully, adding details to the trace for observability.++ Args:+ wrapped: The original 'chat.completions' method to be wrapped.+ instance: The instance of the class where the original method is defined.+ args: Positional arguments for the 'chat.completions' method.+ kwargs: Keyword arguments for the 'chat.completions' method.++ Returns:+ The response from the original 'chat.completions' method.+ """++ # pylint: disable=line-too-long+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:+ response = wrapped(*args, **kwargs)++ try:+ # Set base span attribues+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,+ SemanticConvetion.GEN_AI_SYSTEM_PHIDATA)+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,+ SemanticConvetion.GEN_AI_TYPE_AGENT)+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,+ gen_ai_endpoint)+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,+ application_name)+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,+ getattr(instance, 'agent_id', '') or '')+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,+ getattr(instance, 'name', '') or '')+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,+ getattr(getattr(instance, 'model', None), 'id', '') or '')+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TOOLS,+ str(getattr(instance, 'tools', '')) or '')+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_CONTEXT,+ str(getattr(instance, 'knowledge', '')) or '')+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TASK,+ str(getattr(instance, 'task', '')) or '')+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_INSTRUCTIONS,+ str(getattr(instance, 'instructions', '')) or '')+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_STORAGE,+ str(getattr(instance, 'storage', '')) or '')+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ENABLE_HISTORY,+ str(getattr(instance, 'add_history_to_messages', '')) or '')++ span.set_status(Status(StatusCode.OK))++ # Return original response+ return response++ except Exception as e:+ handle_exception(span, e)+ logger.error("Error in trace creation: %s", e)++ # Return original response+ return response++ return wrapperdiff --git a/sdk/python/src/openlit/semcov/__init__.py b/sdk/python/src/openlit/semcov/__init__.pyindex 442495dd..22a6aef3 100644--- a/sdk/python/src/openlit/semcov/__init__.py+++ b/sdk/python/src/openlit/semcov/__init__.py@@ -112,6 +112,8 @@ class SemanticConvetion:GEN_AI_SYSTEM_LITELLM = "litellm"GEN_AI_SYSTEM_CREWAI = "crewai"GEN_AI_SYSTEM_AG2 = "ag2"+ GEN_AI_SYSTEM_DYNAMIQ = "dynamiq"+ GEN_AI_SYSTEM_PHIDATA = "phidata"# Vector DBDB_REQUESTS = "db.total.requests"@@ -133,6 +135,7 @@ class SemanticConvetion:DB_OPERATION_PEEK = "peek"DB_ID_COUNT = "db.ids_count"DB_VECTOR_COUNT = "db.vector_count"+ DB_METADATA = "db.metadata"DB_METADATA_COUNT = "db.metadatas_count"DB_DOCUMENTS_COUNT = "db.documents_count"DB_PAYLOAD_COUNT = "db.payload_count"@@ -160,17 +163,21 @@ class SemanticConvetion:# AgentsGEN_AI_AGENT_ID = "gen_ai.agent.id"+ GEN_AI_AGENT_TYPE = "gen_ai.agent.type"GEN_AI_AGENT_TASK_ID = "gen_ai.agent.task.id"GEN_AI_AGENT_ROLE = "gen_ai.agent.role"GEN_AI_AGENT_GOAL = "gen_ai.agent.goal"GEN_AI_AGENT_CONTEXT = "gen_ai.agent.context"GEN_AI_AGENT_ENABLE_CACHE = "gen_ai.agent.enable_cache"+ GEN_AI_AGENT_ENABLE_HISTORY = "gen_ai.agent.enable_history"GEN_AI_AGENT_ALLOW_DELEGATION = "gen_ai.agent.allow_delegation"GEN_AI_AGENT_ALLOW_CODE_EXECUTION = "gen_ai.agent.allow_code_execution"GEN_AI_AGENT_MAX_RETRY_LIMIT = "gen_ai.agent.max_retry_limit"GEN_AI_AGENT_TOOLS = "gen_ai.agent.tools"GEN_AI_AGENT_TOOL_RESULTS = "gen_ai.agent.tool_results"GEN_AI_AGENT_TASK = "gen_ai.agent.task"+ GEN_AI_AGENT_INSTRUCTIONS = "gen_ai.agent.instructions"+ GEN_AI_AGENT_STORAGE = "gen_ai.agent.storage"GEN_AI_AGENT_EXPECTED_OUTPUT = "gen_ai.agent.expected_output"GEN_AI_AGENT_ACTUAL_OUTPUT = "gen_ai.agent.actual_output"GEN_AI_AGENT_HUMAN_INPUT = "gen_ai.agent.human_input"