Skip to content

Upgrade Datadog plugin to ddtrace 4.x public API#1563

Open
Dev-iL wants to merge 1 commit intoapache:mainfrom
SummitSG-LLC:2604/upgrade_ddtrace
Open

Upgrade Datadog plugin to ddtrace 4.x public API#1563
Dev-iL wants to merge 1 commit intoapache:mainfrom
SummitSG-LLC:2604/upgrade_ddtrace

Conversation

@Dev-iL
Copy link
Copy Markdown
Collaborator

@Dev-iL Dev-iL commented Apr 26, 2026

related: #1288
fixes: #1562

ddtrace 3.0 removed Span and context from the top-level package. Migrate to the canonical ddtrace.trace module, bump the version constraint to >=4.0, fix stale sf-hamilton package references, and add smoke tests for the plugin.

Summary

  • Migrate h_ddog.py imports from removed top-level ddtrace.Span/ddtrace.context to the canonical ddtrace.trace module (ddtrace.trace.Span, ddtrace.trace.Context)
  • Bump version constraint from ddtrace<3.0 to ddtrace>=4.0 in both the datadog optional dependency and the docs dependency group
  • Fix stale sf-hamilton package references to apache-hamilton in the ImportError message and DDOGTracer docstring
  • Remove the outdated TODO comment about ddtrace 3.0 deprecation
  • Add smoke tests for the plugin (tests/plugins/test_h_ddog.py)

Motivation

ddtrace 3.0 removed Span and context from the top-level ddtrace package (DataDog/dd-trace-py#12186). The Hamilton plugin was pinned to ddtrace<3.0 as a temporary workaround. This PR migrates to the stable public API at ddtrace.trace, which is the canonical location in ddtrace 4.x.

Changes

File What changed
hamilton/plugins/h_ddog.py from ddtrace import Span, context, tracer split into from ddtrace import tracer + from ddtrace.trace import Context, Span; context.Context replaced with Context in type annotations and constructor calls; TODO comment removed; sf-hamilton references updated to apache-hamilton
pyproject.toml ddtrace<3.0 changed to ddtrace>=4.0 in [project.optional-dependencies].datadog and docs
tests/plugins/test_h_ddog.py New file with 7 tests covering span lifecycle (happy path, error path, task-based), AsyncDDOGTracer instantiation, and serialization/deserialization round-trip

No breaking changes

The public API surface of DDOGTracer and AsyncDDOGTracer is unchanged: same constructor signatures, same methods, same base class hierarchy. Only internal import paths changed.

Test plan

  • DDOGTracer span lifecycle: before_graph -> before_node -> after_node -> after_graph
  • Error propagation through span __exit__
  • Task-based span lifecycle with before_task/after_task
  • AsyncDDOGTracer instantiation with all parameter combinations
  • __getstate__/__setstate__ serialization round-trip
  • _serialize_span_dict/_deserialize_span_dict round-trip
  • Module imports successfully with ddtrace 4.4.0
  • No stale ddtrace<3.0 pins or sf-hamilton references remain

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

ddtrace 3.0 removed `Span` and `context` from the top-level package.
Migrate to the canonical `ddtrace.trace` module, bump the version constraint to `>=4.0`, fix stale `sf-hamilton` package references, and add smoke tests for the plugin.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Dev-iL Dev-iL force-pushed the 2604/upgrade_ddtrace branch from 64b35ca to 1dcfe4a Compare April 26, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv sync fails because of ddtrace

1 participant