monocle-apptrace 0.5.1__py3-none-any.whl → 0.5.1b1__py3-none-any.whl

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.

@@ -0,0 +1,94 @@
1
+ import logging
2
+ import click
3
+ from mcp.server.fastmcp import FastMCP
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+ app = FastMCP(
8
+ "monocle-mcp",
9
+ )
10
+ code_snippets = {
11
+ "python": "from monocle_apptrace import setup_monocle_telemetry"
12
+ "setup_monocle_telemetry(workflow_name='my_workflow')\n",
13
+ "typescript": "import { trace } from 'monocle';\n\ntrace();\n",
14
+ }
15
+ setup_instructions = {
16
+ "python": "pip install monocle_apptrace package and add monocle_apptrace at the end of the requirement.txt for future. This code snippet provided below should be just below other imports in your application code.",
17
+ "typescript": "Install monocle package and add the trace function call at the top of your application. This code snippet provided below should be just below other imports in your application code.",
18
+ }
19
+
20
+ description = {
21
+ "python": "This will automatically trace your Python application, capturing telemetry data for your genAI operations.",
22
+ "typescript": "This will automatically trace your TypeScript application, capturing telemetry data for your genAI operations.",
23
+ }
24
+
25
+
26
+ # Use the existing dictionaries to get language-specific information
27
+ # code_snippet = code_snippets.get(app_language, code_snippets['python'])
28
+ # instructions = setup_instructions.get(app_language, setup_instructions['python'])
29
+ # desc = description.get(app_language, description['python'])
30
+ enable_monocle_prompt = """Do following changes to the project:
31
+ 1. run command 'pip install monocle_apptrace'
32
+ 2. Add following line to requirements.txt in current directory 'monocle_apptrace' if it's not there already
33
+ 3. Add following lines just below other imports in the file if it's not there already:
34
+ from monocle_apptrace import setup_monocle_telemetry
35
+ setup_monocle_telemetry(workflow_name=<module-name>, monocle_exporters_list='file'))
36
+ """
37
+
38
+ monocle_trace_prompt: str = """
39
+ You are a helpful assistant to analyze given Monocle trace data. Review the trace data and provide a summary of whether the execution was successful or if there were any errors. Your job is to analyze the trace data and provide a summary. Be very concise in reporting. Check for errors or problem situations. First provide a headline that indicates status of the trace and if there are problems. If there are problems, then provide a brief summary of the problems. If there are problems, then provide a brief summary of the root causes.
40
+ Use the trace details provided below to understand the data.
41
+
42
+ Monocle trace has recorded the traced the execution of a genAI application. Each step of the genAI operation is captured as span. The trace file is a JSON structure that is an array of span JSON elements. There's a root span that represents the overall execution context.
43
+ The important span JSON elements are as follows:
44
+ - context.trace_id is the unique id common for alls spans.
45
+ - context.span_id is the unique id for each span.
46
+ - parent_id indicates the parent span of that span. The span that has no parent is the root span.
47
+ - status.status_code indicate the status of span. It can be OK or ERROR or UNSET. If the span status is ERROR, then it generally propogated to it's parent and all the way to the root span. This means the entire trace is in error. However, sometimes the parent span will handle the error (eg. if parent name indicagtes 'retry') and the trace will be successful, even though an individual span has error.
48
+ - attributes captures various attributes involved in that span's operation
49
+ - attribute."span.type" indicates the type of operation
50
+ - When the span.type is "workflow", that span captures the summary of the entire application
51
+ - entity.[NUMBER] are the different entties involved in the operation, for example large language model, agent, tool etc
52
+ - entity.type indicates the type of that entity
53
+ - events is an array that captures the details of the operation such as input, output and metadata
54
+ - events array element with name=data.input captures the input provided to the operation
55
+ - events array element with name=data.output captures the output generated by the operation
56
+ - events array element with name=metaata captures the metadata of the operation
57
+ - total_tokens is the count of tokens
58
+ - completion_tokens is the count of ouput tokens
59
+ - prompt_tokens is the count of input tokens
60
+ - finish_type indicates how the operation finished, for example stop sequence or max tokens etc. If the finish_type is not success and indicates problems such as max tokens, then the operation is not successful. Check the status of it's parent span and check if it's due to the finish type of this child span. In that case callout the root cause as the child span error for the parent span error.
61
+ """
62
+
63
+ @app.prompt(name="enable_tracing")
64
+ def enable_monocle_tracing_prompt(app_language: str = "python") -> str:
65
+ """Trace agentic code"""
66
+ return enable_monocle_prompt.format(app_language=app_language)
67
+
68
+
69
+ @app.prompt(name="analyze")
70
+ def analyze_monocle_tracing_prompt() -> str:
71
+ """Identify root cause from trace"""
72
+ return monocle_trace_prompt
73
+
74
+
75
+ @click.command()
76
+ @click.option(
77
+ "--log-level",
78
+ default="info",
79
+ help="Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
80
+ )
81
+ def main(log_level: str) -> int:
82
+ # Configure logging
83
+ logging.basicConfig(
84
+ level=getattr(logging, log_level.upper()),
85
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
86
+ )
87
+
88
+ # Run the FastMCP server using stdio transport
89
+ app.run(transport="stdio")
90
+ return 0
91
+
92
+
93
+ if __name__ == "__main__":
94
+ main() # type: ignore
@@ -1,18 +1,23 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: monocle_apptrace
3
- Version: 0.5.1
3
+ Version: 0.5.1b1
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
7
+ Author-email: "Okahu Inc." <okahu-pypi@okahu.ai>
8
+ License: Apache-2.0
7
9
  License-File: LICENSE
8
10
  License-File: NOTICE
9
- Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: License :: OSI Approved :: Apache Software License
10
12
  Classifier: Operating System :: OS Independent
11
13
  Classifier: Programming Language :: Python :: 3
12
14
  Requires-Python: >=3.8
15
+ Requires-Dist: click==8.2.1
16
+ Requires-Dist: mcp>=1.13.1
13
17
  Requires-Dist: opentelemetry-api>=1.21.0
14
18
  Requires-Dist: opentelemetry-instrumentation
15
19
  Requires-Dist: opentelemetry-sdk>=1.21.0
20
+ Requires-Dist: pydantic>=2.11.7
16
21
  Requires-Dist: requests
17
22
  Requires-Dist: wrapt>=1.14.0
18
23
  Provides-Extra: aws
@@ -132,6 +137,26 @@ Benefits:
132
137
  See [Monocle user guide](Monocle_User_Guide.md) for more details.
133
138
 
134
139
 
140
+ ## Use Monocle MCP
141
+
142
+ First install monocle-apptrace: pip install monocle-apptrace
143
+
144
+ Open bash and run the following command to run the monocle mcp server with stdio:
145
+ monocle_apptrace
146
+
147
+ If you are using VS Code you can add following entry to your .vscode/mcp.json
148
+
149
+ ```json
150
+ "monocle-mcp-server": {
151
+ "type": "stdio",
152
+ "command": "uvx",
153
+ "args": [
154
+ "monocle_apptrace"
155
+ ],
156
+ "env": {}
157
+ }
158
+ ```
159
+
135
160
  ## Roadmap
136
161
 
137
162
  Goal of Monocle is to support tracing for apps written in *any language* with *any LLM orchestration or agentic framework* and built using models, vectors, agents or other components served up by *any cloud or model inference provider*.
@@ -1,6 +1,7 @@
1
1
  monocle_apptrace/README.md,sha256=T5NFC01bF8VR0oVnAX_n0bhsEtttwqfTxDNAe5Y_ivE,3765
2
2
  monocle_apptrace/__init__.py,sha256=XtoX7gHUSZgkY1nry8IFny8RslPhutZQUuEkqIrBzFQ,30
3
3
  monocle_apptrace/__main__.py,sha256=MLLPbC4YTp8O2wQrn8BROSZGvQpQd5brk_d1n_dWVWA,573
4
+ monocle_apptrace/mcp_server.py,sha256=X5NFOE1QHkIktykGlRH-bzOnLsby5E9sTRAT-4BOQx0,5591
4
5
  monocle_apptrace/exporters/base_exporter.py,sha256=xm2MkDjuVZc-vmSXBMMsNMyIoy4z0O4g6wOAyuEnHwo,2062
5
6
  monocle_apptrace/exporters/exporter_processor.py,sha256=-spCIJ_UfJ0fax_jE-ii3ODQBwtnHZgYIGVNd91Q718,6298
6
7
  monocle_apptrace/exporters/file_exporter.py,sha256=bqRo1h9ubuUltYTj7-LxHWtPwlevBV6dvRbnJXQEwqs,7873
@@ -136,8 +137,9 @@ monocle_apptrace/instrumentation/metamodel/teamsai/entities/__init__.py,sha256=4
136
137
  monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
137
138
  monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/actionplanner_output_processor.py,sha256=FRR9iBdDBXfYscP-lkORMNKl_lllflZN6gMlC7m_94w,3206
138
139
  monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/teamsai_output_processor.py,sha256=o9jrBIEqPDg3VfR6zexUCpkq3jlX0lQji8CKLUUK4Wk,3022
139
- monocle_apptrace-0.5.1.dist-info/METADATA,sha256=5zCg558h1uTrkzO6jupxY0Zt5KhmZGvK-vb9HmVCE9c,7424
140
- monocle_apptrace-0.5.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
141
- monocle_apptrace-0.5.1.dist-info/licenses/LICENSE,sha256=ay9trLiP5I7ZsFXo6AqtkLYdRqe5S9r-DrPOvsNlZrg,9136
142
- monocle_apptrace-0.5.1.dist-info/licenses/NOTICE,sha256=9jn4xtwM_uUetJMx5WqGnhrR7MIhpoRlpokjSTlyt8c,112
143
- monocle_apptrace-0.5.1.dist-info/RECORD,,
140
+ monocle_apptrace-0.5.1b1.dist-info/METADATA,sha256=ScYyK_Mw2BqC9Eyet78MFcoV3b7CwtQ3GHkseNJQd2o,8013
141
+ monocle_apptrace-0.5.1b1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
142
+ monocle_apptrace-0.5.1b1.dist-info/entry_points.txt,sha256=rxpPKb3klrgZEbSyOFQ2J6KRPO7ri9ES-zmC8Jtikx8,70
143
+ monocle_apptrace-0.5.1b1.dist-info/licenses/LICENSE,sha256=ay9trLiP5I7ZsFXo6AqtkLYdRqe5S9r-DrPOvsNlZrg,9136
144
+ monocle_apptrace-0.5.1b1.dist-info/licenses/NOTICE,sha256=9jn4xtwM_uUetJMx5WqGnhrR7MIhpoRlpokjSTlyt8c,112
145
+ monocle_apptrace-0.5.1b1.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ monocle_apptrace = monocle_apptrace.mcp_server:main