4. Prompty Observability¶
Using Tracing in Prompty¶
Prompty supports tracing to help you understand the execution of your prompts. This functionality is customizable and can be used to trace the execution of your prompts in a way that makes sense to you. Prompty has two default traces built in: console_tracer
and PromptyTracer
. The console_tracer
writes the trace to the console, and the PromptyTracer
writes the trace to a JSON file. You can also create your own tracer by creating your own hook.
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
You can also bring your own tracer by your own tracing hook. The console_tracer
is the simplest example of a tracer. It writes the trace to the console.
This is what it looks like:
Python | |
---|---|
1 2 3 4 5 6 7 |
|
It uses a context manager to define the start and end of the trace so you can do whatever setup and teardown you need. The yield
statement returns a function that you can use to write the trace. The console_tracer
writes the trace to the console using the print
function.
The PromptyTracer
is a more complex example of a tracer. This tracer manages its internal state using a full class. Here's an example of the class based approach that writes each function trace to a JSON file:
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
The tracing mechanism is supported for all of the prompty runtime internals and can be used to trace the execution of the prompt along with all of the paramters. There is also a @trace
decorator that can be used to trace the execution of any function external to the runtime. This is provided as a facility to trace the execution of the prompt and whatever supporting code you have.
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
In this case, whenever this code is executed, a .tracy
file will be created in the path/to/output
directory. This file will contain the trace of the execution of the get_response
function, the execution of the get_customer
function, and the prompty internals that generated the response.
OpenTelemetry Tracing¶
You can add OpenTelemetry tracing to your application using the same hook mechanism. In your application, you might create something like trace_span
to trace the execution of your prompts:
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
This will produce spans during the execution of the prompt that can be sent to an OpenTelemetry collector for further analysis.
To get started with Observability at refer debugging Prompty in the Getting Started section.
Want to Contribute To the Project? - Updated Guidance Coming Soon.