ci(workflow): enable datadog traces for the tests (#50619)

### What?

This PR attempts to enable datadog trace integrations to the next.js integration tests if env is configured. With this, datadog can observe each test suite's results and detect some meaningful information (i.e flaky) for us.

However, I wasn't able to verify this works with next.js repo since for some reason CI worker does not pick up the api key in the env (https://vercel.slack.com/archives/C04KC8A53T7/p1685597124894539). Still this won't affect existing workflow, and once enabled I can test it over vercel/turbo repo instead.

Partially resolved WEB-1150.
This commit is contained in:
OJ Kwon 2023-06-05 13:28:22 -07:00 committed by GitHub
parent 78ed08d88e
commit 2b1f0d9351
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 0 deletions

View file

@ -23,6 +23,8 @@ env:
# we build a dev binary for use in CI so skip downloading
# canary next-swc binaries in the monorepo
NEXT_SKIP_NATIVE_POSTINSTALL: 1
DATADOG_API_KEY: ${{ secrets.DATA_DOG_API_KEY }}
DATADOG_TRACE_NEXTJS_TEST: 'true'
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
NEXT_TEST_JOB: 1

View file

@ -41,6 +41,8 @@ env:
# we build a dev binary for use in CI so skip downloading
# canary next-swc binaries in the monorepo
NEXT_SKIP_NATIVE_POSTINSTALL: 1
DATADOG_API_KEY: ${{ secrets.DATA_DOG_API_KEY }}
DATADOG_TRACE_NEXTJS_TEST: 'true'
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
NEXT_TEST_JOB: 1

View file

@ -322,6 +322,23 @@ async function main() {
const shouldRecordTestWithReplay = process.env.RECORD_REPLAY && isRetry
const traceEnv =
process.env.DATADOG_API_KEY && process.env.DATADOG_TRACE_NEXTJS_TEST
? {
DD_API_KEY: process.env.DATADOG_API_KEY,
DD_CIVISIBILITY_AGENTLESS_ENABLED: 'true',
DD_ENV: 'ci',
DD_SERVICE: 'nextjs',
NODE_OPTIONS: !!process.env.DATADOG_API_KEY
? '-r dd-trace/ci/init'
: undefined,
}
: {}
if (traceEnv.DD_API_KEY) {
console.log(`Running test with Datadog tracing enabled`)
}
const child = spawn(
jestPath,
[
@ -341,6 +358,7 @@ async function main() {
stdio: ['ignore', 'pipe', 'pipe'],
env: {
...process.env,
...traceEnv,
RECORD_REPLAY: shouldRecordTestWithReplay,
// run tests in headless mode by default
HEADLESS: 'true',