Skip to content

feat(test-optimization): create final_status tag on test event for mocha#7844

Merged
cbasitodx merged 17 commits intomasterfrom
sebas_conde/feat/create-final-status-tag-for-mocha
Apr 1, 2026
Merged

feat(test-optimization): create final_status tag on test event for mocha#7844
cbasitodx merged 17 commits intomasterfrom
sebas_conde/feat/create-final-status-tag-for-mocha

Conversation

@cbasitodx
Copy link
Copy Markdown
Contributor

@cbasitodx cbasitodx commented Mar 23, 2026

What does this PR do?

Create a @test.final_status tag that is added to every mocha test event that represents the final execution of that test (there can be multiple executions of a single test due to retry mechanisms being active)

Motivation

Tracers send each test execution as a span to the backend. When retry mechanisms are enabled a single test can run several times with different outcomes. These mechanisms differ in behavior. Some stop once the test reaches the desired state such as ATR ending when a test passes. Others always run a fixed number of attempts such as EFD or Attempt to fix.

To ensure the correct final result for the customer some intermediate outcomes are suppressed and the testing framework receives an adjusted final status. For example if an early EFD attempt passes but later attempts fail the test is still reported as passed and the failing attempts are hidden to avoid failing CI pipelines.

Both external and internal users have requested a way to query tests in Datadog by this final status. Their main goal is to build monitors and alerts for hard failures on default branches.

To support this a new tag will be added to the last retry of a test named: @test.final_status:pass|fail|skip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 2026

Overall package size

Self size: 5.07 MB
Deduped: 5.91 MB
No deduping: 5.91 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 23, 2026

Benchmarks

Benchmark execution time: 2026-03-30 12:44:21

Comparing candidate commit b84b08e in PR branch sebas_conde/feat/create-final-status-tag-for-mocha with baseline commit 1733e97 in branch master.

Found 9 performance improvements and 5 performance regressions! Performance is the same for 216 metrics, 30 unstable metrics.

scenario:appsec-iast-no-vulnerability-control-18

  • 🟩 execution_time [-32.773ms; -28.177ms] or [-5.938%; -5.105%]

scenario:appsec-iast-no-vulnerability-control-24

  • 🟩 execution_time [-27.861ms; -23.002ms] or [-6.184%; -5.106%]

scenario:appsec-iast-with-vulnerability-control-18

  • 🟩 execution_time [-62.659ms; -56.681ms] or [-6.831%; -6.179%]

scenario:appsec-iast-with-vulnerability-control-22

  • 🟩 execution_time [-60.916ms; -53.699ms] or [-7.160%; -6.311%]

scenario:appsec-iast-with-vulnerability-control-24

  • 🟩 execution_time [-58.805ms; -52.575ms] or [-7.457%; -6.667%]

scenario:net-control-18

  • 🟥 execution_time [+19.386ms; +27.362ms] or [+14.625%; +20.642%]
  • 🟥 instructions [+16.0M instructions; +17.3M instructions] or [+6.982%; +7.567%]

scenario:net-control-24

  • 🟩 execution_time [-25.077ms; -17.748ms] or [-15.065%; -10.662%]
  • 🟩 instructions [-20.2M instructions; -18.0M instructions] or [-8.562%; -7.648%]

scenario:net-with-tracer-24

  • 🟩 execution_time [-34.191ms; -31.240ms] or [-8.140%; -7.437%]

scenario:plugin-http-server-querystring-obfuscation-18

  • 🟥 execution_time [+51.486ms; +70.318ms] or [+5.627%; +7.686%]
  • 🟥 instructions [+32.5M instructions; +47.5M instructions] or [+5.891%; +8.614%]

scenario:plugin-http-server-querystring-obfuscation-24

  • 🟩 execution_time [-38.016ms; -34.458ms] or [-5.895%; -5.343%]

scenario:shimmer-runtime-asyncarrow-wrap-22

  • 🟥 execution_time [+2.702ms; +7.672ms] or [+5.157%; +14.644%]

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.35%. Comparing base (6a9c89a) to head (0e0d07b).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...ckages/datadog-instrumentations/src/mocha/utils.js 0.00% 22 Missing ⚠️
packages/datadog-plugin-mocha/src/index.js 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7844      +/-   ##
==========================================
- Coverage   74.40%   74.35%   -0.05%     
==========================================
  Files         768      768              
  Lines       35834    35855      +21     
==========================================
  Hits        26661    26661              
- Misses       9173     9194      +21     
Flag Coverage Δ
aiguard-macos 39.23% <ø> (-0.10%) ⬇️
aiguard-ubuntu 39.35% <ø> (-0.10%) ⬇️
aiguard-windows 39.02% <ø> (-0.10%) ⬇️
apm-capabilities-tracing-macos 49.08% <0.00%> (-0.01%) ⬇️
apm-capabilities-tracing-ubuntu 48.99% <0.00%> (-0.01%) ⬇️
apm-capabilities-tracing-windows 48.86% <0.00%> (-0.01%) ⬇️
apm-integrations-child-process 38.56% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-18 37.36% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-eol 37.71% <ø> (-0.24%) ⬇️
apm-integrations-oracledb 37.71% <ø> (-0.10%) ⬇️
appsec-express 55.17% <ø> (-0.07%) ⬇️
appsec-fastify 51.52% <ø> (-0.07%) ⬇️
appsec-graphql 51.68% <ø> (-0.08%) ⬇️
appsec-kafka 44.32% <ø> (-0.08%) ⬇️
appsec-ldapjs 43.94% <ø> (-0.08%) ⬇️
appsec-lodash 43.54% <ø> (-0.08%) ⬇️
appsec-macos 58.03% <0.00%> (-0.14%) ⬇️
appsec-mongodb-core 48.70% <ø> (-0.09%) ⬇️
appsec-mongoose 49.36% <ø> (-0.08%) ⬇️
appsec-mysql 50.79% <ø> (-0.17%) ⬇️
appsec-node-serialize 43.12% <ø> (-0.08%) ⬇️
appsec-passport 47.55% <ø> (-0.09%) ⬇️
appsec-postgres 50.51% <ø> (-0.07%) ⬇️
appsec-sourcing 42.37% <ø> (-0.08%) ⬇️
appsec-stripe 44.55% <ø> (-0.08%) ⬇️
appsec-template 43.29% <ø> (-0.08%) ⬇️
appsec-ubuntu 58.11% <0.00%> (-0.14%) ⬇️
appsec-windows 57.84% <0.00%> (-0.16%) ⬇️
instrumentations-instrumentation-bluebird 32.20% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-body-parser 40.46% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-child_process 37.90% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-cookie-parser 34.23% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express 34.55% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.36% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-session 40.10% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-fs 31.89% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-generic-pool 29.21% <0.00%> (-0.13%) ⬇️
instrumentations-instrumentation-http 39.81% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-knex 32.27% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-mongoose 33.39% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-multer 40.21% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-mysql2 38.24% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport 43.98% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-http 43.66% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-local 44.19% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-pg 37.68% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-promise 32.13% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-promise-js 32.14% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-q 32.18% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-url 32.10% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-when 32.15% <ø> (-0.10%) ⬇️
llmobs-ai 42.37% <ø> (-0.10%) ⬇️
llmobs-anthropic 40.39% <ø> (-0.09%) ⬇️
llmobs-bedrock 39.18% <ø> (-0.08%) ⬇️
llmobs-google-genai 39.72% <ø> (-0.21%) ⬇️
llmobs-langchain 40.08% <ø> (-0.08%) ⬇️
llmobs-openai 43.90% <ø> (-0.09%) ⬇️
llmobs-vertex-ai 39.97% <ø> (-0.09%) ⬇️
platform-core 31.47% <ø> (ø)
platform-esbuild 34.42% <ø> (ø)
platform-instrumentations-misc 48.41% <ø> (ø)
platform-shimmer 37.56% <ø> (ø)
platform-unit-guardrails 32.89% <ø> (ø)
platform-webpack 19.96% <0.00%> (-0.03%) ⬇️
plugins-azure-durable-functions 25.74% <ø> (ø)
plugins-azure-event-hubs 25.90% <ø> (ø)
plugins-azure-service-bus 25.26% <ø> (ø)
plugins-bullmq 44.27% <ø> (-0.22%) ⬇️
plugins-cassandra 37.73% <ø> (-0.23%) ⬇️
plugins-cookie 26.96% <ø> (ø)
plugins-cookie-parser 26.75% <ø> (ø)
plugins-crypto 26.73% <ø> (ø)
plugins-dd-trace-api 38.26% <ø> (-0.10%) ⬇️
plugins-express-mongo-sanitize 26.89% <ø> (ø)
plugins-express-session 26.70% <ø> (ø)
plugins-fastify 42.18% <ø> (-0.09%) ⬇️
plugins-fetch 38.35% <ø> (-0.10%) ⬇️
plugins-fs 38.58% <ø> (-0.10%) ⬇️
plugins-generic-pool 25.94% <ø> (ø)
plugins-google-cloud-pubsub 45.49% <ø> (-0.09%) ⬇️
plugins-grpc 40.84% <ø> (-0.09%) ⬇️
plugins-handlebars 26.94% <ø> (ø)
plugins-hapi 40.10% <ø> (-0.10%) ⬇️
plugins-hono 40.43% <ø> (-0.10%) ⬇️
plugins-ioredis 38.43% <ø> (-0.10%) ⬇️
plugins-knex 26.57% <ø> (ø)
plugins-langgraph 38.45% <ø> (-0.10%) ⬇️
plugins-ldapjs 24.43% <ø> (ø)
plugins-light-my-request 26.30% <ø> (ø)
plugins-limitd-client 32.48% <ø> (-0.10%) ⬇️
plugins-lodash 26.03% <ø> (ø)
plugins-mariadb 39.44% <ø> (-0.10%) ⬇️
plugins-memcached 38.14% <ø> (-0.10%) ⬇️
plugins-microgateway-core 39.17% <ø> (-0.10%) ⬇️
plugins-moleculer 40.46% <ø> (-0.09%) ⬇️
plugins-mongodb 39.11% <ø> (-0.09%) ⬇️
plugins-mongodb-core 38.95% <ø> (-0.10%) ⬇️
plugins-mongoose 38.85% <ø> (-0.12%) ⬇️
plugins-multer 26.70% <ø> (ø)
plugins-mysql 39.14% <ø> (-0.10%) ⬇️
plugins-mysql2 39.23% <ø> (-0.10%) ⬇️
plugins-node-serialize 27.00% <ø> (ø)
plugins-opensearch 37.59% <ø> (-0.10%) ⬇️
plugins-passport-http 26.76% <ø> (ø)
plugins-postgres 35.45% <0.00%> (-0.14%) ⬇️
plugins-process 26.73% <ø> (ø)
plugins-pug 26.96% <ø> (ø)
plugins-redis 38.86% <ø> (-0.10%) ⬇️
plugins-router 43.16% <ø> (-0.10%) ⬇️
plugins-sequelize 25.55% <ø> (ø)
plugins-test-and-upstream-amqp10 38.45% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-amqplib 44.15% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-apollo 39.08% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-avsc 38.52% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-bunyan 33.80% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-connect 40.75% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-graphql 40.10% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-koa 40.34% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-protobufjs 38.75% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-rhea 44.18% <ø> (-0.07%) ⬇️
plugins-undici 39.07% <ø> (-0.09%) ⬇️
plugins-url 26.73% <ø> (ø)
plugins-valkey 38.13% <ø> (-0.26%) ⬇️
plugins-vm 26.73% <ø> (ø)
plugins-winston 33.99% <ø> (-0.10%) ⬇️
plugins-ws 41.93% <ø> (-0.10%) ⬇️
profiling-macos 40.47% <ø> (-0.10%) ⬇️
profiling-ubuntu 40.59% <ø> (-0.10%) ⬇️
profiling-windows 42.15% <ø> (-0.10%) ⬇️
serverless-azure-functions-client 25.62% <ø> (ø)
serverless-azure-functions-eventhubs 25.62% <ø> (ø)
serverless-azure-functions-servicebus 25.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-prod-us1-6
Copy link
Copy Markdown

datadog-prod-us1-6 bot commented Mar 23, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 0.00%
Overall Coverage: 68.80% (-0.04%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 0e0d07b | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@cbasitodx cbasitodx changed the title Final status tag for mocha feat(test-optimization): create final_status tag on test event for mocha Mar 23, 2026
Copy link
Copy Markdown
Collaborator

@juan-fernandez juan-fernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job! Some nitpick and a comment about test coverage

@juan-fernandez juan-fernandez marked this pull request as ready for review March 27, 2026 13:48
@juan-fernandez juan-fernandez requested a review from a team as a code owner March 27, 2026 13:48
@juan-fernandez
Copy link
Copy Markdown
Collaborator

E2E Test Report: SUCCESS ✅

Tested by: Shepherd Agent (autonomous QA for Datadog Test Optimization)

Test Environment

  • Method: Local testing with mockdog (mock Datadog backend)
  • Revision tested: 2a7d0a59d8f988cde09d1da91f4df5d81acca3e4
  • Playgrounds: express (Mocha, ~1249 tests), decap-cms (Jest, ~1670 tests)

Results

Check Expected Result
test.final_status on mocha spans (no retries) All test spans tagged ✅ 1249/1249
test.final_status absent on master branch Tag is new, not on master ✅ Confirmed
test.final_status with EFD (10 retries per test) Only last execution tagged ✅ 5/55 executions
Intermediate retries NOT tagged No tag on non-final executions ✅ 50/55 untagged
test.final_status value matches final test status pass when test passes ✅ Confirmed
Jest not broken (decap-cms) No regressions ✅ 1670 tests pass

Test Methodology

Express playground (Mocha):

  1. Ran the full Express test suite (./node_modules/.bin/mocha --require test/support/env test/ test/acceptance/) with --dep ddtracejs=sebas_conde/feat/create-final-status-tag-for-mocha and mockdog as backend — 1249 tests, 88 suites captured
  2. Verified all 1249 mocha test spans carry test.final_status tag
  3. Re-ran against master branch — confirmed test.final_status is absent on master (new feature)
  4. Ran a single file (test/app.listen.js, 5 tests) with EFD enabled and all tests marked as "new" — 55 total executions (1 original + 10 EFD retries each), test.final_status set on exactly 1 per test (the final retry), none on the 50 intermediate executions

decap-cms playground (Jest):

  1. Ran full suite with the PR branch — 1670 tests pass, no regressions in Jest instrumentation

Issues Found

  • 4 pre-existing test failures in test/res.format.js (Express 5 + dd-trace router instrumentation incompatibility). These failures appear on both master and the PR branch — not caused by this PR.

This E2E test was performed by Shepherd — autonomous QA agent for Datadog Test Optimization

Copy link
Copy Markdown
Collaborator

@juan-fernandez juan-fernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job! I left some minor comments

Copy link
Copy Markdown
Collaborator

@juan-fernandez juan-fernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great! Almost there 🎉

Copy link
Copy Markdown
Collaborator

@juan-fernandez juan-fernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@cbasitodx cbasitodx merged commit 2bb443c into master Apr 1, 2026
788 checks passed
@cbasitodx cbasitodx deleted the sebas_conde/feat/create-final-status-tag-for-mocha branch April 1, 2026 10:48
@dd-octo-sts dd-octo-sts bot mentioned this pull request Apr 1, 2026
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