refactor(otel): replace Any with Tracer and [T] generics#34883
Merged
asukaminato0721 merged 5 commits intolanggenius:mainfrom Apr 10, 2026
Merged
Conversation
Contributor
Pyrefly DiffNo changes detected. |
Contributor
Pyrefly DiffNo changes detected. |
Contributor
Pyrefly DiffNo changes detected. |
1 similar comment
Contributor
Pyrefly DiffNo changes detected. |
…lers - Type tracer parameter as Tracer instead of Any across all handlers - Add [T] generic to WorkflowAppRunnerHandler.wrapper to match base class - Use tuple[object, ...] and Mapping[str, object] instead of Any in args - Narrow _signature_cache and _build_span_name to Callable[..., object] - Remove unused Any import from workflow and generate handlers
….wrapper - Change wrapper signature from (wrapped, args, kwargs) to (wrapped, *args: P.args, **kwargs: P.kwargs) using ParamSpec - Update base.py caller to forward args variadically - Update all tests to match new variadic call convention
bfed08e to
43a5640
Compare
Contributor
Pyrefly DiffNo changes detected. |
Contributor
Pyrefly DiffNo changes detected. |
Contributor
Author
|
@asukaminato0721 resolved comments. |
asukaminato0721
approved these changes
Apr 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the OpenTelemetry span handler APIs to preserve wrapped function return types via PEP 695 generics and to tighten typing around the tracer parameter and argument passing.
Changes:
- Update
SpanHandler.wrapper/_extract_argumentsto accept*args/**kwargs(ParamSpec) and returnR, preserving wrapped return types. - Type
tracerasopentelemetry.trace.Traceracross handlers and narrow signature cache typing. - Update unit tests to match the new calling conventions for
_extract_argumentsandwrapper.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| api/extensions/otel/decorators/handler.py | Refactors core handler APIs to ParamSpec-based *args/**kwargs, preserves return type R, and types tracer as Tracer. |
| api/extensions/otel/decorators/base.py | Updates the decorator to forward arguments via handler.wrapper(tracer, func, *args, **kwargs). |
| api/extensions/otel/decorators/handlers/generate_handler.py | Aligns handler override with the new generic wrapper signature and typed Tracer. |
| api/extensions/otel/decorators/handlers/workflow_app_runner_handler.py | Aligns handler override with the new generic wrapper signature and typed Tracer. |
| api/tests/unit_tests/extensions/otel/decorators/test_handler.py | Updates SpanHandler unit tests to call _extract_arguments/wrapper using *args/**kwargs. |
| api/tests/unit_tests/extensions/otel/decorators/handlers/test_generate_handler.py | Updates generate handler tests for the new _extract_arguments/wrapper signatures. |
| api/tests/unit_tests/extensions/otel/decorators/handlers/test_workflow_app_runner_handler.py | Updates workflow runner handler test to call wrapper with positional args. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
HanqingZ
pushed a commit
to HanqingZ/dify
that referenced
this pull request
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of: #34878
Summary
tracerparameter asTracerinstead ofAnyinSpanHandler.wrapperand both handler subclasses[T]generic toWorkflowAppRunnerHandler.wrapperto match base class signature — was erasing return type toAnytuple[object, ...]andMapping[str, object]instead ofAnyforargs/kwargsinWorkflowAppRunnerHandler_signature_cacheand_build_span_nametoCallable[..., object]Anyimport from workflow and generate handlersWhy this change
WorkflowAppRunnerHandler.wrapperoverrode the base class[T]generic withAny, erasing the return type that the base class preserves. Thetracerparameter was typed asAnyacross all handlers despite always receiving anopentelemetry.trace.Tracerinstance fromget_tracer().Changes
extensions/otel/decorators/handler.py:Tracertype,Callable[..., object]extensions/otel/decorators/handlers/workflow_app_runner_handler.py:[T]generic,Tracer, removeAnyextensions/otel/decorators/handlers/generate_handler.py:Tracer, removeAnyTest plan
basedpyrightpassesruff checkpasses