pks otel errors

stable

Find the exception behind a production failure: scan recent errors from Application Insights, narrow by app and time window, then pivot on an operation ID.

Author: Poul Kjeldager
Usage: pks otel errors [APP] [options]
Category: infrastructure

Examples

$ pks otel errors

Last hour of exceptions across all apps

$ pks otel errors my-app --since 6h --limit 50

Six hours of exceptions for one app

$ pks otel errors --operation-id abc123

Exceptions tied to one request

$ pks otel errors --format Json

Machine-readable output for jq

pks otel errors queries the exceptions table in Azure Application Insights and prints the most recent exceptions first. It is the first stop when a deployed app misbehaves and you want the stack-level detail without opening the Azure Portal.

1. Prerequisites

  • An Application Insights resource registered with pks. Run pks appinsights init once. It stores the App ID in the global pks config; pks otel errors refuses to run without it.
  • An Azure AD sign-in. Run pks foundry init. The query service exchanges that identity for a token scoped to https://api.applicationinsights.io/.default.
  • Telemetry already flowing. The command reads what the app has emitted; it does not instrument anything.

2. Scan the last hour

Start broad, with no filters at all.

pks otel errors

You get a rounded-border table of up to 20 exceptions from the last hour, newest first, with the exception message and the operation ID of the request that raised it.

Two columns are shortened for the terminal: the message is truncated to 60 characters and the operation ID to 16. That is fine for scanning and wrong for copying — see step 5.

3. Narrow by app and window

The optional positional argument is an application name, matched against the cloud_RoleName dimension. Use it when several apps report into the same Application Insights resource.

pks otel errors my-app --since 6h --limit 50

--since accepts a number with a trailing d, h, or m suffix. An unparseable value falls back to one hour without an error message, so check the value you typed if the window looks wrong.

4. Confirm what was actually queried

pks otel errors is the one command in the group that honors --verbose. It prints the resolved App ID, the resolved time window, and the exact KQL sent to Application Insights before the results.

pks otel errors my-app --since 6h --verbose

Use it whenever the result set surprises you — it separates "no matching telemetry" from "my filter did not mean what I thought".

5. Pivot on an operation ID

Once pks otel traces or a table row gives you an operation ID, pass it back in to isolate the exception raised by that one request.

pks otel errors --operation-id abc123

The filter is an exact match on operation_Id, so a truncated ID from the table will return nothing. Take the full value from JSON output instead.

pks otel errors --format Json

JSON is written compact, straight to standard output, with no ANSI escapes or Spectre.Console markup, so it pipes into jq cleanly.

6. Verify

Run the command with verbose output against a window you know contains an error.

pks otel errors --since 24h --verbose

You should see the App ID and the generated KQL printed first, then a table of exceptions. If you instead see Application Insights is not configured. the prerequisites in step 1 are not met.

Options

FlagDefaultDescription
--since <DURATION>1hTime window, such as 1h, 6h, 24h, or 7d. Unparseable values fall back to one hour.
--limit <COUNT>20Maximum rows returned. Applied as the KQL take clause.
--format <FORMAT>TableOutput format: Table or Json.
--verbose, -vPrint the App ID, the resolved window, and the KQL before the results.
--operation-id <ID>Return only exceptions whose operation_Id matches exactly.

The positional APP argument is optional and filters on the application name.

Troubleshooting

Application Insights is not configured. — the command exits with code 1 and points at pks appinsights init. Run that first.

Not authenticated. Run 'pks foundry init' to sign in. — the App ID is stored but no Azure AD token is available. Sign in with pks foundry init.

Empty table with no error. — check the window with --verbose. A typo in --since silently degrades to one hour, and the app-name argument matches cloud_RoleName exactly.

An operation ID from the table returns nothing. — the table truncates operation IDs to 16 characters. Re-run with --format Json and copy the full value.

Next steps