refactor(api): type OpsTraceProviderConfigMap with TracingProviderCon…#34424
Conversation
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-01 21:14:02.423393651 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-01 21:13:51.343414178 +0000
@@ -61,9 +61,27 @@
ERROR Argument `dict[str, int | str | None]` is not assignable to parameter `attributes` with type `dict[str, str] | None` in function `mlflow.tracing.fluent.start_span_no_context` [bad-argument-type]
--> core/ops/mlflow_trace/mlflow_trace.py:415:24
ERROR Class member `OpsTraceProviderConfigMap.__getitem__` overrides parent class `UserDict` in an inconsistent manner [bad-param-name-override]
- --> core/ops/ops_trace_manager.py:199:9
+ --> core/ops/ops_trace_manager.py:208:9
+ERROR `BaseTracingConfig` is not assignable to variable `tracing_config` with type `dict[Unknown, Unknown]` [bad-assignment]
+ --> core/ops/ops_trace_manager.py:597:26
+ERROR Object of class `BaseTraceInstance` has no attribute `api_check` [missing-attribute]
+ --> core/ops/ops_trace_manager.py:598:16
+ERROR Argument `dict[Unknown, Unknown]` is not assignable to parameter `trace_config` with type `BaseTracingConfig` in function `core.ops.base_trace_instance.BaseTraceInstance.__init__` [bad-argument-type]
+ --> core/ops/ops_trace_manager.py:598:31
+ERROR `BaseTracingConfig` is not assignable to variable `tracing_config` with type `dict[Unknown, Unknown]` [bad-assignment]
+ --> core/ops/ops_trace_manager.py:612:26
+ERROR Object of class `BaseTraceInstance` has no attribute `get_project_key` [missing-attribute]
+ --> core/ops/ops_trace_manager.py:613:16
+ERROR Argument `dict[Unknown, Unknown]` is not assignable to parameter `trace_config` with type `BaseTracingConfig` in function `core.ops.base_trace_instance.BaseTraceInstance.__init__` [bad-argument-type]
+ --> core/ops/ops_trace_manager.py:613:31
+ERROR `BaseTracingConfig` is not assignable to variable `tracing_config` with type `dict[Unknown, Unknown]` [bad-assignment]
+ --> core/ops/ops_trace_manager.py:627:26
+ERROR Object of class `BaseTraceInstance` has no attribute `get_project_url` [missing-attribute]
+ --> core/ops/ops_trace_manager.py:628:16
+ERROR Argument `dict[Unknown, Unknown]` is not assignable to parameter `trace_config` with type `BaseTracingConfig` in function `core.ops.base_trace_instance.BaseTraceInstance.__init__` [bad-argument-type]
+ --> core/ops/ops_trace_manager.py:628:31
ERROR Object of class `dict` has no attribute `model_dump` [missing-attribute]
- --> core/ops/ops_trace_manager.py:1521:32
+ --> core/ops/ops_trace_manager.py:1530:32
ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `BaseModel | Generator[BaseModel | Mapping[Unknown, Unknown] | str] | Mapping[Unknown, Unknown]` [unsafe-overlap]
--> core/plugin/backwards_invocation/base.py:10:33
ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `Generator[LLMResultChunkWithStructuredOutput] | LLMResultWithStructuredOutput` [unsafe-overlap]
@@ -398,6 +416,8 @@
--> services/external_knowledge_service.py:230:17
ERROR Returned type `dict[Unknown, Unknown] | None` is not assignable to declared return type `dict[str, Any]` [bad-return]
--> services/external_knowledge_service.py:232:16
+ERROR `TracingProviderConfigEntry` is not assignable to `dict[str, Any]` [bad-assignment]
+ --> services/ops_service.py:153:43
ERROR `handled_tenant_count` was assigned in the current scope before the nonlocal declaration [unknown-name]
--> services/plugin/plugin_migration.py:82:34
ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
|
b7349c6 to
39bd111
Compare
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-01 22:53:14.090627548 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-01 22:53:03.602487236 +0000
@@ -61,9 +61,15 @@
ERROR Argument `dict[str, int | str | None]` is not assignable to parameter `attributes` with type `dict[str, str] | None` in function `mlflow.tracing.fluent.start_span_no_context` [bad-argument-type]
--> core/ops/mlflow_trace/mlflow_trace.py:415:24
ERROR Class member `OpsTraceProviderConfigMap.__getitem__` overrides parent class `UserDict` in an inconsistent manner [bad-param-name-override]
- --> core/ops/ops_trace_manager.py:199:9
+ --> core/ops/ops_trace_manager.py:208:9
+ERROR Object of class `BaseTraceInstance` has no attribute `api_check` [missing-attribute]
+ --> core/ops/ops_trace_manager.py:598:16
+ERROR Object of class `BaseTraceInstance` has no attribute `get_project_key` [missing-attribute]
+ --> core/ops/ops_trace_manager.py:613:16
+ERROR Object of class `BaseTraceInstance` has no attribute `get_project_url` [missing-attribute]
+ --> core/ops/ops_trace_manager.py:628:16
ERROR Object of class `dict` has no attribute `model_dump` [missing-attribute]
- --> core/ops/ops_trace_manager.py:1521:32
+ --> core/ops/ops_trace_manager.py:1530:32
ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `BaseModel | Generator[BaseModel | Mapping[Unknown, Unknown] | str] | Mapping[Unknown, Unknown]` [unsafe-overlap]
--> core/plugin/backwards_invocation/base.py:10:33
ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `Generator[LLMResultChunkWithStructuredOutput] | LLMResultWithStructuredOutput` [unsafe-overlap]
|
…figEntry TypedDict
39bd111 to
c0984f7
Compare
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-01 23:10:42.538413401 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-01 23:10:30.618373659 +0000
@@ -61,9 +61,9 @@
ERROR Argument `dict[str, int | str | None]` is not assignable to parameter `attributes` with type `dict[str, str] | None` in function `mlflow.tracing.fluent.start_span_no_context` [bad-argument-type]
--> core/ops/mlflow_trace/mlflow_trace.py:415:24
ERROR Class member `OpsTraceProviderConfigMap.__getitem__` overrides parent class `UserDict` in an inconsistent manner [bad-param-name-override]
- --> core/ops/ops_trace_manager.py:199:9
+ --> core/ops/ops_trace_manager.py:207:9
ERROR Object of class `dict` has no attribute `model_dump` [missing-attribute]
- --> core/ops/ops_trace_manager.py:1521:32
+ --> core/ops/ops_trace_manager.py:1529:32
ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `BaseModel | Generator[BaseModel | Mapping[Unknown, Unknown] | str] | Mapping[Unknown, Unknown]` [unsafe-overlap]
--> core/plugin/backwards_invocation/base.py:10:33
ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `Generator[LLMResultChunkWithStructuredOutput] | LLMResultWithStructuredOutput` [unsafe-overlap]
|
|
@asukaminato0721 Could you please review this first? |
There was a problem hiding this comment.
Pull request overview
This PR refactors the ops tracing provider configuration map typing to make the provider config entry shape explicit (instead of dict[str, Any]), improving type safety for internal consumers that destructure known keys.
Changes:
- Introduces
TracingProviderConfigEntryTypedDictto model the fixed provider-config shape returned byprovider_config_map[...]. - Updates
OpsTraceProviderConfigMapgenerics and__getitem__return type to use the newTypedDict. - Updates
OpsService.create_tracing_app_configto annotateprovider_configwith the newTypedDict.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| api/core/ops/ops_trace_manager.py | Adds TracingProviderConfigEntry and applies it to the provider config map typing. |
| api/services/ops_service.py | Updates provider config typing to use TracingProviderConfigEntry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| class TracingProviderConfigEntry(TypedDict): | ||
| config_class: type[BaseTracingConfig] | ||
| secret_keys: list[str] | ||
| other_keys: list[str] | ||
| trace_instance: type[Any] |
There was a problem hiding this comment.
TracingProviderConfigEntry.trace_instance is still typed as type[Any], which doesn’t match the PR description (and largely defeats the benefit of introducing the TypedDict for this field). Consider tightening this type: either (a) import a shared base/Protocol for trace instances (e.g., a Protocol exposing api_check() / get_project_url() / get_project_key() as applicable) and use type[ThatProtocol], or (b) update BaseTraceInstance to declare these methods and then use type[BaseTraceInstance]. If keeping type[Any] is intentional, the PR description should be updated accordingly to avoid confusion for reviewers/callers.
Summary
TracingProviderConfigEntryTypedDict to replacedict[str, Any]inOpsTraceProviderConfigMapconfig_class(type[BaseTracingConfig]),secret_keys(list[str]),other_keys(list[str]),trace_instance(type[BaseTraceInstance])Why this change
OpsTraceProviderConfigMap.__getitem__returns a dict with 4 well-known keys, but the return type isdict[str, Any]. All 10 provider branches (LANGFUSE, LANGSMITH, OPIK, WEAVE, ARIZE, PHOENIX, ALIYUN, MLFLOW, DATABRICKS, TENCENT) return the exact same shape. Callers destructure the result via["config_class"],["secret_keys"],["other_keys"], and["trace_instance"]— all within the same file. A TypedDict makes these keys and their types explicit.Changes
ops_trace_manager.py: DefineTracingProviderConfigEntryTypedDict, updateOpsTraceProviderConfigMapclass signature and__getitem__return type, importBaseTracingConfigandBaseTraceInstancefor precise field typesTest plan
ruff checkpassesPart of #32863 (
core/ops/ops_trace_manager.py)