Skip to content

Commit

Permalink
Chore: add CI step to create and upload sourcemaps to unminify RUM er…
Browse files Browse the repository at this point in the history
…rors in Datadog (#2509)

* Webpack config to create source maps to upload to Datadog

* GHA to create and upload sourcemaps for unminified RUM error logs in Datadog

* Add logic to only generate & upload sourcemaps for datadog GHA on push events to main
  • Loading branch information
heatlikeheatwave authored Jul 12, 2024
1 parent b285d77 commit 68f234e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/upload-sourcemaps-to-datadog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This GitHub Actions workflow is responsible for creating and uploading sourcemaps to Datadog to unminify Real User Monitoring (RUM) error logs. It runs on the `main` branch whenever a push event occurs.

# This job runs on an `ubuntu-latest` runner and consists of the following steps:

# 1. **Checkout code**: Checks out the code from the repository using the `actions/checkout` action.
# 2. **Set up Node.js**: Sets up Node.js using the `actions/setup-node` action with Node.js version 20.
# 3. **Install Dependencies**: Installs the project dependencies using the `npm ci` command.
# 4. **Build sourcemaps**: Builds the sourcemaps using the `npm run build` command.
# 5. **Upload sourcemaps to Datadog**: Uploads the sourcemaps to Datadog using the `datadog-ci` command. It sets the necessary environment variables (`DATADOG_API_KEY` and `LATEST_SHA`) and specifies the required options (`--service`, `--dry-run`, `--release-version`, `--minified-path-prefix`).
# Note: The values for `DATADOG_API_KEY` and `LATEST_SHA` are retrieved from the repository secrets and the current commit SHA, respectively.
# 6. **Clean up build**: Cleans up the build by removing the `.next` directory.
name: Create and Upload Sourcemaps to Datadog

on:
push:
branches:
- main

jobs:
build-and-upload:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Set up Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20

- name: Install Dependencies
run: npm ci

- name: Build sourcemaps
env:
GENERATE_SOURCEMAPS: true
GITHUB_TOKEN: ${{ secrets.CI_GH_TOKEN }}
run: |
npm run build
- name: Upload sourcemaps to Datadog
env:
DATADOG_API_KEY: '${{ secrets.DATADOG_API_KEY }}'
LATEST_SHA: ${{ github.sha }}
run: |
output=$(npx @datadog/datadog-ci sourcemaps upload .next/static/ --service=developer.hashicorp.com --release-version=$LATEST_SHA --minified-path-prefix=https://developer.hashicorp.com/_next/static/ 2>&1)
echo "$output"
echo "$output" >> $GITHUB_STEP_SUMMARY
if [[ "$output" == *"No sourcemaps detected. Did you specify the correct directory?"* ]]; then
echo "Failure: No sourcemaps detected" | tee -a $GITHUB_STEP_SUMMARY
exit 1
else
echo "Success: Sourcemaps were uploaded." >> $GITHUB_STEP_SUMMARY
fi
- name: Clean up build
run: rm -rf .next
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ module.exports = withHashicorp({
],
webpack(config) {
config.plugins.push(HashiConfigPlugin())
if (process.env.GENERATE_SOURCEMAPS === 'true') {
// only generate source maps in GHA .github/workflows/upload-sourcemaps-to-datadog.yml
config.devtool = 'source-map'
}
return config
},
async headers() {
Expand Down

0 comments on commit 68f234e

Please sign in to comment.