monocle-apptrace 0.3.0b7__tar.gz → 0.3.1__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.

Potentially problematic release.


This version of monocle-apptrace might be problematic. Click here for more details.

Files changed (98) hide show
  1. monocle_apptrace-0.3.1/CHANGELOG.md +86 -0
  2. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/PKG-INFO +2 -1
  3. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/pyproject.toml +3 -2
  4. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/exporters/monocle_exporters.py +5 -2
  5. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/common/__init__.py +1 -1
  6. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/common/constants.py +7 -1
  7. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/common/instrumentor.py +20 -9
  8. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/common/span_handler.py +36 -25
  9. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/common/tracing.md +68 -0
  10. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/common/utils.py +25 -10
  11. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/common/wrapper.py +24 -22
  12. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/common/wrapper_method.py +5 -2
  13. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/anthropic/_helper.py +64 -0
  14. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/anthropic/entities/inference.py +72 -0
  15. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/anthropic/methods.py +24 -0
  16. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/botocore/entities/inference.py +2 -2
  17. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/botocore/handlers/botocore_span_handler.py +1 -1
  18. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/flask/_helper.py +71 -0
  19. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/flask/entities/http.py +49 -0
  20. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/flask/methods.py +22 -0
  21. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/haystack/entities/inference.py +4 -1
  22. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/haystack/methods.py +1 -4
  23. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/langchain/_helper.py +12 -4
  24. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/langchain/methods.py +6 -14
  25. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/methods.py +2 -15
  26. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/openai/__init__.py +0 -0
  27. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/openai/_helper.py +9 -4
  28. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/openai/entities/__init__.py +0 -0
  29. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/openai/methods.py +16 -2
  30. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/requests/_helper.py +31 -0
  31. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/requests/entities/http.py +51 -0
  32. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/requests/methods.py +2 -1
  33. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/teamsai/__init__.py +0 -0
  34. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/teamsai/_helper.py +58 -0
  35. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/teamsai/entities/__init__.py +0 -0
  36. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/__init__.py +0 -0
  37. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/actionplanner_output_processor.py +80 -0
  38. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/teamsai_output_processor.py +70 -0
  39. monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/teamsai/methods.py +26 -0
  40. monocle_apptrace-0.3.0b7/CHANGELOG.md +0 -49
  41. monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/flask/_helper.py +0 -29
  42. monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/flask/methods.py +0 -13
  43. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/.gitignore +0 -0
  44. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/CODEOWNERS.md +0 -0
  45. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/CODE_OF_CONDUCT.md +0 -0
  46. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/CONTRIBUTING.md +0 -0
  47. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/COPYRIGHT.template +0 -0
  48. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/LICENSE +0 -0
  49. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/MAINTAINER.md +0 -0
  50. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/Monocle_User_Guide.md +0 -0
  51. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/Monocle_committer_guide.md +0 -0
  52. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/Monocle_contributor_guide.md +0 -0
  53. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/NOTICE +0 -0
  54. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/README.md +0 -0
  55. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/SECURITY.md +0 -0
  56. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/README.md +0 -0
  57. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/__init__.py +0 -0
  58. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/__main__.py +0 -0
  59. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/exporters/aws/s3_exporter.py +0 -0
  60. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/exporters/aws/s3_exporter_opendal.py +0 -0
  61. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/exporters/azure/blob_exporter.py +0 -0
  62. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/exporters/azure/blob_exporter_opendal.py +0 -0
  63. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/exporters/base_exporter.py +0 -0
  64. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/exporters/exporter_processor.py +0 -0
  65. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/exporters/file_exporter.py +0 -0
  66. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/exporters/okahu/okahu_exporter.py +0 -0
  67. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/__init__.py +0 -0
  68. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/__init__.py +0 -0
  69. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/botocore → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/anthropic}/__init__.py +0 -0
  70. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/botocore → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/anthropic}/entities/__init__.py +0 -0
  71. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/flask → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/botocore}/__init__.py +0 -0
  72. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/botocore/_helper.py +0 -0
  73. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/haystack → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/botocore/entities}/__init__.py +0 -0
  74. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/botocore/methods.py +0 -0
  75. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/haystack/entities → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/flask}/__init__.py +0 -0
  76. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/langchain → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/haystack}/__init__.py +0 -0
  77. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/haystack/_helper.py +0 -0
  78. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/langchain → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/haystack}/entities/__init__.py +0 -0
  79. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/haystack/entities/retrieval.py +0 -0
  80. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/langgraph → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/langchain}/__init__.py +0 -0
  81. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/langgraph → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/langchain}/entities/__init__.py +0 -0
  82. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/langchain/entities/inference.py +0 -0
  83. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/langchain/entities/retrieval.py +0 -0
  84. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/llamaindex → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/langgraph}/__init__.py +0 -0
  85. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/langgraph/_helper.py +0 -0
  86. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/llamaindex → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/langgraph}/entities/__init__.py +0 -0
  87. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/langgraph/entities/inference.py +0 -0
  88. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/langgraph/methods.py +0 -0
  89. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/openai → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/llamaindex}/__init__.py +0 -0
  90. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/_helper.py +0 -0
  91. {monocle_apptrace-0.3.0b7/src/monocle_apptrace/instrumentation/metamodel/openai → monocle_apptrace-0.3.1/src/monocle_apptrace/instrumentation/metamodel/llamaindex}/entities/__init__.py +0 -0
  92. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/entities/agent.py +0 -0
  93. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/entities/inference.py +0 -0
  94. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/entities/retrieval.py +0 -0
  95. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/openai/entities/inference.py +0 -0
  96. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/openai/entities/retrieval.py +0 -0
  97. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/src/monocle_apptrace/instrumentation/metamodel/requests/__init__.py +0 -0
  98. {monocle_apptrace-0.3.0b7 → monocle_apptrace-0.3.1}/tox.ini +0 -0
@@ -0,0 +1,86 @@
1
+ ## Version 0.3.1 (2024-04-18)
2
+
3
+ - Add MetaModel for Anthropic SDK ([#159](https://github.com/monocle2ai/monocle/pull/159))
4
+ - Add openAI response for openAI and AzureOpenAI ([#158](https://github.com/monocle2ai/monocle/pull/158))
5
+ - Update retrieval span for Boto Client ([#157](https://github.com/monocle2ai/monocle/pull/157))
6
+ - Resolve token threshold error ([#156](https://github.com/monocle2ai/monocle/pull/156))
7
+ - Update Inference Span ([#155](https://github.com/monocle2ai/monocle/pull/155))
8
+ - Refactor workflow and spans ([#160](https://github.com/monocle2ai/monocle/pull/160))
9
+ - Support monocle exporter list as parameter to `setup_monocle_telemetry()` ([#161](https://github.com/monocle2ai/monocle/pull/161))
10
+ - Add langchain anthropic sample ([#165](https://github.com/monocle2ai/monocle/pull/165))
11
+
12
+ ## Version 0.3.0 (2024-12-10)
13
+
14
+ - Fixed issue with passing context in async case ([#150](https://github.com/monocle2ai/monocle/pull/150))
15
+ - Added lambda processor ([#148](https://github.com/monocle2ai/monocle/pull/148))
16
+ - Setup package level init scripts to make the monocle import simpler ([#147](https://github.com/monocle2ai/monocle/pull/147))
17
+ - Boto attributes and test cleanup ([#146](https://github.com/monocle2ai/monocle/pull/146))
18
+ - Openai workflow ([#142](https://github.com/monocle2ai/monocle/pull/142))
19
+ - Add input/output for openai embedding ([#141](https://github.com/monocle2ai/monocle/pull/141))
20
+ - Async method and scope fix ([#140](https://github.com/monocle2ai/monocle/pull/140))
21
+ - Bug fix for helper langchain and langgraph ([#137](https://github.com/monocle2ai/monocle/pull/137))
22
+ - Package main script to run any app with monocle instrumentation ([#132](https://github.com/monocle2ai/monocle/pull/132))
23
+ - Add openai api metamodel ([#131](https://github.com/monocle2ai/monocle/pull/131))
24
+ - Support notion of scopes to group traces/snaps into logical constructs ([#130](https://github.com/monocle2ai/monocle/pull/130))
25
+ - Add Llamaindex ReAct agent ([#127](https://github.com/monocle2ai/monocle/pull/127))
26
+ - Langhcain input fix and s3 exporter prefix support ([#126](https://github.com/monocle2ai/monocle/pull/126))
27
+ - Use standard AWS credential envs ([#123](https://github.com/monocle2ai/monocle/pull/123))
28
+ - Check additional attributes for Azure OpenAI model and consolidate common method in utils ([#122](https://github.com/monocle2ai/monocle/pull/122))
29
+ - Bug fix for accessor ([#121](https://github.com/monocle2ai/monocle/pull/121))
30
+ - Bug fix for empty response ([#120](https://github.com/monocle2ai/monocle/pull/120))
31
+ - Bug fix for inference endpoint ([#119](https://github.com/monocle2ai/monocle/pull/119))
32
+ - Opendal exporter for S3 and Blob ([#117](https://github.com/monocle2ai/monocle/pull/117))
33
+ - Handle specific ModuleNotFoundError exceptions gracefully ([#115](https://github.com/monocle2ai/monocle/pull/115))
34
+ - Adding support for console and memory exporter to list of monocle exporters ([#113](https://github.com/monocle2ai/monocle/pull/113))
35
+ - Add trace id propogation for constant trace id and from request ([#111](https://github.com/monocle2ai/monocle/pull/111))
36
+ - Restructure of monoocle code for easy extensibility ([#109](https://github.com/monocle2ai/monocle/pull/109))
37
+ - S3 update filename prefix ([#98](https://github.com/monocle2ai/monocle/pull/98))
38
+ - Update inference span for botocore sagemaker ([#93](https://github.com/monocle2ai/monocle/pull/93))
39
+ - Capturing inference output and token metadata for bedrock ([#82](https://github.com/monocle2ai/monocle/pull/82))
40
+ - Add dev dependency for Mistral AI integration ([#81](https://github.com/monocle2ai/monocle/pull/81))
41
+ - Add VectorStore deployment URL capture support ([#80](https://github.com/monocle2ai/monocle/pull/80))
42
+ - Clean up cloud exporter implementation ([#79](https://github.com/monocle2ai/monocle/pull/79))
43
+ - Capture inference span input/output events attributes ([#77](https://github.com/monocle2ai/monocle/pull/77))
44
+ - Add release automation workflows ([#76](https://github.com/monocle2ai/monocle/pull/76))
45
+ - Fix gaps in Monocle SDK implementation ([#72](https://github.com/monocle2ai/monocle/pull/72))
46
+ - Add kwargs and return value handling in Accessor ([#71](https://github.com/monocle2ai/monocle/pull/71))
47
+ - Update workflow name formatting ([#69](https://github.com/monocle2ai/monocle/pull/69))
48
+ - Implement Haystack metamodel support ([#68](https://github.com/monocle2ai/monocle/pull/68))
49
+
50
+ ## Version 0.2.0 (2024-12-05)
51
+
52
+ ## 0.2.0 (Oct 22, 2024)
53
+
54
+ - Ndjson format for S3 and Blob exporters ([#61](https://github.com/monocle2ai/monocle/pull/61))
55
+ - Set monocle exporter from env setting ([#60](https://github.com/monocle2ai/monocle/pull/60))
56
+ - Update workflow name and type with new format ([#59](https://github.com/monocle2ai/monocle/pull/59))
57
+ - Updated async and custom output processor testcase for metamodel([#58](https://github.com/monocle2ai/monocle/pull/58))
58
+ - Build okahu exporter and added test cases for okahu exporte ([#56](https://github.com/monocle2ai/monocle/pull/56))
59
+ - Handle exception in span wrappers([#52](https://github.com/monocle2ai/monocle/pull/52))
60
+ - Metamodel entity changes ([#51](https://github.com/monocle2ai/monocle/pull/51)), ([#54](https://github.com/monocle2ai/monocle/pull/54))
61
+ - Error handling for llm_endpoint and tags ([#50](https://github.com/monocle2ai/monocle/pull/50))
62
+ - Context_output for vector store retriever ([#48](https://github.com/monocle2ai/monocle/pull/48))
63
+ - Direct exporter - AWS S3 ([#42](https://github.com/monocle2ai/monocle/pull/42))
64
+ - Direct Exporter - Blob store ([#41](https://github.com/monocle2ai/monocle/pull/41))
65
+ - Initial metamodel definition ([#39](https://github.com/monocle2ai/monocle/pull/39))
66
+ - Improvement in vectorstore traces ([#38](https://github.com/monocle2ai/monocle/pull/38))
67
+ - Update key for session context field in attributes ([#34](https://github.com/monocle2ai/monocle/pull/34))
68
+
69
+
70
+ ## 0.1.0 (Aug 27, 2024)
71
+
72
+ - Fixed LlamaIndex tracing bugs ([#32](https://github.com/monocle2ai/monocle/pull/32))
73
+ - Added support to add AWS cloud infra attributes ([#29](https://github.com/monocle2ai/monocle/pull/29))
74
+ - Added support to add Azure cloud infra attributes ([#23](https://github.com/monocle2ai/monocle/pull/23))
75
+ - Added support for adding provider name in LLM span in traces ([#22](https://github.com/monocle2ai/monocle/pull/22))
76
+ - Added a default file span exporter ([#21](https://github.com/monocle2ai/monocle/pull/21))
77
+ - Moved input and output context and prompts from attributes to events ([#15](https://github.com/monocle2ai/monocle/pull/15))
78
+
79
+
80
+
81
+
82
+
83
+
84
+ ## 0.0.1 (Jul 17, 2024)
85
+
86
+ - First monocle release
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: monocle_apptrace
3
- Version: 0.3.0b7
3
+ Version: 0.3.1
4
4
  Summary: package with monocle genAI tracing
5
5
  Project-URL: Homepage, https://github.com/monocle2ai/monocle
6
6
  Project-URL: Issues, https://github.com/monocle2ai/monocle/issues
@@ -20,6 +20,7 @@ Requires-Dist: boto3==1.35.19; extra == 'aws'
20
20
  Provides-Extra: azure
21
21
  Requires-Dist: azure-storage-blob==12.22.0; extra == 'azure'
22
22
  Provides-Extra: dev
23
+ Requires-Dist: anthropic==0.49.0; extra == 'dev'
23
24
  Requires-Dist: azure-storage-blob==12.22.0; extra == 'dev'
24
25
  Requires-Dist: boto3==1.34.131; extra == 'dev'
25
26
  Requires-Dist: chromadb==0.4.22; extra == 'dev'
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "monocle_apptrace"
7
- version = "0.3.0b7"
7
+ version = "0.3.1"
8
8
  authors = []
9
9
  description = "package with monocle genAI tracing"
10
10
  readme = "README.md"
@@ -72,7 +72,8 @@ dev = [
72
72
  'flask',
73
73
  'opentelemetry-instrumentation-flask',
74
74
  'langgraph==0.2.68',
75
- 'opendal==0.45.14'
75
+ 'opendal==0.45.14',
76
+ 'anthropic==0.49.0',
76
77
  ]
77
78
 
78
79
  azure = [
@@ -18,9 +18,12 @@ monocle_exporters: Dict[str, Any] = {
18
18
  }
19
19
 
20
20
 
21
- def get_monocle_exporter() -> List[SpanExporter]:
21
+ def get_monocle_exporter(exporters_list:str=None) -> List[SpanExporter]:
22
22
  # Retrieve the MONOCLE_EXPORTER environment variable and split it into a list
23
- exporter_names = os.environ.get("MONOCLE_EXPORTER", "file").split(",")
23
+ if exporters_list:
24
+ exporter_names = exporters_list.split(",")
25
+ else:
26
+ exporter_names = os.environ.get("MONOCLE_EXPORTER", "file").split(",")
24
27
  exporters = []
25
28
 
26
29
  # Create task processor for AWS Lambda environment
@@ -1,2 +1,2 @@
1
1
  from .instrumentor import setup_monocle_telemetry, start_trace, stop_trace, start_scope, stop_scope, http_route_handler, monocle_trace_scope, monocle_trace_scope_method, monocle_trace
2
- from .utils import MonocleSpanException
2
+ from .utils import MonocleSpanException
@@ -13,6 +13,7 @@ GITHUB_CODESPACE_IDENTIFIER_ENV_NAME = "GITHUB_REPOSITORY"
13
13
 
14
14
  # Azure naming reference can be found here
15
15
  # https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-abbreviations
16
+ # https://docs.aws.amazon.com/resource-explorer/latest/userguide/supported-resource-types.html#services-lookoutmetrics
16
17
  AZURE_FUNCTION_NAME = "azure.func"
17
18
  AZURE_APP_SERVICE_NAME = "azure.asp"
18
19
  AZURE_ML_SERVICE_NAME = "azure.mlw"
@@ -48,6 +49,9 @@ llm_type_map = {
48
49
  "sagemakerllm": "aws_sagemaker",
49
50
  "chatbedrock": "aws_bedrock",
50
51
  "openaigenerator": "openai",
52
+ "bedrockruntime":"aws_bedrock",
53
+ "sagemakerruntime":"aws_sagemaker",
54
+ "chatanthropic":"anthropic",
51
55
  }
52
56
 
53
57
  MONOCLE_INSTRUMENTOR = "monocle_apptrace"
@@ -67,5 +71,7 @@ SCOPE_METHOD_FILE = 'monocle_scopes.json'
67
71
  SCOPE_CONFIG_PATH = 'MONOCLE_SCOPE_CONFIG_PATH'
68
72
  TRACE_PROPOGATION_URLS = "MONOCLE_TRACE_PROPAGATATION_URLS"
69
73
  WORKFLOW_TYPE_KEY = "monocle.workflow_type"
74
+ ADD_NEW_WORKFLOW = "monocle.add_new_workflow"
70
75
  WORKFLOW_TYPE_GENERIC = "workflow.generic"
71
- MONOCLE_SDK_VERSION = "monocle_apptrace.version"
76
+ MONOCLE_SDK_VERSION = "monocle_apptrace.version"
77
+ MONOCLE_SDK_LANGUAGE = "monocle_apptrace.language"
@@ -3,6 +3,7 @@ import inspect
3
3
  from typing import Collection, Dict, List, Union
4
4
  import random
5
5
  import uuid
6
+ import inspect
6
7
  from opentelemetry import trace
7
8
  from contextlib import contextmanager
8
9
  from opentelemetry.context import attach, get_value, set_value, get_current, detach
@@ -13,6 +14,7 @@ from opentelemetry.sdk.trace import TracerProvider, Span, id_generator
13
14
  from opentelemetry.sdk.resources import SERVICE_NAME, Resource
14
15
  from opentelemetry.sdk.trace import Span, TracerProvider
15
16
  from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanProcessor
17
+ from opentelemetry.sdk.trace.export import SpanExporter
16
18
  from opentelemetry.trace import get_tracer
17
19
  from wrapt import wrap_function_wrapper
18
20
  from opentelemetry.trace.propagation import set_span_in_context, _SPAN_KEY
@@ -27,7 +29,7 @@ from monocle_apptrace.instrumentation.common.wrapper import scope_wrapper, ascop
27
29
  from monocle_apptrace.instrumentation.common.utils import (
28
30
  set_scope, remove_scope, http_route_handler, load_scopes, async_wrapper, http_async_route_handler
29
31
  )
30
- from monocle_apptrace.instrumentation.common.constants import MONOCLE_INSTRUMENTOR, WORKFLOW_TYPE_KEY
32
+ from monocle_apptrace.instrumentation.common.constants import MONOCLE_INSTRUMENTOR, WORKFLOW_TYPE_GENERIC
31
33
  from functools import wraps
32
34
  logger = logging.getLogger(__name__)
33
35
 
@@ -39,19 +41,22 @@ monocle_tracer_provider: TracerProvider = None
39
41
 
40
42
  class MonocleInstrumentor(BaseInstrumentor):
41
43
  workflow_name: str = ""
42
- user_wrapper_methods: list[Union[dict,WrapperMethod]] = []
44
+ user_wrapper_methods: list[Union[dict,WrapperMethod]] = [],
45
+ exporters: list[SpanExporter] = [],
43
46
  instrumented_method_list: list[object] = []
44
- handlers:Dict[str,SpanHandler] = {} # dict of handlers
47
+ handlers:Dict[str,SpanHandler] = None # dict of handlers
45
48
  union_with_default_methods: bool = False
46
49
 
47
50
  def __init__(
48
51
  self,
49
52
  handlers,
50
53
  user_wrapper_methods: list[Union[dict,WrapperMethod]] = None,
54
+ exporters: list[SpanExporter] = None,
51
55
  union_with_default_methods: bool = True
52
56
  ) -> None:
53
57
  self.user_wrapper_methods = user_wrapper_methods or []
54
58
  self.handlers = handlers
59
+ self.exporters = exporters
55
60
  if self.handlers is not None:
56
61
  for key, val in MONOCLE_SPAN_HANDLERS.items():
57
62
  if key not in self.handlers:
@@ -155,7 +160,8 @@ def setup_monocle_telemetry(
155
160
  span_processors: List[SpanProcessor] = None,
156
161
  span_handlers: Dict[str,SpanHandler] = None,
157
162
  wrapper_methods: List[Union[dict,WrapperMethod]] = None,
158
- union_with_default_methods: bool = True) -> None:
163
+ union_with_default_methods: bool = True,
164
+ monocle_exporters_list:str = None) -> None:
159
165
  """
160
166
  Set up Monocle telemetry for the application.
161
167
 
@@ -165,7 +171,7 @@ def setup_monocle_telemetry(
165
171
  The name of the workflow to be used as the service name in telemetry.
166
172
  span_processors : List[SpanProcessor], optional
167
173
  Custom span processors to use instead of the default ones. If None,
168
- BatchSpanProcessors with Monocle exporters will be used.
174
+ BatchSpanProcessors with Monocle exporters will be used. This can't be combined with `monocle_exporters_list`.
169
175
  span_handlers : Dict[str, SpanHandler], optional
170
176
  Dictionary of span handlers to be used by the instrumentor, mapping handler names to handler objects.
171
177
  wrapper_methods : List[Union[dict, WrapperMethod]], optional
@@ -173,11 +179,16 @@ def setup_monocle_telemetry(
173
179
  union_with_default_methods : bool, default=True
174
180
  If True, combine the provided wrapper_methods with the default methods.
175
181
  If False, only use the provided wrapper_methods.
182
+ monocle_exporters_list : str, optional
183
+ Comma-separated list of exporters to use. This will override the env setting MONOCLE_EXPORTERS.
184
+ Supported exporters are: s3, blob, okahu, file, memory, console. This can't be combined with `span_processors`.
176
185
  """
177
186
  resource = Resource(attributes={
178
187
  SERVICE_NAME: workflow_name
179
188
  })
180
- exporters = get_monocle_exporter()
189
+ if span_processors and monocle_exporters_list:
190
+ raise ValueError("span_processors and monocle_exporters_list can't be used together")
191
+ exporters:List[SpanExporter] = get_monocle_exporter(monocle_exporters_list)
181
192
  span_processors = span_processors or [BatchSpanProcessor(exporter) for exporter in exporters]
182
193
  set_tracer_provider(TracerProvider(resource=resource))
183
194
  attach(set_value("workflow_name", workflow_name))
@@ -192,7 +203,7 @@ def setup_monocle_telemetry(
192
203
  get_tracer_provider().add_span_processor(processor)
193
204
  if is_proxy_provider:
194
205
  trace.set_tracer_provider(get_tracer_provider())
195
- instrumentor = MonocleInstrumentor(user_wrapper_methods=wrapper_methods or [],
206
+ instrumentor = MonocleInstrumentor(user_wrapper_methods=wrapper_methods or [], exporters=exporters,
196
207
  handlers=span_handlers, union_with_default_methods = union_with_default_methods)
197
208
  # instrumentor.app_name = workflow_name
198
209
  if not instrumentor.is_instrumented_by_opentelemetry:
@@ -228,7 +239,7 @@ def start_trace():
228
239
  updated_span_context = set_span_in_context(span=span)
229
240
  SpanHandler.set_default_monocle_attributes(span)
230
241
  SpanHandler.set_workflow_properties(span)
231
- token = SpanHandler.attach_workflow_type(context=updated_span_context)
242
+ token = attach(updated_span_context)
232
243
  return token
233
244
  except:
234
245
  logger.warning("Failed to start trace")
@@ -250,7 +261,7 @@ def stop_trace(token) -> None:
250
261
  if parent_span is not None:
251
262
  parent_span.end()
252
263
  if token is not None:
253
- SpanHandler.detach_workflow_type(token)
264
+ detach(token)
254
265
  except:
255
266
  logger.warning("Failed to stop trace")
256
267
 
@@ -1,6 +1,6 @@
1
1
  import logging
2
2
  import os
3
- from importlib.metadata import version
3
+ from contextlib import contextmanager
4
4
  from opentelemetry.context import get_value, set_value, attach, detach
5
5
  from opentelemetry.sdk.trace import Span
6
6
  from opentelemetry.trace.status import Status, StatusCode
@@ -8,9 +8,9 @@ from monocle_apptrace.instrumentation.common.constants import (
8
8
  QUERY,
9
9
  service_name_map,
10
10
  service_type_map,
11
- MONOCLE_SDK_VERSION
11
+ MONOCLE_SDK_VERSION, MONOCLE_SDK_LANGUAGE
12
12
  )
13
- from monocle_apptrace.instrumentation.common.utils import set_attribute, get_scopes, MonocleSpanException
13
+ from monocle_apptrace.instrumentation.common.utils import set_attribute, get_scopes, MonocleSpanException, get_monocle_version
14
14
  from monocle_apptrace.instrumentation.common.constants import WORKFLOW_TYPE_KEY, WORKFLOW_TYPE_GENERIC
15
15
 
16
16
  logger = logging.getLogger(__name__)
@@ -39,9 +39,9 @@ class SpanHandler:
39
39
  pass
40
40
 
41
41
  def skip_span(self, to_wrap, wrapped, instance, args, kwargs) -> bool:
42
- # If this is a workflow span type and a workflow span is already generated, then skip generating this span
43
- if to_wrap.get('span_type') == "workflow" and self.is_workflow_span_active():
44
- return True
42
+ return False
43
+
44
+ def skip_processor(self, to_wrap, wrapped, instance, args, kwargs) -> bool:
45
45
  return False
46
46
 
47
47
  def pre_task_processing(self, to_wrap, wrapped, instance, args,kwargs, span):
@@ -51,11 +51,8 @@ class SpanHandler:
51
51
  @staticmethod
52
52
  def set_default_monocle_attributes(span: Span):
53
53
  """ Set default monocle attributes for all spans """
54
- try:
55
- sdk_version = version("monocle_apptrace")
56
- span.set_attribute(MONOCLE_SDK_VERSION, sdk_version)
57
- except Exception as e:
58
- logger.warning("Exception finding monocle-apptrace version.")
54
+ span.set_attribute(MONOCLE_SDK_VERSION, get_monocle_version())
55
+ span.set_attribute(MONOCLE_SDK_LANGUAGE, "python")
59
56
  for scope_key, scope_value in get_scopes().items():
60
57
  span.set_attribute(f"scope.{scope_key}", scope_value)
61
58
 
@@ -64,8 +61,14 @@ class SpanHandler:
64
61
  """ Set attributes of workflow if this is a root span"""
65
62
  SpanHandler.set_workflow_attributes(to_wrap, span)
66
63
  SpanHandler.set_app_hosting_identifier_attribute(span)
64
+
67
65
  span.set_status(StatusCode.OK)
68
66
 
67
+ @staticmethod
68
+ def set_non_workflow_properties(span: Span, to_wrap = None):
69
+ workflow_name = SpanHandler.get_workflow_name(span=span)
70
+ if workflow_name:
71
+ span.set_attribute("workflow.name", workflow_name)
69
72
 
70
73
  def post_task_processing(self, to_wrap, wrapped, instance, args, kwargs, result, span:Span):
71
74
  if span.status.status_code == StatusCode.UNSET:
@@ -79,7 +82,8 @@ class SpanHandler:
79
82
  span_index = 0
80
83
  if SpanHandler.is_root_span(span):
81
84
  span_index = 2 # root span will have workflow and hosting entities pre-populated
82
- if 'output_processor' in to_wrap and to_wrap["output_processor"] is not None:
85
+ if not self.skip_processor(to_wrap, wrapped, instance, args, kwargs) and (
86
+ 'output_processor' in to_wrap and to_wrap["output_processor"] is not None):
83
87
  output_processor=to_wrap['output_processor']
84
88
  if 'type' in output_processor:
85
89
  span.set_attribute("span.type", output_processor['type'])
@@ -107,6 +111,8 @@ class SpanHandler:
107
111
  span_index += 1
108
112
  else:
109
113
  logger.debug("attributes not found or incorrect written in entity json")
114
+ else:
115
+ span.set_attribute("span.type", "generic")
110
116
 
111
117
  # set scopes as attributes by calling get_scopes()
112
118
  # scopes is a Mapping[str:object], iterate directly with .items()
@@ -118,7 +124,8 @@ class SpanHandler:
118
124
 
119
125
 
120
126
  def hydrate_events(self, to_wrap, wrapped, instance, args, kwargs, result, span):
121
- if 'output_processor' in to_wrap and to_wrap["output_processor"] is not None:
127
+ if not self.skip_processor(to_wrap, wrapped, instance, args, kwargs) and (
128
+ 'output_processor' in to_wrap and to_wrap["output_processor"] is not None):
122
129
  output_processor=to_wrap['output_processor']
123
130
  arguments = {"instance": instance, "args": args, "kwargs": kwargs, "result": result}
124
131
  if 'events' in output_processor:
@@ -147,6 +154,7 @@ class SpanHandler:
147
154
  span_index = 1
148
155
  workflow_name = SpanHandler.get_workflow_name(span=span)
149
156
  if workflow_name:
157
+ span.update_name("workflow")
150
158
  span.set_attribute("span.type", "workflow")
151
159
  span.set_attribute(f"entity.{span_index}.name", workflow_name)
152
160
  workflow_type = SpanHandler.get_workflow_type(to_wrap)
@@ -186,26 +194,19 @@ class SpanHandler:
186
194
  @staticmethod
187
195
  def is_root_span(curr_span: Span) -> bool:
188
196
  try:
189
- if curr_span is not None and hasattr(curr_span, "parent"):
197
+ if curr_span is not None and hasattr(curr_span, "parent") or curr_span.context.trace_state:
190
198
  return curr_span.parent is None
191
199
  except Exception as e:
192
200
  logger.warning(f"Error finding root span: {e}")
193
201
 
194
- def is_non_workflow_root_span(self, curr_span: Span, to_wrap) -> bool:
195
- return SpanHandler.is_root_span(curr_span) and to_wrap.get("span_type") != "workflow"
196
-
197
- def is_workflow_span_active(self):
198
- return get_value(WORKFLOW_TYPE_KEY) is not None
199
-
200
202
  @staticmethod
201
203
  def attach_workflow_type(to_wrap=None, context=None):
202
204
  token = None
203
205
  if to_wrap:
204
- if to_wrap.get('span_type') == "workflow":
206
+ workflow_type = SpanHandler.get_workflow_type(to_wrap)
207
+ if workflow_type != WORKFLOW_TYPE_GENERIC:
205
208
  token = attach(set_value(WORKFLOW_TYPE_KEY,
206
209
  SpanHandler.get_workflow_type(to_wrap), context))
207
- else:
208
- token = attach(set_value(WORKFLOW_TYPE_KEY, WORKFLOW_TYPE_GENERIC, context))
209
210
  return token
210
211
 
211
212
  @staticmethod
@@ -213,8 +214,18 @@ class SpanHandler:
213
214
  if token:
214
215
  return detach(token)
215
216
 
217
+ @staticmethod
218
+ @contextmanager
219
+ def workflow_type(to_wrap=None):
220
+ token = SpanHandler.attach_workflow_type(to_wrap)
221
+ try:
222
+ yield
223
+ finally:
224
+ SpanHandler.detach_workflow_type(token)
225
+
226
+
216
227
  class NonFrameworkSpanHandler(SpanHandler):
217
228
 
218
- # If the language framework is being executed, then skip generating direct openAI spans
219
- def skip_span(self, to_wrap, wrapped, instance, args, kwargs) -> bool:
229
+ # If the language framework is being executed, then skip generating direct openAI attributes and events
230
+ def skip_processor(self, to_wrap, wrapped, instance, args, kwargs) -> bool:
220
231
  return get_value(WORKFLOW_TYPE_KEY) in WORKFLOW_TYPE_MAP.values()
@@ -0,0 +1,68 @@
1
+ # Monocle tracing: concepts and principles
2
+
3
+ ## Span
4
+ Span is an observation of a code/method executed. Each span has a unique ID. It records the start time and end time of the code's execution along with additional information relevant to that operation. Before the code execution starts, a span object is created in the memory of the host process executing this code. It'll capture the current time as start of time of span. At this stage the span is considered active. It'll stay active till the code execution ends. Once the code execution is complete, it'll record the current time as end time, capture any additional relevant information (eg argument, return value, environment setttings etc.). Now the span is marked as closed and it will be queued to be saved to some configured storage.
5
+ Note that the code that generated this span could in turn call other methods that are also instrumented. Those will generate spans of their own. These will be "child" spans which will refer to the span ID of the calling code as "parent" span. An initial span which has no parent is referred as "root" span.
6
+
7
+ ## Trace
8
+ A trace is a collection of spans with a common ID called traceID. When the first active span gets created, a new unique traceID is generated and assigned to that span. All the child spans generated by execution of other instrumented code/methods will share the same traceID. Once this top span ends, this trace ends. This way all the code executed as part of the top level instrumented code will have a common traceID to group them together. For example, consider following sequence where `f1()` is the first instrumented method is executed, it calls other instrumented methods `f2(),f3(),f4() and f5()`
9
+ ```
10
+ f1()--> f2() --> f3()
11
+ --> f4() --> f5()
12
+ ```
13
+ In the above sequence, all method execution will generate a span each and they all will have a common traceID. Now if a new instrumented methods is executed after f1() finishes, it will be the first active span in the process's execution context and a will get a new traceID.
14
+
15
+ ### Trace ID propogation
16
+ Each child span inherits the parent's trace ID. When spans running in same process, it captures it from process memory/context etc. But consider the above example again, where the `f4()-->f5()` code is not part of the process that executing f1(). It's a remote call, say over REST. From the overall application's point of view, the work done if `f4()` and `f5()` is part of `f1()` and you want same traceID associated with all spans. You want the instrumentation to seamlessly pass the tracedID over such remote calls and continue that instead of generating a new one. It's the responsibility of Monocle to provide such mechanism to make thsi trace ID propogation transparent to the application logic and architecture.
17
+
18
+ ## Propogation
19
+ When the execution logic spans mulitple processes using remote calling mechanisms like REST, you want the trace ID also to propogate from process that originated it to the one that's continueing the remote execution. Monocle supports seamlessly propogating traceID over REST if both the sides for the trace execution are instrumented.
20
+
21
+ ## Types of spans in Monocle
22
+ Monocle extends these generic span types by enriching additional attributes/data for genAI specific operations.
23
+ ### GenAI spans
24
+ There are the core spans that capture details of genAI component operations like call to an LLM or vectore store. The purpose of these spans is to capture the details the applications interaction with core genAI comoponents. These spans are triggered by pre-instrumented methods that handle such operations.
25
+ - Inference span
26
+ Represents interaction with LLMs, captures details like model, prompts, response and other metadata (eg tokens)
27
+ - Retrieval span
28
+ Represents interactions with vector stores like embedding creating, vector retrieval etc. Captures the model, search query, response, vector embedding etc.
29
+
30
+ ### anchor spans
31
+ These are the spans that are created by a top level method that anchors a higher level of abstraction for underlying core genAI APIs. For example a langchain.invoke() which under the cover calls langchain.llm_invoke() or langchain.vector_retrieval(). Consider following psuedo code of a langchain rag pattern API,
32
+ ```
33
+ response = rag_chain.invoke(prompt)
34
+ --> cleaned_prompt = llm1.chat(prompt)
35
+ --> context = vector_store.retrieve(cleaned_prompt)
36
+ --> response = llm2.chat(system_prompt+context+cleaned_prompt)
37
+ --> return response
38
+ ```
39
+ If we only instrument the top level invoke call, then we'll trace the top level prompt and response interaction between application and langchain. But we'll miss the details like how a system prompt was added and send to mulitple LLMs and what context was extracted from a vector store etc. On the other hand, if we only instrument the low level calls to LLM and vector, then we'll miss the fact that those are part of same RAG. Hence we instrument all of them. This exaple would genearte an anchor spna for `invoke()` method, a retrieval span for `retrieve()` method and two inference spans for each `chat()` method. All of these will have common traceID.
40
+ The anchor spans also provides an observation window of your application interaction with an high level SDK or service. It will illustrate facts such as how much time take by the genAI service invocation compared to other local logic.
41
+
42
+ ### Workflow spans
43
+ Workflow spans are synthetic spans that are created to trace the full trace. It captures the summary of the full trace including the time window, the process running this code (set as `workflow_name` in the API to enab le Monocle instrumentation) and runtime environment details such as hosting service (Azure function, Lambda function etc).
44
+ The workflow spans is generated when a new trace starts or when a trace is propogated. They provide the base line observation window for the entire trace or a fragment of trace executed in a process.
45
+ Consider following example,
46
+ ```
47
+ setup_monocle_telemetry(workflow='bot')
48
+ rag_chain.invoke()
49
+ --> context = retrieval()
50
+ --> new_prompt = REST --> azure.func.chat(prompt) -->
51
+ setup_monocle_telemetry(workflow='moderator')
52
+ return llm(moderator_system_prompt+prompt)
53
+ --> response = llm(new_prompt)
54
+ ```
55
+ This will generate following spans:
56
+ ```
57
+ Span{name='workflow.bot', type= workflow, traceID = xx1, spanID = yy0, parentID=None} ==> Workflow for new trace start
58
+ Span{name='chain.invoke', type=anchor, traceID = xx1, spanID = yy1, parentID=yy0} ==> anchor span for chain invoke
59
+ Span{name='chain.retrieval', type=retrieval, traceID = xx1, spanID = yy2, parentID = yy1} ==> Retrieval API span
60
+ Span{name='workflow.moderator', type=workflow, traceID = xx1, spanID = zz1, parentID=yy1} ==> Workflow for propogated trace fragement
61
+ Span{name='az.func.chat', type=anchor, traceID = xx1, spanID = zz2, parentID=zz1} ==> anchor span for az function invoke
62
+ Span{name='chain.infer', type=inference, traceID = xx1, spanID = zz2, parentID=zz2} ==> inference
63
+ Span{name='chain.infer',type=inference, traceID = xx1, spanID = yy3, parentID=yy1} ==> inference
64
+ ```
65
+
66
+ ## Scopes
67
+ Scope is an way of grouping across traces. It's a tag with a value that can either be specified or auto generated (GUID) by Monocle. There can be any number of scopes active in an application code at a given point in time. All the active scopes are recorded in every span that's emmitted.
68
+
@@ -9,7 +9,8 @@ from opentelemetry.trace.propagation import _SPAN_KEY
9
9
  from opentelemetry.sdk.trace import id_generator, TracerProvider
10
10
  from opentelemetry.propagate import inject, extract
11
11
  from opentelemetry import baggage
12
- from monocle_apptrace.instrumentation.common.constants import MONOCLE_SCOPE_NAME_PREFIX, SCOPE_METHOD_FILE, SCOPE_CONFIG_PATH, llm_type_map
12
+ from monocle_apptrace.instrumentation.common.constants import MONOCLE_SCOPE_NAME_PREFIX, SCOPE_METHOD_FILE, SCOPE_CONFIG_PATH, llm_type_map, MONOCLE_SDK_VERSION, ADD_NEW_WORKFLOW
13
+ from importlib.metadata import version
13
14
 
14
15
  T = TypeVar('T')
15
16
  U = TypeVar('U')
@@ -21,6 +22,12 @@ embedding_model_context = {}
21
22
  scope_id_generator = id_generator.RandomIdGenerator()
22
23
  http_scopes:dict[str:str] = {}
23
24
 
25
+ try:
26
+ monocle_sdk_version = version("monocle_apptrace")
27
+ except Exception as e:
28
+ monocle_sdk_version = "unknown"
29
+ logger.warning("Exception finding monocle-apptrace version.")
30
+
24
31
  class MonocleSpanException(Exception):
25
32
  def __init__(self, err_message:str):
26
33
  """
@@ -96,8 +103,8 @@ def with_tracer_wrapper(func):
96
103
  def resolve_from_alias(my_map, alias):
97
104
  """Find a alias that is not none from list of aliases"""
98
105
 
99
- for i in alias and my_map[i] is not None:
100
- if i in my_map.keys():
106
+ for i in alias:
107
+ if i in my_map.keys() and my_map[i] is not None:
101
108
  return my_map[i]
102
109
  return None
103
110
 
@@ -236,6 +243,7 @@ def set_scopes_from_baggage(baggage_context:Context):
236
243
  def extract_http_headers(headers) -> object:
237
244
  global http_scopes
238
245
  trace_context:Context = extract(headers, context=get_current())
246
+ trace_context = set_value(ADD_NEW_WORKFLOW, True, trace_context)
239
247
  imported_scope:dict[str, object] = {}
240
248
  for http_header, http_scope in http_scopes.items():
241
249
  if http_header in headers:
@@ -311,6 +319,19 @@ def async_wrapper(method, scope_name=None, scope_value=None, headers=None, *args
311
319
  if token:
312
320
  remove_scope(token)
313
321
 
322
+ def get_monocle_version() -> str:
323
+ global monocle_sdk_version
324
+ return monocle_sdk_version
325
+
326
+ def add_monocle_trace_state(headers:dict[str:str]) -> None:
327
+ if headers is None:
328
+ return
329
+ monocle_trace_state = f"{MONOCLE_SDK_VERSION}={get_monocle_version()}"
330
+ if 'tracestate' in headers:
331
+ headers['tracestate'] = f"{headers['tracestate']},{monocle_trace_state}"
332
+ else:
333
+ headers['tracestate'] = monocle_trace_state
334
+
314
335
  class Option(Generic[T]):
315
336
  def __init__(self, value: Optional[T]):
316
337
  self.value = value
@@ -343,14 +364,8 @@ def try_option(func: Callable[..., T], *args, **kwargs) -> Option[T]:
343
364
 
344
365
  def get_llm_type(instance):
345
366
  try:
367
+ t_name = type(instance).__name__.lower()
346
368
  llm_type = llm_type_map.get(type(instance).__name__.lower())
347
369
  return llm_type
348
370
  except:
349
371
  pass
350
-
351
- def resolve_from_alias(my_map, alias):
352
- """Find a alias that is not none from list of aliases"""
353
- for i in alias:
354
- if i in my_map.keys():
355
- return my_map[i]
356
- return None