Docs
Upload Custom Server Logs

Upload Custom Server Logs

Feature Availability: Enterprise Plan Only

To further debug test failures and flakes, it can be useful to correlate server-side logs with a test run to understand what's happening on the backend when a test fails.

To do this, you can upload a custom log file at the end of the test run to DeploySentinel, and we'll correlate the backend logs to your test runs and actions.

You can upload logs via the ds upload-logs command.

Example:

npx ds upload-logs logs.txt

You'll need to ensure that the ds upload-logs command is run on the same machine and within the same directory as your test command was run from, as it needs access to metadata files written by the debugger.

The log file must contain a timestamp on each line, recommended to be in ISO 8601 format, but can be any format accepted by Node.js's Date.parse (opens in a new tab) function.

Example valid log line: [start:api] 2023-02-07T06:52:07.172Z POST 200 /testData/seed 4.691

Note: This is only an example, log lines do not have to be strictly formatted in this manner.

backend logs

Github Actions Example

To capture logs, you'll likely want to push the output of the server command to a file, and background the server. In the below example, we'll run yart start:ci, pipe the logs to logs.txt via > logs.txt and then end the command with & to background the server and logs so we can continue to the next npx ds run to start running the test.

- name: Run Cypress Test
  working-directory: ./tests/e2e
  run: |
    yarn start:ci > logs.txt &
    npx ds run --parallel --record --headless
  env:
    CYPRESS_DEPLOYSENTINEL_KEY: ${{ secrets.DEPLOYSENTINEL_KEY }}
 
- name: Upload Logs
  working-directory: ./tests/e2e
  run: npx ds upload-logs logs.txt
  env:
    CYPRESS_DEPLOYSENTINEL_KEY: ${{ secrets.DEPLOYSENTINEL_KEY }}

Github Actions + Docker Example

Similar to the example above, we run a command to forward logs into a file, and background it with the & bash operator. We have to specify --timestamps to docker compose logs to ensure that timestamps will be attached to each log line automatically.

If you run your tests in a specific directory (ex. ./e2e in the example below), you'll need to make sure to run the ds upload-logs command from the same directory.

- name: Spin up services
  run: docker compose up -d
 
- name: Capture Logs
  run: docker compose logs --timestamps --follow > logs.txt &
 
- name: Run Tests
  working-directory: ./e2e
  run: npx ds run --parallel --record --headless
  env:
    CYPRESS_DEPLOYSENTINEL_KEY: ${{ secrets.DEPLOYSENTINEL_KEY }}
 
- name: Upload Logs
  working-directory: ./e2e
  run: npx ds upload-logs ../logs.txt
  env:
    CYPRESS_DEPLOYSENTINEL_KEY: ${{ secrets.DEPLOYSENTINEL_KEY }}