langtrace-python-sdk 2.1.20__tar.gz → 2.1.22__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/PKG-INFO +1 -1
  2. langtrace_python_sdk-2.1.22/src/examples/crewai_example/basic.py +70 -0
  3. langtrace_python_sdk-2.1.22/src/examples/dspy_example/math_problems_cot.py +42 -0
  4. langtrace_python_sdk-2.1.22/src/examples/dspy_example/program_of_thought_basic.py +35 -0
  5. langtrace_python_sdk-2.1.22/src/examples/dspy_example/quiz_gen.py +113 -0
  6. langtrace_python_sdk-2.1.22/src/examples/dspy_example/react.py +39 -0
  7. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/common.py +2 -0
  8. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/__init__.py +4 -0
  9. langtrace_python_sdk-2.1.22/src/langtrace_python_sdk/instrumentation/crewai/__init__.py +3 -0
  10. langtrace_python_sdk-2.1.22/src/langtrace_python_sdk/instrumentation/crewai/instrumentation.py +53 -0
  11. langtrace_python_sdk-2.1.22/src/langtrace_python_sdk/instrumentation/crewai/patch.py +173 -0
  12. langtrace_python_sdk-2.1.22/src/langtrace_python_sdk/instrumentation/dspy/__init__.py +3 -0
  13. langtrace_python_sdk-2.1.22/src/langtrace_python_sdk/instrumentation/dspy/instrumentation.py +85 -0
  14. langtrace_python_sdk-2.1.22/src/langtrace_python_sdk/instrumentation/dspy/patch.py +206 -0
  15. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/openai/patch.py +106 -187
  16. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/langtrace.py +4 -0
  17. langtrace_python_sdk-2.1.22/src/langtrace_python_sdk/version.py +1 -0
  18. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/run_example.py +1 -1
  19. langtrace_python_sdk-2.1.20/src/langtrace_python_sdk/version.py +0 -1
  20. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/.gitignore +0 -0
  21. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/LICENSE +0 -0
  22. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/README.md +0 -0
  23. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/pyproject.toml +0 -0
  24. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/__init__.py +0 -0
  25. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/__init__.py +0 -0
  26. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/anthropic_example/__init__.py +0 -0
  27. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/anthropic_example/completion.py +0 -0
  28. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/chroma_example/__init__.py +0 -0
  29. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/chroma_example/basic.py +0 -0
  30. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/cohere_example/__init__.py +0 -0
  31. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/cohere_example/chat.py +0 -0
  32. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/cohere_example/chat_stream.py +0 -0
  33. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/cohere_example/embed.py +0 -0
  34. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/cohere_example/rerank.py +0 -0
  35. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/cohere_example/tools.py +0 -0
  36. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/fastapi_example/__init__.py +0 -0
  37. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/fastapi_example/basic_route.py +0 -0
  38. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/hiveagent_example/basic.py +0 -0
  39. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/inspect_ai_example/basic_eval.py +0 -0
  40. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/langchain_example/__init__.py +0 -0
  41. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/langchain_example/basic.py +0 -0
  42. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/langchain_example/groq_example.py +0 -0
  43. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/langchain_example/langgraph_example.py +0 -0
  44. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/langchain_example/tool.py +0 -0
  45. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/llamaindex_example/__init__.py +0 -0
  46. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/llamaindex_example/agent.py +0 -0
  47. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/llamaindex_example/basic.py +0 -0
  48. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/llamaindex_example/data/abramov.txt +0 -0
  49. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/ollama_example/__init__.py +0 -0
  50. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/ollama_example/basic.py +0 -0
  51. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/__init__.py +0 -0
  52. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/async_tool_calling_nonstreaming.py +0 -0
  53. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/async_tool_calling_streaming.py +0 -0
  54. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/chat_completion.py +0 -0
  55. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/embeddings_create.py +0 -0
  56. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/function_calling.py +0 -0
  57. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/images_edit.py +0 -0
  58. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/images_generate.py +0 -0
  59. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/resources/lounge_flamingo.png +0 -0
  60. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/resources/mask.png +0 -0
  61. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/tool_calling.py +0 -0
  62. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/tool_calling_nonstreaming.py +0 -0
  63. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/openai_example/tool_calling_streaming.py +0 -0
  64. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/perplexity_example/basic.py +0 -0
  65. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/pinecone_example/__init__.py +0 -0
  66. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/pinecone_example/basic.py +0 -0
  67. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/qdrant_example/__init__.py +0 -0
  68. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/qdrant_example/basic.py +0 -0
  69. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/weaviate_example/__init__.py +0 -0
  70. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/examples/weaviate_example/query_text.py +0 -0
  71. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/__init__.py +0 -0
  72. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/__init__.py +0 -0
  73. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/exporter/langtrace_exporter.py +0 -0
  74. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/__init__.py +0 -0
  75. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/anthropic.py +0 -0
  76. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/chroma.py +0 -0
  77. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/cohere.py +0 -0
  78. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/groq.py +0 -0
  79. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/ollama.py +0 -0
  80. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/openai.py +0 -0
  81. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/pinecone.py +0 -0
  82. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/qdrant.py +0 -0
  83. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/constants/instrumentation/weaviate.py +0 -0
  84. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/extensions/__init__.py +0 -0
  85. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/extensions/langtrace_exporter.py +0 -0
  86. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/extensions/langtrace_filesystem.py +0 -0
  87. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/anthropic/__init__.py +0 -0
  88. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/anthropic/instrumentation.py +0 -0
  89. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/anthropic/patch.py +0 -0
  90. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/chroma/__init__.py +0 -0
  91. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/chroma/instrumentation.py +0 -0
  92. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/chroma/patch.py +0 -0
  93. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/cohere/__init__.py +0 -0
  94. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/cohere/instrumentation.py +0 -0
  95. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/cohere/patch.py +0 -0
  96. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/groq/__init__.py +0 -0
  97. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/groq/instrumentation.py +0 -0
  98. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/groq/patch.py +0 -0
  99. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langchain/__init__.py +0 -0
  100. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langchain/instrumentation.py +0 -0
  101. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langchain/patch.py +0 -0
  102. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langchain_community/__init__.py +0 -0
  103. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langchain_community/instrumentation.py +0 -0
  104. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langchain_community/patch.py +0 -0
  105. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langchain_core/__init__.py +0 -0
  106. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langchain_core/instrumentation.py +0 -0
  107. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langchain_core/patch.py +0 -0
  108. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langgraph/__init__.py +0 -0
  109. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langgraph/instrumentation.py +0 -0
  110. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/langgraph/patch.py +0 -0
  111. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/llamaindex/__init__.py +0 -0
  112. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/llamaindex/instrumentation.py +0 -0
  113. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/llamaindex/patch.py +0 -0
  114. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/ollama/__init__.py +0 -0
  115. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/ollama/instrumentation.py +0 -0
  116. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/ollama/patch.py +0 -0
  117. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/openai/__init__.py +0 -0
  118. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/openai/instrumentation.py +0 -0
  119. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/pinecone/__init__.py +0 -0
  120. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/pinecone/instrumentation.py +0 -0
  121. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/pinecone/patch.py +0 -0
  122. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/qdrant/__init__.py +0 -0
  123. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/qdrant/instrumentation.py +0 -0
  124. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/qdrant/patch.py +0 -0
  125. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/weaviate/__init__.py +0 -0
  126. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/weaviate/instrumentation.py +0 -0
  127. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/instrumentation/weaviate/patch.py +0 -0
  128. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/types/__init__.py +0 -0
  129. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/utils/__init__.py +0 -0
  130. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/utils/langtrace_sampler.py +0 -0
  131. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/utils/llm.py +0 -0
  132. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/utils/misc.py +0 -0
  133. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/utils/prompt_registry.py +0 -0
  134. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/utils/sdk_version_checker.py +0 -0
  135. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/utils/silently_fail.py +0 -0
  136. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/utils/types.py +0 -0
  137. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/langtrace_python_sdk/utils/with_root_span.py +0 -0
  138. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/__init__.py +0 -0
  139. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/anthropic/cassettes/test_anthropic.yaml +0 -0
  140. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/anthropic/cassettes/test_anthropic_streaming.yaml +0 -0
  141. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/anthropic/cassettes/test_async_anthropic_streaming.yaml +0 -0
  142. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/anthropic/conftest.py +0 -0
  143. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/anthropic/test_anthropic.py +0 -0
  144. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/chroma/conftest.py +0 -0
  145. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/chroma/test_chroma.py +0 -0
  146. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/cohere/cassettes/test_cohere_chat.yaml +0 -0
  147. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/cohere/cassettes/test_cohere_chat_streaming.yaml +0 -0
  148. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/cohere/cassettes/test_cohere_embed.yaml +0 -0
  149. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/cohere/cassettes/test_cohere_rerank.yaml +0 -0
  150. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/cohere/conftest.py +0 -0
  151. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/cohere/test_cohere_chat.py +0 -0
  152. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/cohere/test_cohere_embed.py +0 -0
  153. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/cohere/test_cohere_rerank.py +0 -0
  154. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/conftest.py +0 -0
  155. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/langchain/cassettes/test_langchain.yaml +0 -0
  156. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/langchain/conftest.py +0 -0
  157. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/langchain/test_langchain.py +0 -0
  158. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/openai/cassettes/test_async_chat_completion_streaming.yaml +0 -0
  159. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/openai/cassettes/test_async_image_generation.yaml +0 -0
  160. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/openai/cassettes/test_chat_completion.yaml +0 -0
  161. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/openai/cassettes/test_chat_completion_streaming.yaml +0 -0
  162. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/openai/cassettes/test_image_generation.yaml +0 -0
  163. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/openai/conftest.py +0 -0
  164. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/openai/test_chat_completion.py +0 -0
  165. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/openai/test_embeddings.py +0 -0
  166. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/openai/test_image_generation.py +0 -0
  167. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/pinecone/cassettes/test_query.yaml +0 -0
  168. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/pinecone/cassettes/test_upsert.yaml +0 -0
  169. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/pinecone/conftest.py +0 -0
  170. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/pinecone/test_pinecone.py +0 -0
  171. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/qdrant/conftest.py +0 -0
  172. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/qdrant/test_qdrant.py +0 -0
  173. {langtrace_python_sdk-2.1.20 → langtrace_python_sdk-2.1.22}/src/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.1.20
3
+ Version: 2.1.22
4
4
  Summary: Python SDK for LangTrace
5
5
  Project-URL: Homepage, https://github.com/Scale3-Labs/langtrace-python-sdk
6
6
  Author-email: Scale3 Labs <engineering@scale3labs.com>
@@ -0,0 +1,70 @@
1
+ import os
2
+
3
+ os.environ["OPENAI_MODEL_NAME"] = "gpt-3.5-turbo"
4
+ os.environ["SERPER_API_KEY"] = "" # serper.dev API key
5
+ from langtrace_python_sdk import langtrace
6
+ from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
7
+ from crewai import Crew, Process
8
+ from crewai import Task
9
+ from crewai import Agent
10
+ from crewai_tools import SerperDevTool
11
+ from crewai_tools import YoutubeVideoSearchTool
12
+
13
+ langtrace.init()
14
+
15
+ search_tool = SerperDevTool()
16
+
17
+ # Targeted search within a specific Youtube video's content
18
+ youtube_tool = YoutubeVideoSearchTool(
19
+ youtube_video_url="https://www.youtube.com/watch?v=blqIZGXWUpU"
20
+ )
21
+
22
+ # Creating a senior researcher agent with memory and verbose mode
23
+ researcher = Agent(
24
+ role="Senior Researcher",
25
+ goal="Uncover groundbreaking technologies in {topic}",
26
+ verbose=True,
27
+ memory=True,
28
+ backstory=(
29
+ "Driven by curiosity, you're at the forefront of"
30
+ "innovation, eager to explore and share knowledge that could change"
31
+ "the world."
32
+ ),
33
+ tools=[youtube_tool],
34
+ )
35
+
36
+ # Research task
37
+ research_task = Task(
38
+ description=(
39
+ "Do a {topic} of the given youtube video."
40
+ "Focus on identifying the overall narrative."
41
+ "Your final report should clearly articulate the key points."
42
+ ),
43
+ expected_output="10 key points from the shared video.",
44
+ tools=[youtube_tool],
45
+ agent=researcher,
46
+ callback="research_callback", # Example of task callback
47
+ human_input=True,
48
+ )
49
+
50
+
51
+ # Forming the tech-focused crew with some enhanced configurations
52
+ crew = Crew(
53
+ agents=[researcher],
54
+ tasks=[research_task],
55
+ process=Process.sequential, # Optional: Sequential task execution is default
56
+ memory=False,
57
+ cache=False,
58
+ max_rpm=20,
59
+ )
60
+
61
+ # Starting the task execution process with enhanced feedback
62
+
63
+
64
+ @with_langtrace_root_span("Crew")
65
+ def test_crew():
66
+ result = crew.kickoff(inputs={"topic": "summary"})
67
+ return result
68
+
69
+
70
+ test_crew()
@@ -0,0 +1,42 @@
1
+ import dspy
2
+ from dspy.datasets.gsm8k import GSM8K, gsm8k_metric
3
+ from dspy.teleprompt import BootstrapFewShot
4
+
5
+ # flake8: noqa
6
+ from langtrace_python_sdk import langtrace, with_langtrace_root_span
7
+
8
+ langtrace.init()
9
+
10
+ turbo = dspy.OpenAI(model="gpt-3.5-turbo", max_tokens=250)
11
+ dspy.settings.configure(lm=turbo)
12
+
13
+ # Load math questions from the GSM8K dataset
14
+ gsm8k = GSM8K()
15
+ gsm8k_trainset, gsm8k_devset = gsm8k.train[:10], gsm8k.dev[:10]
16
+
17
+
18
+ class CoT(dspy.Module):
19
+ def __init__(self):
20
+ super().__init__()
21
+ self.prog = dspy.ChainOfThought("question -> answer")
22
+
23
+ def forward(self, question):
24
+ return self.prog(question=question)
25
+
26
+
27
+ @with_langtrace_root_span(name="math_problems_cot_example")
28
+ def example():
29
+
30
+ # Set up the optimizer: we want to "bootstrap" (i.e., self-generate) 4-shot examples of our CoT program.
31
+ config = dict(max_bootstrapped_demos=4, max_labeled_demos=4)
32
+
33
+ # Optimize! Use the `gsm8k_metric` here. In general, the metric is going to tell the optimizer how well it's doing.
34
+ teleprompter = BootstrapFewShot(metric=gsm8k_metric, **config)
35
+ optimized_cot = teleprompter.compile(CoT(), trainset=gsm8k_trainset)
36
+
37
+ ans = optimized_cot(question="What is the sqrt of 345?")
38
+ print(ans)
39
+
40
+
41
+ if __name__ == "__main__":
42
+ example()
@@ -0,0 +1,35 @@
1
+ import dspy
2
+
3
+ # flake8: noqa
4
+ from langtrace_python_sdk import langtrace, with_langtrace_root_span
5
+
6
+ langtrace.init()
7
+
8
+ turbo = dspy.OpenAI(model="gpt-3.5-turbo", max_tokens=250)
9
+ dspy.settings.configure(lm=turbo)
10
+
11
+
12
+ # Define a simple signature for basic question answering
13
+ class BasicQA(dspy.Signature):
14
+ """Answer questions with short factoid answers."""
15
+
16
+ question = dspy.InputField()
17
+ answer = dspy.OutputField(desc="often between 1 and 5 words")
18
+
19
+
20
+ @with_langtrace_root_span(name="pot_example")
21
+ def example():
22
+
23
+ # Pass signature to ProgramOfThought Module
24
+ pot = dspy.ProgramOfThought(BasicQA)
25
+
26
+ # Call the ProgramOfThought module on a particular input
27
+ question = "Sarah has 5 apples. She buys 7 more apples from the store. How many apples does Sarah have now?"
28
+ result = pot(question=question)
29
+
30
+ print(f"Question: {question}")
31
+ print(f"Final Predicted Answer (after ProgramOfThought process): {result.answer}")
32
+
33
+
34
+ if __name__ == "__main__":
35
+ example()
@@ -0,0 +1,113 @@
1
+ import dspy
2
+ import json
3
+ from dspy.datasets import HotPotQA
4
+ from dspy.teleprompt import BootstrapFewShot
5
+ from dspy.evaluate.evaluate import Evaluate
6
+
7
+ # flake8: noqa
8
+ from langtrace_python_sdk import langtrace, with_langtrace_root_span
9
+
10
+ langtrace.init()
11
+
12
+
13
+ colbertv2_wiki17_abstracts = dspy.ColBERTv2(
14
+ url="http://20.102.90.50:2017/wiki17_abstracts"
15
+ )
16
+ dspy.settings.configure(rm=colbertv2_wiki17_abstracts)
17
+ turbo = dspy.OpenAI(model="gpt-3.5-turbo-0613", max_tokens=500)
18
+ dspy.settings.configure(lm=turbo, trace=[], temperature=0.7)
19
+
20
+ dataset = HotPotQA(
21
+ train_seed=1,
22
+ train_size=300,
23
+ eval_seed=2023,
24
+ dev_size=300,
25
+ test_size=0,
26
+ keep_details=True,
27
+ )
28
+ trainset = [x.with_inputs("question", "answer") for x in dataset.train]
29
+ devset = [x.with_inputs("question", "answer") for x in dataset.dev]
30
+
31
+
32
+ class GenerateAnswerChoices(dspy.Signature):
33
+ """Generate answer choices in JSON format that include the correct answer and plausible distractors for the specified question."""
34
+
35
+ question = dspy.InputField()
36
+ correct_answer = dspy.InputField()
37
+ number_of_choices = dspy.InputField()
38
+ answer_choices = dspy.OutputField(desc="JSON key-value pairs")
39
+
40
+
41
+ class QuizAnswerGenerator(dspy.Module):
42
+ def __init__(self):
43
+ super().__init__()
44
+ self.prog = dspy.ChainOfThought(GenerateAnswerChoices)
45
+
46
+ def forward(self, question, answer):
47
+ choices = self.prog(
48
+ question=question, correct_answer=answer, number_of_choices="4"
49
+ ).answer_choices
50
+ # dspy.Suggest(
51
+ # format_checker(choices),
52
+ # "The format of the answer choices should be in JSON format. Please revise accordingly.",
53
+ # target_module=GenerateAnswerChoices,
54
+ # )
55
+ return dspy.Prediction(choices=choices)
56
+
57
+
58
+ def format_checker(choice_string):
59
+ try:
60
+ choices = json.loads(choice_string)
61
+ if isinstance(choices, dict) and all(
62
+ isinstance(key, str) and isinstance(value, str)
63
+ for key, value in choices.items()
64
+ ):
65
+ return True
66
+ except json.JSONDecodeError:
67
+ return False
68
+
69
+ return False
70
+
71
+
72
+ def format_valid_metric(gold, pred, trace=None):
73
+ generated_choices = pred.choices
74
+ format_valid = format_checker(generated_choices)
75
+ score = format_valid
76
+ return score
77
+
78
+
79
+ @with_langtrace_root_span(name="quiz_generator_1")
80
+ def quiz_generator_1():
81
+ quiz_generator = QuizAnswerGenerator()
82
+
83
+ example = devset[67]
84
+ print("Example Question: ", example.question)
85
+ print("Example Answer: ", example.answer)
86
+ # quiz_choices = quiz_generator(question=example.question, answer=example.answer)
87
+ # print("Generated Quiz Choices: ", quiz_choices.choices)
88
+
89
+ optimizer = BootstrapFewShot(
90
+ metric=format_valid_metric, max_bootstrapped_demos=4, max_labeled_demos=4
91
+ )
92
+ compiled_quiz_generator = optimizer.compile(
93
+ quiz_generator,
94
+ trainset=trainset,
95
+ )
96
+ quiz_choices = compiled_quiz_generator(
97
+ question=example.question, answer=example.answer
98
+ )
99
+ print("Generated Quiz Choices: ", quiz_choices.choices)
100
+
101
+ # Evaluate
102
+ evaluate = Evaluate(
103
+ metric=format_valid_metric,
104
+ devset=devset[67:70],
105
+ num_threads=1,
106
+ display_progress=True,
107
+ display_table=5,
108
+ )
109
+ evaluate(quiz_generator)
110
+
111
+
112
+ if __name__ == "__main__":
113
+ quiz_generator_1()
@@ -0,0 +1,39 @@
1
+ import sys
2
+ import os
3
+ import dspy
4
+
5
+ # Add the local src folder to the Python path
6
+ sys.path.insert(0, os.path.abspath('/Users/karthikkalyanaraman/work/langtrace/langtrace-python-sdk/src'))
7
+
8
+ # flake8: noqa
9
+ from langtrace_python_sdk import langtrace, with_langtrace_root_span
10
+ langtrace.init()
11
+
12
+ turbo = dspy.OpenAI(model='gpt-3.5-turbo', max_tokens=250)
13
+ dspy.settings.configure(lm=turbo)
14
+
15
+ colbertv2_wiki17_abstracts = dspy.ColBERTv2(url='http://20.102.90.50:2017/wiki17_abstracts')
16
+ dspy.settings.configure(rm=colbertv2_wiki17_abstracts)
17
+ retriever = dspy.Retrieve(k=3)
18
+
19
+ # Define a simple signature for basic question answering
20
+ class BasicQA(dspy.Signature):
21
+ """Answer questions with short factoid answers."""
22
+ question = dspy.InputField()
23
+ answer = dspy.OutputField(desc="often between 1 and 5 words")
24
+
25
+ @with_langtrace_root_span(name="react_example")
26
+ def example():
27
+
28
+ # Pass signature to ReAct module
29
+ react_module = dspy.ReAct(BasicQA)
30
+
31
+ # Call the ReAct module on a particular input
32
+ question = 'Aside from the Apple Remote, what other devices can control the program Apple Remote was originally designed to interact with?'
33
+ result = react_module(question=question)
34
+
35
+ print(f"Question: {question}")
36
+ print(f"Final Predicted Answer (after ReAct process): {result.answer}")
37
+
38
+ if __name__ == '__main__':
39
+ example()
@@ -11,6 +11,8 @@ SERVICE_PROVIDERS = {
11
11
  "ANTHROPIC": "Anthropic",
12
12
  "AZURE": "Azure",
13
13
  "CHROMA": "Chroma",
14
+ "CREWAI": "CrewAI",
15
+ "DSPY": "DSPy",
14
16
  "GROQ": "Groq",
15
17
  "LANGCHAIN": "Langchain",
16
18
  "LANGCHAIN_COMMUNITY": "Langchain Community",
@@ -1,6 +1,7 @@
1
1
  from .anthropic import AnthropicInstrumentation
2
2
  from .chroma import ChromaInstrumentation
3
3
  from .cohere import CohereInstrumentation
4
+ from .crewai import CrewAIInstrumentation
4
5
  from .groq import GroqInstrumentation
5
6
  from .langchain import LangchainInstrumentation
6
7
  from .langchain_community import LangchainCommunityInstrumentation
@@ -12,11 +13,13 @@ from .pinecone import PineconeInstrumentation
12
13
  from .qdrant import QdrantInstrumentation
13
14
  from .weaviate import WeaviateInstrumentation
14
15
  from .ollama import OllamaInstrumentor
16
+ from .dspy import DspyInstrumentation
15
17
 
16
18
  __all__ = [
17
19
  "AnthropicInstrumentation",
18
20
  "ChromaInstrumentation",
19
21
  "CohereInstrumentation",
22
+ "CrewAIInstrumentation",
20
23
  "GroqInstrumentation",
21
24
  "LangchainInstrumentation",
22
25
  "LangchainCommunityInstrumentation",
@@ -28,4 +31,5 @@ __all__ = [
28
31
  "QdrantInstrumentation",
29
32
  "WeaviateInstrumentation",
30
33
  "OllamaInstrumentor",
34
+ "DspyInstrumentation",
31
35
  ]
@@ -0,0 +1,3 @@
1
+ from .instrumentation import CrewAIInstrumentation
2
+
3
+ __all__ = ["CrewAIInstrumentation"]
@@ -0,0 +1,53 @@
1
+ """
2
+ Copyright (c) 2024 Scale3 Labs
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+
17
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
18
+ from opentelemetry.trace import get_tracer
19
+ from wrapt import wrap_function_wrapper as _W
20
+ from typing import Collection
21
+ from importlib_metadata import version as v
22
+ from .patch import patch_crew
23
+
24
+
25
+ class CrewAIInstrumentation(BaseInstrumentor):
26
+ """
27
+ The CrewAIInstrumentation class represents the CrewAI instrumentation"""
28
+
29
+ def instrumentation_dependencies(self) -> Collection[str]:
30
+ return ["crewai >= 0.32.0"]
31
+
32
+ def _instrument(self, **kwargs):
33
+ tracer_provider = kwargs.get("tracer_provider")
34
+ tracer = get_tracer(__name__, "", tracer_provider)
35
+ version = v("crewai")
36
+ _W(
37
+ "crewai.crew",
38
+ "Crew.kickoff",
39
+ patch_crew("Crew.kickoff", version, tracer),
40
+ )
41
+ _W(
42
+ "crewai.agent",
43
+ "Agent.execute_task",
44
+ patch_crew("Agent.execute_task", version, tracer),
45
+ )
46
+ _W(
47
+ "crewai.task",
48
+ "Task.execute",
49
+ patch_crew("Task.execute", version, tracer),
50
+ )
51
+
52
+ def _uninstrument(self, **kwargs):
53
+ pass
@@ -0,0 +1,173 @@
1
+ import json
2
+ from importlib_metadata import version as v
3
+ from langtrace_python_sdk.constants import LANGTRACE_SDK_NAME
4
+ from langtrace_python_sdk.utils import set_span_attribute
5
+ from langtrace_python_sdk.utils.silently_fail import silently_fail
6
+ from langtrace_python_sdk.constants.instrumentation.common import (
7
+ LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY,
8
+ SERVICE_PROVIDERS,
9
+ )
10
+ from opentelemetry import baggage
11
+ from langtrace.trace_attributes import FrameworkSpanAttributes
12
+ from opentelemetry.trace import SpanKind
13
+ from opentelemetry.trace.status import Status, StatusCode
14
+
15
+
16
+ crew_properties = {
17
+ "tasks": "object",
18
+ "agents": "object",
19
+ "cache": "bool",
20
+ "process": "object",
21
+ "verbose": "bool",
22
+ "memory": "bool",
23
+ "embedder": "json",
24
+ "full_output": "bool",
25
+ "manager_llm": "object",
26
+ "manager_agent": "object",
27
+ "manager_callbacks": "object",
28
+ "function_calling_llm": "object",
29
+ "config": "json",
30
+ "id": "object",
31
+ "max_rpm": "int",
32
+ "share_crew": "bool",
33
+ "step_callback": "object",
34
+ "task_callback": "object",
35
+ "prompt_file": "object",
36
+ "output_log_file": "object",
37
+ }
38
+
39
+ task_properties = {
40
+ "id": "object",
41
+ "used_tools": "int",
42
+ "tools_errors": "int",
43
+ "delegations": "int",
44
+ "i18n": "object",
45
+ "thread": "object",
46
+ "prompt_context": "object",
47
+ "description": "str",
48
+ "expected_output": "str",
49
+ "config": "object",
50
+ "callback": "str",
51
+ "agent": "object",
52
+ "context": "object",
53
+ "async_execution": "bool",
54
+ "output_json": "object",
55
+ "output_pydantic": "object",
56
+ "output_file": "object",
57
+ "output": "object",
58
+ "tools": "object",
59
+ "human_input": "bool",
60
+ }
61
+
62
+ agent_properties = {
63
+ "formatting_errors": "int",
64
+ "id": "object",
65
+ "role": "str",
66
+ "goal": "str",
67
+ "backstory": "str",
68
+ "cache": "bool",
69
+ "config": "object",
70
+ "max_rpm": "int",
71
+ "verbose": "bool",
72
+ "allow_delegation": "bool",
73
+ "tools": "object",
74
+ "max_iter": "int",
75
+ "max_execution_time": "object",
76
+ "agent_executor": "object",
77
+ "tools_handler": "object",
78
+ "force_answer_max_iterations": "int",
79
+ "crew": "object",
80
+ "cache_handler": "object",
81
+ "step_callback": "object",
82
+ "i18n": "object",
83
+ "llm": "object",
84
+ "function_calling_llm": "object",
85
+ "callbacks": "object",
86
+ "system_template": "object",
87
+ "prompt_template": "object",
88
+ "response_template": "object",
89
+ }
90
+
91
+
92
+ def patch_crew(operation_name, version, tracer):
93
+ def traced_method(wrapped, instance, args, kwargs):
94
+
95
+ service_provider = SERVICE_PROVIDERS["CREWAI"]
96
+ extra_attributes = baggage.get_baggage(LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY)
97
+ span_attributes = {
98
+ "langtrace.sdk.name": "langtrace-python-sdk",
99
+ "langtrace.service.name": service_provider,
100
+ "langtrace.service.type": "framework",
101
+ "langtrace.service.version": version,
102
+ "langtrace.version": v(LANGTRACE_SDK_NAME),
103
+ **(extra_attributes if extra_attributes is not None else {}),
104
+ }
105
+
106
+ crew_config = {}
107
+ for key, value in instance.__dict__.items():
108
+ if instance.__class__.__name__ == "Crew":
109
+ if key in crew_properties and value is not None:
110
+ if crew_properties[key] == "json":
111
+ crew_config[key] = json.dumps(value)
112
+ elif crew_properties[key] == "object":
113
+ crew_config[key] = str(value)
114
+ else:
115
+ crew_config[key] = value
116
+ elif instance.__class__.__name__ == "Agent":
117
+ if key in agent_properties and value is not None:
118
+ if agent_properties[key] == "json":
119
+ crew_config[key] = json.dumps(value)
120
+ elif agent_properties[key] == "object":
121
+ crew_config[key] = str(value)
122
+ else:
123
+ crew_config[key] = value
124
+ elif instance.__class__.__name__ == "Task":
125
+ if key in task_properties and value is not None:
126
+ if task_properties[key] == "json":
127
+ crew_config[key] = json.dumps(value)
128
+ elif task_properties[key] == "object":
129
+ crew_config[key] = str(value)
130
+ else:
131
+ crew_config[key] = value
132
+ if crew_config:
133
+ if instance.__class__.__name__ == "Crew":
134
+ if "inputs" in kwargs and kwargs["inputs"]:
135
+ crew_config["inputs"] = json.dumps(kwargs["inputs"])
136
+ span_attributes["crewai.crew.config"] = json.dumps(crew_config)
137
+ elif instance.__class__.__name__ == "Agent":
138
+ if "context" in kwargs and kwargs["context"]:
139
+ crew_config["context"] = json.dumps(kwargs["context"])
140
+ span_attributes["crewai.agent.config"] = json.dumps(crew_config)
141
+ elif instance.__class__.__name__ == "Task":
142
+ span_attributes["crewai.task.config"] = json.dumps(crew_config)
143
+
144
+ attributes = FrameworkSpanAttributes(**span_attributes)
145
+
146
+ with tracer.start_as_current_span(operation_name, kind=SpanKind.CLIENT) as span:
147
+ _set_input_attributes(span, kwargs, attributes)
148
+
149
+ try:
150
+ result = wrapped(*args, **kwargs)
151
+ if result:
152
+ span.set_status(Status(StatusCode.OK))
153
+
154
+ span.end()
155
+ return result
156
+
157
+ except Exception as err:
158
+ # Record the exception in the span
159
+ span.record_exception(err)
160
+
161
+ # Set the span status to indicate an error
162
+ span.set_status(Status(StatusCode.ERROR, str(err)))
163
+
164
+ # Reraise the exception to ensure it's not swallowed
165
+ raise
166
+
167
+ return traced_method
168
+
169
+
170
+ @silently_fail
171
+ def _set_input_attributes(span, kwargs, attributes):
172
+ for field, value in attributes.model_dump(by_alias=True).items():
173
+ set_span_attribute(span, field, value)
@@ -0,0 +1,3 @@
1
+ from .instrumentation import DspyInstrumentation
2
+
3
+ __all__ = ["DspyInstrumentation"]
@@ -0,0 +1,85 @@
1
+ """
2
+ Copyright (c) 2024 Scale3 Labs
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+
17
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
18
+ from opentelemetry.trace import get_tracer
19
+ from wrapt import wrap_function_wrapper as _W
20
+ from typing import Collection
21
+ from importlib_metadata import version as v
22
+ from .patch import patch_bootstrapfewshot_optimizer, patch_signature, patch_evaluate
23
+
24
+
25
+ class DspyInstrumentation(BaseInstrumentor):
26
+ """
27
+ The DspyInstrumentor class represents the DSPy instrumentation"""
28
+
29
+ def instrumentation_dependencies(self) -> Collection[str]:
30
+ return ["dspy >= 0.1.5"]
31
+
32
+ def _instrument(self, **kwargs):
33
+ tracer_provider = kwargs.get("tracer_provider")
34
+ tracer = get_tracer(__name__, "", tracer_provider)
35
+ version = v("dspy")
36
+ _W(
37
+ "dspy.teleprompt.bootstrap",
38
+ "BootstrapFewShot.compile",
39
+ patch_bootstrapfewshot_optimizer(
40
+ "BootstrapFewShot.compile", version, tracer
41
+ ),
42
+ )
43
+ _W(
44
+ "dspy.predict.predict",
45
+ "Predict.forward",
46
+ patch_signature("Predict.forward", version, tracer),
47
+ )
48
+ _W(
49
+ "dspy.predict.chain_of_thought",
50
+ "ChainOfThought.forward",
51
+ patch_signature("ChainOfThought.forward", version, tracer),
52
+ )
53
+ _W(
54
+ "dspy.predict.chain_of_thought_with_hint",
55
+ "ChainOfThoughtWithHint.forward",
56
+ patch_signature("ChainOfThoughtWithHint.forward", version, tracer),
57
+ )
58
+ _W(
59
+ "dspy.predict.react",
60
+ "ReAct.forward",
61
+ patch_signature("ReAct.forward", version, tracer),
62
+ )
63
+ _W(
64
+ "dspy.predict.program_of_thought",
65
+ "ProgramOfThought.forward",
66
+ patch_signature("ProgramOfThought.forward", version, tracer),
67
+ )
68
+ _W(
69
+ "dspy.predict.multi_chain_comparison",
70
+ "MultiChainComparison.forward",
71
+ patch_signature("MultiChainComparison.forward", version, tracer),
72
+ )
73
+ _W(
74
+ "dspy.predict.retry",
75
+ "Retry.forward",
76
+ patch_signature("Retry.forward", version, tracer),
77
+ )
78
+ _W(
79
+ "dspy.evaluate.evaluate",
80
+ "Evaluate.__call__",
81
+ patch_evaluate("Evaluate", version, tracer),
82
+ )
83
+
84
+ def _uninstrument(self, **kwargs):
85
+ pass