You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# This cookbook provides receipts of various instrumenation solution with Monocle
2
+
3
+
## Generate out of box telemetry, without any code chante
4
+
If you have a python app that run locally ie ```python my-app.py [args]``` (as opposed to hosting in a cloud serverless container like AWS Lambda or Azure Function), you can use Monocle package to enable telemetry with any code change
5
+
```shell
6
+
python -m monocle_apptrace my-app.py [args]
7
+
```
8
+
This will genearate the trace files monocle_trace_*.json in the local directory
9
+
10
+
## Instrument your app to enable Monocle telemetry
11
+
- Python
12
+
Install monocle package or add `monocle_telemetry` in your ```requirements.txt``` file.
13
+
```shell
14
+
pip install monocle_telemetry
15
+
```
16
+
Import the package and add Monocle a single line of code to enable Monocle telemetry
17
+
```python
18
+
from monocle_apptrace import setup_monocle_telemetry
result = rag_chat_chain.invoke(message) ==> GenAI code
45
+
```
46
+
47
+
The above code will generate two traces (one per chain invocation). All the spans in these traces will have an attribute called `Conversaion` with a unique value.
Copy file name to clipboardExpand all lines: documentation/Monocle_User_Guide.md
+146-3Lines changed: 146 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,12 +209,155 @@ Monocle exporters handle storing the trace for future analysis. By default each
209
209
|OpenSearch|✅|✅|
210
210
211
211
## Using scopes
212
-
Imagine you have a chatbot application that supports a long conversion ie multiple question/answer back and forth between end user and bot. It uses various genAI tech components like LLMs and vector stores. A simple instrumentation will generate a trace per genAI API call (eg invocation of a framework chat or direct OpenAI API). As the app developer or owner, you are more interested in tracking the conversions than just APIs. The scopes in Monocle enables that use case.
213
-
You can set the scope in application either programatically or declaratively. You can specific a value for scope or Monocle will generate a unique value (GUID) which gives you options to choose what's best suited for your use case. Please see the [Monocle scopes guide](Monocle_scopes.md) for the details and examples.
214
-
212
+
Imagine you have a chatbot application that supports a long conversion ie multiple question/answer back and forth between end user and bot. It uses various genAI tech components/services like LLMs and vector stores. A simple instrumentation will generate a trace per genAI API call (eg invocation of a framework chat or direct OpenAI API). As the app developer or owner, you are more interested in tracking the conversions than just APIs. The scopes in Monocle enables that use case.
213
+
You can set the scope in application either programatically or declaratively. You can specific a value for scope or Monocle will generate a unique value (GUID) which gives you options to choose what's best suited for your use case. Please see the [Monocle cookbook](Monocle_scopes.md) for the details and examples.
215
214
216
215
## Extending Monocle
217
216
If you are using a genAI technology that's not yet supported by Monocle out of the box or have you own proparitory code, you can extend monocle to generate traces in the Monocle format. Please refer to [extending monocle guide](Extending_monocle.md)
| workflow_name |str| The name of the workflow to be used as the service name in telemetry. |None|
238
+
| span_processors | List[SpanProcessor] | Custom span processors to use instead of the default ones. If None, <br>BatchSpanProcessors with Monocle exporters will be used. | ones |
239
+
| span_handlers | Dict[str, SpanHandler] | Dictionary of span handlers to be used by the instrumentor, mapping handler names to handler objects. |None|
240
+
| wrapper_methods | List[Union[dict, WrapperMethod]] | Custom wrapper methods for instrumentation. If None, default methods will be used. | methods |
241
+
| union_with_default_methods |bool, default=True| If True, combine the provided wrapper_methods with the default methods.<br>If False, only use the provided wrapper_methods. | methods |
Starts a new trace. All the spans created after this call will be part of the same trace.
252
+
253
+
**Returns:**
254
+
255
+
| Type | Description |
256
+
|---|---|
257
+
| Token | A token representing the attached context for the workflow span.<br>This token is to be used later to stop the current trace.<br>Returns Noneif tracing fails. |
258
+
259
+
**Raises:**
260
+
261
+
| Type | Description |
262
+
|---|---|
263
+
|Exception| The function catches all exceptions internally and logs a warning. |
Decorator to start and stop a continue traces and scope for a http route. It will also initiate new scopes from the http headers if configured in``monocle_scopes.json``
220
362
363
+
All the spans, across traces created in the route will have the scope attached.
0 commit comments