The Services Change Report can be used in any GitHub workflow where taking a Snapshot might provide needed information for next steps. For example, it can be very helpful to have context when issues are being debugged. This example shows how to use it to capture a Snapshot anytime an issue in GitHub is labeled as a bug.

Check out the Services Change Report repo for other examples!

This example:

  • Runs when an issue is labeled.
  • If the issue is labeled as a bug, takes a snapshot of services in the current SHA.
  • Stores that snapshot locally.
  • Reports a summary of the snapshot, with links into Lightstep to begin investigation.

Here’s the full example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
name: Attach Lightstep Snapshot to Issue

on:
  workflow_dispatch:
  issues:
    types: [labeled]

jobs:
  add_snapshot_to_issue:
    runs-on: ubuntu-latest
    name: Take Snapshot
    # Run this if an issue has the label 'bug'
    if: contains(github.event.issue.labels.*.name, 'bug')

    steps:
      # Check out the repo to read configuration 
      # from the `.lightstep.yml` file in the repo root directory.
      - name: 🛎️ Checkout
        uses: actions/checkout@v2

      - name: 📸 Take Lightstep Snapshot
        id: take-lightstep-snapshot
        uses: lightstep/lightstep-action-snapshot@v2
        # Pass in partner API token integrations
        env:
          ROLLBAR_API_TOKEN: ${{ secrets.ROLLBAR_API_TOKEN }}
          PAGERDUTY_API_TOKEN: ${{ secrets.PAGERDUTY_API_TOKEN }}
        with:
          lightstep_snapshot_query: '"github.sha" IN ("${{ github.sha }}")'

      - name: Wait for Snapshot to Complete
        run: sleep 240

      - name: Cache Snapshots
        id: cache-snapshots
        uses: actions/cache@v2
        with:
          path: /tmp/lightstep
          key: ${{ steps.take-lightstep-project.outputs.lightstep_project }}-snapshots

      - name: Snapshot Summary
        id: lightstep-snapshot-summary
        uses: lightstep/lightstep-action-snapshot@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          lightstep_api_key: ${{ secrets.LIGHTSTEP_API_TOKEN }}
          lightstep_snapshot_id: ${{ steps.take-lightstep-snapshot.outputs.lightstep_snapshot_id }} 
          # If your project has lots of services, you can filter the output
          # to a subset. This is useful for monorepos.
          lightstep_service_filter: web,iOS,android,inventory

In the next step, you’ll learn how to use the Services Change Report to warn you of best practice violations in committed code.


What Did We Learn?

  • You can use the Services Change Report in any GitHub workflow where it makes sense to capture before/after performance information.