-
Notifications
You must be signed in to change notification settings - Fork 407
feat(debugger): report guardrail telemetry metrics #10152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8fcf8eb
feat(debugger): report guardrail telemetry metrics
watson f106b30
fix(debugger): flush guardrail counters when the application exits
watson 12b31b4
docs(debugger): document the final guardrail drain race in stop()
watson 8423dd5
fix(debugger): only count actual runtime errors as incomplete captures
watson 61ee44a
fix(debugger): count truncated log messages as incomplete
watson 88570ae
fix(debugger): report a trimmed scope as an incomplete capture
watson ca2c73d
fix(debugger): ignore capture limits hit on redacted values
watson f353d53
test(debugger): restore the hrtime stubs of the collector deadline specs
watson cecfa51
fix(debugger): only report a timeout for what the deadline actually cut
watson 6be613e
fix(debugger): only report a capture expression timeout for what was cut
watson af28a57
refactor(debugger): simplify the remaining scope check after the dead…
watson 4457c55
test(appsec): complete telemetry config fixture
watson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| 'use strict' | ||
|
|
||
| const assert = require('node:assert/strict') | ||
| const { inspect } = require('node:util') | ||
|
|
||
| const { setup } = require('./utils') | ||
|
|
||
| // The guardrail counters are converted into telemetry metrics every 10 seconds, which are then sent on the next | ||
| // telemetry heartbeat | ||
| const GUARDRAIL_METRICS_FLUSH_INTERVAL_MS = 10_000 | ||
| const TELEMETRY_HEARTBEAT_INTERVAL_SECONDS = 1 | ||
|
|
||
| describe('Dynamic Instrumentation', function () { | ||
| const t = setup({ | ||
| testApp: 'target-app/basic.js', | ||
| dependencies: ['fastify'], | ||
| env: { | ||
| DD_TELEMETRY_HEARTBEAT_INTERVAL: String(TELEMETRY_HEARTBEAT_INTERVAL_SECONDS), | ||
| // The app-started event is sent before the test can listen for it, but the extended heartbeat repeats its | ||
| // application payload | ||
| DD_TELEMETRY_EXTENDED_HEARTBEAT_INTERVAL: String(TELEMETRY_HEARTBEAT_INTERVAL_SECONDS), | ||
| }, | ||
| }) | ||
|
|
||
| describe('guardrail telemetry', function () { | ||
| this.timeout(GUARDRAIL_METRICS_FLUSH_INTERVAL_MS * 3) | ||
|
|
||
| it('should report Dynamic Instrumentation as an enabled product', async function () { | ||
| await t.agent.assertTelemetryReceived({ | ||
| fn: ({ payload }) => { | ||
| assert.deepStrictEqual(payload.payload.products.dynamic_instrumentation, { enabled: true }) | ||
| }, | ||
| requestType: 'app-extended-heartbeat', | ||
| }) | ||
| }) | ||
|
|
||
| it('should report skipped events and incomplete captures', async function () { | ||
| // A log probe that is hit far more often than its per-probe rate limit allows | ||
| const rateLimitedProbe = t.breakpoints[0].generateRemoteConfig({ sampling: { snapshotsPerSecond: 1 } }) | ||
| // A snapshot probe that cannot capture the request object within its reference depth limit | ||
| const shallowSnapshotProbe = t.breakpoints[1].generateRemoteConfig({ | ||
| captureSnapshot: true, | ||
| capture: { maxReferenceDepth: 0 }, | ||
| }) | ||
|
|
||
| const installed = new Set() | ||
| const allInstalled = new Promise((/** @type {(value?: void) => void} */ resolve) => { | ||
| t.agent.on('debugger-diagnostics', ({ payload }) => { | ||
| for (const { debugger: { diagnostics: { probeId, status } } } of payload) { | ||
| if (status === 'INSTALLED') installed.add(probeId) | ||
| } | ||
| if (installed.size === 2) resolve() | ||
| }) | ||
| }) | ||
|
|
||
| const checkMetrics = t.agent.assertTelemetryReceived({ | ||
| fn: ({ payload }) => { | ||
| const { series } = payload.payload | ||
|
|
||
| const skipped = findMetric(series, 'events.skipped', ['event_type:log', 'reason:rateLimitProbe']) | ||
| assert.strictEqual(skipped.type, 'count') | ||
| assert.strictEqual(skipped.common, true) | ||
| assert.strictEqual(skipped.points.length, 1) | ||
| assert.ok(skipped.points[0][1] >= 1, `Expected ${skipped.points[0][1]} >= 1`) | ||
|
|
||
| const incomplete = findMetric(series, 'capture.incomplete', ['event_type:snapshot', 'reason:depth']) | ||
| assert.strictEqual(incomplete.type, 'count') | ||
| assert.strictEqual(incomplete.common, true) | ||
| assert.strictEqual(incomplete.points.length, 1) | ||
| assert.strictEqual(incomplete.points[0][1], 1) | ||
| }, | ||
| requestType: 'generate-metrics', | ||
| timeout: GUARDRAIL_METRICS_FLUSH_INTERVAL_MS * 2, | ||
| resolveAtFirstSuccess: true, | ||
| namespace: 'live_debugger', | ||
| }) | ||
|
|
||
| t.agent.addRemoteConfig(rateLimitedProbe) | ||
| t.agent.addRemoteConfig(shallowSnapshotProbe) | ||
| await allInstalled | ||
|
|
||
| // Trigger the rate limited probe well within a single second, so all but the first hit are skipped | ||
| await Promise.all(Array.from({ length: 5 }, () => t.request(t.breakpoints[0].url))) | ||
| await t.request(t.breakpoints[1].url) | ||
|
|
||
| await checkMetrics | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| /** | ||
| * @param {Array<{ metric: string, tags: string[] }>} series - The telemetry metric series | ||
| * @param {string} metric - The metric name to find | ||
| * @param {string[]} tags - The exact tags the metric must carry | ||
| * @returns {object} The matching series entry | ||
| */ | ||
| function findMetric (series, metric, tags) { | ||
| const match = series.find((entry) => { | ||
| return entry.metric === metric && entry.tags.length === tags.length && tags.every((tag) => entry.tags.includes(tag)) | ||
| }) | ||
| assert.ok(match, `Expected metric ${metric} with tags ${inspect(tags)} in ${inspect(series)}`) | ||
| return match | ||
| } |
15 changes: 15 additions & 0 deletions
15
packages/dd-trace/src/debugger/devtools_client/guardrail-metrics.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| 'use strict' | ||
|
|
||
| const { workerData } = require('node:worker_threads') | ||
|
|
||
| const { GuardrailMetrics } = require('../guardrail-metrics') | ||
|
|
||
| // For testing purposes, we allow `workerData` to be undefined and fallback to counters that are never drained | ||
| const buffer = workerData?.guardrailMetricsBuffer ?? GuardrailMetrics.createBuffer() | ||
|
|
||
| /** | ||
| * The worker's view of the guardrail counters shared with the main thread, which drains them into telemetry. | ||
| * | ||
| * @type {GuardrailMetrics} | ||
| */ | ||
| module.exports = new GuardrailMetrics(buffer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.