Go
Send errors, structured logs and linked spans from Go.
Prepare the application
Use the template's examples/go/ directory. Set SENTRY_DSN in the runtime environment using the private DSN. The pinned SDK version is 0.35.0, from go.mod.
Run in the same Railway environment as the template, or use a locally reachable installation. A laptop cannot reach the private Railway listener through railway run.
Run the example
From the template repository root:
cd examples/go
go run .Example source
This is the included main.go, reproduced without changes.
package main
import (
"context"
"fmt"
"github.com/getsentry/sentry-go"
"os"
"time"
)
func main() {
dsn := os.Getenv("SENTRY_DSN")
if dsn == "" {
panic("Set SENTRY_DSN first")
}
if err := sentry.Init(sentry.ClientOptions{
Dsn: dsn, EnableTracing: true, TracesSampleRate: 1,
EnableLogs: true, SendDefaultPII: false,
}); err != nil {
panic(err)
}
tx := sentry.StartTransaction(context.Background(), "railway-example",
sentry.WithOpName("task"))
child := tx.StartChild("work", sentry.WithDescription("example-work"))
sentry.NewLogger(child.Context()).Info().Emit("Railway structured log from Go")
sentry.CaptureException(fmt.Errorf("Railway error example from Go"))
child.Finish()
tx.Finish()
if !sentry.Flush(10 * time.Second) {
panic("Telemetry flush timed out")
}
}Verify in Sentry
Open Issues, Logs and Traces for the same project and environment. Look for Railway error example from Go, Railway structured log from Go and railway-example. Confirm the child span belongs to its parent.
The sample uses full trace sampling for verification. Choose sampling for your workload. A completed flush does not prove server indexing. Use Troubleshooting if any telemetry type is missing.