monocle-apptrace 0.0.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 (33) hide show
  1. monocle_apptrace-0.0.1/.gitignore +15 -0
  2. monocle_apptrace-0.0.1/CODEOWNERS.md +10 -0
  3. monocle_apptrace-0.0.1/CODE_OF_CONDUCT.md +3 -0
  4. monocle_apptrace-0.0.1/CONTRIBUTING.md +28 -0
  5. monocle_apptrace-0.0.1/COPYRIGHT.template +2 -0
  6. monocle_apptrace-0.0.1/LICENSE +51 -0
  7. monocle_apptrace-0.0.1/MAINTAINER.md +10 -0
  8. monocle_apptrace-0.0.1/Monocle_User_Guide.md +154 -0
  9. monocle_apptrace-0.0.1/Monocle_committer_guide.md +26 -0
  10. monocle_apptrace-0.0.1/Monocle_contributor_guide.md +1 -0
  11. monocle_apptrace-0.0.1/NOTICE +4 -0
  12. monocle_apptrace-0.0.1/PKG-INFO +76 -0
  13. monocle_apptrace-0.0.1/README.md +42 -0
  14. monocle_apptrace-0.0.1/SECURITY.md +9 -0
  15. monocle_apptrace-0.0.1/pyproject.toml +79 -0
  16. monocle_apptrace-0.0.1/src/monocle_apptrace/README.md +77 -0
  17. monocle_apptrace-0.0.1/src/monocle_apptrace/__init__.py +2 -0
  18. monocle_apptrace-0.0.1/src/monocle_apptrace/haystack/__init__.py +28 -0
  19. monocle_apptrace-0.0.1/src/monocle_apptrace/haystack/wrap_node.py +27 -0
  20. monocle_apptrace-0.0.1/src/monocle_apptrace/haystack/wrap_openai.py +52 -0
  21. monocle_apptrace-0.0.1/src/monocle_apptrace/haystack/wrap_pipeline.py +49 -0
  22. monocle_apptrace-0.0.1/src/monocle_apptrace/instrumentor.py +127 -0
  23. monocle_apptrace-0.0.1/src/monocle_apptrace/langchain/__init__.py +95 -0
  24. monocle_apptrace-0.0.1/src/monocle_apptrace/llamaindex/__init__.py +71 -0
  25. monocle_apptrace-0.0.1/src/monocle_apptrace/utils.py +53 -0
  26. monocle_apptrace-0.0.1/src/monocle_apptrace/wrap_common.py +214 -0
  27. monocle_apptrace-0.0.1/src/monocle_apptrace/wrapper.py +24 -0
  28. monocle_apptrace-0.0.1/storage/default__vector_store.json +1 -0
  29. monocle_apptrace-0.0.1/storage/docstore.json +1 -0
  30. monocle_apptrace-0.0.1/storage/graph_store.json +1 -0
  31. monocle_apptrace-0.0.1/storage/image__vector_store.json +1 -0
  32. monocle_apptrace-0.0.1/storage/index_store.json +1 -0
  33. monocle_apptrace-0.0.1/tox.ini +32 -0
@@ -0,0 +1,15 @@
1
+ # Python
2
+ *~
3
+ *.log
4
+ *.pyc
5
+ *.pyo
6
+ *.pyt
7
+ *.pytc
8
+ *.egg-info
9
+ .*.swp
10
+ storage
11
+ traces.txt
12
+ dist
13
+ .tox
14
+ .DS_Store
15
+ Pipfile**
@@ -0,0 +1,10 @@
1
+ #MAINTAINERS
2
+ Following is the current list of maintainers on this project
3
+
4
+ The maintainers are listed in alphabetical order.
5
+
6
+ - [@prasad-okahu] (https://github.com/prasad-okahu) (Prasad Mujumdar)
7
+ - [@oi-raanne] (https://github.com/oi-raanne) (Ravi Anne)
8
+ - [@akshay-okahu](https://github.com/akshay-okahu) (Akshay Yadav)
9
+ - [@anshul7665] (https://github.com/anshul7665) (Anshul Sharma)
10
+ - [@kshitiz-okahu] (https://github.com/kshitiz-okahu) (Kshitiz Vijayvargiya)
@@ -0,0 +1,3 @@
1
+ # Monocle Code of Conduct
2
+
3
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers agree to abide by the Code of Conduct available at https://lfprojects.org/policies/code-of-conduct/
@@ -0,0 +1,28 @@
1
+ # Contributing to Monocle
2
+ Contributions to Monocle are welcome from everyone. The following are a set of guidelines for contributing to Monocle. Following these guidelines makes contributing to this project easy and transparent. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request. Please refer to our code of conduct when making contributions.
3
+
4
+ ## How can you contribute?
5
+ ### Contributing code
6
+ If you encounter a bug, you can
7
+ - (Recommended) File an issue about the bug.
8
+ - Provide clear and concrete ways/scripts to reproduce the bug.
9
+ - Provide possible solutions for the bug.
10
+ - Pull a request to fix the bug.
11
+
12
+ If you're interested in existing issues, you can
13
+ - (Recommended) Provide answers for issue labeled question.
14
+ - Provide help for issues labeled bug, improvement, and enhancement by
15
+ -- (Recommended) Ask questions, reproduce the issue, or provide solutions.
16
+ -- Pull a request to fix the issue.
17
+
18
+ If you require a new feature or major enhancement, you can
19
+ - (Recommended) File an issue about the feature/enhancement with reasons.
20
+ - Pull a request to implement the feature.
21
+
22
+ If you are a reviewer/approver of Monocle, you can
23
+ - Participate in PR review process.
24
+ - Instruct newcomers in the community to complete the PR process.
25
+
26
+ If you want to become a contributor of Monocle, submit your pull requests. All contributions to this project must be accompanied by acknowledgment of, and agreement to, the [Developer Certificate of Origin](https://github.com/apps/dco). All submissions will be reviewed as quickly as possible.
27
+
28
+
@@ -0,0 +1,2 @@
1
+ Copyright Contributors to the Monocle project.
2
+ SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,51 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
37
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
38
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
39
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
40
+
41
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
42
+
43
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
44
+
45
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
46
+
47
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
48
+
49
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
50
+
51
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,10 @@
1
+ #MAINTAINERS
2
+ Following is the current list of maintainers on this project
3
+
4
+ The maintainers are listed in alphabetical order.
5
+
6
+ - [@prasad-okahu] (https://github.com/prasad-okahu) (Prasad Mujumdar)
7
+ - [@oi-raanne] (https://github.com/oi-raanne) (Ravi Anne)
8
+ - [@akshay-okahu](https://github.com/akshay-okahu) (Akshay Yadav)
9
+ - [@anshul7665] (https://github.com/anshul7665) (Anshul Sharma)
10
+ - [@kshitiz-okahu] (https://github.com/kshitiz-okahu) (Kshitiz Vijayvargiya)
@@ -0,0 +1,154 @@
1
+ #Monocle User Guide
2
+
3
+ ## Monocle Concepts
4
+ ### Traces
5
+ Traces are the full view of a single end-to-end application KPI, for example Chatbot application to provide a response to end user’s question. Traces consist of various metadata about the application run including status, start time, duration, input/outputs etc. They also include a list of individual steps aka “spans with details about that step.
6
+ It’s typically the workflow code components of an application that generate the traces for application runs.
7
+ ### Spans
8
+ Spans are the individual steps executed by the application to perform a GenAI related task”, for example app retrieving vectors from DB, app querying LLM for inference etc. The span includes the type of operation, start time, duration and metadata relevant to that step e.g., Model name, parameters and model endpoint/server for an inference request.
9
+ It’s typically the workflow code components of an application that generate the traces for application runs.
10
+
11
+ ## Setup Monocle
12
+ - You can download Monocle library releases from Pypi
13
+ ```
14
+ > pip install monocle_apptrace
15
+ ```
16
+ - You can locally build and install Monocle library from source
17
+ ```
18
+ > pip install .
19
+ ```
20
+ - Install the optional test dependencies listed against dev in pyproject.toml in editable mode
21
+ ```
22
+ > pip install -e ".[dev]"
23
+ ```
24
+
25
+ ## Using Monocle with your application to generate traces
26
+ ### Enable Monocle tracing
27
+ You need to import monocle package and invoke the API ``setup_monocle_telemetry(workflow=<workflow-name>)`` to enable the tracing. The 'workflow-name' is what you define to identify the give application workflow, for example "customer-chatbot". Monocle trace will include this name in every trace. The trace output will include a list of spans in the traces. You can print the output on the console or send it to an HTTP endpoint.
28
+
29
+ ### Using Monocle's out of box support of genAI technology components
30
+ Monocle community has done the hard work of figuring out what to trace and how to extract relevant details from multiple genAI technology components. For example, if you have a python app coded using LlamaIndex and using models hostsed in OpenAI, Monocle can seamlessly trace your app. All you need to do enable Monocle tracing.
31
+ #### Example - Enable Monocle tracing in your application
32
+ ```python
33
+ from monocle_apptrace.instrumentor import setup_monocle_telemetry
34
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
35
+ from langchain.chains import LLMChain
36
+ from langchain_openai import OpenAI
37
+ from langchain.prompts import PromptTemplate
38
+
39
+ # Call the setup Monocle telemetry method
40
+ setup_monocle_telemetry(workflow_name = "simple_math_app",
41
+ span_processors=[BatchSpanProcessor(ConsoleSpanExporter())])
42
+
43
+ llm = OpenAI()
44
+ prompt = PromptTemplate.from_template("1 + {number} = ")
45
+
46
+ chain = LLMChain(llm=llm, prompt=prompt)
47
+ chain.invoke({"number":2})
48
+
49
+ # Request callbacks: Finally, let's use the request `callbacks` to achieve the same result
50
+ chain = LLMChain(llm=llm, prompt=prompt)
51
+ chain.invoke({"number":2}, {"callbacks":[handler]})
52
+
53
+ ```
54
+ ### Leveraging Monocle's extensibility to handle customization
55
+ When the out of box features from app frameworks are not sufficent, the app developers have to add custom code. For example, if you are extending a LLM class in LlamaIndex to use a model hosted in NVIDIA Triton. This new class is not know to Monocle. You can specify this new class method part of Monocle enabling API and it will be able to trace it.
56
+
57
+ #### Default configuration of instrumented methods in Monocle
58
+ The following files comprise of default configuration of instrumented methods and span names corresponding to them, for each framework respectively.
59
+ - [src/monocle_apptrace/langchain/__init__.py](src/monocle_apptrace/langchain/__init__.py),
60
+ - [src/monocle_apptrace/llamaindex/__init__.py](src/monocle_apptrace/llamaindex/__init__.py),
61
+ - [src/monocle_apptrace/haystack/__init__.py](src/monocle_apptrace/haystack/__init__.py)
62
+
63
+ Following configuration instruments ```invoke(..)``` of ```RunnableSequence```, aka chain or worflow in Langchain parlance, to emit the span.
64
+ ```
65
+ {
66
+ "package": "langchain.schema.runnable",
67
+ "object": "RunnableSequence",
68
+ "method": "invoke",
69
+ "span_name": "langchain.workflow",
70
+ "wrapper": task_wrapper
71
+ }
72
+ ```
73
+ #### Example - Monitoring custom methods with Monocle
74
+ ```python
75
+ from monocle_apptrace.wrapper import WrapperMethod,task_wrapper,atask_wrapper
76
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
77
+
78
+ # extend the default wrapped methods list as follows
79
+ app_name = "simple_math_app"
80
+ setup_monocle_telemetry(
81
+ workflow_name=app_name,
82
+ span_processors=[BatchSpanProcessor(ConsoleSpanExporter())],
83
+ wrapper_methods=[
84
+ WrapperMethod(
85
+ package="langchain.schema.runnable",
86
+ object="RunnableParallel",
87
+ method="invoke",
88
+ span_name="langchain.workflow",
89
+ wrapper=task_wrapper),
90
+ WrapperMethod(
91
+ package="langchain.schema.runnable",
92
+ object="RunnableParallel",
93
+ method="ainvoke",
94
+ span_name="langchain.workflow",
95
+ wrapper=atask_wrapper)
96
+ ])
97
+
98
+ ```
99
+
100
+ ### Going beyond supported genAI components
101
+ - If you are using an application framework, model hosting service/infra etc. that's not currently supported by Monocle, please submit a github issue to add that support.
102
+ - Monocle community is working on adding an SDK to enable applications to generate their own traces.
103
+
104
+ ## Understanding the trace output
105
+
106
+ ### Trace span json
107
+
108
+ Monocle generates spans which adhere to [Tracing API | OpenTelemetry](https://opentelemetry.io/docs/specs/otel/trace/api/#span) format. The trace output is an array of spans. Each trace has a unique id. Every span has in the trace has this parent ```trace_id```. Please note that ```trace_id``` groups related spans and is auto generated with-in Monocle.
109
+
110
+ | Span JSON | Description |
111
+ | ------------- | ------------- |
112
+ | {||
113
+ | "```name```": "langchain.workflow",|span name and is configurable in [__init.py__](src/monocle_apptrace/langchain/__init__.py) or in ```setup_okahu_telemetry(...)```|
114
+ | "```context```": {|this gets autogenerated|
115
+ | &ensp; "```trace_id```": "0xe5269f0e534efa098b240f974220d6b7",||
116
+ | &ensp; "```span_id```": "0x30b13075eca52f44",||
117
+ | &ensp; "```trace_state```": "[]"||
118
+ | &ensp; },||
119
+ |"```kind```": "SpanKind.INTERNAL",| an enum that describes what this span is about. Default value is SpanKind.INTERNAL, as current enums do not cover ML apps |
120
+ |"```parent_id```": null,|if null, this is root span|
121
+ |"```start_time```": "2024-07-16T17:05:15.544861Z",||
122
+ |"```end_time```": "2024-07-16T17:05:43.502007Z",||
123
+ |"```status```": {||
124
+ |&ensp; "```status_code```": "UNSET"| status of span to OK or ERROR. Default is UNSET|
125
+ |&ensp; },||
126
+ |"```attributes```": {||
127
+ |&ensp; "workflow_name": "ml_rag_app",|defines the name of the service being set in ```setup_okahu_telemetry(...)``` during initialization of instrumentation|
128
+ |&ensp; "workflow_type": "workflow.langchain"|type of framework that generated this span|
129
+ |&ensp; },||
130
+ |"```events```": [|captures the log records|
131
+ |&ensp; {||
132
+ |&ensp;&emsp; "```name```": "input",|name of the event. If the span is about LLM, then this will be 'input'. For vector store retrieval, this would be 'context_input'|
133
+ |&ensp;&emsp; "```timestamp```": "2024-07-16T17:05:15.544874Z",||
134
+ |&ensp;&emsp; "```attributes```": {|captures the 'input' attributes. Based on the workflow of the ML framework being used, the attributes change|
135
+ |&emsp;&emsp;&emsp; "question": "What is Task Decomposition?",|represents LLM query|
136
+ |&emsp;&emsp;&emsp; "q_a_pairs": "..." |represents questions and answers for a few shot LLM prompting |
137
+ |&emsp;&emsp; }||
138
+ |&emsp; },||
139
+ |&emsp; {||
140
+ |&emsp;&emsp; "```name```": "output",|represents 'ouput' event of LLM|
141
+ |&emsp;&emsp; "```timestamp```": "2024-07-16T17:05:43.501996Z",||
142
+ |&emsp;&emsp;"```attributes```": {||
143
+ |&emsp;&emsp;&emsp; "response": "Task Decomposition is ..."|response to LLM query. |
144
+ |&emsp;&emsp;&emsp;}||
145
+ |&emsp;&emsp;}||
146
+ |&emsp; ],||
147
+ |&emsp; "```links```": [],|unused. Ideally this links other causally-related spans,<br/> but as spans are grouped by ```trace_id```, and ```parent_id``` links to parent span, this is unused|
148
+ |&emsp; "```resource```": {|represents the service name or server or machine or container which generated the span|
149
+ |&emsp;&emsp;&emsp; "```attributes```": {||
150
+ |&emsp;&emsp;&emsp;&emsp; "service.name": "ml_rag_app"|only service.name is being populated and defaults to the value of 'workflow_name' |
151
+ |&emsp;&emsp;&emsp; },||
152
+ |&emsp;&emsp;"```schema_url```": ""|unused|
153
+ |&emsp;&emsp; }||
154
+ |} | |
@@ -0,0 +1,26 @@
1
+ # Monocle Committer Guide
2
+ This document provide details for Monocle committers tasks
3
+
4
+ ## Build and publishing python packages
5
+ ### Building the package
6
+
7
+ ```
8
+ > python3 -m build
9
+ ```
10
+ ### Publishing the package
11
+
12
+ ```
13
+ > python3 -m pip install --upgrade twine
14
+ > python3 -m twine upload --repository testpypi dist/*
15
+ ```
16
+ ### Installing the package
17
+
18
+ The steps to set the credential can be found here:
19
+ https://packaging.python.org/en/latest/specifications/pypirc/
20
+
21
+ After setup of credentials, follow the commands below to publish the package to testpypi:
22
+
23
+ ```
24
+ > python3 -m pip install pipenv
25
+ > pipenv install monocle-observability
26
+ ```
@@ -0,0 +1 @@
1
+ Coming soon ...
@@ -0,0 +1,4 @@
1
+ Monocle
2
+ Copyright 2018-2021 Monocle Project Authors
3
+
4
+ Licensed under Apache License 2.0. See LICENSE for terms.
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.3
2
+ Name: monocle_apptrace
3
+ Version: 0.0.1
4
+ Summary: package with monocle genAI tracing
5
+ Project-URL: Homepage, https://github.com/monocle2ai/monocle
6
+ Project-URL: Issues, https://github.com/monocle2ai/monocle/issues
7
+ License-File: LICENSE
8
+ License-File: NOTICE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.8
13
+ Requires-Dist: opentelemetry-api>=1.21.0
14
+ Requires-Dist: opentelemetry-instrumentation
15
+ Requires-Dist: opentelemetry-sdk>=1.21.0
16
+ Requires-Dist: requests
17
+ Requires-Dist: wrapt>=1.14.0
18
+ Provides-Extra: dev
19
+ Requires-Dist: datasets==2.20.0; extra == 'dev'
20
+ Requires-Dist: faiss-cpu==1.8.0; extra == 'dev'
21
+ Requires-Dist: instructorembedding==1.0.1; extra == 'dev'
22
+ Requires-Dist: langchain-chroma==0.1.1; extra == 'dev'
23
+ Requires-Dist: langchain-community==0.2.5; extra == 'dev'
24
+ Requires-Dist: langchain-openai==0.1.8; extra == 'dev'
25
+ Requires-Dist: langchain==0.2.5; extra == 'dev'
26
+ Requires-Dist: llama-index-embeddings-huggingface==0.2.0; extra == 'dev'
27
+ Requires-Dist: llama-index-vector-stores-chroma==0.1.9; extra == 'dev'
28
+ Requires-Dist: llama-index==0.10.30; extra == 'dev'
29
+ Requires-Dist: numpy==1.26.4; extra == 'dev'
30
+ Requires-Dist: pytest==8.0.0; extra == 'dev'
31
+ Requires-Dist: sentence-transformers==2.6.1; extra == 'dev'
32
+ Requires-Dist: types-requests==2.31.0.20240106; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # monocle genAI observability
36
+ ### Background
37
+ Generative AI (GenAI) is the type of AI used to create content such as conversations, images, or video based on prior learning from existing content. GenAI relies on foundational models, which are exceptionally large ML models trained on vast amounts of generalized and unlabeled data to perform variety of general tasks such as understanding language and generating new text, audio or images from user provided prompts in a human language. Foundational models (FM) work by using learned patterns and relationships from the training data to predict the next item in a sequence given a prompt. It is cheaper and faster for data scientists to use foundational models as starting points rather than building models from scratch to build ML apps.
38
+ Large Language Models (LLMs) are a class of foundational models trained on text data used to perform a variety of tasks such as understanding language, reasoning over text, and generating new text based on user prompts in a human language. Examples of LLMs include ChatGPT, Llama, and Claude.
39
+ LLM-based AI apps leverage understanding language, reasoning & text generation to augment or automate complex tasks that typically require human intervention such as summarizing legal documents, triaging customer support tickets, or more.
40
+ Typically, AI developers build LLM-based AI apps that automate complex workflows by combining multiple LLMs and components such as prompts, vectors, or agents that each solve a discrete task that are connected by chains or pipelines in different ways using LLM (Large Language Model) orchestration frameworks.
41
+ When deployed to production, different parts of multi-component distributed LLM-based AI apps run on a combination of different kinds of AI infrastructure such as LLM-as-a-Service, GPU (graphics processing units) clouds, managed services from cloud, or custom-engineered AI stack. Typically, these systems are managed in production by IT DevOps engineers.
42
+ AI developers code, monitor, debug and optimize the resources in an LLM-based AI application. IT DevOps engineers monitor, troubleshoot, and optimize the services in the AI infra that the LLM-based AI application runs on.
43
+
44
+ ## Introducing “Monocle – An eye for A.I.”
45
+ The goal of project Monocle is to help GenAI developer to trace their applications. A typical GenAI application comprises of several technology components like application code/workflow, models, inferences services, vector databases etc. Understanding the dependencies and tracking application quickly becomes a difficult task. Monocle can be integrated into application code with very little to no code changes. Monocle supports tracing all GenAI technology components, application frameworks, LLM hosting services. We do all the hard work of finding what needs to be instrumented and how to instrument it. This enables the enlightened applications to generate detailed traces without any additional efforts from the developers.
46
+ The traces are compatible with OpenTelemetry format. They are further enriched to contain lot more attribute relevant to GenAI applications like prompts. The project will have out of box support to store the traces locally and a extensibility for a third party store which can be implemented by end user or a supplied by third party vendors.
47
+
48
+ ## Monocle integration
49
+ ### genAI Appliation frameworks
50
+ - Langchain
51
+ - LlamaIndex
52
+ - Haystack
53
+ ### LLMs
54
+ - OpenAI
55
+ - Azure OpenAI
56
+ - NVIDIA Triton
57
+
58
+ ## Getting started
59
+ ### Try Monocle with your python genAI application
60
+ - Get latest Monocle python brary
61
+ ```
62
+ pip install monocle_apptrace
63
+ ```
64
+ - Enable Monocle tracing in your app by adding following
65
+ ```
66
+ setup_okahu_telemetry(workflow_name="your-app-name")
67
+ ```
68
+ Please refer to [Monocle user guide](Monocle_User_Guide.md) for more details
69
+
70
+ ## Get involved
71
+ ### Provide feedback
72
+ - Submit issues and enhancements requests via Github issues
73
+
74
+ ### Contribute
75
+ - Monocle is community based open source project. We welcome your contributions. Please refer to the CONTRIBUTING and CODE_OF_CONDUCT for guidelines. The [contributor's guide](CONTRIBUTING.md) provides technical details of the project.
76
+
@@ -0,0 +1,42 @@
1
+ # monocle genAI observability
2
+ ### Background
3
+ Generative AI (GenAI) is the type of AI used to create content such as conversations, images, or video based on prior learning from existing content. GenAI relies on foundational models, which are exceptionally large ML models trained on vast amounts of generalized and unlabeled data to perform variety of general tasks such as understanding language and generating new text, audio or images from user provided prompts in a human language. Foundational models (FM) work by using learned patterns and relationships from the training data to predict the next item in a sequence given a prompt. It is cheaper and faster for data scientists to use foundational models as starting points rather than building models from scratch to build ML apps.
4
+ Large Language Models (LLMs) are a class of foundational models trained on text data used to perform a variety of tasks such as understanding language, reasoning over text, and generating new text based on user prompts in a human language. Examples of LLMs include ChatGPT, Llama, and Claude.
5
+ LLM-based AI apps leverage understanding language, reasoning & text generation to augment or automate complex tasks that typically require human intervention such as summarizing legal documents, triaging customer support tickets, or more.
6
+ Typically, AI developers build LLM-based AI apps that automate complex workflows by combining multiple LLMs and components such as prompts, vectors, or agents that each solve a discrete task that are connected by chains or pipelines in different ways using LLM (Large Language Model) orchestration frameworks.
7
+ When deployed to production, different parts of multi-component distributed LLM-based AI apps run on a combination of different kinds of AI infrastructure such as LLM-as-a-Service, GPU (graphics processing units) clouds, managed services from cloud, or custom-engineered AI stack. Typically, these systems are managed in production by IT DevOps engineers.
8
+ AI developers code, monitor, debug and optimize the resources in an LLM-based AI application. IT DevOps engineers monitor, troubleshoot, and optimize the services in the AI infra that the LLM-based AI application runs on.
9
+
10
+ ## Introducing “Monocle – An eye for A.I.”
11
+ The goal of project Monocle is to help GenAI developer to trace their applications. A typical GenAI application comprises of several technology components like application code/workflow, models, inferences services, vector databases etc. Understanding the dependencies and tracking application quickly becomes a difficult task. Monocle can be integrated into application code with very little to no code changes. Monocle supports tracing all GenAI technology components, application frameworks, LLM hosting services. We do all the hard work of finding what needs to be instrumented and how to instrument it. This enables the enlightened applications to generate detailed traces without any additional efforts from the developers.
12
+ The traces are compatible with OpenTelemetry format. They are further enriched to contain lot more attribute relevant to GenAI applications like prompts. The project will have out of box support to store the traces locally and a extensibility for a third party store which can be implemented by end user or a supplied by third party vendors.
13
+
14
+ ## Monocle integration
15
+ ### genAI Appliation frameworks
16
+ - Langchain
17
+ - LlamaIndex
18
+ - Haystack
19
+ ### LLMs
20
+ - OpenAI
21
+ - Azure OpenAI
22
+ - NVIDIA Triton
23
+
24
+ ## Getting started
25
+ ### Try Monocle with your python genAI application
26
+ - Get latest Monocle python brary
27
+ ```
28
+ pip install monocle_apptrace
29
+ ```
30
+ - Enable Monocle tracing in your app by adding following
31
+ ```
32
+ setup_okahu_telemetry(workflow_name="your-app-name")
33
+ ```
34
+ Please refer to [Monocle user guide](Monocle_User_Guide.md) for more details
35
+
36
+ ## Get involved
37
+ ### Provide feedback
38
+ - Submit issues and enhancements requests via Github issues
39
+
40
+ ### Contribute
41
+ - Monocle is community based open source project. We welcome your contributions. Please refer to the CONTRIBUTING and CODE_OF_CONDUCT for guidelines. The [contributor's guide](CONTRIBUTING.md) provides technical details of the project.
42
+
@@ -0,0 +1,9 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Please upgrade to latest stable version of Monocle which will have know security issues addressed.
6
+
7
+ ## Reporting a Vulnerability
8
+
9
+ Please report security vulnerabilities privately to the Monocle [maintainer team] (https://github.com/monocle2ai/monocle/blob/main/MAINTAINER.md). Please do not post security vulnerabilities to the public issue tracker.
@@ -0,0 +1,79 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "monocle_apptrace"
7
+ version = "0.0.1"
8
+ authors = []
9
+ description = "package with monocle genAI tracing"
10
+ readme = "README.md"
11
+ requires-python = ">=3.8"
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: OS Independent",
16
+ ]
17
+ dependencies = [
18
+ 'requests',
19
+ 'wrapt>=1.14.0',
20
+ 'opentelemetry-api>=1.21.0',
21
+ 'opentelemetry-sdk>=1.21.0',
22
+ 'opentelemetry-instrumentation',
23
+ ]
24
+
25
+ [tool.pytest.ini_options]
26
+ pythonpath = [
27
+ "src"
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ dev = [
32
+ 'langchain-openai==0.1.8',
33
+ 'langchain-chroma==0.1.1',
34
+ 'langchain-community==0.2.5',
35
+ 'langchain==0.2.5',
36
+ 'datasets==2.20.0',
37
+ 'numpy==1.26.4',
38
+ 'types-requests==2.31.0.20240106',
39
+ 'InstructorEmbedding==1.0.1',
40
+ 'sentence-transformers==2.6.1',
41
+ 'faiss-cpu==1.8.0',
42
+ 'pytest==8.0.0',
43
+ 'llama-index==0.10.30',
44
+ 'llama-index-embeddings-huggingface==0.2.0',
45
+ 'llama-index-vector-stores-chroma==0.1.9'
46
+ ]
47
+
48
+ [project.urls]
49
+ Homepage = "https://github.com/monocle2ai/monocle"
50
+ Issues = "https://github.com/monocle2ai/monocle/issues"
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["src/monocle_apptrace"]
54
+
55
+ [tool.hatch.build.targets.sdist]
56
+ ignore-vcs = true
57
+
58
+ [tool.hatch.build]
59
+ exclude = [
60
+ "/.*",
61
+ "*.txt",
62
+ "Pipfile",
63
+ "/data",
64
+ "/docs",
65
+ "/tests",
66
+ "*.yml",
67
+ ]
68
+
69
+ [tool.pylint]
70
+ max-line-length = 120
71
+ disable = [
72
+ "C0103", # (invalid-name)
73
+ "C0114", # (missing-module-docstring)
74
+ "C0115", # (missing-class-docstring)
75
+ "C0116", # (missing-function-docstring)
76
+ "R0903", # (too-few-public-methods)
77
+ "R0913", # (too-many-arguments)
78
+ "W0105", # (pointless-string-statement)
79
+ ]
@@ -0,0 +1,77 @@
1
+ #Monocle User Guide
2
+
3
+ ## Monocle Concepts
4
+ ### Traces
5
+ Traces are the full view of a single end-to-end application KPI eg Chatbot application to provide a response to end user’s question. Traces consists of various metadata about the application run including status, start time, duration, input/outputs etc. It also includes a list of individual steps aka “spans with details about that step.
6
+ It’s typically the workflow code components of an application that generate the traces for application runs.
7
+ ### Spans
8
+ Spans are the individual steps executed by the application to perform a GenAI related task” eg app retrieving vectors from DB, app querying LLM for inference etc. The span includes the type of operation, start time, duration and metadata relevant to that step eg Model name, parameters and model endpoint/server for an inference request.
9
+ It’s typically the workflow code components of an application that generate the traces for application runs.
10
+
11
+ ## Setup Monocle
12
+ - You can download Monocle library releases from Pypi
13
+ ```
14
+ > python3 -m pip install pipenv
15
+ > pip install monocle-observability
16
+ ```
17
+ - You can locally build and install Monocle library from source
18
+ ```
19
+ > pip install .
20
+ > pip install -e ".[dev]"
21
+
22
+ > python3 -m pip install pipenv
23
+ > pipenv install build
24
+ ```
25
+
26
+ ## Examples
27
+ ### Enable Monocle tracing in your application
28
+ ```python
29
+ from monocle_apptrace.instrumentor import setup_monocle_telemetry
30
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
31
+ from langchain.chains import LLMChain
32
+ from langchain_openai import OpenAI
33
+ from langchain.prompts import PromptTemplate
34
+
35
+ # Call the setup Monocle telemetry method
36
+ setup_monocle_telemetry(workflow_name = "simple_math_app",
37
+ span_processors=[BatchSpanProcessor(ConsoleSpanExporter())])
38
+
39
+ llm = OpenAI()
40
+ prompt = PromptTemplate.from_template("1 + {number} = ")
41
+
42
+ chain = LLMChain(llm=llm, prompt=prompt)
43
+ chain.invoke({"number":2})
44
+
45
+ # Request callbacks: Finally, let's use the request `callbacks` to achieve the same result
46
+ chain = LLMChain(llm=llm, prompt=prompt)
47
+ chain.invoke({"number":2}, {"callbacks":[handler]})
48
+
49
+ ```
50
+
51
+ ### Monitoring custom methods with Monocle
52
+
53
+ ```python
54
+ from monocle_apptrace.wrapper import WrapperMethod,task_wrapper,atask_wrapper
55
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
56
+
57
+ # extend the default wrapped methods list as follows
58
+ app_name = "simple_math_app"
59
+ setup_monocle_telemetry(
60
+ workflow_name=app_name,
61
+ span_processors=[BatchSpanProcessor(ConsoleSpanExporter())],
62
+ wrapper_methods=[
63
+ WrapperMethod(
64
+ package="langchain.schema.runnable",
65
+ object="RunnableParallel",
66
+ method="invoke",
67
+ span_name="langchain.workflow",
68
+ wrapper=task_wrapper),
69
+ WrapperMethod(
70
+ package="langchain.schema.runnable",
71
+ object="RunnableParallel",
72
+ method="ainvoke",
73
+ span_name="langchain.workflow",
74
+ wrapper=atask_wrapper)
75
+ ])
76
+
77
+ ```