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")
	}
}
