Skip to content

refactor(api): type OpsTraceProviderConfigMap with TracingProviderCon…#34424

Merged
asukaminato0721 merged 1 commit intolanggenius:mainfrom
YB0y:refactor/typed-dict-ops-trace-provider-config
Apr 2, 2026
Merged

refactor(api): type OpsTraceProviderConfigMap with TracingProviderCon…#34424
asukaminato0721 merged 1 commit intolanggenius:mainfrom
YB0y:refactor/typed-dict-ops-trace-provider-config

Conversation

@YB0y
Copy link
Copy Markdown
Contributor

@YB0y YB0y commented Apr 1, 2026

Summary

  • Add TracingProviderConfigEntry TypedDict to replace dict[str, Any] in OpsTraceProviderConfigMap
  • Typed keys: config_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 is dict[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: Define TracingProviderConfigEntry TypedDict, update OpsTraceProviderConfigMap class signature and __getitem__ return type, import BaseTracingConfig and BaseTraceInstance for precise field types

Test plan

  • ruff check passes
  • Import verification — no circular imports

Part of #32863 (core/ops/ops_trace_manager.py)

@YB0y YB0y requested a review from QuantumGhost as a code owner April 1, 2026 21:12
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

Pyrefly Diff

base → 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]

@YB0y YB0y force-pushed the refactor/typed-dict-ops-trace-provider-config branch from b7349c6 to 39bd111 Compare April 1, 2026 22:51
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

Pyrefly Diff

base → 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]

@YB0y YB0y force-pushed the refactor/typed-dict-ops-trace-provider-config branch from 39bd111 to c0984f7 Compare April 1, 2026 23:09
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

Pyrefly Diff

base → 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]

@YB0y
Copy link
Copy Markdown
Contributor Author

YB0y commented Apr 2, 2026

@asukaminato0721 Could you please review this first?

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 2, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 2, 2026
@asukaminato0721 asukaminato0721 requested a review from Copilot April 2, 2026 01:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TracingProviderConfigEntry TypedDict to model the fixed provider-config shape returned by provider_config_map[...].
  • Updates OpsTraceProviderConfigMap generics and __getitem__ return type to use the new TypedDict.
  • Updates OpsService.create_tracing_app_config to annotate provider_config with the new TypedDict.

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.

Comment on lines +199 to +203
class TracingProviderConfigEntry(TypedDict):
config_class: type[BaseTracingConfig]
secret_keys: list[str]
other_keys: list[str]
trace_instance: type[Any]
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Merged via the queue into langgenius:main with commit 2d29345 Apr 2, 2026
31 checks passed
@YB0y YB0y deleted the refactor/typed-dict-ops-trace-provider-config branch April 8, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants