|Docs

railway trace

Manage tracing for the services of an environment and inspect their traces. railway trace changes the same settings as the Tracing setup panel on the Traces page and lists the same traces.

Note: Tracing is a preview feature under active development.

Usage

railway trace <COMMAND> [OPTIONS]

Aliases

  • railway traces
  • railway tracing

Subcommands

SubcommandAliasesDescription
enableTurn tracing on for a service in the environment, or for every service with --all
disableTurn tracing off for a service in the environment, or for every service with --all
statusShow tracing settings and when spans were last exported
listlsList traces, newest first
getshowShow the spans of one trace as a tree

Options

These options apply to every subcommand:

FlagDescription
-s, --service <SERVICE>Service name or ID (defaults to the linked service)
-e, --environment <ENV>Environment to use (defaults to the linked environment)
-p, --project <PROJECT_ID>Project to use (defaults to the linked project)
--jsonOutput in JSON format

Tracing is set per service and environment, so every subcommand works in one environment: the linked one, or the one you pass with --environment. When you pass --project, pass --environment as well.

Changing tracing needs a user or workspace token. A project token set as RAILWAY_TOKEN can run status, list, and get, but not enable or disable.

Examples

Show tracing status

railway trace status

Prints, for the linked service in the linked environment, whether it's traced, whether automatic instrumentation is on and active, and when the edge and the app last exported a span.

Show status for every service

railway trace status --all

Enable tracing for a service

railway trace enable --service api

Turns tracing on for the service in the linked environment. The edge starts tracing requests to the service's domains within seconds. An app that runs an OpenTelemetry SDK gets the provided variables on its next deploy.

Enable tracing with automatic instrumentation

railway trace enable --auto-instrument

Turns on tracing and automatic instrumentation for the service in one step. Railway instruments the running processes within about a minute, with no redeploy.

Enable tracing for every service in an environment

railway trace enable --all --environment staging

Turns tracing on for every service in staging. Add --auto-instrument to switch automatic instrumentation on for all of them as well.

Disable tracing for a service

railway trace disable

Turns tracing off for the linked service in the linked environment. Add --auto-instrument to turn automatic instrumentation off with it, or --all to turn tracing off for every service in the environment.

List recent traces

railway trace list --since 30m --errors

Lists traces of the linked service from the last 30 minutes that contain at least one span with an error status, newest first. Each row shows when the trace started, its duration, the number of spans and errors, the root span, and the trace ID.

List traces across the environment with a filter

railway trace list --all --filter '@http.route:/api/users @duration:>500'

--all lists traces of every service in the environment. --filter takes the same syntax as the Traces page and railway logs: keywords, @field:value pairs, AND, OR, and - for negation. See Search traces for the built-in fields.

Show one trace

railway trace get 4bf92f3577b34da6a3ce929d0e0e4736

Prints every span of the trace as an indented tree, with each span's name, the component and service that exported it, its duration, and its status. Get the ID from railway trace list, from the x-railway-trace-id response header, or from the Traces page.

JSON output

railway trace list --json
railway trace get 4bf92f3577b34da6a3ce929d0e0e4736 --json

list --json prints one trace summary per line and get --json one span per line, as newline-delimited JSON like railway logs --json. Each span includes its attributes, resource attributes, events, and links. status, enable, and disable print a single JSON document with the environment and the state of each service.

Options for

FlagDescription
--auto-instrumentAlso turn on automatic instrumentation for the service
-a, --allChange every service in the environment instead of one. Conflicts with --service

Options for

FlagDescription
--auto-instrumentAlso turn off automatic instrumentation for the service
-a, --allChange every service in the environment instead of one. Conflicts with --service

Options for

FlagDescription
-a, --allShow every service in the environment. Conflicts with --service

Options for

FlagDescription
-a, --allList traces of every service in the environment. Conflicts with --service
-f, --filter <QUERY>Filter expression over spans, for example @status:error @http.route:/api/users
--errorsOnly traces with an error span. Adds @status:error to the filter
-S, --since <TIME>Start of the time window. Relative (30m, 2h, 1d) or ISO 8601. Defaults to 1h
-U, --until <TIME>End of the time window, same formats as --since. Defaults to now
-n, --limit <N>Maximum number of traces to return, from 1 to 500. Defaults to 100

Options for

Argument or flagDescription
<TRACE_ID>W3C trace ID, 32 hexadecimal characters. Required
--max-spans <N>Maximum number of spans to return, oldest first. Defaults to 1000, at most 2000