Skip to content

Add --json flag and ResourceOutcome model#479

Open
nathantournant wants to merge 4 commits intomainfrom
nathan.tournant/json-outcome-model
Open

Add --json flag and ResourceOutcome model#479
nathantournant wants to merge 4 commits intomainfrom
nathan.tournant/json-outcome-model

Conversation

@nathantournant
Copy link
Member

Summary

  • Introduce --json CLI flag (gated via DD_JSON envvar) to emit per-resource outcomes as JSON lines to stdout
  • ResourceOutcome dataclass with 6 fields structurally aligned with the CLI's existing datadog.org-sync.action metric tags: resource_type, id, action_type, status, action_sub_type, reason
  • 10 unit tests covering construction, serialization, JSONL format, all status/action_type/action_sub_type values

Context

The managed-sync Go worker currently runs the CLI via cmd.CombinedOutput() with no per-resource visibility. This PR introduces the data model and flag that enable streaming structured outcomes — the worker can forward these fields as statsd tags without translation.

Stack

Test plan

  • 10 unit tests pass (TestResourceOutcome, TestEmit)
  • Review field alignment with _send_action_metrics in base_resource.py

🤖 Generated with Claude Code

heyronhay
heyronhay previously approved these changes Mar 20, 2026
@nathantournant nathantournant force-pushed the nathan.tournant/json-outcome-model branch from 5597040 to 7ffbc4f Compare March 20, 2026 13:53
@nathantournant nathantournant force-pushed the nathan.tournant/json-outcome-model branch 2 times, most recently from 8ab1217 to 963da8c Compare March 20, 2026 14:36
nathantournant and others added 4 commits March 20, 2026 14:48
…document diffs semantics

- S2: Truncate reason field to 1024 chars in __post_init__ to bound
  raw API error bodies crossing the CLI→worker boundary
- S5: Document diffs-mode semantics in docstring (outcomes describe
  intended actions, not completed mutations)
- N1: Add flush=True to emit() for piped-stdout crash resilience
- N2: Rename DD_JSON → DD_SYNC_JSON to avoid envvar namespace collision

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- M1: action_type and status fields now use Literal types for static
  analysis coverage over the 24 _emit call sites
- M2: Replace hand-rolled to_dict() with dataclasses.asdict()
- M3: Add -> None return annotation to __post_init__

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nathantournant nathantournant force-pushed the nathan.tournant/json-outcome-model branch from 963da8c to 43dfa47 Compare March 20, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants