Skip to content

[SDTEST-3775] Add common telemetry manager with counter/histogram instances#271

Merged
ypopovych merged 2 commits into
mainfrom
yehor.popovych/sdtest-3775-telemetry-manager
Jun 3, 2026
Merged

[SDTEST-3775] Add common telemetry manager with counter/histogram instances#271
ypopovych merged 2 commits into
mainfrom
yehor.popovych/sdtest-3775-telemetry-manager

Conversation

@ypopovych

@ypopovych ypopovych commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

What

Implements SDTEST-3775 — the first piece of M3 (gather SDK metrics). Adds a common telemetry manager that owns the metric pipeline and provides a counter/histogram instance for every CI Visibility metric.

This PR only provides the instances; features do not record into them yet (that's the follow-up "gather" subtask).

Design

  • Telemetry (DatadogSDKTesting) owns a MeterProviderSdk wired to the Datadog instrumentation-telemetry pipeline: PeriodicMetricReader → TelemetryMetricExporter → TelemetryExporter, with the civisibility namespace stamped on the meter Resource.
  • Metrics are exposed as a typed, discoverable tree so callers never need to look up metric names or allowed tags:
    telemetry?.metrics.git.command.add(command: .getRepository)
    telemetry?.metrics.endpointPayload.requestsErrors.add(errorType: .timeout, endpoint: .testCycle)
    telemetry?.metrics.events.created.add(testFramework: "XCTest", eventType: .test, isBenchmark: false)
    telemetry?.metrics.knownTests.responseTests.record(42)
    Each metric's add/record names exactly the tags it accepts. Tag values are typed enums / Bool / Int, rendered to wire strings via the existing SpanAttributeConvertible.
  • The metric set comes from the shared instrumentation-telemetry spec and is cross-checked against dd-trace-go59 metrics (37 counters + 22 distributions), so nothing is missed.

Configuration

  • DD_INSTRUMENTATION_TELEMETRY_ENABLED — default true; when off, SessionConfig.telemetry is nil.
  • DD_TELEMETRY_HEARTBEAT_INTERVAL — collection/export interval in seconds, clamped to 1...3600, default 60.

Changes

  • EventsExporter: made TelemetryMetricExporter / TelemetryLogExporter public (were internal only because previously unused); added civisibility to the metric & distribution namespace enums.
  • Config / EnvironmentKeys: the two env vars above.
  • SessionManager: builds the manager (gated by the enable flag), threads it through the new optional SessionConfig.telemetry, and shuts it down on stop.

Testing

New TelemetryTests verify the typed tags map to correct wire values (command:get_repository, error_type:timeout, endpoint:test_cycle), the civisibility namespace, and counter increment values. Build + TelemetryTests/ConfigTests pass; the full EventsExporter suite still passes.

🤖 Generated with Claude Code

…tances

Introduce a `Telemetry` manager (DatadogSDKTesting) that owns a MeterProvider
wired to the Datadog instrumentation-telemetry metric pipeline
(PeriodicMetricReader -> TelemetryMetricExporter -> TelemetryExporter, under the
`civisibility` namespace) and provides an instrument for every CI Visibility
metric.

Metrics are exposed as a typed, discoverable tree -
`telemetry.metrics.git.command.add(command: .getRepository)` - where each
metric's add()/record() names exactly the tags it accepts and tag values are
typed enums/Bool/Int rendered via the existing `SpanAttributeConvertible`.
The metric set is taken from the shared instrumentation-telemetry spec and
cross-checked against dd-trace-go (59 metrics: 37 counters + 22 distributions).

This only provides the instances; features do not record into them yet.

- EventsExporter: make TelemetryMetricExporter / TelemetryLogExporter public;
  add `civisibility` to the metric/distribution namespace enums.
- Config: add DD_INSTRUMENTATION_TELEMETRY_ENABLED (default true) and
  DD_TELEMETRY_HEARTBEAT_INTERVAL (seconds, clamped 1...3600, default 60).
- SessionManager: build the Telemetry manager (gated by the enable flag) and
  thread it through the optional SessionConfig.telemetry; shut it down on stop.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ypopovych
ypopovych requested review from a team as code owners June 2, 2026 17:41
@datadog-official

This comment has been minimized.

The `appendToOneFile` storage mock used `minFileAgeForRead: -1`, making the
still-open file immediately eligible for the periodic upload worker (firing
every 0.05s). When the worker fired between the test's synchronous writes it
uploaded and deleted the file after only some entries, splitting the batch
across uploads and intermittently failing the 4-entry assertion.

`flush()` drains via `getAllReadableFiles()`, which ignores `minFileAgeForRead`,
so setting it to `.greatestFiniteMagnitude` keeps the periodic worker from ever
racing the writes while flush still drains the whole file as one batch — exactly
the behaviour under test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ypopovych
ypopovych merged commit f35d42c into main Jun 3, 2026
11 checks passed
@ypopovych
ypopovych deleted the yehor.popovych/sdtest-3775-telemetry-manager branch June 3, 2026 10:43
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.

2 participants