Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Executor][Trace] Enable traces for LLM streaming (#2127)
# Description Add the span for LLM streaming scenario. This pull request primarily focuses on improving the tracing capabilities in the `src/promptflow/promptflow/_core/tracer.py` file. The changes include importing additional modules, adding a mechanism to check the OpenAI version, modifying the `enrich_span_with_trace_type` function to return the output, adding a new function `traced_generator`, and altering the `wrapped` functions to utilize the modified `enrich_span_with_trace_type`. Here are the most important changes: Import and OpenAI Version Check: * [`src/promptflow/promptflow/_core/tracer.py`](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8R13-R20): Imported the `version` module from `importlib.metadata` and `Link` from `opentelemetry.trace`. Added a mechanism to check if the OpenAI version is legacy. [[1]](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8R13-R20) [[2]](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8R33-R36) Function Modifications: * [`src/promptflow/promptflow/_core/tracer.py`](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8L291-R345): In the `enrich_span_with_trace_type` function, removed the call to `enrich_span_with_output` and instead returned its output. Added a new function `traced_generator` to create a new span for each generator iteration and enrich the span with attributes. Function Usage: * [`src/promptflow/promptflow/_core/tracer.py`](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8L410-R452): In both `wrapped` functions, modified the usage of `enrich_span_with_trace_type` to capture its returned output. [[1]](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8L410-R452) [[2]](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8L459-R501) # All Promptflow Contribution checklist: - [ ] **The pull request does not introduce [breaking changes].** - [ ] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).** - [ ] **Create an issue and link to the pull request to get dedicated review from promptflow team. Learn more: [suggested workflow](../CONTRIBUTING.md#suggested-workflow).** ## General Guidelines and Best Practices - [ ] Title of the pull request is clear and informative. - [ ] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### Testing Guidelines - [ ] Pull request includes test coverage for the included changes. --------- Co-authored-by: Heyi <[email protected]> Co-authored-by: Lina Tang <[email protected]>
- Loading branch information