The only tool you need to know what is happening and how to fix it.
Go alertingexception-trackerissue-trackinglogsmetricsmonitoringobservability-platformopen-telemetryotelsession-replaytelemetrytraces
testing progress
dduxe566c20a9646
diff --git a/testing/go/chi/go.mod b/testing/go/chi/go.modnew file mode 100644index 00000000..9383cb43--- /dev/null+++ b/testing/go/chi/go.mod@@ -0,0 +1,21 @@+module testing/go/chi++go 1.25.1++require (+ github.com/go-chi/chi/v5 v5.2.1+ go.tracewayapp.com v0.4.1+ go.tracewayapp.com/tracewaychi v0.0.0-00010101000000-000000000000+)++require (+ github.com/google/uuid v1.6.0 // indirect+ go.tracewayapp.com/tracewayhttp v0.4.1 // indirect+ golang.org/x/sys v0.35.0 // indirect+)++replace go.tracewayapp.com => ../../../../go-client++replace go.tracewayapp.com/tracewaychi => ../../../../go-client/tracewaychi++replace go.tracewayapp.com/tracewayhttp => ../../../../go-client/tracewayhttpdiff --git a/testing/go/chi/go.sum b/testing/go/chi/go.sumnew file mode 100644index 00000000..918295ff--- /dev/null+++ b/testing/go/chi/go.sum@@ -0,0 +1,6 @@+github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=+github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=+golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=+golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=diff --git a/testing/go/chi/main.go b/testing/go/chi/main.gonew file mode 100644index 00000000..5e74a256--- /dev/null+++ b/testing/go/chi/main.go@@ -0,0 +1,175 @@+package main++import (+ "context"+ "encoding/json"+ "errors"+ "fmt"+ "io"+ "net/http"+ "os"+ "time"++ traceway "go.tracewayapp.com"+ tracewaychi "go.tracewayapp.com/tracewaychi"++ "github.com/go-chi/chi/v5"+)++func innerFunction() error {+ return traceway.NewStackTraceErrorf("error from inner function")+}++func middleFunction() error {+ return innerFunction()+}++func outerFunction() error {+ return middleFunction()+}++func writeJSON(w http.ResponseWriter, status int, data interface{}) {+ w.Header().Set("Content-Type", "application/json")+ w.WriteHeader(status)+ json.NewEncoder(w).Encode(data)+}++func main() {+ endpoint := os.Getenv("TRACEWAY_ENDPOINT")+ if endpoint == "" {+ endpoint = "default_token_change_me@http://localhost:8082/api/report"+ }++ port := os.Getenv("PORT")+ if port == "" {+ port = "8080"+ }++ r := chi.NewRouter()++ r.Use(tracewaychi.New(+ endpoint,+ tracewaychi.WithDebug(true),+ tracewaychi.WithOnErrorRecording(tracewaychi.RecordingUrl|tracewaychi.RecordingQuery|tracewaychi.RecordingHeader|tracewaychi.RecordingBody),+ ))++ r.Get("/test-ok", func(w http.ResponseWriter, r *http.Request) {+ writeJSON(w, 200, map[string]string{"status": "ok"})+ })++ r.Get("/test-not-found", func(w http.ResponseWriter, r *http.Request) {+ writeJSON(w, 404, map[string]string{"status": "not-found"})+ })++ r.Get("/test-exception", func(w http.ResponseWriter, r *http.Request) {+ panic("test panic from /test-exception")+ })++ r.Get("/test-error-simple", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureExceptionWithContext(r.Context(), errors.New("simple error without stack"))+ writeJSON(w, 500, map[string]string{"error": "simple error"})+ })++ r.Get("/test-error-stacktrace", func(w http.ResponseWriter, r *http.Request) {+ err := traceway.NewStackTraceErrorf("error with stack trace")+ traceway.CaptureExceptionWithContext(r.Context(), err)+ writeJSON(w, 500, map[string]string{"error": "stacktrace error"})+ })++ r.Get("/test-error-wrapped", func(w http.ResponseWriter, r *http.Request) {+ base := errors.New("base error")+ wrapped := fmt.Errorf("layer 1: %w", base)+ wrapped2 := fmt.Errorf("layer 2: %w", wrapped)+ traceway.CaptureExceptionWithContext(r.Context(), wrapped2)+ writeJSON(w, 500, map[string]string{"error": "wrapped error"})+ })++ r.Get("/test-error-nested", func(w http.ResponseWriter, r *http.Request) {+ err := outerFunction()+ traceway.CaptureExceptionWithContext(r.Context(), err)+ writeJSON(w, 500, map[string]string{"error": "nested error"})+ })++ r.Get("/test-message", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureMessageWithContext(r.Context(), "test message from /test-message")+ writeJSON(w, 200, map[string]string{"status": "message sent"})+ })++ r.Get("/test-message-attributes", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureMessageAttributes("test message with attributes", map[string]string{+ "source": "test-message-attributes",+ "priority": "high",+ })+ writeJSON(w, 200, map[string]string{"status": "message with attributes sent"})+ })++ r.Get("/test-spans", func(w http.ResponseWriter, r *http.Request) {+ dbSpan := traceway.StartSpan(r.Context(), "db.query")+ time.Sleep(50 * time.Millisecond)+ dbSpan.End()++ cacheSpan := traceway.StartSpan(r.Context(), "cache.set")+ time.Sleep(20 * time.Millisecond)+ cacheSpan.End()++ httpSpan := traceway.StartSpan(r.Context(), "http.external_api")+ time.Sleep(100 * time.Millisecond)+ httpSpan.End()++ writeJSON(w, 200, map[string]string{"status": "spans captured"})+ })++ r.Get("/test-task", func(w http.ResponseWriter, r *http.Request) {+ go func() {+ traceway.MeasureTask("background-data-processor", func(twctx context.Context) {+ span := traceway.StartSpan(twctx, "processing")+ time.Sleep(200 * time.Millisecond)+ span.End()+ })+ }()+ writeJSON(w, 200, map[string]string{"status": "task started"})+ })++ r.Get("/test-metric", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureMetric("test.custom_metric", 42.0)+ writeJSON(w, 200, map[string]string{"status": "metric captured"})+ })++ r.Get("/test-attributes", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureExceptionWithAttributes(+ errors.New("exception with custom attributes"),+ map[string]string{+ "user_id": "usr_123",+ "request_id": "req_456",+ "env": "testing",+ },+ nil,+ )+ writeJSON(w, 200, map[string]string{"status": "exception with attributes captured"})+ })++ r.Post("/test-recording", func(w http.ResponseWriter, r *http.Request) {+ bodyBytes, err := io.ReadAll(r.Body)+ if err != nil {+ writeJSON(w, 400, map[string]string{"error": err.Error()})+ return+ }+ defer r.Body.Close()++ var body map[string]interface{}+ if err := json.Unmarshal(bodyBytes, &body); err != nil {+ writeJSON(w, 400, map[string]string{"error": err.Error()})+ return+ }++ action, _ := body["action"].(string)+ if action == "panic" {+ panic("panic triggered by /test-recording")+ }++ writeJSON(w, 200, map[string]interface{}{"status": "ok", "received": body})+ })++ fmt.Printf("Chi server starting on :%s\n", port)+ http.ListenAndServe(":"+port, r)+}diff --git a/testing/go/fasthttp/go.mod b/testing/go/fasthttp/go.modnew file mode 100644index 00000000..a6c27934--- /dev/null+++ b/testing/go/fasthttp/go.mod@@ -0,0 +1,23 @@+module testing/go/fasthttp++go 1.25.1++require (+ github.com/fasthttp/router v1.5.4+ github.com/valyala/fasthttp v1.62.0+ go.tracewayapp.com v0.4.1+ go.tracewayapp.com/tracewayfasthttp v0.0.0-00010101000000-000000000000+)++require (+ github.com/andybalholm/brotli v1.1.1 // indirect+ github.com/google/uuid v1.6.0 // indirect+ github.com/klauspost/compress v1.18.0 // indirect+ github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38 // indirect+ github.com/valyala/bytebufferpool v1.0.0 // indirect+ golang.org/x/sys v0.35.0 // indirect+)++replace go.tracewayapp.com => ../../../../go-client++replace go.tracewayapp.com/tracewayfasthttp => ../../../../go-client/tracewayfasthttpdiff --git a/testing/go/fasthttp/go.sum b/testing/go/fasthttp/go.sumnew file mode 100644index 00000000..bfa7c8ec--- /dev/null+++ b/testing/go/fasthttp/go.sum@@ -0,0 +1,18 @@+github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=+github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=+github.com/fasthttp/router v1.5.4 h1:oxdThbBwQgsDIYZ3wR1IavsNl6ZS9WdjKukeMikOnC8=+github.com/fasthttp/router v1.5.4/go.mod h1:3/hysWq6cky7dTfzaaEPZGdptwjwx0qzTgFCKEWRjgc=+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=+github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=+github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=+github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38 h1:D0vL7YNisV2yqE55+q0lFuGse6U8lxlg7fYTctlT5Gc=+github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38/go.mod h1:sM7Mt7uEoCeFSCBM+qBrqvEo+/9vdmj19wzp3yzUhmg=+github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=+github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=+github.com/valyala/fasthttp v1.62.0 h1:8dKRBX/y2rCzyc6903Zu1+3qN0H/d2MsxPPmVNamiH0=+github.com/valyala/fasthttp v1.62.0/go.mod h1:FCINgr4GKdKqV8Q0xv8b+UxPV+H/O5nNFo3D+r54Htg=+github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=+github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=+golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=+golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=diff --git a/testing/go/fasthttp/main.go b/testing/go/fasthttp/main.gonew file mode 100644index 00000000..5382a48a--- /dev/null+++ b/testing/go/fasthttp/main.go@@ -0,0 +1,169 @@+package main++import (+ "context"+ "encoding/json"+ "errors"+ "fmt"+ "os"+ "time"++ traceway "go.tracewayapp.com"+ tracewayfasthttp "go.tracewayapp.com/tracewayfasthttp"++ "github.com/fasthttp/router"+ "github.com/valyala/fasthttp"+)++func innerFunction() error {+ return traceway.NewStackTraceErrorf("error from inner function")+}++func middleFunction() error {+ return innerFunction()+}++func outerFunction() error {+ return middleFunction()+}++func writeJSON(ctx *fasthttp.RequestCtx, status int, data interface{}) {+ ctx.SetContentType("application/json")+ ctx.SetStatusCode(status)+ json.NewEncoder(ctx) .Encode(data)+}++func main() {+ endpoint := os.Getenv("TRACEWAY_ENDPOINT")+ if endpoint == "" {+ endpoint = "default_token_change_me@http://localhost:8082/api/report"+ }++ port := os.Getenv("PORT")+ if port == "" {+ port = "8080"+ }++ r := router.New()++ r.GET("/test-ok", func(ctx *fasthttp.RequestCtx) {+ writeJSON(ctx, 200, map[string]string{"status": "ok"})+ })++ r.GET("/test-not-found", func(ctx *fasthttp.RequestCtx) {+ writeJSON(ctx, 404, map[string]string{"status": "not-found"})+ })++ r.GET("/test-exception", func(ctx *fasthttp.RequestCtx) {+ panic("test panic from /test-exception")+ })++ r.GET("/test-error-simple", func(ctx *fasthttp.RequestCtx) {+ traceway.CaptureException(errors.New("simple error without stack"))+ writeJSON(ctx, 500, map[string]string{"error": "simple error"})+ })++ r.GET("/test-error-stacktrace", func(ctx *fasthttp.RequestCtx) {+ err := traceway.NewStackTraceErrorf("error with stack trace")+ traceway.CaptureException(err)+ writeJSON(ctx, 500, map[string]string{"error": "stacktrace error"})+ })++ r.GET("/test-error-wrapped", func(ctx *fasthttp.RequestCtx) {+ base := errors.New("base error")+ wrapped := fmt.Errorf("layer 1: %w", base)+ wrapped2 := fmt.Errorf("layer 2: %w", wrapped)+ traceway.CaptureException(wrapped2)+ writeJSON(ctx, 500, map[string]string{"error": "wrapped error"})+ })++ r.GET("/test-error-nested", func(ctx *fasthttp.RequestCtx) {+ err := outerFunction()+ traceway.CaptureException(err)+ writeJSON(ctx, 500, map[string]string{"error": "nested error"})+ })++ r.GET("/test-message", func(ctx *fasthttp.RequestCtx) {+ traceway.CaptureMessage("test message from /test-message")+ writeJSON(ctx, 200, map[string]string{"status": "message sent"})+ })++ r.GET("/test-message-attributes", func(ctx *fasthttp.RequestCtx) {+ traceway.CaptureMessageAttributes("test message with attributes", map[string]string{+ "source": "test-message-attributes",+ "priority": "high",+ })+ writeJSON(ctx, 200, map[string]string{"status": "message with attributes sent"})+ })++ r.GET("/test-spans", func(ctx *fasthttp.RequestCtx) {+ bgCtx := context.Background()++ dbSpan := traceway.StartSpan(bgCtx, "db.query")+ time.Sleep(50 * time.Millisecond)+ dbSpan.End()++ cacheSpan := traceway.StartSpan(bgCtx, "cache.set")+ time.Sleep(20 * time.Millisecond)+ cacheSpan.End()++ httpSpan := traceway.StartSpan(bgCtx, "http.external_api")+ time.Sleep(100 * time.Millisecond)+ httpSpan.End()++ writeJSON(ctx, 200, map[string]string{"status": "spans captured"})+ })++ r.GET("/test-task", func(ctx *fasthttp.RequestCtx) {+ go func() {+ traceway.MeasureTask("background-data-processor", func(twctx context.Context) {+ span := traceway.StartSpan(twctx, "processing")+ time.Sleep(200 * time.Millisecond)+ span.End()+ })+ }()+ writeJSON(ctx, 200, map[string]string{"status": "task started"})+ })++ r.GET("/test-metric", func(ctx *fasthttp.RequestCtx) {+ traceway.CaptureMetric("test.custom_metric", 42.0)+ writeJSON(ctx, 200, map[string]string{"status": "metric captured"})+ })++ r.GET("/test-attributes", func(ctx *fasthttp.RequestCtx) {+ traceway.CaptureExceptionWithAttributes(+ errors.New("exception with custom attributes"),+ map[string]string{+ "user_id": "usr_123",+ "request_id": "req_456",+ "env": "testing",+ },+ nil,+ )+ writeJSON(ctx, 200, map[string]string{"status": "exception with attributes captured"})+ })++ r.POST("/test-recording", func(ctx *fasthttp.RequestCtx) {+ var body map[string]interface{}+ if err := json.Unmarshal(ctx.PostBody(), &body); err != nil {+ writeJSON(ctx, 400, map[string]string{"error": err.Error()})+ return+ }++ action, _ := body["action"].(string)+ if action == "panic" {+ panic("panic triggered by /test-recording")+ }++ writeJSON(ctx, 200, map[string]interface{}{"status": "ok", "received": body})+ })++ middleware := tracewayfasthttp.New(+ endpoint,+ tracewayfasthttp.WithDebug(true),+ tracewayfasthttp.WithOnErrorRecording(tracewayfasthttp.RecordingUrl|tracewayfasthttp.RecordingQuery|tracewayfasthttp.RecordingHeader|tracewayfasthttp.RecordingBody),+ )++ fmt.Printf("Fasthttp server starting on :%s\n", port)+ fasthttp.ListenAndServe(":"+port, middleware(r.Handler))+}diff --git a/testing/go/fiber/go.mod b/testing/go/fiber/go.modnew file mode 100644index 00000000..6f65ab3e--- /dev/null+++ b/testing/go/fiber/go.mod@@ -0,0 +1,27 @@+module testing/go/fiber++go 1.25.1++require (+ github.com/gofiber/fiber/v2 v2.52.6+ go.tracewayapp.com v0.4.1+ go.tracewayapp.com/tracewayfiber v0.0.0-00010101000000-000000000000+)++require (+ github.com/andybalholm/brotli v1.1.0 // indirect+ github.com/google/uuid v1.6.0 // indirect+ github.com/klauspost/compress v1.17.9 // indirect+ github.com/mattn/go-colorable v0.1.13 // indirect+ github.com/mattn/go-isatty v0.0.20 // indirect+ github.com/mattn/go-runewidth v0.0.16 // indirect+ github.com/rivo/uniseg v0.2.0 // indirect+ github.com/valyala/bytebufferpool v1.0.0 // indirect+ github.com/valyala/fasthttp v1.51.0 // indirect+ github.com/valyala/tcplisten v1.0.0 // indirect+ golang.org/x/sys v0.35.0 // indirect+)++replace go.tracewayapp.com => ../../../../go-client++replace go.tracewayapp.com/tracewayfiber => ../../../../go-client/tracewayfiberdiff --git a/testing/go/fiber/go.sum b/testing/go/fiber/go.sumnew file mode 100644index 00000000..5f093e1a--- /dev/null+++ b/testing/go/fiber/go.sum@@ -0,0 +1,27 @@+github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=+github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=+github.com/gofiber/fiber/v2 v2.52.6 h1:Rfp+ILPiYSvvVuIPvxrBns+HJp8qGLDnLJawAu27XVI=+github.com/gofiber/fiber/v2 v2.52.6/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=+github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=+github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=+github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=+github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=+github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=+github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=+github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=+github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=+github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=+github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=+github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=+github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=+github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=+github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=+github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=+golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=+golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=+golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=diff --git a/testing/go/fiber/main.go b/testing/go/fiber/main.gonew file mode 100644index 00000000..410ec37f--- /dev/null+++ b/testing/go/fiber/main.go@@ -0,0 +1,166 @@+package main++import (+ "context"+ "errors"+ "fmt"+ "os"+ "time"++ traceway "go.tracewayapp.com"+ tracewayfiber "go.tracewayapp.com/tracewayfiber"++ "github.com/gofiber/fiber/v2"+)++func innerFunction() error {+ return traceway.NewStackTraceErrorf("error from inner function")+}++func middleFunction() error {+ return innerFunction()+}++func outerFunction() error {+ return middleFunction()+}++func main() {+ endpoint := os.Getenv("TRACEWAY_ENDPOINT")+ if endpoint == "" {+ endpoint = "default_token_change_me@http://localhost:8082/api/report"+ }++ port := os.Getenv("PORT")+ if port == "" {+ port = "8080"+ }++ app := fiber.New()++ app.Use(tracewayfiber.New(+ endpoint,+ tracewayfiber.WithDebug(true),+ tracewayfiber.WithOnErrorRecording(tracewayfiber.RecordingUrl|tracewayfiber.RecordingQuery|tracewayfiber.RecordingHeader|tracewayfiber.RecordingBody),+ ))++ app.Get("/test-ok", func(c *fiber.Ctx) error {+ return c.JSON(fiber.Map{"status": "ok"})+ })++ app.Get("/test-not-found", func(c *fiber.Ctx) error {+ c.Status(404)+ return c.JSON(fiber.Map{"status": "not-found"})+ })++ app.Get("/test-exception", func(c *fiber.Ctx) error {+ panic("test panic from /test-exception")+ })++ app.Get("/test-error-simple", func(c *fiber.Ctx) error {+ traceway.CaptureException(errors.New("simple error without stack"))+ c.Status(500)+ return c.JSON(fiber.Map{"error": "simple error"})+ })++ app.Get("/test-error-stacktrace", func(c *fiber.Ctx) error {+ err := traceway.NewStackTraceErrorf("error with stack trace")+ traceway.CaptureException(err)+ c.Status(500)+ return c.JSON(fiber.Map{"error": "stacktrace error"})+ })++ app.Get("/test-error-wrapped", func(c *fiber.Ctx) error {+ base := errors.New("base error")+ wrapped := fmt.Errorf("layer 1: %w", base)+ wrapped2 := fmt.Errorf("layer 2: %w", wrapped)+ traceway.CaptureException(wrapped2)+ c.Status(500)+ return c.JSON(fiber.Map{"error": "wrapped error"})+ })++ app.Get("/test-error-nested", func(c *fiber.Ctx) error {+ err := outerFunction()+ traceway.CaptureException(err)+ c.Status(500)+ return c.JSON(fiber.Map{"error": "nested error"})+ })++ app.Get("/test-message", func(c *fiber.Ctx) error {+ traceway.CaptureMessage("test message from /test-message")+ return c.JSON(fiber.Map{"status": "message sent"})+ })++ app.Get("/test-message-attributes", func(c *fiber.Ctx) error {+ traceway.CaptureMessageAttributes("test message with attributes", map[string]string{+ "source": "test-message-attributes",+ "priority": "high",+ })+ return c.JSON(fiber.Map{"status": "message with attributes sent"})+ })++ app.Get("/test-spans", func(c *fiber.Ctx) error {+ ctx := context.Background()++ dbSpan := traceway.StartSpan(ctx, "db.query")+ time.Sleep(50 * time.Millisecond)+ dbSpan.End()++ cacheSpan := traceway.StartSpan(ctx, "cache.set")+ time.Sleep(20 * time.Millisecond)+ cacheSpan.End()++ httpSpan := traceway.StartSpan(ctx, "http.external_api")+ time.Sleep(100 * time.Millisecond)+ httpSpan.End()++ return c.JSON(fiber.Map{"status": "spans captured"})+ })++ app.Get("/test-task", func(c *fiber.Ctx) error {+ go func() {+ traceway.MeasureTask("background-data-processor", func(twctx context.Context) {+ span := traceway.StartSpan(twctx, "processing")+ time.Sleep(200 * time.Millisecond)+ span.End()+ })+ }()+ return c.JSON(fiber.Map{"status": "task started"})+ })++ app.Get("/test-metric", func(c *fiber.Ctx) error {+ traceway.CaptureMetric("test.custom_metric", 42.0)+ return c.JSON(fiber.Map{"status": "metric captured"})+ })++ app.Get("/test-attributes", func(c *fiber.Ctx) error {+ traceway.CaptureExceptionWithAttributes(+ errors.New("exception with custom attributes"),+ map[string]string{+ "user_id": "usr_123",+ "request_id": "req_456",+ "env": "testing",+ },+ nil,+ )+ return c.JSON(fiber.Map{"status": "exception with attributes captured"})+ })++ app.Post("/test-recording", func(c *fiber.Ctx) error {+ var body map[string]interface{}+ if err := c.BodyParser(&body); err != nil {+ c.Status(400)+ return c.JSON(fiber.Map{"error": err.Error()})+ }++ action, _ := body["action"].(string)+ if action == "panic" {+ panic("panic triggered by /test-recording")+ }++ return c.JSON(fiber.Map{"status": "ok", "received": body})+ })++ fmt.Printf("Fiber server starting on :%s\n", port)+ app.Listen(":" + port)+}diff --git a/testing/go/gin/go.mod b/testing/go/gin/go.modnew file mode 100644index 00000000..6e9148ba--- /dev/null+++ b/testing/go/gin/go.mod@@ -0,0 +1,48 @@+module testing/go/gin++go 1.25.1++require (+ github.com/gin-gonic/gin v1.11.0+ go.tracewayapp.com v0.4.1+ go.tracewayapp.com/tracewaygin v0.0.0-00010101000000-000000000000+)++require (+ github.com/bytedance/sonic v1.14.0 // indirect+ github.com/bytedance/sonic/loader v0.3.0 // indirect+ github.com/cloudwego/base64x v0.1.6 // indirect+ github.com/gabriel-vasile/mimetype v1.4.8 // indirect+ github.com/gin-contrib/sse v1.1.0 // indirect+ github.com/go-playground/locales v0.14.1 // indirect+ github.com/go-playground/universal-translator v0.18.1 // indirect+ github.com/go-playground/validator/v10 v10.27.0 // indirect+ github.com/goccy/go-json v0.10.2 // indirect+ github.com/goccy/go-yaml v1.18.0 // indirect+ github.com/google/uuid v1.6.0 // indirect+ github.com/json-iterator/go v1.1.12 // indirect+ github.com/klauspost/cpuid/v2 v2.3.0 // indirect+ github.com/leodido/go-urn v1.4.0 // indirect+ github.com/mattn/go-isatty v0.0.20 // indirect+ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect+ github.com/modern-go/reflect2 v1.0.2 // indirect+ github.com/pelletier/go-toml/v2 v2.2.4 // indirect+ github.com/quic-go/qpack v0.5.1 // indirect+ github.com/quic-go/quic-go v0.54.0 // indirect+ github.com/twitchyliquid64/golang-asm v0.15.1 // indirect+ github.com/ugorji/go/codec v1.3.0 // indirect+ go.uber.org/mock v0.5.0 // indirect+ golang.org/x/arch v0.20.0 // indirect+ golang.org/x/crypto v0.40.0 // indirect+ golang.org/x/mod v0.25.0 // indirect+ golang.org/x/net v0.42.0 // indirect+ golang.org/x/sync v0.16.0 // indirect+ golang.org/x/sys v0.35.0 // indirect+ golang.org/x/text v0.27.0 // indirect+ golang.org/x/tools v0.34.0 // indirect+ google.golang.org/protobuf v1.36.9 // indirect+)++replace go.tracewayapp.com => ../../../../go-client++replace go.tracewayapp.com/tracewaygin => ../../../../go-client/tracewaygindiff --git a/testing/go/gin/go.sum b/testing/go/gin/go.sumnew file mode 100644index 00000000..bf14dfab--- /dev/null+++ b/testing/go/gin/go.sum@@ -0,0 +1,90 @@+github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=+github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=+github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=+github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=+github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=+github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=+github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=+github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=+github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=+github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=+github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=+github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=+github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=+github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=+github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=+github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=+github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=+github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=+github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=+github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=+github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=+github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=+github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=+github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=+github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=+github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=+github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=+github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=+github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=+github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=+github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=+github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=+github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=+github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=+github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=+github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=+github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=+github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=+github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=+github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=+github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=+github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=+github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=+github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=+github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=+github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=+github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=+github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=+github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=+github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=+github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=+go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=+go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=+golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=+golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=+golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=+golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=+golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=+golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=+golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=+golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=+golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=+golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=+golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=+golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=+golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=+golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=+golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=+golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=+google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=+google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=diff --git a/testing/go/gin/main.go b/testing/go/gin/main.gonew file mode 100644index 00000000..cce28531--- /dev/null+++ b/testing/go/gin/main.go@@ -0,0 +1,161 @@+package main++import (+ "context"+ "encoding/json"+ "errors"+ "fmt"+ "net/http"+ "os"+ "time"++ traceway "go.tracewayapp.com"+ tracewaygin "go.tracewayapp.com/tracewaygin"++ "github.com/gin-gonic/gin"+)++func innerFunction() error {+ return traceway.NewStackTraceErrorf("error from inner function")+}++func middleFunction() error {+ return innerFunction()+}++func outerFunction() error {+ return middleFunction()+}++func main() {+ endpoint := os.Getenv("TRACEWAY_ENDPOINT")+ if endpoint == "" {+ endpoint = "default_token_change_me@http://localhost:8082/api/report"+ }++ port := os.Getenv("PORT")+ if port == "" {+ port = "8080"+ }++ router := gin.Default()++ router.Use(tracewaygin.New(+ endpoint,+ tracewaygin.WithDebug(true),+ tracewaygin.WithOnErrorRecording(tracewaygin.RecordingUrl|tracewaygin.RecordingQuery|tracewaygin.RecordingHeader|tracewaygin.RecordingBody),+ ))++ router.GET("/test-ok", func(c *gin.Context) {+ c.JSON(200, gin.H{"status": "ok"})+ })++ router.GET("/test-not-found", func(c *gin.Context) {+ c.JSON(404, gin.H{"status": "not-found"})+ })++ router.GET("/test-exception", func(c *gin.Context) {+ panic("test panic from /test-exception")+ })++ router.GET("/test-error-simple", func(c *gin.Context) {+ c.Error(errors.New("simple error without stack"))+ c.JSON(http.StatusInternalServerError, gin.H{"error": "simple error"})+ })++ router.GET("/test-error-stacktrace", func(c *gin.Context) {+ err := traceway.NewStackTraceErrorf("error with stack trace")+ c.Error(err)+ c.JSON(http.StatusInternalServerError, gin.H{"error": "stacktrace error"})+ })++ router.GET("/test-error-wrapped", func(c *gin.Context) {+ base := errors.New("base error")+ wrapped := fmt.Errorf("layer 1: %w", base)+ wrapped2 := fmt.Errorf("layer 2: %w", wrapped)+ c.Error(wrapped2)+ c.JSON(http.StatusInternalServerError, gin.H{"error": "wrapped error"})+ })++ router.GET("/test-error-nested", func(c *gin.Context) {+ err := outerFunction()+ c.Error(err)+ c.JSON(http.StatusInternalServerError, gin.H{"error": "nested error"})+ })++ router.GET("/test-message", func(c *gin.Context) {+ traceway.CaptureMessageWithContext(c, "test message from /test-message")+ c.JSON(200, gin.H{"status": "message sent"})+ })++ router.GET("/test-message-attributes", func(c *gin.Context) {+ traceway.CaptureMessageAttributes("test message with attributes", map[string]string{+ "source": "test-message-attributes",+ "priority": "high",+ })+ c.JSON(200, gin.H{"status": "message with attributes sent"})+ })++ router.GET("/test-spans", func(c *gin.Context) {+ dbSpan := traceway.StartSpan(c, "db.query")+ time.Sleep(50 * time.Millisecond)+ dbSpan.End()++ cacheSpan := traceway.StartSpan(c, "cache.set")+ time.Sleep(20 * time.Millisecond)+ cacheSpan.End()++ httpSpan := traceway.StartSpan(c, "http.external_api")+ time.Sleep(100 * time.Millisecond)+ httpSpan.End()++ c.JSON(200, gin.H{"status": "spans captured"})+ })++ router.GET("/test-task", func(c *gin.Context) {+ go func() {+ traceway.MeasureTask("background-data-processor", func(twctx context.Context) {+ span := traceway.StartSpan(twctx, "processing")+ time.Sleep(200 * time.Millisecond)+ span.End()+ })+ }()+ c.JSON(200, gin.H{"status": "task started"})+ })++ router.GET("/test-metric", func(c *gin.Context) {+ traceway.CaptureMetric("test.custom_metric", 42.0)+ c.JSON(200, gin.H{"status": "metric captured"})+ })++ router.GET("/test-attributes", func(c *gin.Context) {+ traceway.CaptureExceptionWithAttributes(+ errors.New("exception with custom attributes"),+ map[string]string{+ "user_id": "usr_123",+ "request_id": "req_456",+ "env": "testing",+ },+ nil,+ )+ c.JSON(200, gin.H{"status": "exception with attributes captured"})+ })++ router.POST("/test-recording", func(c *gin.Context) {+ var body map[string]interface{}+ if err := c.ShouldBindJSON(&body); err != nil {+ c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})+ return+ }++ action, _ := body["action"].(string)+ if action == "panic" {+ panic("panic triggered by /test-recording")+ }++ raw, _ := json.Marshal(body)+ c.JSON(200, gin.H{"status": "ok", "received": json.RawMessage(raw)})+ })++ router.Run(":" + port)+}diff --git a/testing/go/stdlib/go.mod b/testing/go/stdlib/go.modnew file mode 100644index 00000000..a4db0e89--- /dev/null+++ b/testing/go/stdlib/go.mod@@ -0,0 +1,17 @@+module testing/go/stdlib++go 1.25.1++require (+ go.tracewayapp.com v0.4.1+ go.tracewayapp.com/tracewayhttp v0.0.0-00010101000000-000000000000+)++require (+ github.com/google/uuid v1.6.0 // indirect+ golang.org/x/sys v0.35.0 // indirect+)++replace go.tracewayapp.com => ../../../../go-client++replace go.tracewayapp.com/tracewayhttp => ../../../../go-client/tracewayhttpdiff --git a/testing/go/stdlib/go.sum b/testing/go/stdlib/go.sumnew file mode 100644index 00000000..1922b07b--- /dev/null+++ b/testing/go/stdlib/go.sum@@ -0,0 +1,4 @@+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=+golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=+golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=diff --git a/testing/go/stdlib/main.go b/testing/go/stdlib/main.gonew file mode 100644index 00000000..be7d7c27--- /dev/null+++ b/testing/go/stdlib/main.go@@ -0,0 +1,173 @@+package main++import (+ "context"+ "encoding/json"+ "errors"+ "fmt"+ "io"+ "net/http"+ "os"+ "time"++ traceway "go.tracewayapp.com"+ tracewayhttp "go.tracewayapp.com/tracewayhttp"+)++func innerFunction() error {+ return traceway.NewStackTraceErrorf("error from inner function")+}++func middleFunction() error {+ return innerFunction()+}++func outerFunction() error {+ return middleFunction()+}++func writeJSON(w http.ResponseWriter, status int, data interface{}) {+ w.Header().Set("Content-Type", "application/json")+ w.WriteHeader(status)+ json.NewEncoder(w).Encode(data)+}++func main() {+ endpoint := os.Getenv("TRACEWAY_ENDPOINT")+ if endpoint == "" {+ endpoint = "default_token_change_me@http://localhost:8082/api/report"+ }++ port := os.Getenv("PORT")+ if port == "" {+ port = "8080"+ }++ mux := http.NewServeMux()++ mux.HandleFunc("GET /test-ok", func(w http.ResponseWriter, r *http.Request) {+ writeJSON(w, 200, map[string]string{"status": "ok"})+ })++ mux.HandleFunc("GET /test-not-found", func(w http.ResponseWriter, r *http.Request) {+ writeJSON(w, 404, map[string]string{"status": "not-found"})+ })++ mux.HandleFunc("GET /test-exception", func(w http.ResponseWriter, r *http.Request) {+ panic("test panic from /test-exception")+ })++ mux.HandleFunc("GET /test-error-simple", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureExceptionWithContext(r.Context(), errors.New("simple error without stack"))+ writeJSON(w, 500, map[string]string{"error": "simple error"})+ })++ mux.HandleFunc("GET /test-error-stacktrace", func(w http.ResponseWriter, r *http.Request) {+ err := traceway.NewStackTraceErrorf("error with stack trace")+ traceway.CaptureExceptionWithContext(r.Context(), err)+ writeJSON(w, 500, map[string]string{"error": "stacktrace error"})+ })++ mux.HandleFunc("GET /test-error-wrapped", func(w http.ResponseWriter, r *http.Request) {+ base := errors.New("base error")+ wrapped := fmt.Errorf("layer 1: %w", base)+ wrapped2 := fmt.Errorf("layer 2: %w", wrapped)+ traceway.CaptureExceptionWithContext(r.Context(), wrapped2)+ writeJSON(w, 500, map[string]string{"error": "wrapped error"})+ })++ mux.HandleFunc("GET /test-error-nested", func(w http.ResponseWriter, r *http.Request) {+ err := outerFunction()+ traceway.CaptureExceptionWithContext(r.Context(), err)+ writeJSON(w, 500, map[string]string{"error": "nested error"})+ })++ mux.HandleFunc("GET /test-message", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureMessageWithContext(r.Context(), "test message from /test-message")+ writeJSON(w, 200, map[string]string{"status": "message sent"})+ })++ mux.HandleFunc("GET /test-message-attributes", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureMessageAttributes("test message with attributes", map[string]string{+ "source": "test-message-attributes",+ "priority": "high",+ })+ writeJSON(w, 200, map[string]string{"status": "message with attributes sent"})+ })++ mux.HandleFunc("GET /test-spans", func(w http.ResponseWriter, r *http.Request) {+ dbSpan := traceway.StartSpan(r.Context(), "db.query")+ time.Sleep(50 * time.Millisecond)+ dbSpan.End()++ cacheSpan := traceway.StartSpan(r.Context(), "cache.set")+ time.Sleep(20 * time.Millisecond)+ cacheSpan.End()++ httpSpan := traceway.StartSpan(r.Context(), "http.external_api")+ time.Sleep(100 * time.Millisecond)+ httpSpan.End()++ writeJSON(w, 200, map[string]string{"status": "spans captured"})+ })++ mux.HandleFunc("GET /test-task", func(w http.ResponseWriter, r *http.Request) {+ go func() {+ traceway.MeasureTask("background-data-processor", func(twctx context.Context) {+ span := traceway.StartSpan(twctx, "processing")+ time.Sleep(200 * time.Millisecond)+ span.End()+ })+ }()+ writeJSON(w, 200, map[string]string{"status": "task started"})+ })++ mux.HandleFunc("GET /test-metric", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureMetric("test.custom_metric", 42.0)+ writeJSON(w, 200, map[string]string{"status": "metric captured"})+ })++ mux.HandleFunc("GET /test-attributes", func(w http.ResponseWriter, r *http.Request) {+ traceway.CaptureExceptionWithAttributes(+ errors.New("exception with custom attributes"),+ map[string]string{+ "user_id": "usr_123",+ "request_id": "req_456",+ "env": "testing",+ },+ nil,+ )+ writeJSON(w, 200, map[string]string{"status": "exception with attributes captured"})+ })++ mux.HandleFunc("POST /test-recording", func(w http.ResponseWriter, r *http.Request) {+ bodyBytes, err := io.ReadAll(r.Body)+ if err != nil {+ writeJSON(w, 400, map[string]string{"error": err.Error()})+ return+ }+ defer r.Body.Close()++ var body map[string]interface{}+ if err := json.Unmarshal(bodyBytes, &body); err != nil {+ writeJSON(w, 400, map[string]string{"error": err.Error()})+ return+ }++ action, _ := body["action"].(string)+ if action == "panic" {+ panic("panic triggered by /test-recording")+ }++ writeJSON(w, 200, map[string]interface{}{"status": "ok", "received": body})+ })++ middleware := tracewayhttp.New(+ endpoint,+ tracewayhttp.WithDebug(true),+ tracewayhttp.WithOnErrorRecording(tracewayhttp.RecordingUrl|tracewayhttp.RecordingQuery|tracewayhttp.RecordingHeader|tracewayhttp.RecordingBody),+ )++ fmt.Printf("Stdlib server starting on :%s\n", port)+ http.ListenAndServe(":"+port, middleware(mux))+}diff --git a/testing/js/express/package.json b/testing/js/express/package.jsonnew file mode 100644index 00000000..2b54bee9--- /dev/null+++ b/testing/js/express/package.json@@ -0,0 +1,18 @@+{+ "name": "traceway-test-express",+ "version": "1.0.0",+ "private": true,+ "scripts": {+ "dev": "tsx src/index.ts"+ },+ "dependencies": {+ "@traceway/backend": "file:../../../../js-client/packages/backend",+ "@traceway/core": "file:../../../../js-client/packages/core",+ "express": "^5.1.0"+ },+ "devDependencies": {+ "@types/express": "^5.0.0",+ "tsx": "^4.19.0",+ "typescript": "^5.7.0"+ }+}diff --git a/testing/js/express/src/index.ts b/testing/js/express/src/index.tsnew file mode 100644index 00000000..3d5596c7--- /dev/null+++ b/testing/js/express/src/index.ts@@ -0,0 +1,198 @@+import express, { Request, Response, NextFunction } from "express";+import * as traceway from "@traceway/backend";++const endpoint =+ process.env.TRACEWAY_ENDPOINT ||+ "default_token_change_me@http://localhost:8082/api/report";+const port = process.env.PORT || "8080";++traceway.init(endpoint, { debug: true });++const app = express();+app.use(express.json());++function generateTraceId(): string {+ return crypto.randomUUID().replace(/-/g, "");+}++app.use((req: Request, res: Response, next: NextFunction) => {+ const traceId = generateTraceId();+ const startedAt = new Date();+ const startMs = performance.now();+ const spans: ReturnType<typeof traceway.startSpan>[] = [];++ (req as any).traceId = traceId;+ (req as any).startSpan = (name: string) => {+ const span = traceway.startSpan(name);+ spans.push(span);+ return span;+ };++ res.on("finish", () => {+ const durationMs = performance.now() - startMs;+ const endpoint = `${req.method} ${req.route?.path || req.path}`;+ const completedSpans = spans+ .filter((s) => (s as any).duration !== undefined)+ .map((s) => traceway.endSpan(s));+ const pendingSpans = spans.filter(+ (s) => (s as any).duration === undefined+ );+ for (const s of pendingSpans) {+ completedSpans.push(traceway.endSpan(s));+ }++ traceway.captureTrace(+ traceId,+ endpoint,+ durationMs,+ startedAt,+ res.statusCode,+ 0,+ req.ip || "",+ undefined,+ completedSpans+ );+ });++ next();+});++function innerFunction(): Error {+ const err = new Error("error from inner function");+ Error.captureStackTrace(err, innerFunction);+ return err;+}++function middleFunction(): Error {+ return innerFunction();+}++function outerFunction(): Error {+ return middleFunction();+}++app.get("/test-ok", (_req: Request, res: Response) => {+ res.json({ status: "ok" });+});++app.get("/test-not-found", (_req: Request, res: Response) => {+ res.status(404).json({ status: "not-found" });+});++app.get("/test-exception", () => {+ throw new Error("test panic from /test-exception");+});++app.get("/test-error-simple", (req: Request, res: Response) => {+ const err = new Error("simple error without stack");+ traceway.captureExceptionWithAttributes(err, undefined, (req as any).traceId);+ res.status(500).json({ error: "simple error" });+});++app.get("/test-error-stacktrace", (req: Request, res: Response) => {+ const err = new Error("error with stack trace");+ traceway.captureExceptionWithAttributes(err, undefined, (req as any).traceId);+ res.status(500).json({ error: "stacktrace error" });+});++app.get("/test-error-wrapped", (req: Request, res: Response) => {+ const base = new Error("base error");+ const wrapped = new Error("layer 1: " + base.message, { cause: base });+ const wrapped2 = new Error("layer 2: " + wrapped.message, {+ cause: wrapped,+ });+ traceway.captureExceptionWithAttributes(+ wrapped2,+ undefined,+ (req as any).traceId+ );+ res.status(500).json({ error: "wrapped error" });+});++app.get("/test-error-nested", (req: Request, res: Response) => {+ const err = outerFunction();+ traceway.captureExceptionWithAttributes(err, undefined, (req as any).traceId);+ res.status(500).json({ error: "nested error" });+});++app.get("/test-message", (_req: Request, res: Response) => {+ traceway.captureMessage("test message from /test-message");+ res.json({ status: "message sent" });+});++app.get("/test-message-attributes", (_req: Request, res: Response) => {+ // JS SDK captureMessage does not support attributes; capturing as message only+ traceway.captureMessage("test message with attributes");+ res.json({ status: "message with attributes sent" });+});++app.get("/test-spans", (req: Request, res: Response) => {+ const startSpan = (req as any).startSpan as (+ name: string+ ) => ReturnType<typeof traceway.startSpan>;++ const dbSpan = startSpan("db.query");+ setTimeout(() => {+ traceway.endSpan(dbSpan);++ const cacheSpan = startSpan("cache.set");+ setTimeout(() => {+ traceway.endSpan(cacheSpan);++ const httpSpan = startSpan("http.external_api");+ setTimeout(() => {+ traceway.endSpan(httpSpan);+ res.json({ status: "spans captured" });+ }, 100);+ }, 20);+ }, 50);+});++app.get("/test-task", (_req: Request, res: Response) => {+ traceway.measureTask("background-data-processor", async () => {+ const span = traceway.startSpan("processing");+ await new Promise((resolve) => setTimeout(resolve, 200));+ traceway.endSpan(span);+ });+ res.json({ status: "task started" });+});++app.get("/test-metric", (_req: Request, res: Response) => {+ traceway.captureMetric("test.custom_metric", 42.0);+ res.json({ status: "metric captured" });+});++app.get("/test-attributes", (_req: Request, res: Response) => {+ traceway.captureExceptionWithAttributes(+ new Error("exception with custom attributes"),+ {+ user_id: "usr_123",+ request_id: "req_456",+ env: "testing",+ }+ );+ res.json({ status: "exception with attributes captured" });+});++app.post("/test-recording", (req: Request, res: Response) => {+ const body = req.body;++ if (body?.action === "panic") {+ throw new Error("panic triggered by /test-recording");+ }++ res.json({ status: "ok", received: body });+});++app.use((err: Error, req: Request, res: Response, _next: NextFunction) => {+ traceway.captureExceptionWithAttributes(+ err,+ undefined,+ (req as any).traceId+ );+ res.status(500).json({ error: err.message });+});++app.listen(Number(port), () => {+ console.log(`Express server starting on :${port}`);+});diff --git a/testing/js/express/tsconfig.json b/testing/js/express/tsconfig.jsonnew file mode 100644index 00000000..7ae8994f--- /dev/null+++ b/testing/js/express/tsconfig.json@@ -0,0 +1,12 @@+{+ "compilerOptions": {+ "target": "ES2022",+ "module": "ESNext",+ "moduleResolution": "bundler",+ "esModuleInterop": true,+ "strict": true,+ "outDir": "dist",+ "rootDir": "src"+ },+ "include": ["src"]+}diff --git a/testing/js/nestjs/package.json b/testing/js/nestjs/package.jsonnew file mode 100644index 00000000..de5568fd--- /dev/null+++ b/testing/js/nestjs/package.json@@ -0,0 +1,21 @@+{+ "name": "traceway-test-nestjs",+ "version": "1.0.0",+ "private": true,+ "scripts": {+ "dev": "tsx src/main.ts"+ },+ "dependencies": {+ "@nestjs/common": "^11.0.0",+ "@nestjs/core": "^11.0.0",+ "@nestjs/platform-express": "^11.0.0",+ "@traceway/backend": "file:../../../../js-client/packages/backend",+ "@traceway/core": "file:../../../../js-client/packages/core",+ "reflect-metadata": "^0.2.0",+ "rxjs": "^7.8.0"+ },+ "devDependencies": {+ "tsx": "^4.19.0",+ "typescript": "^5.7.0"+ }+}diff --git a/testing/js/nestjs/src/app.controller.ts b/testing/js/nestjs/src/app.controller.tsnew file mode 100644index 00000000..331e9cdf--- /dev/null+++ b/testing/js/nestjs/src/app.controller.ts@@ -0,0 +1,152 @@+import { Controller, Get, Post, Req, Res, HttpStatus } from "@nestjs/common";+import { Request, Response } from "express";+import * as traceway from "@traceway/backend";++function innerFunction(): Error {+ const err = new Error("error from inner function");+ Error.captureStackTrace(err, innerFunction);+ return err;+}++function middleFunction(): Error {+ return innerFunction();+}++function outerFunction(): Error {+ return middleFunction();+}++@Controller()+export class AppController {+ @Get("test-ok")+ testOk() {+ return { status: "ok" };+ }++ @Get("test-not-found")+ testNotFound(@Res() res: Response) {+ res.status(404).json({ status: "not-found" });+ }++ @Get("test-exception")+ testException() {+ throw new Error("test panic from /test-exception");+ }++ @Get("test-error-simple")+ testErrorSimple(@Req() req: Request, @Res() res: Response) {+ const err = new Error("simple error without stack");+ traceway.captureExceptionWithAttributes(+ err,+ undefined,+ (req as any).traceId+ );+ res.status(500).json({ error: "simple error" });+ }++ @Get("test-error-stacktrace")+ testErrorStacktrace(@Req() req: Request, @Res() res: Response) {+ const err = new Error("error with stack trace");+ traceway.captureExceptionWithAttributes(+ err,+ undefined,+ (req as any).traceId+ );+ res.status(500).json({ error: "stacktrace error" });+ }++ @Get("test-error-wrapped")+ testErrorWrapped(@Req() req: Request, @Res() res: Response) {+ const base = new Error("base error");+ const wrapped = new Error("layer 1: " + base.message, { cause: base });+ const wrapped2 = new Error("layer 2: " + wrapped.message, {+ cause: wrapped,+ });+ traceway.captureExceptionWithAttributes(+ wrapped2,+ undefined,+ (req as any).traceId+ );+ res.status(500).json({ error: "wrapped error" });+ }++ @Get("test-error-nested")+ testErrorNested(@Req() req: Request, @Res() res: Response) {+ const err = outerFunction();+ traceway.captureExceptionWithAttributes(+ err,+ undefined,+ (req as any).traceId+ );+ res.status(500).json({ error: "nested error" });+ }++ @Get("test-message")+ testMessage() {+ traceway.captureMessage("test message from /test-message");+ return { status: "message sent" };+ }++ @Get("test-message-attributes")+ testMessageAttributes() {+ traceway.captureMessage("test message with attributes");+ return { status: "message with attributes sent" };+ }++ @Get("test-spans")+ async testSpans() {+ const dbSpan = traceway.startSpan("db.query");+ await new Promise((r) => setTimeout(r, 50));+ traceway.endSpan(dbSpan);++ const cacheSpan = traceway.startSpan("cache.set");+ await new Promise((r) => setTimeout(r, 20));+ traceway.endSpan(cacheSpan);++ const httpSpan = traceway.startSpan("http.external_api");+ await new Promise((r) => setTimeout(r, 100));+ traceway.endSpan(httpSpan);++ return { status: "spans captured" };+ }++ @Get("test-task")+ testTask() {+ traceway.measureTask("background-data-processor", async () => {+ const span = traceway.startSpan("processing");+ await new Promise((r) => setTimeout(r, 200));+ traceway.endSpan(span);+ });+ return { status: "task started" };+ }++ @Get("test-metric")+ testMetric() {+ traceway.captureMetric("test.custom_metric", 42.0);+ return { status: "metric captured" };+ }++ @Get("test-attributes")+ testAttributes() {+ traceway.captureExceptionWithAttributes(+ new Error("exception with custom attributes"),+ {+ user_id: "usr_123",+ request_id: "req_456",+ env: "testing",+ }+ );+ return { status: "exception with attributes captured" };+ }++ @Post("test-recording")+ testRecording(@Req() req: Request, @Res() res: Response) {+ const body = req.body;++ if (body?.action === "panic") {+ throw new Error("panic triggered by /test-recording");+ }++ res.json({ status: "ok", received: body });+ }+}diff --git a/testing/js/nestjs/src/app.module.ts b/testing/js/nestjs/src/app.module.tsnew file mode 100644index 00000000..ccebbbfd--- /dev/null+++ b/testing/js/nestjs/src/app.module.ts@@ -0,0 +1,12 @@+import { Module, MiddlewareConsumer, NestModule } from "@nestjs/common";+import { AppController } from "./app.controller.js";+import { TracewayMiddleware } from "./traceway.middleware.js";++@Module({+ controllers: [AppController],+})+export class AppModule implements NestModule {+ configure(consumer: MiddlewareConsumer) {+ consumer.apply(TracewayMiddleware).forRoutes("*");+ }+}diff --git a/testing/js/nestjs/src/main.ts b/testing/js/nestjs/src/main.tsnew file mode 100644index 00000000..01c75350--- /dev/null+++ b/testing/js/nestjs/src/main.ts@@ -0,0 +1,19 @@+import "reflect-metadata";+import { NestFactory } from "@nestjs/core";+import { AppModule } from "./app.module.js";+import * as traceway from "@traceway/backend";++const endpoint =+ process.env.TRACEWAY_ENDPOINT ||+ "default_token_change_me@http://localhost:8082/api/report";+const port = process.env.PORT || "8080";++traceway.init(endpoint, { debug: true });++async function bootstrap() {+ const app = await NestFactory.create(AppModule);+ await app.listen(Number(port));+ console.log(`NestJS server starting on :${port}`);+}++bootstrap();diff --git a/testing/js/nestjs/src/traceway.middleware.ts b/testing/js/nestjs/src/traceway.middleware.tsnew file mode 100644index 00000000..5092fdbf--- /dev/null+++ b/testing/js/nestjs/src/traceway.middleware.ts@@ -0,0 +1,31 @@+import { Injectable, NestMiddleware } from "@nestjs/common";+import { Request, Response, NextFunction } from "express";+import * as traceway from "@traceway/backend";++@Injectable()+export class TracewayMiddleware implements NestMiddleware {+ use(req: Request, res: Response, next: NextFunction) {+ const traceId = crypto.randomUUID().replace(/-/g, "");+ const startedAt = new Date();+ const startMs = performance.now();++ (req as any).traceId = traceId;++ res.on("finish", () => {+ const durationMs = performance.now() - startMs;+ const endpoint = `${req.method} ${req.route?.path || req.path}`;++ traceway.captureTrace(+ traceId,+ endpoint,+ durationMs,+ startedAt,+ res.statusCode,+ 0,+ req.ip || ""+ );+ });++ next();+ }+}diff --git a/testing/js/nestjs/tsconfig.json b/testing/js/nestjs/tsconfig.jsonnew file mode 100644index 00000000..4cdd49ca--- /dev/null+++ b/testing/js/nestjs/tsconfig.json@@ -0,0 +1,14 @@+{+ "compilerOptions": {+ "target": "ES2022",+ "module": "ESNext",+ "moduleResolution": "bundler",+ "esModuleInterop": true,+ "strict": true,+ "emitDecoratorMetadata": true,+ "experimentalDecorators": true,+ "outDir": "dist",+ "rootDir": "src"+ },+ "include": ["src"]+}diff --git a/testing/js/nextjs/instrumentation.ts b/testing/js/nextjs/instrumentation.tsnew file mode 100644index 00000000..c4337d89--- /dev/null+++ b/testing/js/nextjs/instrumentation.ts@@ -0,0 +1,9 @@+export async function register() {+ if (process.env.NEXT_RUNTIME === "nodejs") {+ const traceway = await import("@traceway/backend");+ const endpoint =+ process.env.TRACEWAY_ENDPOINT ||+ "default_token_change_me@http://localhost:8082/api/report";+ traceway.init(endpoint, { debug: true });+ }+}diff --git a/testing/js/nextjs/next.config.ts b/testing/js/nextjs/next.config.tsnew file mode 100644index 00000000..5cd1956e--- /dev/null+++ b/testing/js/nextjs/next.config.ts@@ -0,0 +1,7 @@+import type { NextConfig } from "next";++const nextConfig: NextConfig = {+ serverExternalPackages: ["@traceway/backend", "@traceway/core"],+};++export default nextConfig;diff --git a/testing/js/nextjs/package.json b/testing/js/nextjs/package.jsonnew file mode 100644index 00000000..2cb704a3--- /dev/null+++ b/testing/js/nextjs/package.json@@ -0,0 +1,21 @@+{+ "name": "traceway-test-nextjs",+ "version": "1.0.0",+ "private": true,+ "scripts": {+ "dev": "next dev --port ${PORT:-8080}",+ "build": "next build",+ "start": "next start --port ${PORT:-8080}"+ },+ "dependencies": {+ "@traceway/backend": "file:../../../../js-client/packages/backend",+ "@traceway/core": "file:../../../../js-client/packages/core",+ "next": "^15.0.0",+ "react": "^19.0.0",+ "react-dom": "^19.0.0"+ },+ "devDependencies": {+ "@types/react": "^19.0.0",+ "typescript": "^5.7.0"+ }+}diff --git a/testing/js/nextjs/src/app/api/test-attributes/route.ts b/testing/js/nextjs/src/app/api/test-attributes/route.tsnew file mode 100644index 00000000..5b94a6b6--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-attributes/route.ts@@ -0,0 +1,15 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async () => {+ traceway.captureExceptionWithAttributes(+ new Error("exception with custom attributes"),+ {+ user_id: "usr_123",+ request_id: "req_456",+ env: "testing",+ }+ );+ return NextResponse.json({ status: "exception with attributes captured" });+});diff --git a/testing/js/nextjs/src/app/api/test-error-nested/route.ts b/testing/js/nextjs/src/app/api/test-error-nested/route.tsnew file mode 100644index 00000000..dd1c0197--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-error-nested/route.ts@@ -0,0 +1,23 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++function innerFunction(): Error {+ const err = new Error("error from inner function");+ Error.captureStackTrace(err, innerFunction);+ return err;+}++function middleFunction(): Error {+ return innerFunction();+}++function outerFunction(): Error {+ return middleFunction();+}++export const GET = withTraceway(async (_req, { traceId }) => {+ const err = outerFunction();+ traceway.captureExceptionWithAttributes(err, undefined, traceId);+ return NextResponse.json({ error: "nested error" }, { status: 500 });+});diff --git a/testing/js/nextjs/src/app/api/test-error-simple/route.ts b/testing/js/nextjs/src/app/api/test-error-simple/route.tsnew file mode 100644index 00000000..b38e5183--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-error-simple/route.ts@@ -0,0 +1,9 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async (_req, { traceId }) => {+ const err = new Error("simple error without stack");+ traceway.captureExceptionWithAttributes(err, undefined, traceId);+ return NextResponse.json({ error: "simple error" }, { status: 500 });+});diff --git a/testing/js/nextjs/src/app/api/test-error-stacktrace/route.ts b/testing/js/nextjs/src/app/api/test-error-stacktrace/route.tsnew file mode 100644index 00000000..42fb207d--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-error-stacktrace/route.ts@@ -0,0 +1,9 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async (_req, { traceId }) => {+ const err = new Error("error with stack trace");+ traceway.captureExceptionWithAttributes(err, undefined, traceId);+ return NextResponse.json({ error: "stacktrace error" }, { status: 500 });+});diff --git a/testing/js/nextjs/src/app/api/test-error-wrapped/route.ts b/testing/js/nextjs/src/app/api/test-error-wrapped/route.tsnew file mode 100644index 00000000..bf81142e--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-error-wrapped/route.ts@@ -0,0 +1,11 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async (_req, { traceId }) => {+ const base = new Error("base error");+ const wrapped = new Error("layer 1: " + base.message, { cause: base });+ const wrapped2 = new Error("layer 2: " + wrapped.message, { cause: wrapped });+ traceway.captureExceptionWithAttributes(wrapped2, undefined, traceId);+ return NextResponse.json({ error: "wrapped error" }, { status: 500 });+});diff --git a/testing/js/nextjs/src/app/api/test-exception/route.ts b/testing/js/nextjs/src/app/api/test-exception/route.tsnew file mode 100644index 00000000..2298e0b7--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-exception/route.ts@@ -0,0 +1,5 @@+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async () => {+ throw new Error("test panic from /test-exception");+});diff --git a/testing/js/nextjs/src/app/api/test-message-attributes/route.ts b/testing/js/nextjs/src/app/api/test-message-attributes/route.tsnew file mode 100644index 00000000..6c7d3371--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-message-attributes/route.ts@@ -0,0 +1,8 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async () => {+ traceway.captureMessage("test message with attributes");+ return NextResponse.json({ status: "message with attributes sent" });+});diff --git a/testing/js/nextjs/src/app/api/test-message/route.ts b/testing/js/nextjs/src/app/api/test-message/route.tsnew file mode 100644index 00000000..ff506455--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-message/route.ts@@ -0,0 +1,8 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async () => {+ traceway.captureMessage("test message from /test-message");+ return NextResponse.json({ status: "message sent" });+});diff --git a/testing/js/nextjs/src/app/api/test-metric/route.ts b/testing/js/nextjs/src/app/api/test-metric/route.tsnew file mode 100644index 00000000..5e1ab4e8--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-metric/route.ts@@ -0,0 +1,8 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async () => {+ traceway.captureMetric("test.custom_metric", 42.0);+ return NextResponse.json({ status: "metric captured" });+});diff --git a/testing/js/nextjs/src/app/api/test-not-found/route.ts b/testing/js/nextjs/src/app/api/test-not-found/route.tsnew file mode 100644index 00000000..5023ce45--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-not-found/route.ts@@ -0,0 +1,6 @@+import { NextResponse } from "next/server";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async () => {+ return NextResponse.json({ status: "not-found" }, { status: 404 });+});diff --git a/testing/js/nextjs/src/app/api/test-ok/route.ts b/testing/js/nextjs/src/app/api/test-ok/route.tsnew file mode 100644index 00000000..81689168--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-ok/route.ts@@ -0,0 +1,6 @@+import { NextResponse } from "next/server";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async () => {+ return NextResponse.json({ status: "ok" });+});diff --git a/testing/js/nextjs/src/app/api/test-recording/route.ts b/testing/js/nextjs/src/app/api/test-recording/route.tsnew file mode 100644index 00000000..f2b0c273--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-recording/route.ts@@ -0,0 +1,12 @@+import { NextRequest, NextResponse } from "next/server";+import { withTraceway } from "@/lib/traceway-handler";++export const POST = withTraceway(async (req: NextRequest) => {+ const body = await req.json();++ if (body?.action === "panic") {+ throw new Error("panic triggered by /test-recording");+ }++ return NextResponse.json({ status: "ok", received: body });+});diff --git a/testing/js/nextjs/src/app/api/test-spans/route.ts b/testing/js/nextjs/src/app/api/test-spans/route.tsnew file mode 100644index 00000000..7dfe6cc7--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-spans/route.ts@@ -0,0 +1,19 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async (_req, { startSpan }) => {+ const dbSpan = startSpan("db.query");+ await new Promise((r) => setTimeout(r, 50));+ traceway.endSpan(dbSpan);++ const cacheSpan = startSpan("cache.set");+ await new Promise((r) => setTimeout(r, 20));+ traceway.endSpan(cacheSpan);++ const httpSpan = startSpan("http.external_api");+ await new Promise((r) => setTimeout(r, 100));+ traceway.endSpan(httpSpan);++ return NextResponse.json({ status: "spans captured" });+});diff --git a/testing/js/nextjs/src/app/api/test-task/route.ts b/testing/js/nextjs/src/app/api/test-task/route.tsnew file mode 100644index 00000000..8faa8336--- /dev/null+++ b/testing/js/nextjs/src/app/api/test-task/route.ts@@ -0,0 +1,12 @@+import { NextResponse } from "next/server";+import * as traceway from "@traceway/backend";+import { withTraceway } from "@/lib/traceway-handler";++export const GET = withTraceway(async () => {+ traceway.measureTask("background-data-processor", async () => {+ const span = traceway.startSpan("processing");+ await new Promise((r) => setTimeout(r, 200));+ traceway.endSpan(span);+ });+ return NextResponse.json({ status: "task started" });+});diff --git a/testing/js/nextjs/src/lib/traceway-handler.ts b/testing/js/nextjs/src/lib/traceway-handler.tsnew file mode 100644index 00000000..e6e3f59f--- /dev/null+++ b/testing/js/nextjs/src/lib/traceway-handler.ts@@ -0,0 +1,65 @@+import { NextRequest, NextResponse } from "next/server";+import * as traceway from "@traceway/backend";++type HandlerFn = (+ req: NextRequest,+ ctx: { traceId: string; startSpan: (name: string) => ReturnType<typeof traceway.startSpan> }+) => Promise<NextResponse> | NextResponse;++export function withTraceway(handler: HandlerFn) {+ return async (req: NextRequest) => {+ const traceId = crypto.randomUUID().replace(/-/g, "");+ const startedAt = new Date();+ const startMs = performance.now();+ const spans: ReturnType<typeof traceway.startSpan>[] = [];++ const startSpan = (name: string) => {+ const span = traceway.startSpan(name);+ spans.push(span);+ return span;+ };++ try {+ const res = await handler(req, { traceId, startSpan });+ const durationMs = performance.now() - startMs;+ const endpoint = `${req.method} ${req.nextUrl.pathname}`;+ const completedSpans = spans.map((s) => traceway.endSpan(s));++ traceway.captureTrace(+ traceId,+ endpoint,+ durationMs,+ startedAt,+ res.status,+ 0,+ req.headers.get("x-forwarded-for") || "",+ undefined,+ completedSpans+ );++ return res;+ } catch (err) {+ const durationMs = performance.now() - startMs;+ const endpoint = `${req.method} ${req.nextUrl.pathname}`;+ const completedSpans = spans.map((s) => traceway.endSpan(s));++ if (err instanceof Error) {+ traceway.captureExceptionWithAttributes(err, undefined, traceId);+ }++ traceway.captureTrace(+ traceId,+ endpoint,+ durationMs,+ startedAt,+ 500,+ 0,+ req.headers.get("x-forwarded-for") || "",+ undefined,+ completedSpans+ );++ return NextResponse.json({ error: (err as Error).message }, { status: 500 });+ }+ };+}diff --git a/testing/js/nextjs/tsconfig.json b/testing/js/nextjs/tsconfig.jsonnew file mode 100644index 00000000..407a18a6--- /dev/null+++ b/testing/js/nextjs/tsconfig.json@@ -0,0 +1,23 @@+{+ "compilerOptions": {+ "target": "ES2022",+ "lib": ["dom", "dom.iterable", "esnext"],+ "allowJs": true,+ "skipLibCheck": true,+ "strict": true,+ "noEmit": true,+ "esModuleInterop": true,+ "module": "ESNext",+ "moduleResolution": "bundler",+ "resolveJsonModule": true,+ "isolatedModules": true,+ "jsx": "preserve",+ "incremental": true,+ "plugins": [{ "name": "next" }],+ "paths": {+ "@/*": ["./src/*"]+ }+ },+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],+ "exclude": ["node_modules"]+}diff --git a/testing/js/remix/app/lib/traceway.ts b/testing/js/remix/app/lib/traceway.tsnew file mode 100644index 00000000..9915f66f--- /dev/null+++ b/testing/js/remix/app/lib/traceway.ts@@ -0,0 +1,86 @@+import * as traceway from "@traceway/backend";++const endpoint =+ process.env.TRACEWAY_ENDPOINT ||+ "default_token_change_me@http://localhost:8082/api/report";++let initialized = false;++export function ensureInit() {+ if (!initialized) {+ traceway.init(endpoint, { debug: true });+ initialized = true;+ }+}++type HandlerFn = (+ request: Request,+ ctx: { traceId: string; startSpan: (name: string) => ReturnType<typeof traceway.startSpan> }+) => Promise<Response>;++export function withTraceway(handler: HandlerFn) {+ return async ({ request }: { request: Request }) => {+ ensureInit();++ const traceId = crypto.randomUUID().replace(/-/g, "");+ const startedAt = new Date();+ const startMs = performance.now();+ const spans: ReturnType<typeof traceway.startSpan>[] = [];++ const startSpan = (name: string) => {+ const span = traceway.startSpan(name);+ spans.push(span);+ return span;+ };++ try {+ const res = await handler(request, { traceId, startSpan });+ const durationMs = performance.now() - startMs;+ const url = new URL(request.url);+ const endpoint = `${request.method} ${url.pathname}`;+ const completedSpans = spans.map((s) => traceway.endSpan(s));++ traceway.captureTrace(+ traceId,+ endpoint,+ durationMs,+ startedAt,+ res.status,+ 0,+ request.headers.get("x-forwarded-for") || "",+ undefined,+ completedSpans+ );++ return res;+ } catch (err) {+ const durationMs = performance.now() - startMs;+ const url = new URL(request.url);+ const endpoint = `${request.method} ${url.pathname}`;+ const completedSpans = spans.map((s) => traceway.endSpan(s));++ if (err instanceof Error) {+ traceway.captureExceptionWithAttributes(err, undefined, traceId);+ }++ traceway.captureTrace(+ traceId,+ endpoint,+ durationMs,+ startedAt,+ 500,+ 0,+ request.headers.get("x-forwarded-for") || "",+ undefined,+ completedSpans+ );++ return new Response(JSON.stringify({ error: (err as Error).message }), {+ status: 500,+ headers: { "Content-Type": "application/json" },+ });+ }+ };+}++export { traceway };diff --git a/testing/js/remix/app/routes/api.test-attributes.ts b/testing/js/remix/app/routes/api.test-attributes.tsnew file mode 100644index 00000000..56dc637c--- /dev/null+++ b/testing/js/remix/app/routes/api.test-attributes.ts@@ -0,0 +1,15 @@+import { withTraceway, traceway } from "~/lib/traceway";++export const loader = withTraceway(async () => {+ traceway.captureExceptionWithAttributes(+ new Error("exception with custom attributes"),+ {+ user_id: "usr_123",+ request_id: "req_456",+ env: "testing",+ }+ );+ return new Response(JSON.stringify({ status: "exception with attributes captured" }), {+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-error-nested.ts b/testing/js/remix/app/routes/api.test-error-nested.tsnew file mode 100644index 00000000..0e229f09--- /dev/null+++ b/testing/js/remix/app/routes/api.test-error-nested.ts@@ -0,0 +1,24 @@+import { withTraceway, traceway } from "~/lib/traceway";++function innerFunction(): Error {+ const err = new Error("error from inner function");+ Error.captureStackTrace(err, innerFunction);+ return err;+}++function middleFunction(): Error {+ return innerFunction();+}++function outerFunction(): Error {+ return middleFunction();+}++export const loader = withTraceway(async (_request, { traceId }) => {+ const err = outerFunction();+ traceway.captureExceptionWithAttributes(err, undefined, traceId);+ return new Response(JSON.stringify({ error: "nested error" }), {+ status: 500,+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-error-simple.ts b/testing/js/remix/app/routes/api.test-error-simple.tsnew file mode 100644index 00000000..b979d07b--- /dev/null+++ b/testing/js/remix/app/routes/api.test-error-simple.ts@@ -0,0 +1,10 @@+import { withTraceway, traceway } from "~/lib/traceway";++export const loader = withTraceway(async (_request, { traceId }) => {+ const err = new Error("simple error without stack");+ traceway.captureExceptionWithAttributes(err, undefined, traceId);+ return new Response(JSON.stringify({ error: "simple error" }), {+ status: 500,+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-error-stacktrace.ts b/testing/js/remix/app/routes/api.test-error-stacktrace.tsnew file mode 100644index 00000000..8f8e18b1--- /dev/null+++ b/testing/js/remix/app/routes/api.test-error-stacktrace.ts@@ -0,0 +1,10 @@+import { withTraceway, traceway } from "~/lib/traceway";++export const loader = withTraceway(async (_request, { traceId }) => {+ const err = new Error("error with stack trace");+ traceway.captureExceptionWithAttributes(err, undefined, traceId);+ return new Response(JSON.stringify({ error: "stacktrace error" }), {+ status: 500,+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-error-wrapped.ts b/testing/js/remix/app/routes/api.test-error-wrapped.tsnew file mode 100644index 00000000..b1ddf697--- /dev/null+++ b/testing/js/remix/app/routes/api.test-error-wrapped.ts@@ -0,0 +1,12 @@+import { withTraceway, traceway } from "~/lib/traceway";++export const loader = withTraceway(async (_request, { traceId }) => {+ const base = new Error("base error");+ const wrapped = new Error("layer 1: " + base.message, { cause: base });+ const wrapped2 = new Error("layer 2: " + wrapped.message, { cause: wrapped });+ traceway.captureExceptionWithAttributes(wrapped2, undefined, traceId);+ return new Response(JSON.stringify({ error: "wrapped error" }), {+ status: 500,+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-exception.ts b/testing/js/remix/app/routes/api.test-exception.tsnew file mode 100644index 00000000..d90a0cab--- /dev/null+++ b/testing/js/remix/app/routes/api.test-exception.ts@@ -0,0 +1,5 @@+import { withTraceway } from "~/lib/traceway";++export const loader = withTraceway(async () => {+ throw new Error("test panic from /test-exception");+});diff --git a/testing/js/remix/app/routes/api.test-message-attributes.ts b/testing/js/remix/app/routes/api.test-message-attributes.tsnew file mode 100644index 00000000..86462b9d--- /dev/null+++ b/testing/js/remix/app/routes/api.test-message-attributes.ts@@ -0,0 +1,9 @@+import { withTraceway, traceway } from "~/lib/traceway";++export const loader = withTraceway(async () => {+ // JS SDK captureMessage does not support attributes+ traceway.captureMessage("test message with attributes");+ return new Response(JSON.stringify({ status: "message with attributes sent" }), {+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-message.ts b/testing/js/remix/app/routes/api.test-message.tsnew file mode 100644index 00000000..3ce43030--- /dev/null+++ b/testing/js/remix/app/routes/api.test-message.ts@@ -0,0 +1,8 @@+import { withTraceway, traceway } from "~/lib/traceway";++export const loader = withTraceway(async () => {+ traceway.captureMessage("test message from /test-message");+ return new Response(JSON.stringify({ status: "message sent" }), {+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-metric.ts b/testing/js/remix/app/routes/api.test-metric.tsnew file mode 100644index 00000000..d3636a84--- /dev/null+++ b/testing/js/remix/app/routes/api.test-metric.ts@@ -0,0 +1,8 @@+import { withTraceway, traceway } from "~/lib/traceway";++export const loader = withTraceway(async () => {+ traceway.captureMetric("test.custom_metric", 42.0);+ return new Response(JSON.stringify({ status: "metric captured" }), {+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-not-found.ts b/testing/js/remix/app/routes/api.test-not-found.tsnew file mode 100644index 00000000..b38eafe5--- /dev/null+++ b/testing/js/remix/app/routes/api.test-not-found.ts@@ -0,0 +1,8 @@+import { withTraceway } from "~/lib/traceway";++export const loader = withTraceway(async () => {+ return new Response(JSON.stringify({ status: "not-found" }), {+ status: 404,+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-ok.ts b/testing/js/remix/app/routes/api.test-ok.tsnew file mode 100644index 00000000..61e71c9d--- /dev/null+++ b/testing/js/remix/app/routes/api.test-ok.ts@@ -0,0 +1,7 @@+import { withTraceway } from "~/lib/traceway";++export const loader = withTraceway(async () => {+ return new Response(JSON.stringify({ status: "ok" }), {+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-recording.ts b/testing/js/remix/app/routes/api.test-recording.tsnew file mode 100644index 00000000..cd53b988--- /dev/null+++ b/testing/js/remix/app/routes/api.test-recording.ts@@ -0,0 +1,13 @@+import { withTraceway } from "~/lib/traceway";++export const action = withTraceway(async (request) => {+ const body = await request.json();++ if (body?.action === "panic") {+ throw new Error("panic triggered by /test-recording");+ }++ return new Response(JSON.stringify({ status: "ok", received: body }), {+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-spans.ts b/testing/js/remix/app/routes/api.test-spans.tsnew file mode 100644index 00000000..3e558319--- /dev/null+++ b/testing/js/remix/app/routes/api.test-spans.ts@@ -0,0 +1,19 @@+import { withTraceway, traceway } from "~/lib/traceway";++export const loader = withTraceway(async (_request, { startSpan }) => {+ const dbSpan = startSpan("db.query");+ await new Promise((r) => setTimeout(r, 50));+ traceway.endSpan(dbSpan);++ const cacheSpan = startSpan("cache.set");+ await new Promise((r) => setTimeout(r, 20));+ traceway.endSpan(cacheSpan);++ const httpSpan = startSpan("http.external_api");+ await new Promise((r) => setTimeout(r, 100));+ traceway.endSpan(httpSpan);++ return new Response(JSON.stringify({ status: "spans captured" }), {+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/app/routes/api.test-task.ts b/testing/js/remix/app/routes/api.test-task.tsnew file mode 100644index 00000000..3db1f066--- /dev/null+++ b/testing/js/remix/app/routes/api.test-task.ts@@ -0,0 +1,12 @@+import { withTraceway, traceway } from "~/lib/traceway";++export const loader = withTraceway(async () => {+ traceway.measureTask("background-data-processor", async () => {+ const span = traceway.startSpan("processing");+ await new Promise((r) => setTimeout(r, 200));+ traceway.endSpan(span);+ });+ return new Response(JSON.stringify({ status: "task started" }), {+ headers: { "Content-Type": "application/json" },+ });+});diff --git a/testing/js/remix/package.json b/testing/js/remix/package.jsonnew file mode 100644index 00000000..6553ff5b--- /dev/null+++ b/testing/js/remix/package.json@@ -0,0 +1,26 @@+{+ "name": "traceway-test-remix",+ "version": "1.0.0",+ "private": true,+ "type": "module",+ "scripts": {+ "dev": "remix vite:dev --port ${PORT:-8080}",+ "build": "remix vite:build",+ "start": "remix-serve build/server/index.js"+ },+ "dependencies": {+ "@remix-run/node": "^2.15.0",+ "@remix-run/react": "^2.15.0",+ "@remix-run/serve": "^2.15.0",+ "@traceway/backend": "file:../../../../js-client/packages/backend",+ "@traceway/core": "file:../../../../js-client/packages/core",+ "isbot": "^5.1.0",+ "react": "^18.3.0",+ "react-dom": "^18.3.0"+ },+ "devDependencies": {+ "@remix-run/dev": "^2.15.0",+ "typescript": "^5.7.0",+ "vite": "^6.0.0"+ }+}diff --git a/testing/js/remix/tsconfig.json b/testing/js/remix/tsconfig.jsonnew file mode 100644index 00000000..76ce5d86--- /dev/null+++ b/testing/js/remix/tsconfig.json@@ -0,0 +1,18 @@+{+ "compilerOptions": {+ "target": "ES2022",+ "module": "ESNext",+ "moduleResolution": "bundler",+ "esModuleInterop": true,+ "strict": true,+ "lib": ["DOM", "DOM.Iterable", "ES2022"],+ "jsx": "react-jsx",+ "isolatedModules": true,+ "skipLibCheck": true,+ "forceConsistentCasingInFileNames": true,+ "paths": {+ "~/*": ["./app/*"]+ }+ },+ "include": ["app", "env.d.ts"]+}diff --git a/testing/js/remix/vite.config.ts b/testing/js/remix/vite.config.tsnew file mode 100644index 00000000..23dc790c--- /dev/null+++ b/testing/js/remix/vite.config.ts@@ -0,0 +1,13 @@+import { vitePlugin as remix } from "@remix-run/dev";+import { defineConfig } from "vite";++export default defineConfig({+ plugins: [+ remix({+ ssr: true,+ }),+ ],+ server: {+ port: Number(process.env.PORT) || 8080,+ },+});diff --git a/testing/testingapispec.md b/testing/testingapispec.mdnew file mode 100644index 00000000..ac144bb7--- /dev/null+++ b/testing/testingapispec.md@@ -0,0 +1,462 @@+# Traceway SDK Integration Testing API Specification++## Environment Variables++| Variable | Default | Description |+|----------|---------|-------------|+| `PORT` | `8080` | Port the test app listens on |+| `TRACEWAY_ENDPOINT` | `default_token_change_me@http://localhost:8082/api/report` | Traceway connection string (`<token>@<server_url>`) |++## Running Test Apps++### Go Frameworks++```bash+# Gin+cd testing/go/gin && go run .++# Chi+cd testing/go/chi && go run .++# Stdlib (net/http)+cd testing/go/stdlib && go run .++# Fiber+cd testing/go/fiber && go run .++# Fasthttp+cd testing/go/fasthttp && go run .+```++### JS Frameworks++```bash+# Express+cd testing/js/express && npm install && npm run dev++# NestJS+cd testing/js/nestjs && npm install && npm run dev++# Next.js+cd testing/js/nextjs && npm install && npm run dev++# Remix+cd testing/js/remix && npm install && npm run dev+```++## Endpoints++All endpoints use `http://localhost:8080` as the base URL (configurable via `PORT`).++For Next.js and Remix, all endpoints are prefixed with `/api/` (e.g., `/api/test-ok` instead of `/test-ok`).++---++### 1. GET /test-ok++**Purpose:** Basic transaction tracking - verifies the SDK captures a successful HTTP request.++**Expected Response:**+```json+{"status": "ok"}+```+Status: `200`++**curl:**+```bash+curl http://localhost:8080/test-ok+```++**Verification:**+- `transactions` table: row with matching `endpoint` = `GET /test-ok`, `status_code` = `200`+- Duration should be non-zero++---++### 2. GET /test-not-found++**Purpose:** Error status code tracking - verifies the SDK captures non-200 status codes.++**Expected Response:**+```json+{"status": "not-found"}+```+Status: `404`++**curl:**+```bash+curl http://localhost:8080/test-not-found+```++**Verification:**+- `transactions` table: row with `endpoint` = `GET /test-not-found`, `status_code` = `404`++---++### 3. GET /test-exception++**Purpose:** Panic recovery and uncaught exception capture.++**Expected Response:** Status `500` (body varies by framework)++**curl:**+```bash+curl http://localhost:8080/test-exception+```++**Verification:**+- `exception_stack_traces` table: row with `type` containing panic/Error type, `value` containing `"test panic from /test-exception"`+- Stack trace should be present+- `transactions` table: row with `status_code` = `500`++---++### 4. GET /test-error-simple++**Purpose:** Explicit error capture with a plain error (no stack trace attached).++**Expected Response:**+```json+{"error": "simple error"}+```+Status: `500`++**curl:**+```bash+curl http://localhost:8080/test-error-simple+```++**Verification:**+- `exception_stack_traces` table: row with `value` containing `"simple error without stack"`+- `transactions` table: row with `status_code` = `500`++---++### 5. GET /test-error-stacktrace++**Purpose:** Error capture with `NewStackTraceErrorf` (Go) or `Error` with stack (JS).++**Expected Response:**+```json+{"error": "stacktrace error"}+```+Status: `500`++**curl:**+```bash+curl http://localhost:8080/test-error-stacktrace+```++**Verification:**+- `exception_stack_traces` table: row with `value` containing `"error with stack trace"`+- Stack trace should contain the handler function name+- `transactions` table: row with `status_code` = `500`++---++### 6. GET /test-error-wrapped++**Purpose:** Wrapped/chained error capture.++**Expected Response:**+```json+{"error": "wrapped error"}+```+Status: `500`++**curl:**+```bash+curl http://localhost:8080/test-error-wrapped+```++**Verification:**+- `exception_stack_traces` table: row with `value` containing `"layer 2"` and `"base error"` in the chain+- Error chain should preserve wrapping (Go: `fmt.Errorf %w`, JS: `Error.cause`)+- `transactions` table: row with `status_code` = `500`++---++### 7. GET /test-error-nested++**Purpose:** 3-level nested function call error with stack trace from `NewStackTraceErrorf` (Go) or `Error.captureStackTrace` (JS).++**Expected Response:**+```json+{"error": "nested error"}+```+Status: `500`++**curl:**+```bash+curl http://localhost:8080/test-error-nested+```++**Verification:**+- `exception_stack_traces` table: row with `value` containing `"error from inner function"`+- Stack trace should show `innerFunction`, `middleFunction`, `outerFunction` in the call chain+- `transactions` table: row with `status_code` = `500`++---++### 8. GET /test-message++**Purpose:** Message capture via `CaptureMessage` / `captureMessage`.++**Expected Response:**+```json+{"status": "message sent"}+```+Status: `200`++**curl:**+```bash+curl http://localhost:8080/test-message+```++**Verification:**+- `exception_stack_traces` table: row with `value` = `"test message from /test-message"` and `type` = `"message"` (or similar message type marker)+- `transactions` table: row with `status_code` = `200`++---++### 9. GET /test-message-attributes++**Purpose:** Message capture with attributes. Tests `CaptureMessageAttributes` (Go) or plain `captureMessage` (JS - no attributes support).++**Expected Response:**+```json+{"status": "message with attributes sent"}+```+Status: `200`++**curl:**+```bash+curl http://localhost:8080/test-message-attributes+```++**Verification:**+- `exception_stack_traces` table: row with `value` = `"test message with attributes"`+- **Go only:** `tags` map should contain `source` = `"test-message-attributes"` and `priority` = `"high"`+- **JS limitation:** `captureMessage` does not support attributes; message is captured without custom tags++---++### 10. GET /test-spans++**Purpose:** Nested span capture via `StartSpan`/`EndSpan` within a request.++**Expected Response:**+```json+{"status": "spans captured"}+```+Status: `200`++**curl:**+```bash+curl http://localhost:8080/test-spans+```++**Verification:**+- `transactions` table: row with `status_code` = `200` and `endpoint` = `GET /test-spans`+- The transaction should have associated spans:+ - `db.query` span (~50ms)+ - `cache.set` span (~20ms)+ - `http.external_api` span (~100ms)+- Total request duration should be >= 170ms++**Note:** For Fiber and Fasthttp, spans use `context.Background()` since these frameworks don't use `context.Context` natively, so spans won't be attached to the trace context automatically.++---++### 11. GET /test-task++**Purpose:** Background task measurement via `MeasureTask` / `measureTask`.++**Expected Response:**+```json+{"status": "task started"}+```+Status: `200`++**curl:**+```bash+curl http://localhost:8080/test-task+```++**Verification:**+- `transactions` table: a task record with `endpoint` = `"background-data-processor"` should appear after the collection interval (default 5s)+- The task should have a `processing` span (~200ms)+- The task is async, so data may arrive in a subsequent collection frame++---++### 12. GET /test-metric++**Purpose:** Custom metric capture via `CaptureMetric` / `captureMetric`.++**Expected Response:**+```json+{"status": "metric captured"}+```+Status: `200`++**curl:**+```bash+curl http://localhost:8080/test-metric+```++**Verification:**+- `metric_records` table: row with `name` = `"test.custom_metric"` and `value` = `42.0`+- `transactions` table: row with `status_code` = `200`++---++### 13. GET /test-attributes++**Purpose:** Exception capture with custom attributes map via `CaptureExceptionWithAttributes` / `captureExceptionWithAttributes`.++**Expected Response:**+```json+{"status": "exception with attributes captured"}+```+Status: `200`++**curl:**+```bash+curl http://localhost:8080/test-attributes+```++**Verification:**+- `exception_stack_traces` table: row with `value` containing `"exception with custom attributes"`+- `tags` map should contain:+ - `user_id` = `"usr_123"`+ - `request_id` = `"req_456"`+ - `env` = `"testing"`+- `transactions` table: row with `status_code` = `200`++---++### 14. POST /test-recording++**Purpose:** Request body/header recording on error. Tests `WithOnErrorRecording` capturing request details when a panic occurs.++**Request Body:**+```json+{"action": "panic", "data": "test payload"}+```++**Expected Response:** Status `500` (panic response)++**curl (trigger panic with recording):**+```bash+curl -X POST http://localhost:8080/test-recording \+ -H "Content-Type: application/json" \+ -H "X-Custom-Header: test-value" \+ -d '{"action": "panic", "data": "test payload"}'+```++**curl (normal request):**+```bash+curl -X POST http://localhost:8080/test-recording \+ -H "Content-Type: application/json" \+ -d '{"action": "ok", "data": "test payload"}'+```++Normal response:+```json+{"status": "ok", "received": {"action": "ok", "data": "test payload"}}+```++**Verification (panic case):**+- `exception_stack_traces` table: row with `value` containing `"panic triggered by /test-recording"`+- `tags` map should contain recorded request details (depending on framework recording support):+ - URL/path information+ - Request body content+ - Request headers+- `transactions` table: row with `status_code` = `500`++**Note:** Request recording is a Go SDK middleware feature (`WithOnErrorRecording`). JS frameworks capture request details manually in error handlers.++---++## Framework Matrix++| Feature | Gin | Chi | Stdlib | Fiber | Fasthttp | Express | NestJS | Next.js | Remix |+|---------|-----|-----|--------|-------|----------|---------|--------|---------|-------|+| Auto transaction tracking | Middleware | Middleware | Middleware | Middleware | Middleware | Manual | Manual | Manual | Manual |+| Panic/exception recovery | Middleware | Middleware | Middleware | Middleware | Middleware | Error handler | Exception filter | Wrapper | Wrapper |+| Context-based spans | Yes | Yes | Yes | No* | No* | Manual | Manual | Manual | Manual |+| `CaptureMessageAttributes` | Yes | Yes | Yes | Yes | Yes | No** | No** | No** | No** |+| Request recording on error | Middleware | Middleware | Middleware | Middleware | Middleware | Manual | Manual | Manual | Manual |+| Error via framework API | `ctx.Error()` | Manual | Manual | Return err | Manual | Throw | Throw | Throw | Throw |++\* Fiber and Fasthttp don't have native `context.Context` in handlers; spans use `context.Background()`.++\** JS SDK `captureMessage` does not have an attributes parameter; messages are captured without custom tags.++---++## Verification Guide++### 1. Start Backend+```bash+cd backend && go run .+```++### 2. Start Test App+```bash+cd testing/go/gin && go run .+```++### 3. Run All Endpoints+```bash+BASE=http://localhost:8080++curl $BASE/test-ok+curl $BASE/test-not-found+curl $BASE/test-exception+curl $BASE/test-error-simple+curl $BASE/test-error-stacktrace+curl $BASE/test-error-wrapped+curl $BASE/test-error-nested+curl $BASE/test-message+curl $BASE/test-message-attributes+curl $BASE/test-spans+curl $BASE/test-task+curl $BASE/test-metric+curl $BASE/test-attributes+curl -X POST $BASE/test-recording -H "Content-Type: application/json" -d '{"action":"panic","data":"test"}'+```++### 4. Wait for Collection+Wait at least 10 seconds for the SDK to rotate collection frames and upload data.++### 5. Query Backend API++Check transactions:+```bash+curl -H "Authorization: Bearer <jwt>" \+ "http://localhost:8082/api/transactions?projectId=<project-id>"+```++Check exceptions:+```bash+curl -H "Authorization: Bearer <jwt>" \+ "http://localhost:8082/api/exception-stack-traces/grouped?projectId=<project-id>"+```++Check metrics (dashboard):+```bash+curl -H "Authorization: Bearer <jwt>" \+ "http://localhost:8082/api/dashboard?projectId=<project-id>"+```++---++## ClickHouse Tables Reference++| Table | Data From Endpoints |+|-------|-------------------|+| `transactions` | All endpoints (1-14) generate transaction records |+| `exception_stack_traces` | Endpoints 3-9, 13-14 generate exception/message records |+| `metric_records` | Endpoint 12 generates custom metric + automatic system metrics |