monocle-apptrace 0.5.3__py3-none-any.whl → 0.6.0__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.

Files changed (29) hide show
  1. monocle_apptrace/exporters/file_exporter.py +7 -1
  2. monocle_apptrace/instrumentation/common/instrumentor.py +1 -1
  3. monocle_apptrace/instrumentation/common/span_handler.py +2 -1
  4. monocle_apptrace/instrumentation/common/wrapper_method.py +3 -1
  5. monocle_apptrace/instrumentation/metamodel/adk/_helper.py +6 -4
  6. monocle_apptrace/instrumentation/metamodel/adk/entities/agent.py +6 -1
  7. monocle_apptrace/instrumentation/metamodel/agents/_helper.py +5 -5
  8. monocle_apptrace/instrumentation/metamodel/agents/entities/inference.py +7 -2
  9. monocle_apptrace/instrumentation/metamodel/finish_types.py +32 -1
  10. monocle_apptrace/instrumentation/metamodel/hugging_face/__init__.py +0 -0
  11. monocle_apptrace/instrumentation/metamodel/hugging_face/_helper.py +138 -0
  12. monocle_apptrace/instrumentation/metamodel/hugging_face/entities/__init__.py +0 -0
  13. monocle_apptrace/instrumentation/metamodel/hugging_face/entities/inference.py +97 -0
  14. monocle_apptrace/instrumentation/metamodel/hugging_face/methods.py +23 -0
  15. monocle_apptrace/instrumentation/metamodel/langgraph/_helper.py +4 -2
  16. monocle_apptrace/instrumentation/metamodel/langgraph/entities/inference.py +7 -2
  17. monocle_apptrace/instrumentation/metamodel/mcp/_helper.py +6 -5
  18. monocle_apptrace/instrumentation/metamodel/mistral/_helper.py +98 -49
  19. monocle_apptrace/instrumentation/metamodel/mistral/entities/inference.py +14 -5
  20. monocle_apptrace/instrumentation/metamodel/mistral/entities/retrieval.py +41 -0
  21. monocle_apptrace/instrumentation/metamodel/mistral/methods.py +17 -0
  22. {monocle_apptrace-0.5.3.dist-info → monocle_apptrace-0.6.0.dist-info}/METADATA +9 -76
  23. {monocle_apptrace-0.5.3.dist-info → monocle_apptrace-0.6.0.dist-info}/RECORD +26 -23
  24. monocle_apptrace/README.md +0 -101
  25. monocle_apptrace/mcp_server.py +0 -94
  26. monocle_apptrace-0.5.3.dist-info/licenses/NOTICE +0 -4
  27. {monocle_apptrace-0.5.3.dist-info → monocle_apptrace-0.6.0.dist-info}/WHEEL +0 -0
  28. {monocle_apptrace-0.5.3.dist-info → monocle_apptrace-0.6.0.dist-info}/entry_points.txt +0 -0
  29. {monocle_apptrace-0.5.3.dist-info → monocle_apptrace-0.6.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,101 +0,0 @@
1
- ## Monocle Concepts
2
-
3
- ### Traces
4
- Traces are the full view of a single end-to-end application execution.
5
-
6
- Examples of traces include one response to end user’s question by a chatbot app. 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.It’s typically the workflow code components of an application that generate the traces for application runs.
7
-
8
- Traces are collections of spans.
9
-
10
- ### Spans
11
- Spans are the individual steps executed by the application to perform a GenAI related task.
12
-
13
- Examples of spans include 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.
14
-
15
- ## Contribute to Monocle
16
-
17
- Monocle includes:
18
- - Methods for instrumentation of app code
19
- - Base code for wrapping methods of interest in included in current folder
20
- - Framework specific code is organized in a folder with the framework name
21
- - Metamodel for how attributes and events for GenAI components are represented in OpenTelemety format
22
- - See [metamodel](./metamodel/README.md) for supported GenAI entities, how functions operating on those entities map to spans and format of spans
23
- - Exporters to send trace data to various locations. See [exporters](./exporters)
24
-
25
- See [Monocle committer guide](/Monocle_committer_guide.md).
26
-
27
- ## Get Monocle
28
-
29
- Option 1 - Download released packages from Pypi
30
- ```
31
- python3 -m pip install pipenv
32
- pip install monocle-apptrace
33
- ```
34
-
35
- Option 2 - Build and install locally from source
36
- ```
37
- pip install .
38
- pip install -e ".[dev]"
39
-
40
- python3 -m pip install pipenv
41
- pipenv install build
42
- ```
43
-
44
- ## Examples of app instrumentation with Monocle
45
-
46
- ### apps written using LLM orchestration frameworks
47
-
48
- ```python
49
- from langchain.chains import LLMChain
50
- from langchain_openai import OpenAI
51
- from langchain.prompts import PromptTemplate
52
-
53
- # Import the monocle_apptrace instrumentation method
54
- from monocle_apptrace.instrumentor import setup_monocle_telemetry
55
- from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
56
-
57
- # Call the setup Monocle telemetry method
58
- setup_monocle_telemetry(workflow_name = "simple_math_app",
59
- span_processors=[BatchSpanProcessor(ConsoleSpanExporter())])
60
-
61
- llm = OpenAI()
62
- prompt = PromptTemplate.from_template("1 + {number} = ")
63
-
64
- chain = LLMChain(llm=llm, prompt=prompt)
65
- chain.invoke({"number":2})
66
-
67
- # Trace is generated when invoke() method is called
68
-
69
- ```
70
-
71
- ### apps with custom methods
72
-
73
- ```python
74
-
75
- # Import the monocle_apptrace instrumentation method
76
- from monocle_apptrace.wrapper import WrapperMethod,task_wrapper,atask_wrapper
77
- from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
78
-
79
- # Extend the default wrapped methods list as follows
80
- app_name = "simple_math_app"
81
- setup_monocle_telemetry(
82
- workflow_name=app_name,
83
- span_processors=[BatchSpanProcessor(ConsoleSpanExporter())],
84
- wrapper_methods=[
85
- WrapperMethod(
86
- package="langchain.schema.runnable",
87
- object_name="RunnableParallel",
88
- method="invoke",
89
- span_name="langchain.workflow",
90
- wrapper=task_wrapper),
91
- WrapperMethod(
92
- package="langchain.schema.runnable",
93
- object_name="RunnableParallel",
94
- method="ainvoke",
95
- span_name="langchain.workflow",
96
- wrapper=atask_wrapper)
97
- ])
98
-
99
- # Trace is generated when the invoke() method is called in langchain.schema.runnable package
100
-
101
- ```
@@ -1,94 +0,0 @@
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,4 +0,0 @@
1
- Monocle
2
- Copyright 2018-2021 Monocle Project Authors
3
-
4
- Licensed under Apache License 2.0. See LICENSE for terms.