Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Refine tracing doc by separating tracing and devkit #3002

Merged
merged 31 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
856bdf9
refine index
zhengfeiwang Apr 25, 2024
87154de
refine devkit
zhengfeiwang Apr 25, 2024
dc9197b
Merge branch 'main' into zhengfei/doc/refine-tracing-doc
zhengfeiwang Apr 25, 2024
876ac2b
update index
zhengfeiwang Apr 25, 2024
429b8d5
add OTel spec doc link
zhengfeiwang Apr 25, 2024
cc5c3f0
rename
zhengfeiwang Apr 25, 2024
63fb93b
add link
zhengfeiwang Apr 25, 2024
1198cc9
split more
zhengfeiwang Apr 25, 2024
1d5797f
update name
zhengfeiwang Apr 25, 2024
d81f90b
update manage page
zhengfeiwang Apr 25, 2024
3c68c1b
refine trace ui page
zhengfeiwang Apr 25, 2024
4bab27a
update link
zhengfeiwang Apr 25, 2024
c70a830
refine tree
zhengfeiwang Apr 25, 2024
477aa62
update section name
zhengfeiwang Apr 25, 2024
44b9d8f
update sample links
zhengfeiwang Apr 25, 2024
5b66f5d
revert title change
zhengfeiwang Apr 25, 2024
2ef07a1
update order
zhengfeiwang Apr 25, 2024
72a26f6
remove terms of DAG/Flex
zhengfeiwang Apr 25, 2024
e355ca2
update cell type
zhengfeiwang Apr 25, 2024
c6a507e
update title
zhengfeiwang Apr 25, 2024
0c975c2
minor update for inputs
zhengfeiwang Apr 25, 2024
71d45f7
add an overview
zhengfeiwang Apr 25, 2024
540667c
wrap url
zhengfeiwang Apr 25, 2024
8cd0da7
one cmd
zhengfeiwang Apr 25, 2024
be25688
increase readability
zhengfeiwang Apr 25, 2024
957c43b
add some explaination
zhengfeiwang Apr 25, 2024
ea14f8d
add a link
zhengfeiwang Apr 25, 2024
5861673
remove empty toctree
zhengfeiwang Apr 25, 2024
3cf2d00
hide toc tree
zhengfeiwang Apr 25, 2024
dcf10ec
explain collection
zhengfeiwang Apr 25, 2024
832da29
Merge branch 'main' into zhengfei/doc/refine-tracing-doc
zhengfeiwang Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/how-to-guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Simple and short articles grouped by topics, each introduces a core feature of p
:caption: Tracing
:maxdepth: 1
tracing/index
tracing/with-devkit
```

```{toctree}
zhengfeiwang marked this conversation as resolved.
Show resolved Hide resolved
```

```{toctree}
Expand Down
15 changes: 11 additions & 4 deletions docs/how-to-guides/tracing/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Tracing
# Trace with prompt flow

wangchao1230 marked this conversation as resolved.
Show resolved Hide resolved
:::{admonition} Experimental feature
This is an experimental feature, and may change at any time. Learn [more](../faq.md#stable-vs-experimental).
:::

Prompt flow provides the trace feature to enable user to trace LLM call or function, and LLM frameworks like `LangChain` and `AutoGen`, following OpenTelemetry specification.
Prompt flow provides the trace feature to enable user to trace LLM call or function, and LLM frameworks like `LangChain` and `AutoGen`, following [OpenTelemetry specification](https://opentelemetry.io/docs/specs/otel/).

0mza987 marked this conversation as resolved.
Show resolved Hide resolved
## Installing the package

Expand Down Expand Up @@ -75,11 +75,11 @@ def code_gen(client: AzureOpenAI, question: str) -> str:
python math_to_code.py
```

## Trace with prompt flow
## Trace LLM and frameworks

Prompt flow tracing works not only for general LLM application, but also for more frameworks like `autogen` and `langchain`:

1. Example: **[Add trace for LLM](https://github.com/microsoft/promptflow/tree/main/examples/tutorials/tracing/llm)**
1. Example: **[Add trace for LLM](https://microsoft.github.io/promptflow/tutorials/trace-llm.html)**

![llm-trace-detail](../../media/trace/llm-app-trace-detail.png)

Expand All @@ -90,3 +90,10 @@ Prompt flow tracing works not only for general LLM application, but also for mor
3. Example: **[Add trace for Langchain](https://github.com/microsoft/promptflow/tree/main/examples/tutorials/tracing/langchain)**

zhengfeiwang marked this conversation as resolved.
Show resolved Hide resolved
![langchain-trace-detail](../../media/trace/langchain-trace-detail.png)

```{toctree}
:maxdepth: 1

zhengfeiwang marked this conversation as resolved.
Show resolved Hide resolved
manage
trace-ui
```
40 changes: 40 additions & 0 deletions docs/how-to-guides/tracing/manage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Manage traces

:::{admonition} Experimental feature
This is an experimental feature, and may change at any time. Learn [more](../faq.md#stable-vs-experimental).
:::

Prompt flow provides several trace toolkits in `promptflow-devkit`. This page will introduce how to delete traces in local storage with CLI/SDK.

## Local trace management

### Delete

Prompt flow provides capability to delete traces in local storage, user can delete traces by collection, time range or prompt flow run with both CLI and SDK:

::::{tab-set}
:::{tab-item} CLI
:sync: CLI

```bash
pf trace delete --collection <collection-name> # delete specific collection
zhengfeiwang marked this conversation as resolved.
Show resolved Hide resolved
pf trace delete --collection <collection-name> --started-before '2024-03-01T16:00:00.123456' # delete traces started before the time in specific collection
pf trace delete --run <run-name> # delete traces originated from specific prompt flow run
```
:::

:::{tab-item} SDK
:sync: SDK

```python
from promptflow.client import PFClient

pf = PFClient()
pf.traces.delete(collection="<collection-name>") # delete specific collection
pf.traces.delete(collection="<collection-name>", started_before="2024-03-01T16:00:00.123456") # delete traces started before the time in specific collection
pf.traces.delete(run="<run-name>") # delete traces originated from specific prompt flow run
```

:::

::::
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Tracing with promptflow-devkit
# Visualize traces with trace UI

:::{admonition} Experimental feature
This is an experimental feature, and may change at any time. Learn [more](../faq.md#stable-vs-experimental).
:::

Prompt flow provides several trace toolkits in `promptflow-devkit`, so that user can better capture and visualize the internal execution details for all flows:
Prompt flow provides several trace toolkits in `promptflow-devkit`. This page will introduce trace UI, where user can better capture and visualize the internal execution details for all flows:

- For `DAG flow`, user can track and visualize node level inputs/outputs of flow execution, it provides critical insights for developer to understand the internal details of execution.
- For `Flex flow` developers, who might use different frameworks (langchain, semantic kernel, OpenAI, kinds of agents) to create LLM based applications, prompt flow allow user to instrument their code in a [OpenTelemetry](https://opentelemetry.io/) compatible way, and visualize using UI provided by promptflow devkit.

## Trace visualization in flow test and batch run
## Overview

With `promptflow-devkit` installed, running python script with `start_trace` will produce below example output:

Expand All @@ -18,7 +18,7 @@ Prompt flow service has started...
You can view the traces from local: http://localhost:<port>/v1.0/ui/traces/?#collection=basic
```

Click the trace url, user will see a trace list that corresponding to each LLM calls:
Click the url, user will see a trace list that corresponding to each LLM calls:
![LLM-trace-list](../../media/trace/LLM-trace-list.png)


Expand All @@ -28,6 +28,7 @@ Click on one line record, the LLM detail will be displayed with chat window expe
When combine trace and flow, trace UI provides a more comprehensive view of the flow execution, user can easily track the flow execution details, and debug the flow execution issues.

### Flow test

If your application is created with DAG flow, all flow test and batch run will be automatically enable trace function. Take the **[chat_with_pdf](https://github.com/microsoft/promptflow/tree/main/examples/flows/chat/chat-with-pdf/)** as example.

Run `pf flow test --flow .`, each flow test will generate single line in the trace UI:
Expand All @@ -38,6 +39,7 @@ Click a record, the trace details will be visualized as tree view.
![flow-trace-detail](../../media/trace/flow-trace-detail.png)

### Evaluate against batch data

Keep using **[chat_with_pdf](https://github.com/microsoft/promptflow/tree/main/examples/flows/chat/chat-with-pdf)** as example, to trigger a batch run, you can use below commands:

```shell
Expand All @@ -60,36 +62,3 @@ Trace UI supports simple Python expression for search experience, which is demon
Currently it supports bool operator `and` and `or`, compare operator `==`, `!=`, `>`, `>=`, `<`, `<=`; and the fields that are searchable: `name`, `kind`, `status`, `start_time`, `cumulative_token_count.total`, `cumulative_token_count.prompt` and `cumulative_token_count.completion`. You can find the hints by clicking the button right to the search edit box.

zhengfeiwang marked this conversation as resolved.
Show resolved Hide resolved
![search_hint](../../media/trace/trace-ui-search-hint.png)

## Local trace management

### Delete

Prompt flow provides capability to delete traces in local storage, user can delete traces by collection, time range or prompt flow run with both CLI and SDK:

::::{tab-set}
:::{tab-item} CLI
:sync: CLI

```bash
pf trace delete --collection <collection-name> # delete specific collection
pf trace delete --collection <collection-name> --started-before '2024-03-01T16:00:00.123456' # delete traces started before the time in specific collection
pf trace delete --run <run-name> # delete traces originated from specific prompt flow run
```
:::

:::{tab-item} SDK
:sync: SDK

```python
from promptflow.client import PFClient

pf = PFClient()
pf.traces.delete(collection="<collection-name>") # delete specific collection
pf.traces.delete(collection="<collection-name>", started_before="2024-03-01T16:00:00.123456") # delete traces started before the time in specific collection
pf.traces.delete(run="<run-name>") # delete traces originated from specific prompt flow run
```

:::

::::
Loading