Skip to content

How to Setup Sentry Integration for SyRF Services

Overview

The SyRF CI/CD pipeline is configured to automatically:

  • Web Service: Upload sourcemaps and create releases in Sentry
  • .NET Services (API, Project Management, Quartz): Create releases with commit association

This enables:

  • Readable stack traces for minified JavaScript errors
  • "Suspect Commits" feature to identify which commit introduced a bug
  • Release tracking and health monitoring

Prerequisites

  • Admin access to the GitHub repository
  • Admin access to the Sentry organization (camarades)

Sentry Projects

Service Sentry Project Release Format
Web syrf-web syrf-web@{version}
API syrf-api syrf-api@{version}
Project Management syrf-project-management syrf-projectmanagement@{version}
Quartz syrf-quartz syrf-quartz@{version}

Setup Steps

1. Generate Sentry Auth Token

  1. Log into Sentry at https://sentry.io
  2. Navigate to SettingsAuth Tokens
  3. Click Create New Token
  4. Configure the token:
  5. Name: syrf-ci-cd
  6. Scopes (required):
    • project:releases - Create and finalize releases
    • project:write - Upload sourcemaps
    • org:read - Read organization details
  7. Click Create Token
  8. Copy the generated token (you won't be able to see it again)

2. Add Token to GitHub Repository Secrets

  1. Navigate to the GitHub repository: https://github.com/camaradesuk/syrf
  2. Go to SettingsSecrets and variablesActions
  3. Click New repository secret
  4. Create the secret:
  5. Name: SENTRY_AUTH_TOKEN
  6. Value: Paste the token from step 1.6
  7. Click Add secret

How It Works

Web Service (Angular)

The build-web-artifacts job in CI/CD:

- name: Upload sourcemaps to Sentry
  env:
    SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
    SENTRY_ORG: camarades
    SENTRY_PROJECT: syrf-web
  run: |
    # Release name must match Angular SDK: syrf-web@{version}
    RELEASE="syrf-web@${VERSION}"

    # Create release and associate commits
    pnpm exec sentry-cli releases new "${RELEASE}"
    pnpm exec sentry-cli releases set-commits "${RELEASE}" --auto

    # Inject debug IDs and upload sourcemaps
    pnpm exec sentry-cli sourcemaps inject ./dist/browser/
    pnpm exec sentry-cli sourcemaps upload --release "${RELEASE}" ./dist/browser/

    # Finalize release
    pnpm exec sentry-cli releases finalize "${RELEASE}"

The Angular app initializes Sentry in main.ts with:

  • DSN from configuration
  • Release version matching CI/CD release name
  • Browser tracing integration
  • Environment-specific settings

.NET Services

The create-sentry-releases job creates releases after Docker builds:

- name: Create Sentry releases for .NET services
  env:
    SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
    SENTRY_ORG: camarades
  run: |
    sentry-cli releases new "syrf-api@${VERSION}" --project syrf-api
    sentry-cli releases set-commits "syrf-api@${VERSION}" --auto --project syrf-api
    sentry-cli releases finalize "syrf-api@${VERSION}" --project syrf-api

.NET services configure Sentry in HostExtensions.cs:

o.Release = gitVersion.ReleaseName;  // Format: servicename@semver
o.Environment = runtimeEnvironment;
o.TracesSampleRate = customSentryConfig.TracingSampleRate;

Verification

After setting up the token:

  1. Push a change that triggers a service build
  2. Check the GitHub Actions logs:
  3. Web: Look for "Upload sourcemaps to Sentry" step in build-web-artifacts
  4. .NET: Look for "Create Sentry releases" step in create-sentry-releases
  5. Check Sentry dashboard:
  6. Navigate to Releases in each project
  7. Verify the new release appears with associated commits

Troubleshooting

Token Not Working

  • Verify the token has the correct scopes (project:releases, project:write, org:read)
  • Check the token hasn't expired
  • Ensure the secret name is exactly SENTRY_AUTH_TOKEN

Sourcemaps Not Uploading (Web)

  • Check the Sentry organization name matches (camarades)
  • Check the Sentry project name matches (syrf-web)
  • Verify the dist folder structure (dist/browser/)
  • Check that debug IDs are being injected (look for sentry-cli sourcemaps inject output)

Commits Not Associating

  • Ensure fetch-depth: 0 is set in the checkout step
  • Verify the repository has proper git history
  • Check that the release name matches what the SDK sends

Runtime Sourcemap Removal (Web)

Sourcemaps are included in the Docker image but removed at runtime in production:

  • The remove-sourcemaps.sh script checks SPA__RuntimeEnvironment
  • If set to production, all .map files are deleted at container startup
  • In dev/staging environments, sourcemaps remain for debugging

.NET Release Names Not Matching

The .NET SDK gets the release name from GitVersion.ReleaseName:

public string ReleaseName => $"{ServiceName}@{SemVer}";

Ensure the CI/CD release creation uses the same format.

Configuration Reference

Web Service (main.ts)

Sentry.init({
  dsn: config.sentryDsn,
  environment: config.runtimeEnvironment,
  release: config.releaseVersion,
  integrations: [Sentry.browserTracingIntegration()],
  tracesSampleRate: 1.0,
  tracePropagationTargets: [...config.protectedUrls],
});

.NET Services (appsettings.json)

{
  "Sentry": {
    "Dsn": "CHANGEME",
    "IncludeRequestPayload": true,
    "SendDefaultPii": true,
    "MinimumBreadcrumbLevel": "Debug",
    "MinimumEventLevel": "Warning",
    "AttachStackTrace": true
  },
  "CustomSentryConfig": {
    "Enabled": true,
    "OpenTelemetryTracing": false,
    "TracingSampleRate": 1.0
  }
}