Railway

Add Obtrace observability to Railway services with environment variables and the SDK.

Railway

Railway services are instrumented by setting environment variables and adding the Obtrace SDK.

Step 1: Set environment variables

Via Railway CLI

railway variables set \
  OBTRACE_API_KEY=obt_live_xxxxx \
  OBTRACE_PLATFORM=railway

Via Railway dashboard

Go to your service → Variables tab → add:

VariableValue
OBTRACE_API_KEYobt_live_...
OBTRACE_PLATFORMrailway

Step 2: Add the SDK

Node.js

npm install @obtrace/sdk-js
import { initNodeSDK } from "@obtrace/sdk-js/node";
 
const sdk = initNodeSDK({
  apiKey: process.env.OBTRACE_API_KEY!,
  serviceName: process.env.RAILWAY_SERVICE_NAME || "my-service",
});

Python

pip install obtrace-sdk
from obtrace_sdk import ObtraceClient, ObtraceConfig
import os
 
client = ObtraceClient(ObtraceConfig(
    api_key=os.environ["OBTRACE_API_KEY"],
    service_name=os.environ.get("RAILWAY_SERVICE_NAME", "my-service"),
))

Go

go get github.com/obtrace/sdk-go
client := obtrace.NewClient(obtrace.Config{
    APIKey:        os.Getenv("OBTRACE_API_KEY"),
    ServiceName:   os.Getenv("RAILWAY_SERVICE_NAME"),
})

Railway metadata

The SDK auto-detects these Railway environment variables when available:

Railway VariableMapped to
RAILWAY_SERVICE_NAMEservice.name
RAILWAY_ENVIRONMENTdeployment.environment
RAILWAY_REPLICA_IDservice.instance.id
RAILWAY_GIT_COMMIT_SHAservice.version
RAILWAY_GIT_BRANCHvcs.branch

OpenTelemetry native export

Railway apps can also export OTLP directly:

railway variables set \
  OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.obtrace.ai \
  OTEL_EXPORTER_OTLP_HEADERS="x-api-key=obt_live_xxxxx"

This works with any OpenTelemetry-instrumented application in any language.

Nesta página