Skip to content

feat(weave): drop ddtrace dep, inline DogStatsD in datadog.py (PR-7c)#7203

Draft
amwarrier wants to merge 1 commit into
aravind/weave-trace/otel-migration-pr-7b2from
aravind/weave-trace/otel-migration-pr-7c
Draft

feat(weave): drop ddtrace dep, inline DogStatsD in datadog.py (PR-7c)#7203
amwarrier wants to merge 1 commit into
aravind/weave-trace/otel-migration-pr-7b2from
aravind/weave-trace/otel-migration-pr-7c

Conversation

@amwarrier

Copy link
Copy Markdown
Contributor

Summary

Stacked on PR-7b2. Final sub-PR (4 of 4) of the ddtrace → OpenTelemetry migration of weave/trace_server/.

After this PR, pip install . && pip list | grep ddtrace returns empty.

Changes

weave/trace_server/datadog.py rewritten

The module historical name (datadog.py) is preserved for backwards compatibility, but internally ddtrace is gone. Public symbols preserved:

  • DB_INSERT_METRIC, DB_INSERT_PATH_UNKNOWN (constants)
  • db_insert_path(path) (context manager)
  • tag_db_insert_path(path) (decorator)
  • record_db_insert(*, table, count, path=None) (function)
  • set_root_span_dd_tags(tags), set_current_span_dd_tags(tags) (functions)

Removed:

  • generator_trace(span_name) — it existed only to suppress ddtrace's auto-mark-error-on-GeneratorExit. OTel's start_as_current_span doesn't have that behavior (BaseException subclasses propagate through use_span without marking the span errored), so this decorator becomes dead code. Callers should use @traced_generator from weave.trace_server.tracing instead. Empirically verified with the OTel SDK before deletion.

Inline DogStatsD

The DogStatsD client is now a ~30-line _StatsDClient class:

  • Opens a UDP socket to ${DD_DOGSTATSD_URL} (or ${DD_AGENT_HOST}:8125 fallback)
  • Encodes counters in DogStatsD wire format name:value|c|#tags
  • Swallows OSError so stats hiccups never crash the request path
  • Lazily creates the socket (import is side-effect free)

The metric name (weave_trace_server.db_inserts) and tag format are preserved, so existing DD dashboards keep resolving.

set_root_span_dd_tags semantics change

The original used ddtrace.tracer.current_root_span(). OTel has no built-in current-root-span accessor, so this now uses trace.get_current_span() — the currently-active span. Per analysis in services/weave-trace/docs/phase-b-weave-public-plan.md §3.4, none of the three historical call sites actually need root semantics; they just need "the span currently active when this helper is called", which get_current_span() provides. NOT a semantic regression for known callers.

pyproject.toml

Removed ddtrace>=2.7.0 from both occurrences (line 80 in trace_server optional deps, line 425 in the trace_server dependency group).

Test plan

  • python -m py_compile weave/trace_server/datadog.py
  • pip install . && pip list | grep ddtrace returns empty (post-merge validation)
  • Existing tests/trace_server/ suite passes (CI)
  • End-to-end: deploy weave-trace image with all of 7a/7b1/7b2/7c vendored into wandb/core, observe weave_trace_server.db_inserts counter still ingesting in DD

🤖 Generated with Claude Code

@wandbot-3000

wandbot-3000 Bot commented Jun 12, 2026

Copy link
Copy Markdown

Stacked on PR-7b2. Completes the ddtrace -> OpenTelemetry migration of
weave/trace_server/. After this PR, `pip install . && pip list | grep ddtrace`
returns empty.

Changes:

1. weave/trace_server/datadog.py rewritten to remove all ddtrace imports:
   - DogStatsD client is now a ~30-line inline `_StatsDClient` class that
     opens a UDP socket to `${DD_DOGSTATSD_URL}` (or `${DD_AGENT_HOST}:8125`
     fallback), encodes counters in DogStatsD wire format
     `name:value|c|#tags`, and swallows OSError so stats hiccups never
     crash the request path. Metric name (`weave_trace_server.db_inserts`)
     and tag format preserved, so existing DD dashboards keep resolving.
   - `set_root_span_dd_tags` and `set_current_span_dd_tags` now use OTel's
     `get_current_span()` rather than `ddtrace.tracer.current_root_span()`.
     The "root span" semantics aren't preserved exactly — OTel has no
     built-in current-root-span accessor — but per analysis in
     services/weave-trace/docs/phase-b-weave-public-plan.md §3.4, none of
     the historical call sites actually need root semantics; they just
     need "the span currently active when this helper is called", which
     `get_current_span()` provides.
   - `generator_trace` deleted. It existed to suppress ddtrace's
     auto-mark-error-on-GeneratorExit, but OTel's `start_as_current_span`
     doesn't have that behavior (BaseException subclasses propagate
     through `use_span` without setting status=ERROR). Callers should use
     `@traced_generator` from `weave.trace_server.tracing` instead.

2. pyproject.toml: removed `ddtrace>=2.7.0` from the trace_server optional
   dep group (line 80) and the trace_server dependency group (line 425).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@amwarrier amwarrier force-pushed the aravind/weave-trace/otel-migration-pr-7b2 branch from 6036a72 to d54aad8 Compare June 12, 2026 16:07
@amwarrier amwarrier force-pushed the aravind/weave-trace/otel-migration-pr-7c branch from 4b6aa58 to b9e4c15 Compare June 12, 2026 16:07
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.30612% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
weave/trace_server/datadog.py 65.30% 13 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

amwarrier added a commit that referenced this pull request Jun 12, 2026
…ated)

Integrated commit for testing in wandb/core's weave-trace image on
wandbench-small. Represents the combined effect of upstream PRs:
  - #7196 (PR-7a): @Traced + @traced_generator in weave/trace_server/tracing.py
  - #7201 (PR-7b1): 47 wraps in clickhouse_trace_server_batched.py
  - #7202 (PR-7b2): 17 wraps + 2 trace blocks + 3 set_tag + 1 current_root in 10 files
  - #7203 (PR-7c): inline DogStatsD in datadog.py, drop ddtrace dep from pyproject.toml

This branch sits on top of the wandb/core-pinned submodule SHA so the
weave-trace image build picks up only PR-7 changes — no unrelated
upstream drift.

After this commit, `grep -rn "import ddtrace\|from ddtrace"` returns empty
across weave/trace_server/. Only docstring/comment references remain.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant