DataDog / test-visibility-github-action

GitHub Action that installs Datadog Test Visibility
Apache License 2.0
3 stars 1 forks source link

Cannot find module '$DD_TRACE_PACKAGE' #2

Closed adamgrieger closed 4 months ago

adamgrieger commented 4 months ago

Environment details (Operating System, Cloud provider, etc): Microsoft's Playwright Docker image running on ubuntu-latest.

Describe what happened: I followed the README instructions for using the GitHub action, and I also included the -r $DD_TRACE_PACKAGE piece for the NODE_OPTIONS env variable. When the action runs, it says Error: Cannot find module '$DD_TRACE_PACKAGE'. However, the output from the Configure Datadog Test Visibility step shows the DD_TRACE_PACKAGE variable. I have also gotten the same error when using a "vanilla" GitHub action instead of running in the Playwright Docker image. Below is the output for the Datadog action and the Playwright tests.

Run datadog/test-visibility-github-action@v1.0.2
Run echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH

Run mkdir -p $GITHUB_WORKSPACE/.datadog
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  5709  100  5709    0     0  32030      0 --:--:-- --:--:-- --:--:-- 32073
added 58 packages in 9s
Run echo "DD_SITE=US1" >> "$GITHUB_ENV"
Run echo "DD_SERVICE=nimbus-ui" >> "$GITHUB_ENV"
  echo "DD_SERVICE=nimbus-ui" >> "$GITHUB_ENV"
  echo "DD_API_KEY=***" >> "$GITHUB_ENV"
  echo "DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER=github" >> "$GITHUB_ENV"
  shell: bash --noprofile --norc -e -o pipefail {0}
  env:
    DD_CIVISIBILITY_ENABLED: true
    DD_CIVISIBILITY_AGENTLESS_ENABLED: true
    DD_ENV: ci
    DD_TRACE_PACKAGE: /github/workspace/.datadog/lib/node_modules/dd-trace/ci/init
    DD_TRACER_VERSION_JS: 5.18.0
    DD_SITE: US1
Run yarn playwright test
node:internal/modules/cjs/loader:1148
  throw err;
  ^
Error: Cannot find module '$DD_TRACE_PACKAGE'
Require stack:
- internal/preload
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at internalRequire (node:internal/modules/cjs/loader:176:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1563:5)
    at loadPreloadModules (node:internal/process/pre_execution:730:5)
    at setupUserModules (node:internal/process/pre_execution:206:5)
    at prepareExecution (node:internal/process/pre_execution:159:5)
    at prepareMainThreadExecution (node:internal/process/pre_execution:54:10)
    at node:internal/main/run_main_module:11:19 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}
Node.js v20.15.0
Error: Process completed with exit code 1.

Describe what you expected: I would expect the Playwright tests to be able to find $DD_TRACE_PACKAGE especially since it shows as populated in the previous CI step.

Steps to reproduce the issue:

name: Playwright Tests

on: workflow_dispatch

jobs:
  playwright:
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/playwright:v1.45.1-jammy
      env:
        # Redacted
    steps:
      - uses: actions/checkout@v4

      - name: Enable Corepack
        run: corepack enable

      - uses: actions/setup-node@v4
        with:
          node-version: lts/*
          cache: yarn

      - name: Install dependencies
        run: yarn install --immutable

      - name: Configure Datadog Test Visibility
        uses: datadog/test-visibility-github-action@v1.0.2
        with:
          languages: js
          service-name: nimbus-ui
          api-key: ${{ secrets.DD_API_KEY }}
          site: US1

      - name: Run Playwright tests
        shell: bash
        run: yarn playwright test
        env:
          HOME: /root
          NODE_OPTIONS: -r $DD_TRACE_PACKAGE

      - uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 30

Thanks!

adamgrieger commented 4 months ago

I think I found the issue. Instead of doing the following:

NODE_OPTIONS: -r $DD_TRACE_PACKAGE

I think it needs to be:

NODE_OPTIONS: -r ${{ env.DD_TRACE_PACKAGE }}

This was able to expand the variable correctly into the Node options. I suppose the ask of this ticket can be to update the README to reflect this?

nikita-tkachenko-datadog commented 4 months ago

Hi @adamgrieger, thank you for reporting this! Indeed, there was an error in the documentation, which is now fixed.