Skip to content

Latest commit

 

History

History
195 lines (156 loc) · 5.18 KB

File metadata and controls

195 lines (156 loc) · 5.18 KB

Safe Deployment Stack

Combine DevCycle, CodeScene, and Sentry for safe, controlled releases.

Overview

Code Quality          Feature Flags         Error Monitoring
┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  CodeScene   │────▶│  DevCycle    │────▶│   Sentry     │
│              │     │              │     │              │
│ • PR checks  │     │ • Rollouts   │     │ • Errors     │
│ • Code health│     │ • Kill switch│     │ • Performance│
│ • Tech debt  │     │ • A/B tests  │     │ • Alerts     │
└──────────────┘     └──────────────┘     └──────────────┘

Workflow

  1. Before Merge: CodeScene validates code quality
  2. During Rollout: DevCycle controls who sees the feature
  3. After Release: Sentry monitors for errors

Setup

1. GitHub Actions Pipeline

# .github/workflows/safe-deploy.yml
name: Safe Deployment Pipeline

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  # Step 1: Code Quality Gate
  code-quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: CodeScene Delta Analysis
        uses: codescene/codescene-ci-cd@v1
        with:
          api-token: ${{ secrets.CODESCENE_API_TOKEN }}
          project-id: ${{ vars.CODESCENE_PROJECT_ID }}
          fail-on-declining-code-health: true

  # Step 2: Deploy with Feature Flag
  deploy:
    needs: code-quality
    runs-on: ubuntu-latest
    if: github.event_name == 'push'
    steps:
      - uses: actions/checkout@v4

      - name: Deploy Application
        run: |
          # Your deployment command
          npm run deploy

      - name: Create Sentry Release
        uses: getsentry/action-release@v1
        env:
          SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
          SENTRY_ORG: ${{ vars.SENTRY_ORG }}
          SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
        with:
          environment: production
          version: ${{ github.sha }}

      - name: Sync DevCycle References
        uses: DevCycleHQ/feature-flag-code-refs@v1
        with:
          client-id: ${{ secrets.DEVCYCLE_CLIENT_ID }}
          client-secret: ${{ secrets.DEVCYCLE_CLIENT_SECRET }}
          project: your-project

2. Feature Flag Integration

// features/newCheckout.js
import { useVariableValue } from '@devcycle/react-client-sdk';
import * as Sentry from '@sentry/react';

export function CheckoutPage() {
  const useNewCheckout = useVariableValue('new-checkout-flow', false);

  // Track which version users see
  Sentry.setTag('checkout_version', useNewCheckout ? 'v2' : 'v1');

  if (useNewCheckout) {
    return <NewCheckoutFlow />;
  }
  return <LegacyCheckoutFlow />;
}

3. Error Monitoring with Flag Context

// monitoring.js
import * as Sentry from '@sentry/node';
import { getDevCycleClient } from '@devcycle/nodejs-server-sdk';

const devcycle = await getDevCycleClient(process.env.DEVCYCLE_SERVER_SDK_KEY);

export async function captureWithFlags(error, user) {
  // Get all flags for this user
  const variables = await devcycle.allVariables(user);

  Sentry.captureException(error, {
    tags: {
      // Include flag states in Sentry
      ...Object.fromEntries(
        Object.entries(variables).map(([key, v]) => [`flag_${key}`, v.value])
      ),
    },
  });
}

Rollout Strategy

Phase 1: Internal Testing (5%)

// DevCycle targeting: team@company.com only
// CodeScene: Must pass quality gate
// Sentry: Monitor for new errors

Phase 2: Beta Users (20%)

// DevCycle: Enable for beta group
// Sentry: Set up alert for error spike
// Monitor: 24-48 hours

Phase 3: Gradual Rollout (50% → 100%)

// DevCycle: Increase percentage daily
// Sentry: Compare error rates between versions
// CodeScene: Continue monitoring code health

Kill Switch

// If errors spike, disable flag immediately
// DevCycle: Set flag to false for all users
// Sentry: Investigate root cause

Environment Variables

# CodeScene
CODESCENE_API_TOKEN=your_token
CODESCENE_PROJECT_ID=your_project_id

# DevCycle
DEVCYCLE_SERVER_SDK_KEY=server_key
DEVCYCLE_CLIENT_SDK_KEY=client_key

# Sentry
SENTRY_DSN=https://key@sentry.io/project
SENTRY_AUTH_TOKEN=your_token
SENTRY_ORG=your_org
SENTRY_PROJECT=your_project

Monitoring Dashboard

Track these metrics:

Metric Tool Alert Threshold
Code Health CodeScene < 8.0
Error Rate Sentry > 1% increase
P95 Latency Sentry > 500ms
Flag Evaluations DevCycle Anomalies

Best Practices

  1. Gate PRs on code quality: Don't merge declining health
  2. Start small: 5% rollout minimum
  3. Monitor before expanding: 24-48 hours per phase
  4. Include flag state in errors: Debug by version
  5. Have a kill switch: Always be ready to roll back
  6. Clean up after rollout: Remove flag when at 100%