Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Executor] Update prompt info in otel traces (#1969)
# Description This pull request primarily focuses on enhancing the traceability of the `promptflow` application. The changes involve modifying the function parameters, adding new functions, and updating tests to validate the new changes. The most significant changes include the addition of a new `enrich_span_with_prompt_info` function in the `tracer.py` file, the modification of the `render_template_jinja2` function in the `template_rendering.py` file, and the addition of new tests in the `test_traces.py` file. Changes to function parameters: * [`src/promptflow-tools/promptflow/tools/template_rendering.py`](diffhunk://#diff-cd8fa4e9bc7912dced2d024c72d70fb9c3853cd69df5543ce19686bfb0ae196aR4-R9): The `render_template_jinja2` function's `template` parameter type has been changed from `str` to `PromptTemplate`. This change ensures that the function only accepts `PromptTemplate` type inputs, providing a more defined contract for the function usage. New function additions: * [`src/promptflow/promptflow/_core/tracer.py`](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8R267-R282): A new function `enrich_span_with_prompt_info` has been added. This function enriches a span with prompt information, assuming there is only one prompt template parameter in the function. It is used in both the `wrapped` functions within the same file. [[1]](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8R267-R282) [[2]](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8R370) [[3]](diffhunk://#diff-8f8c2ae53e5ffd37a14e8a899119fbb2742486db8faab6df3fcf506e1b720ad8R421) Updated tests: * [`src/promptflow/tests/executor/e2etests/test_traces.py`](diffhunk://#diff-a36689a949893c227689d9dadb4c1e7008a0551206871e371658f4cc70f16f07R390-R430): New tests have been added to validate the changes made in the `tracer.py` file. The `test_otel_trace_with_prompt` test checks if the OpenTelemetry traces include the correct prompt template and variables. Example: After this PR, if the function has input with type `PromptTemplate`, we will add prompt information in the otel traces: ``` "prompt.template": "<template>" "prompt.variables": "<dumped_parameter_name_and_value_pairs>" ``` # All Promptflow Contribution checklist: - [x] **The pull request does not introduce [breaking changes].** - [ ] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [x] **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 - [x] Title of the pull request is clear and informative. - [x] 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 - [x] Pull request includes test coverage for the included changes. --------- Co-authored-by: Lina Tang <[email protected]>
- Loading branch information