# Investigate application errors

[Read this page in HTML](https://www.scopedb.io/docs/guides/investigate-application-errors)

A checkout release starts producing payment errors. Is every payment method affected, or is the regression isolated to a single gateway?

In this guide, you run a checkout simulator that streams structured application logs into ScopeDB through an official SDK (JavaScript, Go, or Rust). While the simulator continuously appends request outcomes in the background, you use Console **Query** and **Explore** to verify the total request population, break down failure rates across `(release, gateway)` pairs, and inspect the nested request context behind individual timeouts. Across every cycle, the repeating signature is **a 66.7% timeout rate on release 1.9 credit-card payments, with bank transfers and release 1.8 unaffected**.

Allow about 15 minutes after workspace setup. Each cycle simulates 12 payment attempts and repeats until you press **Ctrl+C**.

## 1. Connect the sample application

You need a ready [ScopeDB Cloud workspace](https://console.scopedb.cloud), one of the supported runtimes below, Git, and a terminal (macOS, Linux, or WSL). Use a test workspace: the simulator creates `guide_logs.requests` and continuously appends logs in the default `scopedb` database.

In Console, open **Home** in your workspace and copy **ScopeDB API**.

[![Light-mode Console Home page for Northstar Analytics, showing the workspace connection bar with the example API address ap-southeast-1.aws.scopedb.cloud and Create API key.](https://www.scopedb.io/content/docs/console/connect.jpg "Find your workspace connection")](https://www.scopedb.io/content/docs/console/connect.jpg)

Copy the ScopeDB API address from your own workspace, then choose Create API key. The account and address shown are demonstration values.

Choose **Create API key**, give it a name such as `event-tutorial`, and choose an expiration. Select **Create Key** and copy the one-time secret. You can follow the [connection walkthrough](https://www.scopedb.io/docs/guides/connect-to-scopedb.md) for additional setup details.

[![Light-mode Create API Key dialog with the name event-tutorial and a 90-day expiration.](https://www.scopedb.io/content/docs/console/api-key-create.jpg "Create a tutorial API key")](https://www.scopedb.io/content/docs/console/api-key-create.jpg)

Give the key a recognizable name, choose an expiration, and select Create Key. Save the secret when it appears.

Export the endpoint and API key in the terminal where you will run the simulator:

```bash
export SCOPEDB_ENDPOINT="https://<endpoint>"
export SCOPEDB_API_KEY="<api-key>"
```

Keep credentials in your local environment, outside source control. Your Console browser sign-in does not authenticate local SDK processes.

Clone the [Demo Scene repository](https://github.com/scopedb/demo-scene) and enter the `application-logs/js` directory (or the Go or Rust directory from the table below):

```bash
git clone https://github.com/scopedb/demo-scene.git scopedb-demos
cd scopedb-demos/application-logs/js
npm ci
```

All three language implementations write identical rows to `guide_logs.requests`, so every query in this guide works unchanged across runtimes:

| SDK        | Version | Runtime             | Directory               | Start command | Single-cycle check                                             |
| ---------- | ------- | ------------------- | ----------------------- | ------------- | -------------------------------------------------------------- |
| JavaScript | 0.3.0   | Node.js 20 or later | `application-logs/js`   | `npm start`   | `SCOPEDB_DEMO_RUN=checkout-check-js npm start -- --cycles 1`   |
| Go         | 0.7.0   | Go 1.26 or later    | `application-logs/go`   | `go run .`    | `SCOPEDB_DEMO_RUN=checkout-check-go go run . -cycles 1`        |
| Rust       | 0.4.2   | Rust 1.91 or later  | `application-logs/rust` | `cargo run`   | `SCOPEDB_DEMO_RUN=checkout-check-rust cargo run -- --cycles 1` |

## 2. Stream structured request logs

The simulator writes to `scopedb.guide_logs.requests`, which uses four typed envelope columns (`time`, `service`, `level`, `message`) and a semi-structured `var` object column for request-specific context (`run_id`, `request_id`, `release`, `gateway`). Its [Catalog table definition](https://www.scopedb.io/docs/api-reference/catalog.md) is:

```json
{
  "name": "requests",
  "columns": [
    { "name": "time", "data_type": "timestamp" },
    { "name": "service", "data_type": "string" },
    { "name": "level", "data_type": "string" },
    { "name": "message", "data_type": "string" },
    { "name": "var", "data_type": "object" }
  ]
}
```

On startup, the simulator ensures `guide_logs.requests` exists before streaming logs, or you can apply the definition ahead of time with [`scope catalog`](https://www.scopedb.io/docs/guides/scopedb-cli/catalog.md) or in Console **Data**.

In each cycle, the simulator executes three payment attempts for every combination of release (`1.8`, `1.9`) and gateway (`bank_transfer`, `credit_card`). Two of the three `credit_card` attempts on release `1.9` time out, and the request handler records both successful and failed attempts with the same log structure:

```js
const log = {
  time: new Date().toISOString(), service: "checkout", level, message,
  var: { run_id: runId, request_id: requestId, release, gateway },
};
console.log(JSON.stringify(log));
await stream.send(log);
```

Start the producer with `SCOPEDB_DEMO_RUN=checkout-first` and leave this terminal running while you work in Console:

```bash
SCOPEDB_DEMO_RUN=checkout-first npm start
```

Each cycle appends 10 successful requests and 2 `credit_card` timeouts, flushing buffered rows roughly once per second. Press **Ctrl+C** when you finish the walkthrough; the program flushes in-flight logs before exiting and prints the total committed count.

## 3. Compare releases and gateways

Open **Query** in Console and verify that requests are arriving for `checkout-first`:

```scopeql
FROM guide_logs.requests
WHERE var['run_id']::string = 'checkout-first'
AGGREGATE count() AS requests,
    sum(if(level = 'error', 1, 0)) AS errors
```

| Stage                        | requests | errors |
| ---------------------------- | -------- | ------ |
| After 1 cycle                | 12       | 2      |
| After 95 cycles (continuous) | 1140     | 190    |

Recording both successful (`level = 'info'`) and failed (`level = 'error'`) attempts in the same table lets you compute true failure rates instead of raw error counts. Click **Run** again after a few seconds to watch `requests` and `errors` advance together.

Next, extract `var['release']::string` and `var['gateway']::string` directly from the semi-structured `var` column and compare the error rate across all four `(release, gateway)` combinations:

```scopeql
FROM guide_logs.requests
WHERE var['run_id']::string = 'checkout-first'
SELECT level, var['release']::string AS release, var['gateway']::string AS gateway
GROUP BY release, gateway
AGGREGATE count() AS requests,
    sum(if(level = 'error', 1, 0)) AS errors
SELECT *, round(100.0 * errors / requests, 1) AS error_percent
ORDER BY release, gateway
```

After a single 12-request cycle, each `(release, gateway)` group has 3 requests, and only `1.9` + `credit_card` exhibits failures:

| release | gateway        | requests | errors | error\_percent |
| ------- | -------------- | -------- | ------ | -------------- |
| 1.8     | bank\_transfer | 3        | 0      | 0.0            |
| 1.8     | credit\_card   | 3        | 0      | 0.0            |
| 1.9     | bank\_transfer | 3        | 0      | 0.0            |
| 1.9     | credit\_card   | 3        | 2      | 66.7           |

As the simulator continues running across cycles (such as 95 cycles / 285 requests per group in the screenshot below), the `66.7%` failure rate remains isolated to `1.9` + `credit_card` while `bank_transfer` and release `1.8` stay at `0.0%`:

[![Light-mode Console Query view in the Northstar workspace showing 4 release and gateway groups across 285 requests each, with 190 errors and a 66.7% error rate isolated to release 1.9 credit\_card.](https://www.scopedb.io/content/docs/application-errors/gateway-comparison.jpg "Compare failure rates across releases and gateways")](https://www.scopedb.io/content/docs/application-errors/gateway-comparison.jpg)

Grouping by var\['release'] and var\['gateway'] isolates the 66.7% timeout rate to release 1.9 credit\_card while release 1.8 and bank\_transfer remain at 0.0%.

## 4. Inspect failed requests in Query and Explore

Once you isolate the failing slice (`release = '1.9'` and `gateway = 'credit_card'`), retrieve the individual error logs and their correlation IDs (`request_id`):

```scopeql
FROM guide_logs.requests
WHERE var['run_id']::string = 'checkout-first' AND level = 'error'
SELECT time, message, var['request_id']::string AS request_id, var
ORDER BY time, request_id
LIMIT 10
```

Click the `var` cell in row 1 (`req-08`) to open **Row details**. The side panel displays the timestamp, error message, promoted `request_id`, and formatted `var` JSON payload (`gateway: "credit_card"`, `release: "1.9"`, `request_id: "req-08"`, `run_id: "checkout-first"`) so you can copy `request_id` straight into your downstream trace or gateway logs.

[![Light-mode Console Query view showing failed checkout requests and the Row details drawer open on req-08, displaying the formatted var JSON object with gateway credit\_card, release 1.9, request\_id req-08, and run\_id checkout-first.](https://www.scopedb.io/content/docs/application-errors/request-details.jpg "Inspect a failed request in Row details")](https://www.scopedb.io/content/docs/application-errors/request-details.jpg)

Click any var cell to open Row details and inspect the full semi-structured context for that request.

You can also filter and inspect the same table visually without writing ScopeQL. Open **Data**, expand `scopedb` → `guide_logs`, and select `requests`. In **Explore**, click **Filter**, add `level = error`, and click **Run**:

[![Light-mode Console Data Explore view for scopedb.guide\_logs.requests with the level = error filter chip applied and matching timeout records listed.](https://www.scopedb.io/content/docs/application-errors/explore-errors.jpg "Filter failed requests in Data Explore")](https://www.scopedb.io/content/docs/application-errors/explore-errors.jpg)

In Data > Explore, filter requests by level = error and click Run to browse matching timeout records visually.

Click any record in **Explore** to open its **Row details** drawer, or switch from **Records** to **Bar** or **Top list** to group filtered events interactively (see [Explore in Console](https://www.scopedb.io/docs/guides/console-explore.md)).

## 5. Apply this pattern to your own services

When adapting this workflow to production services:

* **Emit one structured outcome event per request**: Record both successful and failed requests with a stable timestamp, service name, severity level, and message so you can calculate true error rates (`errors / requests`) rather than raw error counts.
* **Keep evolving dimensions in `var`**: Store deployment tags (`release`, `region`) and business dimensions (`gateway`, `request_id`) in an `object` column first. ScopeDB automatically maintains a path index on `object` columns, and you can promote hot paths to [computed columns](https://www.scopedb.io/docs/reference/computed-columns.md) later as your queries stabilize (see [Model event data](https://www.scopedb.io/docs/guides/model-flexible-events.md)).
* **Manage schemas declaratively before deployment**: Create and update tables in CI/CD or ahead of rollout with [`scope catalog`](https://www.scopedb.io/docs/guides/scopedb-cli/catalog.md), the [Catalog HTTP API](https://www.scopedb.io/docs/api-reference/catalog.md), or the SDK `.catalog().apply(...)` methods (`JavaScript`, `Go`, `Rust`) so request handlers only append rows.
* **Flush on shutdown**: Share a single SDK append stream across your server process and flush buffered logs during graceful shutdown (see the [JavaScript SDK](https://www.scopedb.io/docs/guides/sdks/nodejs.md#handle-errors), [Go SDK](https://www.scopedb.io/docs/guides/sdks/go.md), and [Rust SDK](https://www.scopedb.io/docs/guides/sdks/rust.md) guides).

Continue with [Model event data](https://www.scopedb.io/docs/guides/model-flexible-events.md) when fields evolve, [Query events](https://www.scopedb.io/docs/guides/query-events.md) for more ScopeQL investigation patterns, or [Set data retention](https://www.scopedb.io/docs/guides/data-retention.md) to manage log lifecycle.

## Troubleshooting

| Symptom                  | Next step                                                                                                                     |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
| `401` or `403`           | Verify `SCOPEDB_ENDPOINT`, `SCOPEDB_API_KEY`, key expiration, and the target workspace.                                       |
| Run ID already has logs  | Query that run ID first, or start a fresh run with a new `SCOPEDB_DEMO_RUN` value and update the `run_id` filter in Query.    |
| No rows in Query         | Confirm the simulator is running in the same workspace, check the `run_id` filter, and wait \~1 second for the stream flush.  |
| No records in Explore    | Check the active table and `level = error` filter, then widen or clear any active time-range filter.                          |
| Timeout or failed append | Check the existing row count for `run_id` before retrying; start a new `SCOPEDB_DEMO_RUN` if you want a clean cycle baseline. |

## Related contents

* [JavaScript SDK](https://www.scopedb.io/docs/guides/sdks/nodejs.md)

* [Query events](https://www.scopedb.io/docs/guides/query-events.md)

* [Explore in Console](https://www.scopedb.io/docs/guides/console-explore.md)
