Skip to content

The only tool you need to know what is happening and how to fix it.

js-symbolicator-v2 (#191)

narrow-adventure9585f6477102
diff --git a/.github/workflows/benchmark-symbolicator-cache.yml b/.github/workflows/benchmark-symbolicator-cache.yml
index 5a894995..8c299761 100644
--- a/.github/workflows/benchmark-symbolicator-cache.yml
+++ b/.github/workflows/benchmark-symbolicator-cache.yml
@@ -39,7 +39,7 @@ on:
default: false
permissions:
- contents: write
+ contents: read
jobs:
bench:
@@ -48,9 +48,6 @@ jobs:
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
steps:
- uses: actions/checkout@v4
- with:
- fetch-depth: 0
- token: ${{ secrets.RELEASE_TOKEN }}
- name: Install hcloud CLI
run: |
@@ -95,31 +92,3 @@ jobs:
name: cachebench-${{ github.event.inputs.tier }}
path: benchmarks/results-cachebench/
if-no-files-found: warn
-
- - name: Commit results
- if: github.event.inputs.smoke != 'true'
- run: |
- set -euo pipefail
- git config user.name "traceway-bot"
- git config user.email "[email protected]"
-
- staged="benchmarks/results-cachebench"
- tmp_staged="$(mktemp -d)/staged"
- cp -a "${staged}" "${tmp_staged}"
-
- git fetch origin main
- git reset --hard origin/main
-
- rm -rf "${staged}"
- mkdir -p "${staged}"
- cp -a "${tmp_staged}/." "${staged}/"
- rm -rf "${tmp_staged%/staged}"
-
- git add -A "${staged}"
- if git diff --cached --quiet; then
- echo "nothing to commit"
- exit 0
- fi
- git commit -m "bench: symbolicator-cache ${{ github.event.inputs.tier }} $(date -u +%Y-%m-%d)"
- git pull --rebase origin main
- git push
diff --git a/.github/workflows/benchmark-symbolicator.yml b/.github/workflows/benchmark-symbolicator.yml
index a9f2a00f..4280d074 100644
--- a/.github/workflows/benchmark-symbolicator.yml
+++ b/.github/workflows/benchmark-symbolicator.yml
@@ -37,8 +37,8 @@ jobs:
path: |
~/.cargo/registry
~/.cargo/git
- backend/app/symbolicator/oxc-shim/target
- key: oxc-shim-${{ runner.os }}-${{ hashFiles('backend/app/symbolicator/oxc-shim/Cargo.lock') }}
+ backend/app/symbolicator/scopes/oxc-shim/target
+ key: oxc-shim-${{ runner.os }}-${{ hashFiles('backend/app/symbolicator/scopes/oxc-shim/Cargo.lock') }}
- name: Run benchmarks
env:
diff --git a/.gitignore b/.gitignore
index d89d0ef3..24f40510 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,3 +56,10 @@ backend/static/dist/
/benchmarks/loadgen/loadgen-linux-arm64
/benchmarks/_artifact/
benchmarks/loadgen/bench-loadgen
+
+# Rust build artifacts (oxc symbolicator shim)
+backend/app/symbolicator/scopes/oxc-shim/target/
+symbolicator-bench.txt
+
+# Benchmark tool binary, built on demand by benchmarks/scripts/cachebench-*.sh
+/backend/cachebench
diff --git a/CLAUDE.md b/CLAUDE.md
index 60d16ef8..99838234 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -258,6 +258,12 @@ SESSION_RECORDING_RETENTION_DAYS=30 # 0 to disable; only applies when STORAGE_
# Session recording uploads (see "Session Recording Uploader" section below)
SESSION_RECORDING_UPLOAD_WORKERS=32 # 0 to disable uploads entirely
SESSION_RECORDING_UPLOAD_QUEUE_SIZE=2048
+
+# Source map symbolicator
+SYMBOLICATOR_PARSER=goja # goja (default) or oxc (requires -tags oxc build, see scripts/build-oxc-shim.sh)
+SOURCEMAP_CACHE_TYPE=memory # memory (default) or disk (mmap-backed .tw cache)
+SOURCEMAP_DISK_CACHE_PATH=./twcache # only used when SOURCEMAP_CACHE_TYPE=disk
+SOURCEMAP_DISK_CACHE_MAX_MB=2048 # capacity-based LRU eviction of local .tw files
```
---
diff --git a/backend/app/config/config.go b/backend/app/config/config.go
index 3b08cc6c..49cb45a6 100644
--- a/backend/app/config/config.go
+++ b/backend/app/config/config.go
@@ -35,6 +35,10 @@ type Cfg struct {
SourceMapCacheMaxEntries string
SourceMapCacheMaxBytesMB string
+ SourceMapCacheType string
+ SourceMapDiskCachePath string
+ SourceMapDiskCacheMaxMB string
+ SymbolicatorParser string
SMTPEnabled string
SMTPHost string
@@ -110,6 +114,10 @@ func LoadFromEnv() *Cfg {
SourceMapCacheMaxEntries: os.Getenv("SOURCEMAP_CACHE_MAX_ENTRIES"),
SourceMapCacheMaxBytesMB: os.Getenv("SOURCEMAP_CACHE_MAX_BYTES_MB"),
+ SourceMapCacheType: os.Getenv("SOURCEMAP_CACHE_TYPE"),
+ SourceMapDiskCachePath: os.Getenv("SOURCEMAP_DISK_CACHE_PATH"),
+ SourceMapDiskCacheMaxMB: os.Getenv("SOURCEMAP_DISK_CACHE_MAX_MB"),
+ SymbolicatorParser: os.Getenv("SYMBOLICATOR_PARSER"),
SMTPEnabled: os.Getenv("SMTP_ENABLED"),
SMTPHost: os.Getenv("SMTP_HOST"),
diff --git a/backend/app/controllers/clientcontrollers/client.controller.go b/backend/app/controllers/clientcontrollers/client.controller.go
index bc6cba72..65e7faac 100644
--- a/backend/app/controllers/clientcontrollers/client.controller.go
+++ b/backend/app/controllers/clientcontrollers/client.controller.go
@@ -148,7 +148,7 @@ func (e clientController) Report(c *gin.Context) {
for _, cst := range cf.StackTraces {
resolvedStackTrace := cst.StackTrace
if resolveJs {
- resolvedStackTrace = services.ResolveStackTrace(c, projectId, cst.StackTrace)
+ resolvedStackTrace = services.ResolveStackTrace(c, projectId, cst.StackTrace, cst.DebugIds)
}
est := cst.ToExceptionStackTrace(ComputeExceptionHash(resolvedStackTrace, cst.IsMessage), request.AppVersion, request.ServerName)
est.StackTrace = resolvedStackTrace
diff --git a/backend/app/controllers/otelcontrollers/logs_converter.go b/backend/app/controllers/otelcontrollers/logs_converter.go
index 20bd1068..6f7bf5c5 100644
--- a/backend/app/controllers/otelcontrollers/logs_converter.go
+++ b/backend/app/controllers/otelcontrollers/logs_converter.go
@@ -1,6 +1,7 @@
package otelcontrollers
import (
+ "context"
"encoding/hex"
"encoding/json"
"strconv"
@@ -14,12 +15,13 @@ import (
"github.com/tracewayapp/traceway/backend/app/models"
)
-func convertLogs(projectId uuid.UUID, req *collogspb.ExportLogsServiceRequest) []models.LogRecord {
+func convertLogs(ctx context.Context, projectId uuid.UUID, req *collogspb.ExportLogsServiceRequest) []models.LogRecord {
var records []models.LogRecord
for _, rl := range req.ResourceLogs {
resAttrs := extractAttributes(rl.GetResource().GetAttributes())
serviceName := getStringAttribute(rl.GetResource().GetAttributes(), "service.name")
+ language := getStringAttribute(rl.GetResource().GetAttributes(), "telemetry.sdk.language")
resourceSchemaUrl := rl.GetSchemaUrl()
for _, sl := range rl.ScopeLogs {
@@ -30,7 +32,11 @@ func convertLogs(projectId uuid.UUID, req *collogspb.ExportLogsServiceRequest) [
scopeSchemaUrl := sl.GetSchemaUrl()
for _, lr := range sl.LogRecords {
- records = append(records, toLogRecord(projectId, lr, serviceName, resourceSchemaUrl, resAttrs, scopeSchemaUrl, scopeName, scopeVersion, scopeAttrs))
+ record := toLogRecord(projectId, lr, serviceName, resourceSchemaUrl, resAttrs, scopeSchemaUrl, scopeName, scopeVersion, scopeAttrs)
+ if stackTrace := record.LogAttributes["exception.stacktrace"]; stackTrace != "" {
+ record.LogAttributes["exception.stacktrace"] = otelSymbolicateJs(projectId, ctx, stackTrace, language, scopeName)
+ }
+ records = append(records, record)
}
}
}
diff --git a/backend/app/controllers/otelcontrollers/logs_converter_test.go b/backend/app/controllers/otelcontrollers/logs_converter_test.go
index 57419e4e..37dd7a61 100644
--- a/backend/app/controllers/otelcontrollers/logs_converter_test.go
+++ b/backend/app/controllers/otelcontrollers/logs_converter_test.go
@@ -1,13 +1,116 @@
package otelcontrollers
import (
+ "context"
"encoding/base64"
"encoding/hex"
+ "strings"
"testing"
+ "github.com/google/uuid"
+ "github.com/tracewayapp/traceway/backend/app/services"
+ "github.com/tracewayapp/traceway/backend/app/storage"
+ collogspb "go.opentelemetry.io/proto/otlp/collector/logs/v1"
+ commonpb "go.opentelemetry.io/proto/otlp/common/v1"
logspb "go.opentelemetry.io/proto/otlp/logs/v1"
+ resourcepb "go.opentelemetry.io/proto/otlp/resource/v1"
)
+const testSourceMap = `{"version":3,"names":["abcd"],"sources":["tests/fixtures/simple/original.js"],"sourcesContent":["// ./node_modules/.bin/terser -c -m --module tests/fixtures/simple/original.js --source-map includeSources -o tests/fixtures/simple/minified.js\nfunction abcd() {}\nexport default abcd;\n"],"mappings":"AACA,SAASA,oBACMA"}`
+
+type fakeStore struct{ files map[string][]byte }
+
+func (s *fakeStore) Read(_ context.Context, key string) ([]byte, error) {
+ if b, ok := s.files[key]; ok {
+ return b, nil
+ }
+ return nil, storage.ErrNotFound
+}
+
+func (s *fakeStore) Write(context.Context, string, []byte) error { return nil }
+
+func (s *fakeStore) Delete(context.Context, string) error { return nil }
+
+func setFakeStore(t *testing.T, files map[string][]byte) {
+ t.Helper()
+ prev := storage.Store
+ storage.Store = &fakeStore{files: files}
+ t.Cleanup(func() { storage.Store = prev })
+}
+
+func logsRequest(language, scopeName string, attrs ...*commonpb.KeyValue) *collogspb.ExportLogsServiceRequest {
+ var resAttrs []*commonpb.KeyValue
+ if language != "" {
+ resAttrs = append(resAttrs, strKV("telemetry.sdk.language", language))
+ }
+ return &collogspb.ExportLogsServiceRequest{
+ ResourceLogs: []*logspb.ResourceLogs{{
+ Resource: &resourcepb.Resource{Attributes: resAttrs},
+ ScopeLogs: []*logspb.ScopeLogs{{
+ Scope: &commonpb.InstrumentationScope{Name: scopeName},
+ LogRecords: []*logspb.LogRecord{{Attributes: attrs}},
+ }},
+ }},
+ }
+}
+
+func TestConvertLogs_SymbolicatesExceptionStacktrace(t *testing.T) {
+ projectId := uuid.MustParse("00000000-0000-0000-0000-0000000000aa")
+ setFakeStore(t, map[string][]byte{
+ services.SourceMapStorageKey(projectId, "minified.js.map"): []byte(testSourceMap),
+ })
+
+ rawStack := "Error: boom\n at t (https://cdn.example.com/assets/minified.js:1:11)"
+ req := logsRequest("webjs", "@opentelemetry/winston-transport",
+ strKV("exception.type", "Error"),
+ strKV("exception.stacktrace", rawStack),
+ )
+
+ records := convertLogs(context.Background(), projectId, req)
+ if len(records) != 1 {
+ t.Fatalf("expected 1 record, got %d", len(records))
+ }
+ got := records[0].LogAttributes["exception.stacktrace"]
+ if !strings.Contains(got, "original.js") {
+ t.Errorf("expected stack trace resolved via source map, got %q", got)
+ }
+ if got := records[0].LogAttributes["exception.type"]; got != "Error" {
+ t.Errorf("expected other attributes untouched, got exception.type=%q", got)
+ }
+}
+
+func TestConvertLogs_ScopeNameDetectsJs(t *testing.T) {
+ projectId := uuid.MustParse("00000000-0000-0000-0000-0000000000ab")
+ setFakeStore(t, nil)
+
+ rawStack := "Error: boom\n at t (https://cdn.example.com/assets/minified.js:1:11)"
+ req := logsRequest("", "@opentelemetry/winston-transport", strKV("exception.stacktrace", rawStack))
+
+ records := convertLogs(context.Background(), projectId, req)
+ if len(records) != 1 {
+ t.Fatalf("expected 1 record, got %d", len(records))
+ }
+ want := "Error: boom\nt()\n https://cdn.example.com/assets/minified.js:1:11"
+ if got := records[0].LogAttributes["exception.stacktrace"]; got != want {
+ t.Errorf("expected canonicalized stack trace stored:\n got %q\nwant %q", got, want)
+ }
+}
+
+func TestConvertLogs_NonJsStacktraceUntouched(t *testing.T) {
+ setFakeStore(t, nil)
+
+ rawStack := "java.lang.RuntimeException: boom\n\tat com.example.Foo.bar(Foo.java:10)"
+ req := logsRequest("java", "io.opentelemetry.tomcat-7.0", strKV("exception.stacktrace", rawStack))
+
+ records := convertLogs(context.Background(), testProjectId, req)
+ if len(records) != 1 {
+ t.Fatalf("expected 1 record, got %d", len(records))
+ }
+ if got := records[0].LogAttributes["exception.stacktrace"]; got != rawStack {
+ t.Errorf("expected non-JS stack trace untouched, got %q", got)
+ }
+}
+
// Pins the protojson base64-of-hex round-trip — see logs_converter.go.
func TestToLogRecord_IDEncoding(t *testing.T) {
const wireTraceHex = "7b873c7bbf35739e79e1f7b9736739f7"
diff --git a/backend/app/controllers/otelcontrollers/otel.controller.go b/backend/app/controllers/otelcontrollers/otel.controller.go
index 1b57b442..92fbbaf3 100644
--- a/backend/app/controllers/otelcontrollers/otel.controller.go
+++ b/backend/app/controllers/otelcontrollers/otel.controller.go
@@ -7,6 +7,7 @@ import (
"time"
"github.com/gin-gonic/gin"
+ "github.com/google/uuid"
"github.com/tracewayapp/traceway/backend/app/hooks"
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/models"
@@ -14,6 +15,7 @@ import (
"github.com/tracewayapp/traceway/backend/app/repositories"
"github.com/tracewayapp/traceway/backend/app/services"
"github.com/tracewayapp/traceway/backend/app/storage"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/jsstack"
traceway "go.tracewayapp.com"
)
@@ -21,6 +23,14 @@ func msSince(t time.Time) float64 {
return float64(time.Since(t).Microseconds()) / 1000.0
}
+func otelSymbolicateJs(projectId uuid.UUID, ctx context.Context, stackTrace, language, scopeName string) string {
+ if !isJsTelemetry(language, scopeName) {
+ return stackTrace
+ }
+ canonical, _ := jsstack.Canonicalize(stackTrace)
+ return services.ResolveStackTrace(ctx, projectId, canonical, nil)
+}
+
type otelController struct{}
var OtelController = otelController{}
@@ -57,15 +67,8 @@ func (o otelController) ExportTraces(c *gin.Context) {
return
}
- symbolicate := func(ctx context.Context, stackTrace, language string) string {
- if !isJsLanguage(language) {
- return stackTrace
- }
- return services.ResolveStackTrace(ctx, projectId, stackTrace)
- }
-
convertStart := time.Now()
- endpoints, tasks, spans, exceptions, aiTraces, aiConversations := convertTraces(c, projectId, req, symbolicate)
+ endpoints, tasks, spans, exceptions, aiTraces, aiConversations := convertTraces(c, projectId, req)
var droppedHealthchecks int
endpoints, spans, droppedHealthchecks = services.FilterHealthchecks(project, endpoints, spans, exceptions)
@@ -226,7 +229,7 @@ func (o otelController) ExportLogs(c *gin.Context) {
}
convertStart := time.Now()
- records := convertLogs(projectId, req)
+ records := convertLogs(c, projectId, req)
convertMs := msSince(convertStart)
insertMs := 0.0
diff --git a/backend/app/controllers/otelcontrollers/trace_converter.go b/backend/app/controllers/otelcontrollers/trace_converter.go
index 59457ba0..1ed98849 100644
--- a/backend/app/controllers/otelcontrollers/trace_converter.go
+++ b/backend/app/controllers/otelcontrollers/trace_converter.go
@@ -42,7 +42,7 @@ func (k entityKind) traceType() string {
return ""
}
-func convertTraces(ctx context.Context, projectId uuid.UUID, req *coltracepb.ExportTraceServiceRequest, symbolicate symbolicateFunc) (
+func convertTraces(ctx context.Context, projectId uuid.UUID, req *coltracepb.ExportTraceServiceRequest) (
endpoints []models.Endpoint,
tasks []models.Task,
spans []models.Span,
@@ -267,7 +267,7 @@ func convertTraces(ctx context.Context, projectId uuid.UUID, req *coltracepb.Exp
if event.Name == "exception" {
exc := buildException(
ctx, projectId, ownerId, traceType, event,
- allAttrs, serverName, appVersion, language, symbolicate,
+ allAttrs, serverName, appVersion, language, entry.scopeName,
)
if owner != nil {
exc.DistributedTraceId = owner.distributedTraceId
@@ -441,16 +441,13 @@ func buildTask(
}
}
-type symbolicateFunc func(ctx context.Context, stackTrace, language string) string
-
func buildException(
ctx context.Context,
projectId, traceId uuid.UUID,
traceType string,
event *tracepb.Span_Event,
spanAttrs map[string]string,
- serverName, appVersion, language string,
- symbolicate symbolicateFunc,
+ serverName, appVersion, language, scopeName string,
) models.ExceptionStackTrace {
eventAttrs := event.Attributes
excType := getStringAttribute(eventAttrs, "exception.type")
@@ -462,9 +459,7 @@ func buildException(
stackTrace = formatExceptionStackTrace(excType, excMessage, excStacktrace)
}
- if symbolicate != nil {
- stackTrace = symbolicate(ctx, stackTrace, language)
- }
+ stackTrace = otelSymbolicateJs(projectId, ctx, stackTrace, language, scopeName)
hash := clientcontrollers.ComputeExceptionHash(stackTrace, false)
@@ -504,6 +499,20 @@ func isJsLanguage(lang string) bool {
return false
}
+// JS instrumentations are also recognizable by their scope name when
+// telemetry.sdk.language is absent: npm scoped packages ("@scope/pkg") are
+// an npm-only naming convention across OTel SDKs, and Next.js's built-in
+// tracer reports the unscoped scope name "next.js".
+func isJsTelemetry(language, scopeName string) bool {
+ if isJsLanguage(language) {
+ return true
+ }
+ if strings.HasPrefix(scopeName, "@") && strings.Contains(scopeName, "/") {
+ return true
+ }
+ return scopeName == "next.js"
+}
+
func buildHoneycombStackTrace(excType, excMessage string, eventAttrs []*commonpb.KeyValue) (string, bool) {
urls := getStringArray(eventAttrs, "exception.structured_stacktrace.urls")
if len(urls) == 0 {
diff --git a/backend/app/controllers/otelcontrollers/trace_converter_test.go b/backend/app/controllers/otelcontrollers/trace_converter_test.go
index b2e2f6ee..0075b50b 100644
--- a/backend/app/controllers/otelcontrollers/trace_converter_test.go
+++ b/backend/app/controllers/otelcontrollers/trace_converter_test.go
@@ -6,9 +6,11 @@ import (
"flag"
"os"
"sort"
+ "strings"
"testing"
"github.com/google/uuid"
+ "github.com/tracewayapp/traceway/backend/app/services"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
@@ -95,7 +97,8 @@ func TestConvertTraces_Snapshot(t *testing.T) {
t.Fatalf("failed to unmarshal fixture %s: %v", tt.fixture, err)
}
- endpoints, _, spans, exceptions, aiTraces, aiConversations := convertTraces(context.Background(), testProjectId, req, nil)
+ setFakeStore(t, nil)
+ endpoints, _, spans, exceptions, aiTraces, aiConversations := convertTraces(context.Background(), testProjectId, req)
// Check if all child spans share a trace ID with an endpoint
endpointIds := map[uuid.UUID]bool{}
@@ -376,7 +379,7 @@ func TestTraceIdResolution_CrossScope(t *testing.T) {
},
}
- endpoints, _, spans, _, _, _ := convertTraces(context.Background(), testProjectId, req, nil)
+ endpoints, _, spans, _, _, _ := convertTraces(context.Background(), testProjectId, req)
if len(endpoints) != 1 {
t.Fatalf("expected 1 endpoint, got %d", len(endpoints))
@@ -469,7 +472,7 @@ func TestConvertTraces_ConsumerNonRoot_BecomesTask(t *testing.T) {
}},
}
- endpoints, tasks, spans, _, _, _ := convertTraces(context.Background(), testProjectId, req, nil)
+ endpoints, tasks, spans, _, _, _ := convertTraces(context.Background(), testProjectId, req)
if len(endpoints) != 0 {
t.Fatalf("expected 0 endpoints, got %d", len(endpoints))
@@ -519,7 +522,7 @@ func TestConvertTraces_ConsoleCommand_BecomesTask(t *testing.T) {
}},
}
- _, tasks, _, _, _, _ := convertTraces(context.Background(), testProjectId, req, nil)
+ _, tasks, _, _, _, _ := convertTraces(context.Background(), testProjectId, req)
if len(tasks) != 1 {
t.Fatalf("expected 1 task, got %d", len(tasks))
}
@@ -551,7 +554,7 @@ func TestConvertTraces_InlineGenAi_BecomesAiTrace(t *testing.T) {
}},
}
- endpoints, _, _, _, aiTraces, _ := convertTraces(context.Background(), testProjectId, req, nil)
+ endpoints, _, _, _, aiTraces, _ := convertTraces(context.Background(), testProjectId, req)
if len(endpoints) != 1 {
t.Fatalf("expected 1 endpoint, got %d", len(endpoints))
}
@@ -605,7 +608,7 @@ func TestConvertTraces_ExceptionOnConsumer_TraceTypeIsTask(t *testing.T) {
}},
}
- _, tasks, _, exceptions, _, _ := convertTraces(context.Background(), testProjectId, req, nil)
+ _, tasks, _, exceptions, _, _ := convertTraces(context.Background(), testProjectId, req)
if len(tasks) != 1 || len(exceptions) != 1 {
t.Fatalf("expected 1 task + 1 exception, got %d / %d", len(tasks), len(exceptions))
}
@@ -639,7 +642,7 @@ func TestConvertTraces_OrphanSpan_FallsBackToTraceId(t *testing.T) {
}},
}
- _, _, spans, _, _, _ := convertTraces(context.Background(), testProjectId, req, nil)
+ _, _, spans, _, _, _ := convertTraces(context.Background(), testProjectId, req)
if len(spans) != 1 {
t.Fatalf("expected 1 span row, got %d", len(spans))
}
@@ -711,6 +714,7 @@ func TestConvertTraces_HoneycombJsExceptionSymbolicates(t *testing.T) {
strKV("telemetry.sdk.language", "webjs"),
}},
ScopeSpans: []*tracepb.ScopeSpans{{
+ Scope: &commonpb.InstrumentationScope{Name: "@opentelemetry/instrumentation-fetch"},
Spans: []*tracepb.Span{{
TraceId: traceId, SpanId: spanId,
Name: "GET /", Kind: tracepb.Span_SPAN_KIND_SERVER,
@@ -733,28 +737,97 @@ func TestConvertTraces_HoneycombJsExceptionSymbolicates(t *testing.T) {
}},
}
- var symInput, symLang string
- symbolicate := func(_ context.Context, stackTrace, language string) string {
- symInput, symLang = stackTrace, language
- return "RESOLVED"
- }
-
- _, _, _, exceptions, _, _ := convertTraces(context.Background(), testProjectId, req, symbolicate)
+ setFakeStore(t, nil)
+ _, _, _, exceptions, _, _ := convertTraces(context.Background(), testProjectId, req)
if len(exceptions) != 1 {
t.Fatalf("expected 1 exception, got %d", len(exceptions))
}
exc := exceptions[0]
- if symLang != "webjs" {
- t.Errorf("expected language webjs passed to symbolicate, got %q", symLang)
- }
wantParsed := "Error: user has no name\nn()\n app.min.js:1:63\n app.min.js:1:146"
- if symInput != wantParsed {
- t.Errorf("honeycomb parse:\n got %q\nwant %q", symInput, wantParsed)
- }
- if exc.StackTrace != "RESOLVED" {
- t.Errorf("expected symbolicated stack trace stored, got %q", exc.StackTrace)
+ if exc.StackTrace != wantParsed {
+ t.Errorf("honeycomb parse:\n got %q\nwant %q", exc.StackTrace, wantParsed)
}
if exc.Attributes["telemetry.sdk.language"] != "webjs" {
t.Errorf("expected stamped telemetry.sdk.language=webjs, got %q", exc.Attributes["telemetry.sdk.language"])
}
}
+
+func TestConvertTraces_JsExceptionResolvesWithSourceMap(t *testing.T) {
+ projectId := uuid.MustParse("00000000-0000-0000-0000-0000000000ac")
+ setFakeStore(t, map[string][]byte{
+ services.SourceMapStorageKey(projectId, "minified.js.map"): []byte(testSourceMap),
+ })
+
+ traceId := []byte{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf}
+ spanId := []byte{0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7}
+ now := uint64(1_700_000_000_000_000_000)
+
+ req := &coltracepb.ExportTraceServiceRequest{
+ ResourceSpans: []*tracepb.ResourceSpans{{
+ Resource: &resourcepb.Resource{Attributes: []*commonpb.KeyValue{
+ strKV("service.name", "web"),
+ strKV("telemetry.sdk.language", "webjs"),
+ }},
+ ScopeSpans: []*tracepb.ScopeSpans{{
+ Scope: &commonpb.InstrumentationScope{Name: "@opentelemetry/instrumentation-fetch"},
+ Spans: []*tracepb.Span{{
+ TraceId: traceId, SpanId: spanId,
+ Name: "GET /", Kind: tracepb.Span_SPAN_KIND_SERVER,
+ StartTimeUnixNano: now, EndTimeUnixNano: now + 1_000_000,
+ Attributes: makeAttrs("http.route", "/"),
+ Events: []*tracepb.Span_Event{{
+ Name: "exception",
+ TimeUnixNano: now + 500_000,
+ Attributes: []*commonpb.KeyValue{
+ strKV("exception.type", "Error"),
+ strKV("exception.message", "boom"),
+ strKV("exception.stacktrace", "Error: boom\n at t (https://cdn.example.com/assets/minified.js:1:11)"),
+ },
+ }},
+ }},
+ }},
+ }},
+ }
+
+ _, _, _, exceptions, _, _ := convertTraces(context.Background(), projectId, req)
+ if len(exceptions) != 1 {
+ t.Fatalf("expected 1 exception, got %d", len(exceptions))
+ }
+ if !strings.Contains(exceptions[0].StackTrace, "original.js") {
+ t.Errorf("expected stack trace resolved via source map, got %q", exceptions[0].StackTrace)
+ }
+}
+
+func TestIsJsTelemetry(t *testing.T) {
+ jsCases := [][2]string{
+ {"webjs", ""},
+ {"nodejs", ""},
+ {"javascript", ""},
+ {"TypeScript", ""},
+ {"", "@opentelemetry/instrumentation-express"},
+ {"", "@vercel/otel"},
+ {"", "@prisma/instrumentation"},
+ {"", "next.js"},
+ {"nodejs", "io.opentelemetry.tomcat-7.0"},
+ }
+ for _, c := range jsCases {
+ if !isJsTelemetry(c[0], c[1]) {
+ t.Errorf("isJsTelemetry(%q, %q) = false, want true", c[0], c[1])
+ }
+ }
+
+ nonJsCases := [][2]string{
+ {"", ""},
+ {"java", "io.opentelemetry.spring-webmvc-6.0"},
+ {"python", "opentelemetry.instrumentation.flask"},
+ {"go", "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"},
+ {"dotnet", "OpenTelemetry.Instrumentation.AspNetCore"},
+ {"ruby", "OpenTelemetry::Instrumentation::Rack"},
+ {"", "@noslash"},
+ }
+ for _, c := range nonJsCases {
+ if isJsTelemetry(c[0], c[1]) {
+ t.Errorf("isJsTelemetry(%q, %q) = true, want false", c[0], c[1])
+ }
+ }
+}
diff --git a/backend/app/controllers/sourcemap.controller.go b/backend/app/controllers/sourcemap.controller.go
index 205dd826..c8f19afd 100644
--- a/backend/app/controllers/sourcemap.controller.go
+++ b/backend/app/controllers/sourcemap.controller.go
@@ -1,6 +1,7 @@
package controllers
import (
+ "context"
"fmt"
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/services"
@@ -8,6 +9,7 @@ import (
"io"
"net/http"
"path/filepath"
+ "strings"
"github.com/gin-gonic/gin"
traceway "go.tracewayapp.com"
@@ -15,15 +17,6 @@ import (
type sourceMapController struct{}
-func isSourceArtifact(name string) bool {
- switch filepath.Ext(name) {
- case ".map", ".js", ".cjs", ".mjs":
- return true
- default:
- return false
- }
-}
-
func (s sourceMapController) Upload(c *gin.Context) {
projectId, err := middleware.GetProjectId(c)
if err != nil {
@@ -43,8 +36,21 @@ func (s sourceMapController) Upload(c *gin.Context) {
}
uploaded := 0
+ var storedNames []string
+ defer func() {
+ if len(storedNames) == 0 {
+ return
+ }
+ genCtx := context.WithoutCancel(c.Request.Context())
+ go func() {
+ defer traceway.Recover()
+ services.GenerateTWArtifacts(genCtx, projectId, storedNames)
+ }()
+ }()
for _, fileHeader := range files {
- if !isSourceArtifact(fileHeader.Filename) {
+ switch filepath.Ext(fileHeader.Filename) {
+ case ".map", ".js", ".cjs", ".mjs":
+ default:
continue
}
@@ -66,12 +72,27 @@ func (s sourceMapController) Upload(c *gin.Context) {
return
}
- storageKey := fmt.Sprintf("sourcemaps/%s/%s", projectId, fileHeader.Filename)
+ storageKey := services.SourceMapStorageKey(projectId, fileHeader.Filename)
if err := storage.Store.Write(c, storageKey, data); err != nil {
c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to write source map to storage: %w", err))
return
}
services.InvalidateSourceMap(projectId, fileHeader.Filename)
+ storedNames = append(storedNames, fileHeader.Filename)
+
+ if debugId := services.ExtractDebugId(fileHeader.Filename, data); debugId != "" {
+ aliasName := services.DebugIdBundleName(debugId)
+ if strings.HasSuffix(fileHeader.Filename, ".map") {
+ aliasName = services.DebugIdMapName(debugId)
+ }
+ aliasKey := services.SourceMapStorageKey(projectId, aliasName)
+ if err := storage.Store.Write(c, aliasKey, data); err != nil {
+ c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to write debug id artifact to storage: %w", err))
+ return
+ }
+ services.InvalidateSourceMap(projectId, aliasName)
+ storedNames = append(storedNames, aliasName)
+ }
uploaded++
}
diff --git a/backend/app/models/clientmodels/clientmodels.model.go b/backend/app/models/clientmodels/clientmodels.model.go
index 683527ae..1f79459f 100644
--- a/backend/app/models/clientmodels/clientmodels.model.go
+++ b/backend/app/models/clientmodels/clientmodels.model.go
@@ -18,6 +18,7 @@ type ClientExceptionStackTrace struct {
SessionRecordingId *string `json:"sessionRecordingId"`
SessionId *string `json:"sessionId"`
DistributedTraceId *string `json:"distributedTraceId"`
+ DebugIds map[string]string `json:"debugIds"`
}
func (c *ClientExceptionStackTrace) ToExceptionStackTrace(exceptionHash, appVersion, serverName string) models.ExceptionStackTrace {
diff --git a/backend/app/monitoring/backend_reporter.go b/backend/app/monitoring/backend_reporter.go
index 0796bcba..57b924b3 100644
--- a/backend/app/monitoring/backend_reporter.go
+++ b/backend/app/monitoring/backend_reporter.go
@@ -14,13 +14,17 @@ import (
const backendReportInterval = 30 * time.Second
type backendBaselines struct {
- smHits uint64
- smMisses uint64
- smEvictions uint64
- smFailures uint64
- smNotFound uint64
- smNegativeHits uint64
- first bool
+ smHits uint64
+ smMisses uint64
+ smEvictions uint64
+ smFailures uint64
+ smNotFound uint64
+ smNegativeHits uint64
+ smDiskHits uint64
+ smStoreHits uint64
+ smBuilds uint64
+ smDiskEvictions uint64
+ first bool
}
func StartBackendReporter(ctx context.Context) {
@@ -65,7 +69,22 @@ func reportBackendOnce(b *backendBaselines) {
traceway.CaptureMetric("traceway.sourcemap.load_failures.delta", float64(safeDelta(b.smFailures, smStats.Failures)))
traceway.CaptureMetric("traceway.sourcemap.not_found.delta", float64(safeDelta(b.smNotFound, smStats.NotFound)))
traceway.CaptureMetric("traceway.sourcemap.negative_hits.delta", float64(safeDelta(b.smNegativeHits, smStats.NegativeHits)))
+ traceway.CaptureMetric("traceway.sourcemap.store_hits.delta", float64(safeDelta(b.smStoreHits, smStats.StoreHits)))
+ traceway.CaptureMetric("traceway.sourcemap.builds.delta", float64(safeDelta(b.smBuilds, smStats.Builds)))
}
+ b.smStoreHits = smStats.StoreHits
+ b.smBuilds = smStats.Builds
+ if smStats.DiskEnabled {
+ traceway.CaptureMetric("traceway.sourcemap.disk.entries", float64(smStats.DiskEntries))
+ traceway.CaptureMetric("traceway.sourcemap.disk.bytes", float64(smStats.DiskBytes))
+ if !b.first {
+ traceway.CaptureMetric("traceway.sourcemap.disk.hits.delta", float64(safeDelta(b.smDiskHits, smStats.DiskHits)))
+ traceway.CaptureMetric("traceway.sourcemap.disk.evictions.delta", float64(safeDelta(b.smDiskEvictions, smStats.DiskEvictions)))
+ }
+ b.smDiskHits = smStats.DiskHits
+ b.smDiskEvictions = smStats.DiskEvictions
+ }
+
b.smHits = smStats.Hits
b.smMisses = smStats.Misses
b.smEvictions = smStats.Evictions
diff --git a/backend/app/recordings/uploader_test.go b/backend/app/recordings/uploader_test.go
index 2b6b7ad9..7b2b0ad8 100644
--- a/backend/app/recordings/uploader_test.go
+++ b/backend/app/recordings/uploader_test.go
@@ -15,6 +15,8 @@ type stubStorage struct {
written atomic.Uint64
}
+func (s *stubStorage) Delete(_ context.Context, _ string) error { return nil }
+
func (s *stubStorage) Write(ctx context.Context, key string, data []byte) error {
if s.delay > 0 {
select {
diff --git a/backend/app/services/sourcemap_cache_test.go b/backend/app/services/sourcemap_cache_test.go
index 026363ea..680fbd3f 100644
--- a/backend/app/services/sourcemap_cache_test.go
+++ b/backend/app/services/sourcemap_cache_test.go
@@ -54,6 +54,13 @@ func (c *countingStorage) Write(_ context.Context, key string, data []byte) erro
return nil
}
+func (c *countingStorage) Delete(_ context.Context, key string) error {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ delete(c.data, key)
+ return nil
+}
+
func (c *countingStorage) Read(_ context.Context, key string) ([]byte, error) {
c.mu.Lock()
c.reads[key]++
@@ -161,6 +168,8 @@ type flakyStorage struct {
func (f *flakyStorage) Write(_ context.Context, _ string, _ []byte) error { return nil }
+func (f *flakyStorage) Delete(_ context.Context, _ string) error { return nil }
+
func (f *flakyStorage) Read(_ context.Context, _ string) ([]byte, error) {
f.mu.Lock()
defer f.mu.Unlock()
@@ -207,6 +216,8 @@ type blockingPanicStorage struct {
func (b *blockingPanicStorage) Write(_ context.Context, _ string, _ []byte) error { return nil }
+func (b *blockingPanicStorage) Delete(_ context.Context, _ string) error { return nil }
+
func (b *blockingPanicStorage) Read(_ context.Context, _ string) ([]byte, error) {
<-b.release
panic("storage exploded")
@@ -286,7 +297,7 @@ func TestResolveStackTraceFailedMapAttemptedOncePerTrace(t *testing.T) {
projectId := uuid.New()
trace := "Error: boom\n fn()\n dead.js:1:10\n fn2()\n dead.js:1:20\n fn3()\n dead.js:1:30"
- resolved := ResolveStackTrace(context.Background(), projectId, trace)
+ resolved := ResolveStackTrace(context.Background(), projectId, trace, nil)
if resolved != trace {
t.Error("trace should be stored as-is when its source map cannot be loaded")
}
@@ -347,11 +358,12 @@ func TestResolveStackTraceTransientFailureNegativeCached(t *testing.T) {
projectId := uuid.New()
trace := "Error: boom\n fn()\n down.js:1:10"
- _ = ResolveStackTrace(context.Background(), projectId, trace)
- _ = ResolveStackTrace(context.Background(), projectId, trace)
+ _ = ResolveStackTrace(context.Background(), projectId, trace, nil)
+ firstReads := fs.reads
+ _ = ResolveStackTrace(context.Background(), projectId, trace, nil)
- if fs.reads != 1 {
- t.Errorf("transient storage failures should be negative cached, got %d reads", fs.reads)
+ if fs.reads != firstReads {
+ t.Errorf("transient storage failures should be negative cached, got %d extra reads", fs.reads-firstReads)
}
}
@@ -366,14 +378,14 @@ func TestInvalidateSourceMapClearsNegative(t *testing.T) {
mapKey := fmt.Sprintf("sourcemaps/%s/late.js.map", projectId)
trace := "Error: boom\n fn()\n late.js:1:1"
- if got := ResolveStackTrace(context.Background(), projectId, trace); got != trace {
+ if got := ResolveStackTrace(context.Background(), projectId, trace, nil); got != trace {
t.Error("trace should pass through while the map is missing")
}
cs.data[mapKey] = []byte(`{"version":3,"sources":["a.js"],"names":[],"mappings":"AAAA"}`)
InvalidateSourceMap(projectId, "late.js.map")
- resolved := ResolveStackTrace(context.Background(), projectId, trace)
+ resolved := ResolveStackTrace(context.Background(), projectId, trace, nil)
if !strings.Contains(resolved, "a.js:1:1") {
t.Errorf("upload should clear the negative entry immediately, got %q", resolved)
}
@@ -391,18 +403,18 @@ func TestInvalidateSourceMapEvictsStaleResolver(t *testing.T) {
cs.data[mapKey] = []byte(`{"version":3,"sources":["a.js"],"names":[],"mappings":"AAAA"}`)
trace := "Error: boom\n fn()\n stable.js:1:1"
- if got := ResolveStackTrace(context.Background(), projectId, trace); !strings.Contains(got, "a.js:1:1") {
+ if got := ResolveStackTrace(context.Background(), projectId, trace, nil); !strings.Contains(got, "a.js:1:1") {
t.Fatalf("expected initial resolution against a.js, got %q", got)
}
cs.data[mapKey] = []byte(`{"version":3,"sources":["b.js"],"names":[],"mappings":"AAAA"}`)
- if got := ResolveStackTrace(context.Background(), projectId, trace); !strings.Contains(got, "a.js:1:1") {
+ if got := ResolveStackTrace(context.Background(), projectId, trace, nil); !strings.Contains(got, "a.js:1:1") {
t.Fatalf("re-upload without invalidation should still serve the cached resolver, got %q", got)
}
- InvalidateSourceMap(projectId, "stable.js")
- if got := ResolveStackTrace(context.Background(), projectId, trace); !strings.Contains(got, "b.js:1:1") {
- t.Errorf("invalidation should evict the cached resolver, got %q", got)
+ GenerateTWArtifacts(context.Background(), projectId, []string{"stable.js.map"})
+ if got := ResolveStackTrace(context.Background(), projectId, trace, nil); !strings.Contains(got, "b.js:1:1") {
+ t.Errorf("upload must evict both the cached resolver and the stale tw artifact, got %q", got)
}
}
@@ -411,6 +423,8 @@ type bundleFailStorage struct {
failBundle bool
}
+func (b *bundleFailStorage) Delete(_ context.Context, _ string) error { return nil }
+
func (b *bundleFailStorage) Write(_ context.Context, key string, data []byte) error {
b.data[key] = data
return nil
@@ -441,14 +455,14 @@ func TestTransientBundleReadFailureFailsBuild(t *testing.T) {
trace := "Error: boom\n fn()\n app.js:1:1"
- if got := ResolveStackTrace(context.Background(), projectId, trace); got != trace {
+ if got := ResolveStackTrace(context.Background(), projectId, trace, nil); got != trace {
t.Errorf("a transient bundle read failure must not cache a names-less resolver, got %q", got)
}
bs.failBundle = false
InvalidateSourceMap(projectId, "app.js.map")
- if got := ResolveStackTrace(context.Background(), projectId, trace); !strings.Contains(got, "a.js:1:1") {
+ if got := ResolveStackTrace(context.Background(), projectId, trace, nil); !strings.Contains(got, "a.js:1:1") {
t.Errorf("expected full resolution once the bundle read recovers, got %q", got)
}
}
diff --git a/backend/app/services/sourcemap_debugid.go b/backend/app/services/sourcemap_debugid.go
new file mode 100644
index 00000000..2f93cea0
--- /dev/null
+++ b/backend/app/services/sourcemap_debugid.go
@@ -0,0 +1,54 @@
+package services
+
+import (
+ "encoding/json"
+ "regexp"
+ "strings"
+)
+
+const sourceMapDebugIdDir = "by-debug-id/"
+
+var debugIdRe = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
+var bundleDebugIdCommentRe = regexp.MustCompile(`//[#@] debugId=([0-9a-fA-F-]{36})`)
+
+func NormalizeDebugId(raw string) string {
+ id := strings.ToLower(strings.TrimSpace(raw))
+ if debugIdRe.MatchString(id) {
+ return id
+ }
+ return ""
+}
+
+func DebugIdMapName(debugId string) string {
+ return sourceMapDebugIdDir + debugId + ".js.map"
+}
+
+func DebugIdBundleName(debugId string) string {
+ return sourceMapDebugIdDir + debugId + ".js"
+}
+
+func ExtractDebugId(fileName string, data []byte) string {
+ if strings.HasSuffix(fileName, ".map") {
+ var fields struct {
+ DebugId string `json:"debugId"`
+ LegacyDebugId string `json:"debug_id"`
+ }
+ if err := json.Unmarshal(data, &fields); err != nil {
+ return ""
+ }
+ if id := NormalizeDebugId(fields.DebugId); id != "" {
+ return id
+ }
+ return NormalizeDebugId(fields.LegacyDebugId)
+ }
+
+ tail := data
+ if len(tail) > 4096 {
+ tail = tail[len(tail)-4096:]
+ }
+ matches := bundleDebugIdCommentRe.FindAllSubmatch(tail, -1)
+ if len(matches) == 0 {
+ return ""
+ }
+ return NormalizeDebugId(string(matches[len(matches)-1][1]))
+}
diff --git a/backend/app/services/sourcemap_debugid_test.go b/backend/app/services/sourcemap_debugid_test.go
new file mode 100644
index 00000000..47d09d54
--- /dev/null
+++ b/backend/app/services/sourcemap_debugid_test.go
@@ -0,0 +1,108 @@
+package services
+
+import (
+ "context"
+ "fmt"
+ "strings"
+ "testing"
+
+ "github.com/tracewayapp/traceway/backend/app/storage"
+
+ "github.com/google/uuid"
+)
+
+func TestExtractDebugIdFromMap(t *testing.T) {
+ id := "85314830-023f-4cf1-a267-535f4e37bb17"
+ if got := ExtractDebugId("app.js.map", []byte(`{"version":3,"debugId":"`+id+`"}`)); got != id {
+ t.Errorf("debugId field: got %q, want %q", got, id)
+ }
+ if got := ExtractDebugId("app.js.map", []byte(`{"version":3,"debug_id":"`+strings.ToUpper(id)+`"}`)); got != id {
+ t.Errorf("debug_id field should normalize: got %q, want %q", got, id)
+ }
+ if got := ExtractDebugId("app.js.map", []byte(`{"version":3}`)); got != "" {
+ t.Errorf("missing field: got %q, want empty", got)
+ }
+ if got := ExtractDebugId("app.js.map", []byte(`{"version":3,"debugId":"not-a-uuid"}`)); got != "" {
+ t.Errorf("invalid id: got %q, want empty", got)
+ }
+}
+
+func TestExtractDebugIdFromBundle(t *testing.T) {
+ id := "85314830-023f-4cf1-a267-535f4e37bb17"
+ code := "console.log(1);\n//# debugId=" + id + "\n//# sourceMappingURL=app.js.map\n"
+ if got := ExtractDebugId("app.js", []byte(code)); got != id {
+ t.Errorf("bundle comment: got %q, want %q", got, id)
+ }
+ if got := ExtractDebugId("app.js", []byte("console.log(1);\n")); got != "" {
+ t.Errorf("no comment: got %q, want empty", got)
+ }
+}
+
+func TestResolveStackTracePrefersDebugId(t *testing.T) {
+ InitSourceMapCache(100, 64<<20)
+ prev := storage.Store
+ defer func() { storage.Store = prev }()
+ cs := &countingStorage{reads: map[string]int{}, data: map[string][]byte{}}
+ storage.Store = cs
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ debugId := "85314830-023f-4cf1-a267-535f4e37bb17"
+ seedFixture(t, cs, prefix+DebugIdMapName(debugId), "testdata/sourcemapcache/simple/minified.js.map")
+ seedFixture(t, cs, prefix+DebugIdBundleName(debugId), "testdata/sourcemapcache/simple/minified.js")
+
+ input := "Error: boom\nanonymous()\n minified.js:1:11"
+ debugIds := map[string]string{"minified.js": debugId}
+ lines := strings.Split(ResolveStackTrace(context.Background(), projectId, input, debugIds), "\n")
+
+ if got, want := lines[2], " tests/fixtures/simple/original.js:2:10"; got != want {
+ t.Errorf("location via debug id: got %q, want %q", got, want)
+ }
+ if got, want := lines[1], "abcd()"; got != want {
+ t.Errorf("function name via debug id bundle: got %q, want %q", got, want)
+ }
+ if got := cs.reads[prefix+"minified.js.map"]; got != 0 {
+ t.Errorf("filename map should not be read when debug id matches, got %d reads", got)
+ }
+}
+
+func TestResolveStackTraceFallsBackToFilenameWhenDebugIdMissing(t *testing.T) {
+ InitSourceMapCache(100, 64<<20)
+ prev := storage.Store
+ defer func() { storage.Store = prev }()
+ cs := &countingStorage{reads: map[string]int{}, data: map[string][]byte{}}
+ storage.Store = cs
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ seedFixture(t, cs, prefix+"minified.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+ seedFixture(t, cs, prefix+"minified.js", "testdata/sourcemapcache/simple/minified.js")
+
+ input := "Error: boom\nanonymous()\n minified.js:1:11"
+ debugIds := map[string]string{"minified.js": "85314830-023f-4cf1-a267-535f4e37bb17"}
+ lines := strings.Split(ResolveStackTrace(context.Background(), projectId, input, debugIds), "\n")
+
+ if got, want := lines[2], " tests/fixtures/simple/original.js:2:10"; got != want {
+ t.Errorf("fallback location: got %q, want %q", got, want)
+ }
+}
+
+func TestInvalidateSourceMapKeepsDebugIdDir(t *testing.T) {
+ InitSourceMapCache(100, 64<<20)
+ projectId := uuid.New()
+ debugId := "85314830-023f-4cf1-a267-535f4e37bb17"
+
+ smCache.mu.Lock()
+ key := SourceMapStorageKey(projectId, DebugIdMapName(debugId))
+ smCache.negative[key] = &negativeEntry{}
+ smCache.mu.Unlock()
+
+ InvalidateSourceMap(projectId, DebugIdBundleName(debugId))
+
+ smCache.mu.Lock()
+ _, stillThere := smCache.negative[key]
+ smCache.mu.Unlock()
+ if stillThere {
+ t.Error("expected debug id map key to be invalidated")
+ }
+}
diff --git a/backend/app/services/sourcemap_disk_cache.go b/backend/app/services/sourcemap_disk_cache.go
new file mode 100644
index 00000000..33dd5c6b
--- /dev/null
+++ b/backend/app/services/sourcemap_disk_cache.go
@@ -0,0 +1,77 @@
+package services
+
+import (
+ "context"
+ "fmt"
+ "strings"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/twcache"
+
+ traceway "go.tracewayapp.com"
+)
+
+type sourceMapDiskCache struct {
+ mem *sourceMapCache
+ disk *twcache.Cache
+}
+
+func EnableSourceMapDiskCache(dir string, maxBytes int64) error {
+ disk, err := twcache.New(dir, maxBytes, func(err error) {
+ traceway.CaptureException(err)
+ })
+ if err != nil {
+ return fmt.Errorf("source map disk cache: %w", err)
+ }
+ activeSMCache = &sourceMapDiskCache{mem: smCache, disk: disk}
+ return nil
+}
+
+func twKeyFor(mapKey string) string {
+ return strings.TrimSuffix(mapKey, ".map") + ".tw"
+}
+
+func (d *sourceMapDiskCache) getOrBuild(ctx context.Context, key string, build resolverBuild) (*symbolicator.Resolver, error) {
+ return d.mem.getOrBuild(ctx, key, func(ctx context.Context) (*symbolicator.Resolver, int64, error) {
+ return d.load(ctx, key, build)
+ })
+}
+
+func (d *sourceMapDiskCache) load(ctx context.Context, mapKey string, build resolverBuild) (*symbolicator.Resolver, int64, error) {
+ name := twKeyFor(mapKey)
+ if r, err := d.disk.Open(name); err == nil {
+ return r, r.ApproxSize(), nil
+ }
+
+ resolver, size, err := build(ctx)
+ if err != nil {
+ return nil, 0, err
+ }
+ if r, werr := d.disk.Write(name, resolver.MarshalTW()); werr == nil {
+ return r, r.ApproxSize(), nil
+ } else {
+ traceway.CaptureException(fmt.Errorf("failed to write tw cache file (key=%s): %w", mapKey, werr))
+ }
+ return resolver, size, nil
+}
+
+func (d *sourceMapDiskCache) isNegative(key string) bool {
+ return d.mem.isNegative(key)
+}
+
+func (d *sourceMapDiskCache) invalidate(key string) {
+ d.mem.invalidate(key)
+ d.disk.Remove(twKeyFor(key))
+}
+
+func (d *sourceMapDiskCache) stats() SourceMapCacheStats {
+ s := d.mem.stats()
+ ds := d.disk.Stats()
+ s.DiskEnabled = true
+ s.DiskEntries = ds.Entries
+ s.DiskBytes = ds.Bytes
+ s.DiskMaxBytes = ds.MaxBytes
+ s.DiskHits = ds.Hits
+ s.DiskEvictions = ds.Evictions
+ return s
+}
diff --git a/backend/app/services/sourcemap_disk_cache_test.go b/backend/app/services/sourcemap_disk_cache_test.go
new file mode 100644
index 00000000..20ed749c
--- /dev/null
+++ b/backend/app/services/sourcemap_disk_cache_test.go
@@ -0,0 +1,397 @@
+package services
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/tracewayapp/traceway/backend/app/storage"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/twcache"
+
+ "github.com/google/uuid"
+)
+
+func newTestDiskCache(t *testing.T, maxBytes int64) *sourceMapDiskCache {
+ t.Helper()
+ return newTestDiskCacheAt(t, t.TempDir(), maxBytes)
+}
+
+func newTestDiskCacheAt(t *testing.T, dir string, maxBytes int64) *sourceMapDiskCache {
+ t.Helper()
+ disk, err := twcache.New(dir, maxBytes, nil)
+ if err != nil {
+ t.Fatalf("twcache.New: %v", err)
+ }
+ return &sourceMapDiskCache{
+ mem: newTestSourceMapCache(100, 64<<20),
+ disk: disk,
+ }
+}
+
+func twPathFor(d *sourceMapDiskCache, mapKey string) string {
+ return filepath.Join(d.disk.Dir(), filepath.FromSlash(twKeyFor(mapKey)))
+}
+
+func swapStorage(t *testing.T) *countingStorage {
+ t.Helper()
+ prev := storage.Store
+ t.Cleanup(func() { storage.Store = prev })
+ cs := &countingStorage{reads: map[string]int{}, data: map[string][]byte{}}
+ storage.Store = cs
+ smStoreHits.Store(0)
+ smBuilds.Store(0)
+ return cs
+}
+
+func assertSimpleLookup(t *testing.T, r *symbolicator.Resolver) {
+ t.Helper()
+ frame, ok := r.Lookup(0, 10)
+ if !ok {
+ t.Fatal("expected lookup to resolve")
+ }
+ if frame.File != "tests/fixtures/simple/original.js" || frame.Fn != "abcd" {
+ t.Fatalf("unexpected frame: %+v", frame)
+ }
+}
+
+func TestDiskCacheBuildsThenServesFromLocalFile(t *testing.T) {
+ cs := swapStorage(t)
+ d := newTestDiskCache(t, 64<<20)
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ seedFixture(t, cs, prefix+"minified.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+ seedFixture(t, cs, prefix+"minified.js", "testdata/sourcemapcache/simple/minified.js")
+
+ mapKey := prefix + "minified.js.map"
+ bundleKey := prefix + "minified.js"
+
+ r, err := d.getOrBuild(context.Background(), mapKey, buildResolver(mapKey, bundleKey))
+ if err != nil {
+ t.Fatalf("getOrBuild: %v", err)
+ }
+ assertSimpleLookup(t, r)
+
+ if _, err := os.Stat(twPathFor(d, mapKey)); err != nil {
+ t.Fatalf("expected tw file on disk: %v", err)
+ }
+ if smBuilds.Load() != 1 {
+ t.Fatalf("builds: got %d, want 1", smBuilds.Load())
+ }
+
+ restarted := newTestDiskCacheAt(t, d.disk.Dir(), 64<<20)
+
+ mapReads := cs.reads[mapKey]
+ r2, err := restarted.getOrBuild(context.Background(), mapKey, buildResolver(mapKey, bundleKey))
+ if err != nil {
+ t.Fatalf("getOrBuild after restart: %v", err)
+ }
+ assertSimpleLookup(t, r2)
+ if hits := restarted.disk.Stats().Hits; hits != 1 {
+ t.Fatalf("disk hits: got %d, want 1", hits)
+ }
+ if cs.reads[mapKey] != mapReads {
+ t.Fatal("restart should serve from local tw file without reading the source map")
+ }
+}
+
+func TestDiskCachePullsTWFromStorage(t *testing.T) {
+ cs := swapStorage(t)
+ d := newTestDiskCache(t, 64<<20)
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ mapKey := prefix + "minified.js.map"
+ bundleKey := prefix + "minified.js"
+
+ mapBytes, err := os.ReadFile("testdata/sourcemapcache/simple/minified.js.map")
+ if err != nil {
+ t.Fatal(err)
+ }
+ bundleBytes, err := os.ReadFile("testdata/sourcemapcache/simple/minified.js")
+ if err != nil {
+ t.Fatal(err)
+ }
+ resolver, err := symbolicator.NewResolver(mapBytes, bundleBytes)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cs.data[prefix+"minified.js.tw"] = resolver.MarshalTW()
+
+ r, err := d.getOrBuild(context.Background(), mapKey, buildResolver(mapKey, bundleKey))
+ if err != nil {
+ t.Fatalf("getOrBuild: %v", err)
+ }
+ assertSimpleLookup(t, r)
+
+ if smStoreHits.Load() != 1 {
+ t.Fatalf("storeHits: got %d, want 1", smStoreHits.Load())
+ }
+ if cs.reads[mapKey] != 0 || cs.reads[bundleKey] != 0 {
+ t.Fatal("tw artifact in storage should make map and bundle reads unnecessary")
+ }
+ if !fileExists(twPathFor(d, mapKey)) {
+ t.Fatal("tw pulled from storage should be cached on local disk")
+ }
+}
+
+func TestDiskCacheCorruptLocalFileFallsBack(t *testing.T) {
+ cs := swapStorage(t)
+ d := newTestDiskCache(t, 64<<20)
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ seedFixture(t, cs, prefix+"minified.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+ mapKey := prefix + "minified.js.map"
+
+ twPath := twPathFor(d, mapKey)
+ if err := os.MkdirAll(filepath.Dir(twPath), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(twPath, []byte("garbage"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ r, err := d.getOrBuild(context.Background(), mapKey, buildResolver(mapKey, prefix+"minified.js"))
+ if err != nil {
+ t.Fatalf("getOrBuild: %v", err)
+ }
+ if _, ok := r.Lookup(0, 10); !ok {
+ t.Fatal("expected lookup to resolve after rebuilding from source map")
+ }
+ if smBuilds.Load() != 1 {
+ t.Fatalf("builds: got %d, want 1", smBuilds.Load())
+ }
+ data, err := os.ReadFile(twPath)
+ if err != nil {
+ t.Fatalf("expected regenerated tw file: %v", err)
+ }
+ if _, err := symbolicator.OpenTW(data); err != nil {
+ t.Fatalf("regenerated tw file should be valid: %v", err)
+ }
+}
+
+func TestDiskCacheCapacityEviction(t *testing.T) {
+ cs := swapStorage(t)
+
+ mapBytes, err := os.ReadFile("testdata/sourcemapcache/simple/minified.js.map")
+ if err != nil {
+ t.Fatal(err)
+ }
+ resolver, err := symbolicator.NewResolver(mapBytes, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ twSize := int64(len(resolver.MarshalTW()))
+
+ d := newTestDiskCache(t, twSize+twSize/2)
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ seedFixture(t, cs, prefix+"first.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+ seedFixture(t, cs, prefix+"second.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+
+ firstKey := prefix + "first.js.map"
+ secondKey := prefix + "second.js.map"
+
+ if _, err := d.getOrBuild(context.Background(), firstKey, buildResolver(firstKey, prefix+"first.js")); err != nil {
+ t.Fatalf("getOrBuild first: %v", err)
+ }
+ if _, err := d.getOrBuild(context.Background(), secondKey, buildResolver(secondKey, prefix+"second.js")); err != nil {
+ t.Fatalf("getOrBuild second: %v", err)
+ }
+
+ if fileExists(twPathFor(d, firstKey)) {
+ t.Fatal("oldest tw file should be evicted when over capacity")
+ }
+ if !fileExists(twPathFor(d, secondKey)) {
+ t.Fatal("newest tw file should survive eviction")
+ }
+ stats := d.disk.Stats()
+ if stats.Evictions != 1 {
+ t.Fatalf("disk evictions: got %d, want 1", stats.Evictions)
+ }
+ if stats.Bytes > stats.MaxBytes {
+ t.Fatalf("cached bytes %d exceed maxBytes %d", stats.Bytes, stats.MaxBytes)
+ }
+}
+
+func TestDiskCacheInvalidateRemovesFile(t *testing.T) {
+ cs := swapStorage(t)
+ d := newTestDiskCache(t, 64<<20)
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ seedFixture(t, cs, prefix+"minified.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+ mapKey := prefix + "minified.js.map"
+
+ if _, err := d.getOrBuild(context.Background(), mapKey, buildResolver(mapKey, prefix+"minified.js")); err != nil {
+ t.Fatalf("getOrBuild: %v", err)
+ }
+ twPath := twPathFor(d, mapKey)
+ if !fileExists(twPath) {
+ t.Fatal("expected tw file before invalidate")
+ }
+
+ d.invalidate(mapKey)
+ if fileExists(twPath) {
+ t.Fatal("invalidate should remove the local tw file")
+ }
+ if stats := d.disk.Stats(); stats.Entries != 0 || stats.Bytes != 0 {
+ t.Fatalf("expected empty disk index, got %d entries / %d bytes", stats.Entries, stats.Bytes)
+ }
+}
+
+func TestDiskCacheResolveStackTraceEndToEnd(t *testing.T) {
+ cs := swapStorage(t)
+ swapActiveCache(t, newTestDiskCache(t, 64<<20))
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ seedFixture(t, cs, prefix+"minified.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+ seedFixture(t, cs, prefix+"minified.js", "testdata/sourcemapcache/simple/minified.js")
+
+ input := "Error: boom\nanonymous()\n minified.js:1:11"
+ lines := strings.Split(ResolveStackTrace(context.Background(), projectId, input, nil), "\n")
+
+ if got, want := lines[2], " tests/fixtures/simple/original.js:2:10"; got != want {
+ t.Errorf("location: got %q, want %q", got, want)
+ }
+ if got, want := lines[1], "abcd()"; got != want {
+ t.Errorf("function name: got %q, want %q", got, want)
+ }
+}
+
+func swapActiveCache(t *testing.T, c resolverCache) {
+ t.Helper()
+ prev := activeSMCache
+ activeSMCache = c
+ t.Cleanup(func() { activeSMCache = prev })
+}
+
+func TestGenerateTWArtifacts(t *testing.T) {
+ cs := swapStorage(t)
+ swapActiveCache(t, newTestDiskCache(t, 64<<20))
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ seedFixture(t, cs, prefix+"minified.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+ seedFixture(t, cs, prefix+"minified.js", "testdata/sourcemapcache/simple/minified.js")
+
+ GenerateTWArtifacts(context.Background(), projectId, []string{"minified.js.map", "minified.js"})
+
+ twBytes, ok := cs.data[prefix+"minified.js.tw"]
+ if !ok {
+ t.Fatal("expected tw artifact in storage after generation")
+ }
+ r, err := symbolicator.OpenTW(twBytes)
+ if err != nil {
+ t.Fatalf("OpenTW: %v", err)
+ }
+ assertSimpleLookup(t, r)
+}
+
+func TestGenerateTWArtifactsDeletesStaleOnFailure(t *testing.T) {
+ cs := swapStorage(t)
+ swapActiveCache(t, newTestDiskCache(t, 64<<20))
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ cs.data[prefix+"minified.js.tw"] = []byte("stale artifact from previous release")
+ cs.data[prefix+"minified.js.map"] = []byte("{not a valid source map")
+
+ GenerateTWArtifacts(context.Background(), projectId, []string{"minified.js.map"})
+
+ if _, ok := cs.data[prefix+"minified.js.tw"]; ok {
+ t.Fatal("stale tw artifact must be deleted even when regeneration fails")
+ }
+}
+
+type twErrStorage struct {
+ *countingStorage
+}
+
+func (s *twErrStorage) Read(ctx context.Context, key string) ([]byte, error) {
+ if strings.HasSuffix(key, ".tw") {
+ return nil, fmt.Errorf("storage backend unavailable")
+ }
+ return s.countingStorage.Read(ctx, key)
+}
+
+func TestDiskCacheTransientTwErrorFallsBackToBuild(t *testing.T) {
+ cs := swapStorage(t)
+ storage.Store = &twErrStorage{countingStorage: cs}
+ d := newTestDiskCache(t, 64<<20)
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ seedFixture(t, cs, prefix+"minified.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+ seedFixture(t, cs, prefix+"minified.js", "testdata/sourcemapcache/simple/minified.js")
+ mapKey := prefix + "minified.js.map"
+
+ r, err := d.getOrBuild(context.Background(), mapKey, buildResolver(mapKey, prefix+"minified.js"))
+ if err != nil {
+ t.Fatalf("getOrBuild should fall back to building from the map, got: %v", err)
+ }
+ assertSimpleLookup(t, r)
+ if smBuilds.Load() != 1 {
+ t.Fatalf("builds: got %d, want 1", smBuilds.Load())
+ }
+ if _, ok := cs.data[prefix+"minified.js.tw"]; ok {
+ t.Fatal("transient tw read error must not trigger a storage refresh")
+ }
+}
+
+func TestDiskCacheRefreshesCorruptStoreTw(t *testing.T) {
+ cs := swapStorage(t)
+ d := newTestDiskCache(t, 64<<20)
+
+ projectId := uuid.New()
+ prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+ seedFixture(t, cs, prefix+"minified.js.map", "testdata/sourcemapcache/simple/minified.js.map")
+ cs.data[prefix+"minified.js.tw"] = []byte("corrupt artifact")
+ mapKey := prefix + "minified.js.map"
+
+ r, err := d.getOrBuild(context.Background(), mapKey, buildResolver(mapKey, prefix+"minified.js"))
+ if err != nil {
+ t.Fatalf("getOrBuild: %v", err)
+ }
+ if _, ok := r.Lookup(0, 10); !ok {
+ t.Fatal("expected lookup to resolve after rebuild")
+ }
+
+ refreshed := cs.data[prefix+"minified.js.tw"]
+ if _, err := symbolicator.OpenTW(refreshed); err != nil {
+ t.Fatalf("corrupt storage tw should be replaced with a valid artifact: %v", err)
+ }
+}
+
+func TestDiskCacheScanSkipsUnreadableEntries(t *testing.T) {
+ swapStorage(t)
+ dir := t.TempDir()
+
+ locked := filepath.Join(dir, "locked")
+ if err := os.MkdirAll(locked, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(locked, "x.tw"), []byte("x"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Chmod(locked, 0o000); err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { _ = os.Chmod(locked, 0o755) })
+
+ if _, err := twcache.New(dir, 64<<20, nil); err != nil {
+ t.Fatalf("scan must tolerate unreadable entries, got: %v", err)
+ }
+}
+
+func fileExists(path string) bool {
+ _, err := os.Stat(path)
+ return err == nil
+}
diff --git a/backend/app/services/sourcemap_resolver.go b/backend/app/services/sourcemap_resolver.go
index 351c8da1..580468e1 100644
--- a/backend/app/services/sourcemap_resolver.go
+++ b/backend/app/services/sourcemap_resolver.go
@@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"sync"
+ "sync/atomic"
"time"
"github.com/tracewayapp/traceway/backend/app/storage"
@@ -28,6 +29,13 @@ const sourceMapNegativeMaxKeys = 10000
type resolverBuild func(context.Context) (*symbolicator.Resolver, int64, error)
+type resolverCache interface {
+ getOrBuild(ctx context.Context, key string, build resolverBuild) (*symbolicator.Resolver, error)
+ isNegative(key string) bool
+ invalidate(key string)
+ stats() SourceMapCacheStats
+}
+
type sourceMapCache struct {
mu sync.Mutex
items map[string]*list.Element
@@ -74,6 +82,8 @@ var smCache = &sourceMapCache{
maxBytes: 500 << 20,
}
+var activeSMCache resolverCache = smCache
+
func InitSourceMapCache(maxEntries int, maxBytes int64) {
smCache.mu.Lock()
defer smCache.mu.Unlock()
@@ -194,12 +204,19 @@ func (c *sourceMapCache) invalidate(key string) {
}
}
+func SourceMapStorageKey(projectId uuid.UUID, fileName string) string {
+ return fmt.Sprintf("sourcemaps/%s/%s", projectId, fileName)
+}
+
func InvalidateSourceMap(projectId uuid.UUID, fileName string) {
- base := filepath.Base(fileName)
- if !strings.HasSuffix(base, ".map") {
- base += ".map"
+ name := fileName
+ if !strings.HasPrefix(name, sourceMapDebugIdDir) {
+ name = filepath.Base(name)
}
- smCache.invalidate(fmt.Sprintf("sourcemaps/%s/%s", projectId, base))
+ if !strings.HasSuffix(name, ".map") {
+ name += ".map"
+ }
+ activeSMCache.invalidate(SourceMapStorageKey(projectId, name))
}
func (c *sourceMapCache) reportLoadFailure(err error) {
@@ -250,31 +267,46 @@ type SourceMapCacheStats struct {
NegativeHits uint64
NegativeEntries int
LastParseMs float64
+
+ DiskEnabled bool
+ DiskEntries int
+ DiskBytes int64
+ DiskMaxBytes int64
+ DiskHits uint64
+ StoreHits uint64
+ Builds uint64
+ DiskEvictions uint64
}
func SourceMapStats() SourceMapCacheStats {
- smCache.mu.Lock()
- defer smCache.mu.Unlock()
+ return activeSMCache.stats()
+}
+
+func (c *sourceMapCache) stats() SourceMapCacheStats {
+ c.mu.Lock()
+ defer c.mu.Unlock()
return SourceMapCacheStats{
- Entries: smCache.order.Len(),
- Bytes: smCache.curBytes,
- MaxEntries: smCache.maxEntries,
- MaxBytes: smCache.maxBytes,
- Hits: smCache.hits,
- Misses: smCache.misses,
- Evictions: smCache.evictions,
- Failures: smCache.failures,
- NotFound: smCache.notFound,
- NegativeHits: smCache.negativeHits,
- NegativeEntries: len(smCache.negative),
- LastParseMs: smCache.lastParseMs,
+ Entries: c.order.Len(),
+ Bytes: c.curBytes,
+ MaxEntries: c.maxEntries,
+ MaxBytes: c.maxBytes,
+ Hits: c.hits,
+ Misses: c.misses,
+ Evictions: c.evictions,
+ Failures: c.failures,
+ NotFound: c.notFound,
+ NegativeHits: c.negativeHits,
+ NegativeEntries: len(c.negative),
+ LastParseMs: c.lastParseMs,
+ StoreHits: smStoreHits.Load(),
+ Builds: smBuilds.Load(),
}
}
var stackFrameRe = regexp.MustCompile(`^(\s{4})(.+):(\d+):(\d+)$`)
-func ResolveStackTrace(ctx context.Context, projectId uuid.UUID, stackTrace string) string {
- prefix := fmt.Sprintf("sourcemaps/%s/", projectId)
+func ResolveStackTrace(ctx context.Context, projectId uuid.UUID, stackTrace string, debugIds map[string]string) string {
+ prefix := SourceMapStorageKey(projectId, "")
lines := strings.Split(stackTrace, "\n")
resolved := make([]string, 0, len(lines))
@@ -300,21 +332,14 @@ func ResolveStackTrace(ctx context.Context, projectId uuid.UUID, stackTrace stri
lineNum, _ := strconv.Atoi(matches[3])
colNum, _ := strconv.Atoi(matches[4])
- base := mapBasename(fileName)
- if base == "" {
- resolved = append(resolved, line)
- continue
- }
- mapKey := prefix + base + ".map"
- bundleKey := prefix + base
-
- if smCache.isNegative(mapKey) {
- resolved = append(resolved, line)
- continue
+ clean := fileName
+ if idx := strings.IndexAny(clean, "?#"); idx != -1 {
+ clean = clean[:idx]
}
+ base := filepath.Base(clean)
- resolver, err := getResolver(ctx, mapKey, buildResolver(mapKey, bundleKey), localResolvers)
- if err != nil || resolver == nil {
+ resolver := frameResolver(ctx, prefix, fileName, base, debugIds, localResolvers)
+ if resolver == nil {
resolved = append(resolved, line)
continue
}
@@ -346,11 +371,37 @@ func ResolveStackTrace(ctx context.Context, projectId uuid.UUID, stackTrace stri
return strings.Join(resolved, "\n")
}
+func frameResolver(ctx context.Context, prefix, fileName, base string, debugIds map[string]string, local map[string]*symbolicator.Resolver) *symbolicator.Resolver {
+ id := NormalizeDebugId(debugIds[fileName])
+ if id == "" {
+ id = NormalizeDebugId(debugIds[base])
+ }
+ if id != "" {
+ mapKey := prefix + DebugIdMapName(id)
+ if !activeSMCache.isNegative(mapKey) {
+ bundleKey := prefix + DebugIdBundleName(id)
+ if r, err := getResolver(ctx, mapKey, buildResolver(mapKey, bundleKey), local); err == nil && r != nil {
+ return r
+ }
+ }
+ }
+
+ mapKey := prefix + base + ".map"
+ if activeSMCache.isNegative(mapKey) {
+ return nil
+ }
+ r, err := getResolver(ctx, mapKey, buildResolver(mapKey, prefix+base), local)
+ if err != nil {
+ return nil
+ }
+ return r
+}
+
func getResolver(ctx context.Context, cacheKey string, build resolverBuild, local map[string]*symbolicator.Resolver) (*symbolicator.Resolver, error) {
if r, ok := local[cacheKey]; ok {
return r, nil
}
- r, err := smCache.getOrBuild(ctx, cacheKey, build)
+ r, err := activeSMCache.getOrBuild(ctx, cacheKey, build)
if err != nil {
local[cacheKey] = nil
return nil, err
@@ -359,18 +410,25 @@ func getResolver(ctx context.Context, cacheKey string, build resolverBuild, loca
return r, nil
}
-func mapBasename(stackFile string) string {
- clean := stackFile
- if idx := strings.IndexAny(clean, "?#"); idx != -1 {
- clean = clean[:idx]
- }
- return filepath.Base(clean)
-}
+var smStoreHits, smBuilds atomic.Uint64
func buildResolver(mapKey, bundleKey string) resolverBuild {
return func(ctx context.Context) (*symbolicator.Resolver, int64, error) {
base := context.WithoutCancel(ctx)
+ refreshStoreTw := true
+ twKey := twKeyFor(mapKey)
+ twBytes, err := readWithTimeout(base, twKey)
+ if err == nil {
+ if r, twErr := symbolicator.OpenTW(twBytes); twErr == nil {
+ smStoreHits.Add(1)
+ return r, r.ApproxSize(), nil
+ }
+ } else if !errors.Is(err, storage.ErrNotFound) {
+ refreshStoreTw = false
+ traceway.CaptureException(fmt.Errorf("failed to read tw artifact, rebuilding from source map (key=%s): %w", twKey, err))
+ }
+
mapBytes, err := readWithTimeout(base, mapKey)
if err != nil {
return nil, 0, err
@@ -387,6 +445,12 @@ func buildResolver(mapKey, bundleKey string) resolverBuild {
if err != nil {
return nil, 0, err
}
+ smBuilds.Add(1)
+ if refreshStoreTw {
+ if werr := storage.Store.Write(base, twKey, resolver.MarshalTW()); werr != nil {
+ traceway.CaptureException(fmt.Errorf("failed to refresh tw artifact in storage (key=%s): %w", twKey, werr))
+ }
+ }
return resolver, resolver.ApproxSize(), nil
}
}
diff --git a/backend/app/services/sourcemap_resolver_test.go b/backend/app/services/sourcemap_resolver_test.go
index 37095bf4..9299d801 100644
--- a/backend/app/services/sourcemap_resolver_test.go
+++ b/backend/app/services/sourcemap_resolver_test.go
@@ -34,7 +34,7 @@ func TestResolveStackTraceWithBundle(t *testing.T) {
seedFixture(t, cs, prefix+"minified.js", "testdata/sourcemapcache/simple/minified.js")
input := "Error: boom\nanonymous()\n minified.js:1:11"
- lines := strings.Split(ResolveStackTrace(context.Background(), projectId, input), "\n")
+ lines := strings.Split(ResolveStackTrace(context.Background(), projectId, input, nil), "\n")
if got, want := lines[2], " tests/fixtures/simple/original.js:2:10"; got != want {
t.Errorf("location: got %q, want %q", got, want)
@@ -56,7 +56,7 @@ func TestResolveStackTraceLocationOnlyWithoutBundle(t *testing.T) {
seedFixture(t, cs, prefix+"preact-missing-source-contents.module.js.map", "testdata/sourcemapcache/preact-missing-source-contents.module.js.map")
input := "Error: boom\nanonymous()\n preact-missing-source-contents.module.js:1:133"
- lines := strings.Split(ResolveStackTrace(context.Background(), projectId, input), "\n")
+ lines := strings.Split(ResolveStackTrace(context.Background(), projectId, input, nil), "\n")
if got, want := lines[2], " ../src/util.js:12:23"; got != want {
t.Errorf("location: got %q, want %q", got, want)
@@ -76,8 +76,8 @@ func TestResolveStackTraceNegativeCacheAvoidsRepeatReads(t *testing.T) {
projectId := uuid.New()
input := "Error: boom\n foo()\n missing.js:1:5"
- _ = ResolveStackTrace(context.Background(), projectId, input)
- _ = ResolveStackTrace(context.Background(), projectId, input)
+ _ = ResolveStackTrace(context.Background(), projectId, input, nil)
+ _ = ResolveStackTrace(context.Background(), projectId, input, nil)
mapKey := fmt.Sprintf("sourcemaps/%s/missing.js.map", projectId)
if got := cs.reads[mapKey]; got != 1 {
diff --git a/backend/app/services/sourcemap_tw.go b/backend/app/services/sourcemap_tw.go
new file mode 100644
index 00000000..df2e0495
--- /dev/null
+++ b/backend/app/services/sourcemap_tw.go
@@ -0,0 +1,37 @@
+package services
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strings"
+
+ "github.com/tracewayapp/traceway/backend/app/storage"
+
+ "github.com/google/uuid"
+ traceway "go.tracewayapp.com"
+)
+
+func GenerateTWArtifacts(ctx context.Context, projectId uuid.UUID, fileNames []string) {
+ ctx = context.WithoutCancel(ctx)
+
+ bases := make(map[string]bool)
+ for _, name := range fileNames {
+ bases[strings.TrimSuffix(name, ".map")] = true
+ }
+
+ for base := range bases {
+ mapKey := SourceMapStorageKey(projectId, base+".map")
+ bundleKey := SourceMapStorageKey(projectId, base)
+ twKey := twKeyFor(mapKey)
+
+ if err := storage.Store.Delete(ctx, twKey); err != nil {
+ traceway.CaptureException(fmt.Errorf("tw generation: failed to delete stale tw artifact (key=%s): %w", twKey, err))
+ }
+ InvalidateSourceMap(projectId, base)
+
+ if _, err := activeSMCache.getOrBuild(ctx, mapKey, buildResolver(mapKey, bundleKey)); err != nil && !errors.Is(err, storage.ErrNotFound) {
+ traceway.CaptureException(fmt.Errorf("tw generation: failed to warm resolver (key=%s): %w", mapKey, err))
+ }
+ }
+}
diff --git a/backend/app/sourcemapbackfill/backfill_test.go b/backend/app/sourcemapbackfill/backfill_test.go
index dbb2ca3f..1353fdbe 100644
--- a/backend/app/sourcemapbackfill/backfill_test.go
+++ b/backend/app/sourcemapbackfill/backfill_test.go
@@ -30,6 +30,13 @@ func (m *memStore) Write(_ context.Context, key string, data []byte) error {
return nil
}
+func (m *memStore) Delete(_ context.Context, key string) error {
+ m.mu.Lock()
+ delete(m.data, key)
+ m.mu.Unlock()
+ return nil
+}
+
func (m *memStore) Read(_ context.Context, key string) ([]byte, error) {
m.mu.Lock()
defer m.mu.Unlock()
diff --git a/backend/app/storage/local.go b/backend/app/storage/local.go
index ee2e4cc0..574502f9 100644
--- a/backend/app/storage/local.go
+++ b/backend/app/storage/local.go
@@ -34,6 +34,14 @@ func (l *localStorage) Write(_ context.Context, key string, data []byte) error {
return nil
}
+func (l *localStorage) Delete(_ context.Context, key string) error {
+ fullPath := filepath.Join(l.basePath, key)
+ if err := os.Remove(fullPath); err != nil && !os.IsNotExist(err) {
+ return fmt.Errorf("failed to delete file %s: %w", fullPath, err)
+ }
+ return nil
+}
+
func (l *localStorage) Read(_ context.Context, key string) ([]byte, error) {
fullPath := filepath.Join(l.basePath, key)
data, err := os.ReadFile(fullPath)
diff --git a/backend/app/storage/s3.go b/backend/app/storage/s3.go
index e3aba66c..d66317f4 100644
--- a/backend/app/storage/s3.go
+++ b/backend/app/storage/s3.go
@@ -58,6 +58,17 @@ func (s *s3Storage) Write(ctx context.Context, key string, data []byte) error {
return nil
}
+func (s *s3Storage) Delete(ctx context.Context, key string) error {
+ _, err := s.client.DeleteObject(ctx, &s3.DeleteObjectInput{
+ Bucket: aws.String(s.bucket),
+ Key: aws.String(key),
+ })
+ if err != nil && !isS3NotFound(err) {
+ return fmt.Errorf("failed to delete object %s: %w", key, err)
+ }
+ return nil
+}
+
func (s *s3Storage) Read(ctx context.Context, key string) ([]byte, error) {
output, err := s.client.GetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(s.bucket),
diff --git a/backend/app/storage/storage.go b/backend/app/storage/storage.go
index 918943c1..46ee475d 100644
--- a/backend/app/storage/storage.go
+++ b/backend/app/storage/storage.go
@@ -12,6 +12,7 @@ var ErrNotFound = errors.New("storage: object not found")
type Storage interface {
Write(ctx context.Context, key string, data []byte) error
Read(ctx context.Context, key string) ([]byte, error)
+ Delete(ctx context.Context, key string) error
}
var Store Storage
diff --git a/backend/app/symbolicator/jsstack/canonicalize.go b/backend/app/symbolicator/jsstack/canonicalize.go
new file mode 100644
index 00000000..9a8cf3d2
--- /dev/null
+++ b/backend/app/symbolicator/jsstack/canonicalize.go
@@ -0,0 +1,119 @@
+package jsstack
+
+import (
+ "regexp"
+ "strings"
+)
+
+type jsStackFrame struct {
+ fn string
+ loc string
+}
+
+var jsLocRe = regexp.MustCompile(`^.+:\d+:\d+$`)
+var jsEvalLocRe = regexp.MustCompile(`\(([^()]+:\d+:\d+)\)`)
+
+func Canonicalize(trace string) (string, bool) {
+ lines := strings.Split(trace, "\n")
+
+ parse := detectJsFrameParser(lines)
+ if parse == nil {
+ return trace, false
+ }
+
+ out := make([]string, 0, len(lines)*2)
+ converted := false
+ for _, line := range lines {
+ f, ok := parse(line)
+ if !ok {
+ out = append(out, line)
+ continue
+ }
+ if f.loc == "" {
+ if f.fn != "" {
+ out = append(out, " "+f.fn+" [native code]")
+ }
+ continue
+ }
+ if f.fn != "" {
+ out = append(out, f.fn+"()")
+ }
+ out = append(out, " "+f.loc)
+ converted = true
+ }
+ if !converted {
+ return trace, false
+ }
+ return strings.Join(out, "\n"), true
+}
+
+func detectJsFrameParser(lines []string) func(string) (jsStackFrame, bool) {
+ v8, gecko := 0, 0
+ for _, line := range lines {
+ if f, ok := parseV8Frame(line); ok && f.loc != "" {
+ v8++
+ } else if f, ok := parseGeckoFrame(line); ok && f.loc != "" {
+ gecko++
+ }
+ }
+ if v8 > 0 && v8 >= gecko {
+ return parseV8Frame
+ }
+ if gecko > 0 {
+ return parseGeckoFrame
+ }
+ return nil
+}
+
+func parseV8Frame(line string) (jsStackFrame, bool) {
+ s := strings.TrimSpace(line)
+ if !strings.HasPrefix(s, "at ") {
+ return jsStackFrame{}, false
+ }
+ s = strings.TrimSpace(s[3:])
+ s = strings.TrimPrefix(s, "async ")
+ s = strings.TrimPrefix(s, "new ")
+
+ name, paren := s, ""
+ hasParen := false
+ if strings.HasSuffix(s, ")") {
+ if i := strings.Index(s, " ("); i != -1 {
+ name, paren, hasParen = s[:i], s[i+2:len(s)-1], true
+ }
+ }
+ if !hasParen {
+ if jsLocRe.MatchString(name) {
+ return jsStackFrame{loc: name}, true
+ }
+ return jsStackFrame{}, false
+ }
+
+ if i := strings.Index(name, " [as "); i != -1 {
+ name = name[:i]
+ }
+ loc := ""
+ if strings.HasPrefix(paren, "eval at ") {
+ if m := jsEvalLocRe.FindStringSubmatch(paren); m != nil {
+ loc = m[1]
+ }
+ } else if jsLocRe.MatchString(paren) {
+ loc = paren
+ }
+ return jsStackFrame{fn: name, loc: loc}, true
+}
+
+func parseGeckoFrame(line string) (jsStackFrame, bool) {
+ s := strings.TrimSpace(line)
+ i := strings.LastIndex(s, "@")
+ if i == -1 {
+ return jsStackFrame{}, false
+ }
+ name, loc := s[:i], s[i+1:]
+ if loc == "[native code]" {
+ return jsStackFrame{fn: name}, true
+ }
+ if !jsLocRe.MatchString(loc) {
+ return jsStackFrame{}, false
+ }
+ return jsStackFrame{fn: name, loc: loc}, true
+}
diff --git a/backend/app/symbolicator/jsstack/canonicalize_test.go b/backend/app/symbolicator/jsstack/canonicalize_test.go
new file mode 100644
index 00000000..7508bc2c
--- /dev/null
+++ b/backend/app/symbolicator/jsstack/canonicalize_test.go
@@ -0,0 +1,147 @@
+package jsstack
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestCanonicalizeChrome(t *testing.T) {
+ input := strings.Join([]string{
+ "TypeError: Cannot read properties of undefined (reading 'name')",
+ " at renderUser (https://app.example.com/assets/app.min.js:1:13337)",
+ " at https://app.example.com/assets/app.min.js:1:24601",
+ " at async loadPage (https://app.example.com/assets/app.min.js:2:99)",
+ " at new Widget (https://app.example.com/assets/vendor.min.js:1:42)",
+ " at Object.run [as start] (https://app.example.com/assets/app.min.js:1:7)",
+ " at Array.forEach (<anonymous>)",
+ }, "\n")
+
+ got, ok := Canonicalize(input)
+ if !ok {
+ t.Fatal("expected chrome trace to be detected")
+ }
+ want := strings.Join([]string{
+ "TypeError: Cannot read properties of undefined (reading 'name')",
+ "renderUser()",
+ " https://app.example.com/assets/app.min.js:1:13337",
+ " https://app.example.com/assets/app.min.js:1:24601",
+ "loadPage()",
+ " https://app.example.com/assets/app.min.js:2:99",
+ "Widget()",
+ " https://app.example.com/assets/vendor.min.js:1:42",
+ "Object.run()",
+ " https://app.example.com/assets/app.min.js:1:7",
+ " Array.forEach [native code]",
+ }, "\n")
+ if got != want {
+ t.Errorf("got:\n%s\nwant:\n%s", got, want)
+ }
+}
+
+func TestCanonicalizeNodeAndBun(t *testing.T) {
+ input := strings.Join([]string{
+ "Error: connect ECONNREFUSED",
+ " at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16)",
+ " at Module._compile (node:internal/modules/cjs/loader:1234:14)",
+ " at /srv/app/dist/server.js:10:5",
+ }, "\n")
+
+ got, ok := Canonicalize(input)
+ if !ok {
+ t.Fatal("expected node trace to be detected")
+ }
+ want := strings.Join([]string{
+ "Error: connect ECONNREFUSED",
+ "TCPConnectWrap.afterConnect()",
+ " node:net:1300:16",
+ "Module._compile()",
+ " node:internal/modules/cjs/loader:1234:14",
+ " /srv/app/dist/server.js:10:5",
+ }, "\n")
+ if got != want {
+ t.Errorf("got:\n%s\nwant:\n%s", got, want)
+ }
+}
+
+func TestCanonicalizeChromeEval(t *testing.T) {
+ input := strings.Join([]string{
+ "Error: boom",
+ " at eval (eval at run (https://x.test/app.min.js:1:100), <anonymous>:5:9)",
+ }, "\n")
+
+ got, ok := Canonicalize(input)
+ if !ok {
+ t.Fatal("expected eval trace to be detected")
+ }
+ want := "Error: boom\neval()\n https://x.test/app.min.js:1:100"
+ if got != want {
+ t.Errorf("got:\n%s\nwant:\n%s", got, want)
+ }
+}
+
+func TestCanonicalizeFirefox(t *testing.T) {
+ input := strings.Join([]string{
+ "TypeError: user is undefined",
+ "renderUser@https://app.example.com/assets/app.min.js:1:13337",
+ "@https://app.example.com/assets/app.min.js:1:24601",
+ "outer@https://app.example.com/assets/app.min.js line 2 > eval:1:1",
+ }, "\n")
+
+ got, ok := Canonicalize(input)
+ if !ok {
+ t.Fatal("expected firefox trace to be detected")
+ }
+ want := strings.Join([]string{
+ "TypeError: user is undefined",
+ "renderUser()",
+ " https://app.example.com/assets/app.min.js:1:13337",
+ " https://app.example.com/assets/app.min.js:1:24601",
+ "outer()",
+ " https://app.example.com/assets/app.min.js line 2 > eval:1:1",
+ }, "\n")
+ if got != want {
+ t.Errorf("got:\n%s\nwant:\n%s", got, want)
+ }
+}
+
+func TestCanonicalizeSafari(t *testing.T) {
+ input := strings.Join([]string{
+ "renderUser@https://app.example.com/assets/app.min.js:1:13337",
+ "global code@https://app.example.com/assets/app.min.js:1:24601",
+ "promiseReactionJob@[native code]",
+ }, "\n")
+
+ got, ok := Canonicalize(input)
+ if !ok {
+ t.Fatal("expected safari trace to be detected")
+ }
+ want := strings.Join([]string{
+ "renderUser()",
+ " https://app.example.com/assets/app.min.js:1:13337",
+ "global code()",
+ " https://app.example.com/assets/app.min.js:1:24601",
+ " promiseReactionJob [native code]",
+ }, "\n")
+ if got != want {
+ t.Errorf("got:\n%s\nwant:\n%s", got, want)
+ }
+}
+
+func TestCanonicalizePassthrough(t *testing.T) {
+ cases := map[string]string{
+ "canonical": "Error: boom\nanonymous()\n minified.js:1:11",
+ "go": "runtime error: invalid memory address\nmain.handler(0x0)\n\t/srv/app/main.go:42 +0x1b",
+ "message": "Script error.",
+ "email": "Error: mail [email protected] bounced",
+ "empty": "",
+ }
+ for name, input := range cases {
+ got, ok := Canonicalize(input)
+ if ok {
+ t.Errorf("%s: expected no detection", name)
+ }
+ if got != input {
+ t.Errorf("%s: trace must pass through unchanged, got %q", name, got)
+ }
+ }
+}
diff --git a/backend/app/symbolicator/jsstack/frames.go b/backend/app/symbolicator/jsstack/frames.go
new file mode 100644
index 00000000..231eff64
--- /dev/null
+++ b/backend/app/symbolicator/jsstack/frames.go
@@ -0,0 +1,51 @@
+package jsstack
+
+import (
+ "strconv"
+ "strings"
+)
+
+type Frame struct {
+ Function string
+ URL string
+ Line uint32
+ Col uint32
+}
+
+func ParseFrames(trace string) []Frame {
+ lines := strings.Split(trace, "\n")
+ parse := detectJsFrameParser(lines)
+ if parse == nil {
+ return nil
+ }
+ var frames []Frame
+ for _, line := range lines {
+ f, ok := parse(line)
+ if !ok || f.loc == "" {
+ continue
+ }
+ url, lineNum, col, ok := splitJsLoc(f.loc)
+ if !ok {
+ continue
+ }
+ frames = append(frames, Frame{Function: f.fn, URL: url, Line: lineNum, Col: col})
+ }
+ return frames
+}
+
+func splitJsLoc(loc string) (string, uint32, uint32, bool) {
+ last := strings.LastIndex(loc, ":")
+ if last == -1 {
+ return "", 0, 0, false
+ }
+ second := strings.LastIndex(loc[:last], ":")
+ if second == -1 {
+ return "", 0, 0, false
+ }
+ line, err1 := strconv.ParseUint(loc[second+1:last], 10, 32)
+ col, err2 := strconv.ParseUint(loc[last+1:], 10, 32)
+ if err1 != nil || err2 != nil {
+ return "", 0, 0, false
+ }
+ return loc[:second], uint32(line), uint32(col), true
+}
diff --git a/backend/app/symbolicator/otelprocessor/README.md b/backend/app/symbolicator/otelprocessor/README.md
new file mode 100644
index 00000000..ed1b6a52
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/README.md
@@ -0,0 +1,91 @@
+# Traceway Source Map Symbolicator Processor
+
+An OpenTelemetry Collector processor that symbolicates minified JavaScript stack traces against your uploaded source maps, powered by Traceway's symbolicator engine. It is a drop-in replacement for [Honeycomb's `source_map_symbolicator` processor](https://github.com/honeycombio/opentelemetry-collector-symbolicator): same component type, same attribute contract, same store layout, same configuration keys. Existing pipelines and instrumentation (for example `@honeycombio/opentelemetry-web` with `GlobalErrorsInstrumentation`) work unchanged.
+
+What you get by swapping:
+
+- **A cache bounded by disk size, not entry count.** Honeycomb's processor holds up to `source_map_cache_size` parsed source maps in RAM (default 128) and re-parses on every eviction and restart. This processor compiles each map and bundle to Traceway's `.tw` binary format once, then memory-maps it from a local cache directory bounded by `cache_max_mb` or `cache_max_disk_pct` (a percentage of the filesystem the cache lives on). Resident memory tracks the hot set; restarts warm from disk; corpus size is a disk budget, not a RAM budget.
+- **Pure Go, no cgo.** Honeycomb's processor links Sentry's `symbolic` C library and requires a glibc base image. This one is pure Go by default and runs in any image, including scratch.
+- **Function names from scope analysis.** When the minified bundle is in the store (it has to be, for `sourceMappingURL` discovery), enclosing function names are resolved through bundle scope analysis, the same approach as Sentry's symbolic.
+
+## Usage
+
+The processor ships as a public package of the `github.com/tracewayapp/traceway/backend` module; the entry point is `otelprocessor.NewFactory()`. Add it to an [OpenTelemetry Collector Builder](https://opentelemetry.io/docs/collector/custom-collector/) manifest (the `import` line points the builder at the package inside the module):
+
+```yaml
+processors:
+ - gomod: github.com/tracewayapp/traceway/backend v1.8.0
+ import: github.com/tracewayapp/traceway/backend/app/symbolicator/otelprocessor
+```
+
+The processor first ships in `v1.8.0`; use that tag or any newer one.
+
+Or, when assembling a collector programmatically, register the factory directly:
+
+```go
+import "github.com/tracewayapp/traceway/backend/app/symbolicator/otelprocessor"
+
+factory := otelprocessor.NewFactory()
+factories.Processors[factory.Type()] = factory
+```
+
+Then reference it in your collector configuration:
+
+```yaml
+processors:
+ source_map_symbolicator:
+ source_map_store: file_store
+ local_source_maps:
+ path: /sourcemaps
+ cache_dir: /var/cache/symbolicator
+ cache_max_disk_pct: 50
+
+service:
+ pipelines:
+ traces:
+ processors: [source_map_symbolicator]
+ logs:
+ processors: [source_map_symbolicator]
+```
+
+## How it works
+
+For each span, span event, or log record carrying `exception.stacktrace`:
+
+1. Frames come from the structured parallel arrays (`exception.structured_stacktrace.{urls,functions,lines,columns}`) when present, or from parsing the raw stack string (V8 and Firefox formats, including `eval`, `async`, and `[as alias]` frames).
+2. Each frame's URL basename (optionally prefixed by the resource's `app.debug.source_map_uuid`) is fetched from the store, its `//# sourceMappingURL=` comment is followed to the map (inline `data:` URIs supported), and both are compiled into a resolver.
+3. The frame resolves to the original file, line, column, and enclosing function name. `exception.stacktrace` is rewritten, the structured arrays are rewritten in place, and the originals are preserved under `.original` keys.
+4. `exception.symbolicator.failed`, `exception.symbolicator.error`, and `exception.symbolicator.parsing_method` report the outcome per record.
+
+## Configuration
+
+| Key | Default | Description |
+|-----|---------|-------------|
+| `source_map_store` | `file_store` | `file_store`, `s3_store`, or `gcs_store` |
+| `local_source_maps.path` | `.` | Root directory for `file_store` |
+| `s3_source_maps.region` / `.bucket` / `.prefix` | | S3 location; credentials from the default AWS chain |
+| `gcs_source_maps.bucket` / `.prefix` | | GCS location; credentials from ADC |
+| `timeout` | `5s` | Per-fetch budget for store reads |
+| `cache_dir` | `""` | Directory for the `.tw` disk cache; empty disables the disk tier |
+| `cache_max_mb` | `2048` | Byte cap for the disk cache, LRU-evicted |
+| `cache_max_disk_pct` | `0` | Cap as a percentage of the cache directory's filesystem; when both caps are set, the smaller wins |
+| `source_map_cache_size` | `128` | Max open resolvers held in memory (cheap mmap handles when the disk tier is on) |
+| `preserve_stack_trace` | `true` | Keep originals under `exception.stacktrace.original` and the `.original` array keys |
+| `build_uuid_attribute_key` | `app.debug.source_map_uuid` | Resource attribute used as a store key prefix |
+| `language_attribute_key` | `telemetry.sdk.language` | Attribute checked against `allowed_languages` |
+| `allowed_languages` | `[]` | When set, only records with a matching language are processed |
+
+All attribute key names (`stack_trace_attribute_key`, `urls_attribute_key`, `symbolicator_failure_attribute_key`, and the rest) are remappable with the same configuration keys and defaults as Honeycomb's processor.
+
+A failed fetch is negative-cached for one minute per bundle URL, so a missing upload cannot turn an error storm into a store-request storm.
+
+## Store layout
+
+The store holds your build output as-is: minified bundles next to their maps, addressed by basename. Re-deploys with content-hashed filenames coexist; stable filenames are overwritten by the newest upload. With `app.debug.source_map_uuid` set on the client's resource, artifacts live under that uuid as a directory prefix, isolating builds completely.
+
+## Links
+
+- [Traceway](https://tracewayapp.com), the MIT-licensed error tracking platform this engine comes from
+- [Hosted docs for this processor](https://docs.tracewayapp.com/learn/collector-symbolicator), including the builder walkthrough
+- [Symbolication pipeline internals](https://docs.tracewayapp.com/learn/symbolication-js), including the `.tw` format
+- [Honeycomb's processor](https://github.com/honeycombio/opentelemetry-collector-symbolicator), whose configuration surface this matches
diff --git a/backend/app/symbolicator/otelprocessor/cache.go b/backend/app/symbolicator/otelprocessor/cache.go
new file mode 100644
index 00000000..342e9a66
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/cache.go
@@ -0,0 +1,165 @@
+package otelprocessor
+
+import (
+ "container/list"
+ "context"
+ "crypto/sha256"
+ "encoding/hex"
+ "fmt"
+ "os"
+ "sync"
+ "time"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/twcache"
+)
+
+const negativeCacheTTL = time.Minute
+const negativeCacheMaxKeys = 10000
+
+type buildFunc func(ctx context.Context) (*symbolicator.Resolver, error)
+
+type resolverCache struct {
+ mu sync.Mutex
+ entries map[string]*list.Element
+ order *list.List
+ maxEntries int
+ loading map[string]*resolverLoad
+ negative map[string]negativeEntry
+ disk *twcache.Cache
+}
+
+type cacheEntry struct {
+ key string
+ resolver *symbolicator.Resolver
+}
+
+type resolverLoad struct {
+ done chan struct{}
+ resolver *symbolicator.Resolver
+ err error
+}
+
+type negativeEntry struct {
+ expiresAt time.Time
+ err error
+}
+
+func newResolverCache(cfg *Config) (*resolverCache, error) {
+ c := &resolverCache{
+ entries: make(map[string]*list.Element),
+ order: list.New(),
+ maxEntries: cfg.SourceMapCacheSize,
+ loading: make(map[string]*resolverLoad),
+ negative: make(map[string]negativeEntry),
+ }
+ if cfg.CacheDir != "" {
+ disk, err := newDiskCache(cfg.CacheDir, int64(cfg.CacheMaxMB)<<20, cfg.CacheMaxDiskPct)
+ if err != nil {
+ return nil, err
+ }
+ c.disk = disk
+ }
+ return c, nil
+}
+
+func (c *resolverCache) get(ctx context.Context, key string, build buildFunc) (*symbolicator.Resolver, error) {
+ c.mu.Lock()
+ if el, ok := c.entries[key]; ok {
+ c.order.MoveToFront(el)
+ r := el.Value.(*cacheEntry).resolver
+ c.mu.Unlock()
+ return r, nil
+ }
+ if n, ok := c.negative[key]; ok {
+ if time.Now().Before(n.expiresAt) {
+ c.mu.Unlock()
+ return nil, n.err
+ }
+ delete(c.negative, key)
+ }
+ if l, ok := c.loading[key]; ok {
+ c.mu.Unlock()
+ <-l.done
+ return l.resolver, l.err
+ }
+ l := &resolverLoad{done: make(chan struct{})}
+ c.loading[key] = l
+ c.mu.Unlock()
+
+ l.resolver, l.err = c.load(ctx, key, build)
+
+ c.mu.Lock()
+ delete(c.loading, key)
+ if l.err == nil && l.resolver != nil {
+ el := c.order.PushFront(&cacheEntry{key: key, resolver: l.resolver})
+ c.entries[key] = el
+ for c.order.Len() > c.maxEntries {
+ back := c.order.Back()
+ evicted := c.order.Remove(back).(*cacheEntry)
+ delete(c.entries, evicted.key)
+ }
+ } else if l.err != nil {
+ if len(c.negative) >= negativeCacheMaxKeys {
+ now := time.Now()
+ for k, n := range c.negative {
+ if now.After(n.expiresAt) {
+ delete(c.negative, k)
+ }
+ }
+ }
+ if len(c.negative) < negativeCacheMaxKeys {
+ c.negative[key] = negativeEntry{expiresAt: time.Now().Add(negativeCacheTTL), err: l.err}
+ }
+ }
+ c.mu.Unlock()
+ close(l.done)
+ return l.resolver, l.err
+}
+
+func (c *resolverCache) load(ctx context.Context, key string, build buildFunc) (*symbolicator.Resolver, error) {
+ if c.disk == nil {
+ return build(ctx)
+ }
+ name := diskNameFor(key)
+ if r, err := c.disk.Open(name); err == nil {
+ return r, nil
+ }
+ r, err := build(ctx)
+ if err != nil {
+ return nil, err
+ }
+ if cached, werr := c.disk.Write(name, r.MarshalTW()); werr == nil {
+ return cached, nil
+ }
+ return r, nil
+}
+
+func diskNameFor(key string) string {
+ sum := sha256.Sum256([]byte(key))
+ return hex.EncodeToString(sum[:]) + ".tw"
+}
+
+func newDiskCache(dir string, maxBytes int64, maxPct int) (*twcache.Cache, error) {
+ if err := os.MkdirAll(dir, 0o755); err != nil {
+ return nil, fmt.Errorf("failed to create cache_dir: %w", err)
+ }
+ if maxPct > 0 {
+ total, err := twcache.DiskCapacityBytes(dir)
+ if err != nil {
+ return nil, fmt.Errorf("cache_max_disk_pct requires disk capacity detection: %w", err)
+ }
+ pctBytes := total / 100 * int64(maxPct)
+ if maxBytes <= 0 || pctBytes < maxBytes {
+ maxBytes = pctBytes
+ }
+ }
+ if maxBytes <= 0 {
+ return nil, fmt.Errorf("the source map cache requires a positive byte cap (cache_max_mb or cache_max_disk_pct)")
+ }
+ cache, err := twcache.New(dir, maxBytes, nil)
+ if err != nil {
+ return nil, fmt.Errorf("failed to initialize cache_dir: %w", err)
+ }
+ return cache, nil
+}
diff --git a/backend/app/symbolicator/otelprocessor/config.go b/backend/app/symbolicator/otelprocessor/config.go
new file mode 100644
index 00000000..c894264d
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/config.go
@@ -0,0 +1,79 @@
+package otelprocessor
+
+import (
+ "fmt"
+ "time"
+)
+
+type LocalSourceMapsConfig struct {
+ Path string `mapstructure:"path"`
+}
+
+type S3SourceMapsConfig struct {
+ Region string `mapstructure:"region"`
+ Bucket string `mapstructure:"bucket"`
+ Prefix string `mapstructure:"prefix"`
+}
+
+type GCSSourceMapsConfig struct {
+ Bucket string `mapstructure:"bucket"`
+ Prefix string `mapstructure:"prefix"`
+}
+
+type Config struct {
+ SymbolicatorFailureAttributeKey string `mapstructure:"symbolicator_failure_attribute_key"`
+ SymbolicatorErrorAttributeKey string `mapstructure:"symbolicator_error_attribute_key"`
+ SymbolicatorParsingMethodAttributeKey string `mapstructure:"symbolicator_parsing_method_attribute_key"`
+
+ ColumnsAttributeKey string `mapstructure:"columns_attribute_key"`
+ FunctionsAttributeKey string `mapstructure:"functions_attribute_key"`
+ LinesAttributeKey string `mapstructure:"lines_attribute_key"`
+ UrlsAttributeKey string `mapstructure:"urls_attribute_key"`
+
+ StackTraceAttributeKey string `mapstructure:"stack_trace_attribute_key"`
+ ExceptionTypeAttributeKey string `mapstructure:"exception_type_attribute_key"`
+ ExceptionMessageAttributeKey string `mapstructure:"exception_message_attribute_key"`
+
+ PreserveStackTrace bool `mapstructure:"preserve_stack_trace"`
+ OriginalStackTraceAttributeKey string `mapstructure:"original_stack_trace_attribute_key"`
+ OriginalColumnsAttributeKey string `mapstructure:"original_columns_attribute_key"`
+ OriginalFunctionsAttributeKey string `mapstructure:"original_functions_attribute_key"`
+ OriginalLinesAttributeKey string `mapstructure:"original_lines_attribute_key"`
+ OriginalUrlsAttributeKey string `mapstructure:"original_urls_attribute_key"`
+
+ BuildUUIDAttributeKey string `mapstructure:"build_uuid_attribute_key"`
+
+ SourceMapStoreKey string `mapstructure:"source_map_store"`
+ LocalSourceMaps LocalSourceMapsConfig `mapstructure:"local_source_maps"`
+ S3SourceMaps S3SourceMapsConfig `mapstructure:"s3_source_maps"`
+ GCSSourceMaps GCSSourceMapsConfig `mapstructure:"gcs_source_maps"`
+
+ Timeout time.Duration `mapstructure:"timeout"`
+
+ SourceMapCacheSize int `mapstructure:"source_map_cache_size"`
+
+ CacheDir string `mapstructure:"cache_dir"`
+ CacheMaxMB int `mapstructure:"cache_max_mb"`
+ CacheMaxDiskPct int `mapstructure:"cache_max_disk_pct"`
+
+ LanguageAttributeKey string `mapstructure:"language_attribute_key"`
+ AllowedLanguages []string `mapstructure:"allowed_languages"`
+}
+
+func (c *Config) Validate() error {
+ switch c.SourceMapStoreKey {
+ case fileStoreKey, s3StoreKey, gcsStoreKey:
+ default:
+ return fmt.Errorf("unknown source_map_store %q (available: %s, %s, %s)", c.SourceMapStoreKey, fileStoreKey, s3StoreKey, gcsStoreKey)
+ }
+ if c.CacheMaxDiskPct < 0 || c.CacheMaxDiskPct > 100 {
+ return fmt.Errorf("cache_max_disk_pct must be between 0 and 100, got %d", c.CacheMaxDiskPct)
+ }
+ if c.CacheMaxMB < 0 {
+ return fmt.Errorf("cache_max_mb must not be negative, got %d", c.CacheMaxMB)
+ }
+ if c.SourceMapCacheSize <= 0 {
+ return fmt.Errorf("source_map_cache_size must be positive, got %d", c.SourceMapCacheSize)
+ }
+ return nil
+}
diff --git a/backend/app/symbolicator/otelprocessor/factory.go b/backend/app/symbolicator/otelprocessor/factory.go
new file mode 100644
index 00000000..bc7f9645
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/factory.go
@@ -0,0 +1,96 @@
+package otelprocessor
+
+import (
+ "context"
+ "time"
+
+ "go.opentelemetry.io/collector/component"
+ "go.opentelemetry.io/collector/consumer"
+ "go.opentelemetry.io/collector/processor"
+ "go.opentelemetry.io/collector/processor/processorhelper"
+)
+
+const processorVersion = "0.1.0"
+
+var componentType = component.MustNewType("source_map_symbolicator")
+
+func NewFactory() processor.Factory {
+ return processor.NewFactory(
+ componentType,
+ createDefaultConfig,
+ processor.WithTraces(createTracesProcessor, component.StabilityLevelAlpha),
+ processor.WithLogs(createLogsProcessor, component.StabilityLevelAlpha),
+ )
+}
+
+func createDefaultConfig() component.Config {
+ return &Config{
+ SymbolicatorFailureAttributeKey: "exception.symbolicator.failed",
+ SymbolicatorErrorAttributeKey: "exception.symbolicator.error",
+ SymbolicatorParsingMethodAttributeKey: "exception.symbolicator.parsing_method",
+
+ ColumnsAttributeKey: "exception.structured_stacktrace.columns",
+ FunctionsAttributeKey: "exception.structured_stacktrace.functions",
+ LinesAttributeKey: "exception.structured_stacktrace.lines",
+ UrlsAttributeKey: "exception.structured_stacktrace.urls",
+
+ StackTraceAttributeKey: "exception.stacktrace",
+ ExceptionTypeAttributeKey: "exception.type",
+ ExceptionMessageAttributeKey: "exception.message",
+
+ PreserveStackTrace: true,
+ OriginalStackTraceAttributeKey: "exception.stacktrace.original",
+ OriginalColumnsAttributeKey: "exception.structured_stacktrace.columns.original",
+ OriginalFunctionsAttributeKey: "exception.structured_stacktrace.functions.original",
+ OriginalLinesAttributeKey: "exception.structured_stacktrace.lines.original",
+ OriginalUrlsAttributeKey: "exception.structured_stacktrace.urls.original",
+
+ BuildUUIDAttributeKey: "app.debug.source_map_uuid",
+
+ SourceMapStoreKey: fileStoreKey,
+ LocalSourceMaps: LocalSourceMapsConfig{Path: "."},
+
+ Timeout: 5 * time.Second,
+
+ SourceMapCacheSize: 128,
+
+ CacheMaxMB: 2048,
+
+ LanguageAttributeKey: "telemetry.sdk.language",
+ }
+}
+
+func newSymbolicator(cfg *Config, set processor.Settings) (*symbolicatorProcessor, error) {
+ store, err := newStore(cfg)
+ if err != nil {
+ return nil, err
+ }
+ cache, err := newResolverCache(cfg)
+ if err != nil {
+ return nil, err
+ }
+ return &symbolicatorProcessor{
+ cfg: cfg,
+ store: store,
+ cache: cache,
+ logger: set.Logger,
+ }, nil
+}
+
+func createTracesProcessor(ctx context.Context, set processor.Settings, cfg component.Config, next consumer.Traces) (processor.Traces, error) {
+ sp, err := newSymbolicator(cfg.(*Config), set)
+ if err != nil {
+ return nil, err
+ }
+ return processorhelper.NewTraces(ctx, set, cfg, next, sp.processTraces,
+ processorhelper.WithCapabilities(consumer.Capabilities{MutatesData: true}))
+}
+
+func createLogsProcessor(ctx context.Context, set processor.Settings, cfg component.Config, next consumer.Logs) (processor.Logs, error) {
+ sp, err := newSymbolicator(cfg.(*Config), set)
+ if err != nil {
+ return nil, err
+ }
+ return processorhelper.NewLogs(ctx, set, cfg, next, sp.processLogs,
+ processorhelper.WithCapabilities(consumer.Capabilities{MutatesData: true}))
+}
diff --git a/backend/app/symbolicator/otelprocessor/factory_test.go b/backend/app/symbolicator/otelprocessor/factory_test.go
new file mode 100644
index 00000000..43d00e37
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/factory_test.go
@@ -0,0 +1,42 @@
+package otelprocessor
+
+import (
+ "context"
+ "testing"
+
+ "go.opentelemetry.io/collector/component/componenttest"
+ "go.opentelemetry.io/collector/consumer/consumertest"
+ "go.opentelemetry.io/collector/processor/processortest"
+)
+
+func TestFactoryCreatesComponents(t *testing.T) {
+ factory := NewFactory()
+ if factory.Type() != componentType {
+ t.Fatalf("unexpected component type %q", factory.Type())
+ }
+
+ cfg := factory.CreateDefaultConfig()
+ set := processortest.NewNopSettings(componentType)
+
+ traces, err := factory.CreateTraces(context.Background(), set, cfg, consumertest.NewNop())
+ if err != nil {
+ t.Fatalf("CreateTraces: %v", err)
+ }
+ if err := traces.Start(context.Background(), componenttest.NewNopHost()); err != nil {
+ t.Fatalf("traces Start: %v", err)
+ }
+ if err := traces.Shutdown(context.Background()); err != nil {
+ t.Fatalf("traces Shutdown: %v", err)
+ }
+
+ logs, err := factory.CreateLogs(context.Background(), set, cfg, consumertest.NewNop())
+ if err != nil {
+ t.Fatalf("CreateLogs: %v", err)
+ }
+ if err := logs.Start(context.Background(), componenttest.NewNopHost()); err != nil {
+ t.Fatalf("logs Start: %v", err)
+ }
+ if err := logs.Shutdown(context.Background()); err != nil {
+ t.Fatalf("logs Shutdown: %v", err)
+ }
+}
diff --git a/backend/app/symbolicator/otelprocessor/processor.go b/backend/app/symbolicator/otelprocessor/processor.go
new file mode 100644
index 00000000..130fa173
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/processor.go
@@ -0,0 +1,45 @@
+package otelprocessor
+
+import (
+ "context"
+
+ "go.opentelemetry.io/collector/pdata/plog"
+ "go.opentelemetry.io/collector/pdata/ptrace"
+)
+
+func (p *symbolicatorProcessor) processTraces(ctx context.Context, td ptrace.Traces) (ptrace.Traces, error) {
+ resourceSpans := td.ResourceSpans()
+ for i := 0; i < resourceSpans.Len(); i++ {
+ rs := resourceSpans.At(i)
+ resourceAttrs := rs.Resource().Attributes()
+ scopeSpans := rs.ScopeSpans()
+ for j := 0; j < scopeSpans.Len(); j++ {
+ spans := scopeSpans.At(j).Spans()
+ for k := 0; k < spans.Len(); k++ {
+ span := spans.At(k)
+ p.processRecord(ctx, span.Attributes(), resourceAttrs)
+ events := span.Events()
+ for l := 0; l < events.Len(); l++ {
+ p.processRecord(ctx, events.At(l).Attributes(), resourceAttrs)
+ }
+ }
+ }
+ }
+ return td, nil
+}
+
+func (p *symbolicatorProcessor) processLogs(ctx context.Context, ld plog.Logs) (plog.Logs, error) {
+ resourceLogs := ld.ResourceLogs()
+ for i := 0; i < resourceLogs.Len(); i++ {
+ rl := resourceLogs.At(i)
+ resourceAttrs := rl.Resource().Attributes()
+ scopeLogs := rl.ScopeLogs()
+ for j := 0; j < scopeLogs.Len(); j++ {
+ records := scopeLogs.At(j).LogRecords()
+ for k := 0; k < records.Len(); k++ {
+ p.processRecord(ctx, records.At(k).Attributes(), resourceAttrs)
+ }
+ }
+ }
+ return ld, nil
+}
diff --git a/backend/app/symbolicator/otelprocessor/processor_test.go b/backend/app/symbolicator/otelprocessor/processor_test.go
new file mode 100644
index 00000000..135fc5fa
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/processor_test.go
@@ -0,0 +1,317 @@
+package otelprocessor
+
+import (
+ "context"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "go.opentelemetry.io/collector/pdata/pcommon"
+ "go.opentelemetry.io/collector/pdata/plog"
+ "go.opentelemetry.io/collector/pdata/ptrace"
+ "go.uber.org/zap"
+)
+
+func stageStore(t *testing.T, subdir string) string {
+ t.Helper()
+ dir := t.TempDir()
+ target := dir
+ if subdir != "" {
+ target = filepath.Join(dir, subdir)
+ if err := os.MkdirAll(target, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ }
+ source, err := os.ReadFile("testdata/minified.js")
+ if err != nil {
+ t.Fatal(err)
+ }
+ source = append(source, []byte("\n//# sourceMappingURL=minified.js.map\n")...)
+ if err := os.WriteFile(filepath.Join(target, "minified.js"), source, 0o644); err != nil {
+ t.Fatal(err)
+ }
+ sourceMap, err := os.ReadFile("testdata/minified.js.map")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(target, "minified.js.map"), sourceMap, 0o644); err != nil {
+ t.Fatal(err)
+ }
+ return dir
+}
+
+func newTestProcessor(t *testing.T, mutate func(*Config)) *symbolicatorProcessor {
+ t.Helper()
+ cfg := createDefaultConfig().(*Config)
+ if mutate != nil {
+ mutate(cfg)
+ }
+ if err := cfg.Validate(); err != nil {
+ t.Fatal(err)
+ }
+ store, err := newStore(cfg)
+ if err != nil {
+ t.Fatal(err)
+ }
+ cache, err := newResolverCache(cfg)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return &symbolicatorProcessor{cfg: cfg, store: store, cache: cache, logger: zap.NewNop()}
+}
+
+func putStructuredFrame(attrs pcommon.Map) {
+ attrs.PutStr("exception.type", "Error")
+ attrs.PutStr("exception.message", "boom")
+ attrs.PutStr("exception.stacktrace", "Error: boom\n at t (https://cdn.example.com/assets/minified.js:1:11)")
+ urls := attrs.PutEmptySlice("exception.structured_stacktrace.urls")
+ urls.AppendEmpty().SetStr("https://cdn.example.com/assets/minified.js")
+ functions := attrs.PutEmptySlice("exception.structured_stacktrace.functions")
+ functions.AppendEmpty().SetStr("t")
+ lines := attrs.PutEmptySlice("exception.structured_stacktrace.lines")
+ lines.AppendEmpty().SetInt(1)
+ columns := attrs.PutEmptySlice("exception.structured_stacktrace.columns")
+ columns.AppendEmpty().SetInt(11)
+}
+
+func TestProcessTracesStructuredRoute(t *testing.T) {
+ storeDir := stageStore(t, "")
+ p := newTestProcessor(t, func(cfg *Config) {
+ cfg.LocalSourceMaps.Path = storeDir
+ })
+
+ td := ptrace.NewTraces()
+ rs := td.ResourceSpans().AppendEmpty()
+ rs.Resource().Attributes().PutStr("telemetry.sdk.language", "webjs")
+ span := rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty()
+ span.SetName("exception")
+ putStructuredFrame(span.Attributes())
+
+ if _, err := p.processTraces(context.Background(), td); err != nil {
+ t.Fatal(err)
+ }
+
+ attrs := span.Attributes()
+ want := "Error: boom\n at abcd(tests/fixtures/simple/original.js:2:10)"
+ if got := strAttr(attrs, "exception.stacktrace"); got != want {
+ t.Errorf("stacktrace:\n got %q\nwant %q", got, want)
+ }
+ if got := strAttr(attrs, "exception.stacktrace.original"); got == "" {
+ t.Error("expected original stacktrace preserved")
+ }
+ if v, ok := attrs.Get("exception.symbolicator.failed"); !ok || v.Bool() {
+ t.Errorf("expected failed=false, got %v (present=%v)", v, ok)
+ }
+ if got := strAttr(attrs, "exception.symbolicator.parsing_method"); got != parsingMethodStructured {
+ t.Errorf("parsing method: got %q", got)
+ }
+
+ urls, _ := sliceAttr(attrs, "exception.structured_stacktrace.urls")
+ if urls.Len() != 1 || urls.At(0).Str() != "tests/fixtures/simple/original.js" {
+ t.Errorf("urls not rewritten: %v", urls.AsRaw())
+ }
+ functions, _ := sliceAttr(attrs, "exception.structured_stacktrace.functions")
+ if functions.At(0).Str() != "abcd" {
+ t.Errorf("function not resolved from bundle scope analysis: %v", functions.AsRaw())
+ }
+ lines, _ := sliceAttr(attrs, "exception.structured_stacktrace.lines")
+ columns, _ := sliceAttr(attrs, "exception.structured_stacktrace.columns")
+ if lines.At(0).Int() != 2 || columns.At(0).Int() != 10 {
+ t.Errorf("position not rewritten: %d:%d", lines.At(0).Int(), columns.At(0).Int())
+ }
+ origUrls, _ := sliceAttr(attrs, "exception.structured_stacktrace.urls.original")
+ if origUrls.Len() != 1 || origUrls.At(0).Str() != "https://cdn.example.com/assets/minified.js" {
+ t.Errorf("original urls not preserved: %v", origUrls.AsRaw())
+ }
+}
+
+func TestProcessTracesParsedRouteOnSpanEvent(t *testing.T) {
+ storeDir := stageStore(t, "")
+ p := newTestProcessor(t, func(cfg *Config) {
+ cfg.LocalSourceMaps.Path = storeDir
+ })
+
+ td := ptrace.NewTraces()
+ rs := td.ResourceSpans().AppendEmpty()
+ span := rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty()
+ event := span.Events().AppendEmpty()
+ event.SetName("exception")
+ event.Attributes().PutStr("exception.stacktrace", "Error: boom\n at t (https://cdn.example.com/minified.js:1:11)")
+
+ if _, err := p.processTraces(context.Background(), td); err != nil {
+ t.Fatal(err)
+ }
+
+ attrs := event.Attributes()
+ if got := strAttr(attrs, "exception.stacktrace"); got != " at abcd(tests/fixtures/simple/original.js:2:10)" {
+ t.Errorf("stacktrace: got %q", got)
+ }
+ if got := strAttr(attrs, "exception.symbolicator.parsing_method"); got != parsingMethodParsed {
+ t.Errorf("parsing method: got %q", got)
+ }
+}
+
+func TestProcessLogs(t *testing.T) {
+ storeDir := stageStore(t, "")
+ p := newTestProcessor(t, func(cfg *Config) {
+ cfg.LocalSourceMaps.Path = storeDir
+ })
+
+ ld := plog.NewLogs()
+ rl := ld.ResourceLogs().AppendEmpty()
+ record := rl.ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()
+ putStructuredFrame(record.Attributes())
+
+ if _, err := p.processLogs(context.Background(), ld); err != nil {
+ t.Fatal(err)
+ }
+
+ if got := strAttr(record.Attributes(), "exception.stacktrace"); got != "Error: boom\n at abcd(tests/fixtures/simple/original.js:2:10)" {
+ t.Errorf("log stacktrace: got %q", got)
+ }
+}
+
+func TestBuildUUIDPrefix(t *testing.T) {
+ storeDir := stageStore(t, "build-uuid-1")
+ p := newTestProcessor(t, func(cfg *Config) {
+ cfg.LocalSourceMaps.Path = storeDir
+ })
+
+ td := ptrace.NewTraces()
+ rs := td.ResourceSpans().AppendEmpty()
+ rs.Resource().Attributes().PutStr("app.debug.source_map_uuid", "build-uuid-1")
+ span := rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty()
+ putStructuredFrame(span.Attributes())
+
+ if _, err := p.processTraces(context.Background(), td); err != nil {
+ t.Fatal(err)
+ }
+
+ if got := strAttr(span.Attributes(), "exception.stacktrace"); got != "Error: boom\n at abcd(tests/fixtures/simple/original.js:2:10)" {
+ t.Errorf("uuid-prefixed lookup failed: %q", got)
+ }
+}
+
+func TestMissingArtifactMarksFailed(t *testing.T) {
+ p := newTestProcessor(t, func(cfg *Config) {
+ cfg.LocalSourceMaps.Path = t.TempDir()
+ })
+
+ td := ptrace.NewTraces()
+ span := td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()
+ putStructuredFrame(span.Attributes())
+
+ if _, err := p.processTraces(context.Background(), td); err != nil {
+ t.Fatal(err)
+ }
+
+ attrs := span.Attributes()
+ if v, ok := attrs.Get("exception.symbolicator.failed"); !ok || !v.Bool() {
+ t.Error("expected failed=true for missing artifacts")
+ }
+ if strAttr(attrs, "exception.symbolicator.error") == "" {
+ t.Error("expected error attribute set")
+ }
+ columns, _ := sliceAttr(attrs, "exception.structured_stacktrace.columns")
+ if columns.At(0).Int() != -1 {
+ t.Errorf("expected -1 column sentinel, got %d", columns.At(0).Int())
+ }
+}
+
+func TestMismatchedArraysPreserveOriginals(t *testing.T) {
+ p := newTestProcessor(t, func(cfg *Config) {
+ cfg.LocalSourceMaps.Path = t.TempDir()
+ })
+
+ td := ptrace.NewTraces()
+ span := td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()
+ attrs := span.Attributes()
+ putStructuredFrame(attrs)
+ attrs.PutEmptySlice("exception.structured_stacktrace.columns")
+
+ if _, err := p.processTraces(context.Background(), td); err != nil {
+ t.Fatal(err)
+ }
+
+ if v, ok := attrs.Get("exception.symbolicator.failed"); !ok || !v.Bool() {
+ t.Error("expected failed=true for mismatched arrays")
+ }
+ urls, _ := sliceAttr(attrs, "exception.structured_stacktrace.urls")
+ if urls.Len() != 1 {
+ t.Error("mismatched input must not destroy the original arrays")
+ }
+}
+
+func TestAllowedLanguagesGate(t *testing.T) {
+ storeDir := stageStore(t, "")
+ p := newTestProcessor(t, func(cfg *Config) {
+ cfg.LocalSourceMaps.Path = storeDir
+ cfg.AllowedLanguages = []string{"webjs"}
+ })
+
+ td := ptrace.NewTraces()
+ rs := td.ResourceSpans().AppendEmpty()
+ rs.Resource().Attributes().PutStr("telemetry.sdk.language", "python")
+ span := rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty()
+ putStructuredFrame(span.Attributes())
+
+ if _, err := p.processTraces(context.Background(), td); err != nil {
+ t.Fatal(err)
+ }
+
+ if _, ok := span.Attributes().Get("exception.symbolicator.failed"); ok {
+ t.Error("expected record skipped for disallowed language")
+ }
+}
+
+func TestDiskCacheServesSecondProcessor(t *testing.T) {
+ storeDir := stageStore(t, "")
+ cacheDir := t.TempDir()
+
+ first := newTestProcessor(t, func(cfg *Config) {
+ cfg.LocalSourceMaps.Path = storeDir
+ cfg.CacheDir = cacheDir
+ })
+ td := ptrace.NewTraces()
+ span := td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()
+ putStructuredFrame(span.Attributes())
+ if _, err := first.processTraces(context.Background(), td); err != nil {
+ t.Fatal(err)
+ }
+
+ entries, err := os.ReadDir(cacheDir)
+ if err != nil || len(entries) != 1 {
+ t.Fatalf("expected one .tw cache file, got %d (err=%v)", len(entries), err)
+ }
+
+ second := newTestProcessor(t, func(cfg *Config) {
+ cfg.LocalSourceMaps.Path = t.TempDir()
+ cfg.CacheDir = cacheDir
+ })
+ td2 := ptrace.NewTraces()
+ span2 := td2.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()
+ putStructuredFrame(span2.Attributes())
+ if _, err := second.processTraces(context.Background(), td2); err != nil {
+ t.Fatal(err)
+ }
+
+ if got := strAttr(span2.Attributes(), "exception.stacktrace"); got != "Error: boom\n at abcd(tests/fixtures/simple/original.js:2:10)" {
+ t.Errorf("expected resolution served from the .tw disk cache without store access, got %q", got)
+ }
+}
+
+func TestConfigValidate(t *testing.T) {
+ cfg := createDefaultConfig().(*Config)
+ if err := cfg.Validate(); err != nil {
+ t.Errorf("default config must validate: %v", err)
+ }
+ cfg.CacheMaxDiskPct = 101
+ if err := cfg.Validate(); err == nil {
+ t.Error("expected error for pct > 100")
+ }
+ cfg.CacheMaxDiskPct = 0
+ cfg.SourceMapStoreKey = "redis_store"
+ if err := cfg.Validate(); err == nil {
+ t.Error("expected error for unknown store")
+ }
+}
diff --git a/backend/app/symbolicator/otelprocessor/store.go b/backend/app/symbolicator/otelprocessor/store.go
new file mode 100644
index 00000000..e5de7937
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/store.go
@@ -0,0 +1,196 @@
+package otelprocessor
+
+import (
+ "context"
+ "encoding/base64"
+ "errors"
+ "fmt"
+ "io"
+ "net/url"
+ "os"
+ "path"
+ "path/filepath"
+ "regexp"
+ "strings"
+
+ "cloud.google.com/go/storage"
+ awsconfig "github.com/aws/aws-sdk-go-v2/config"
+ "github.com/aws/aws-sdk-go-v2/service/s3"
+ "github.com/aws/aws-sdk-go-v2/service/s3/types"
+)
+
+const (
+ fileStoreKey = "file_store"
+ s3StoreKey = "s3_store"
+ gcsStoreKey = "gcs_store"
+)
+
+var errObjectNotFound = errors.New("object not found")
+var sourceMappingURLRe = regexp.MustCompile(`//[#@]\s*sourceMappingURL\s*=\s*(\S+)`)
+
+type objectStore interface {
+ fetch(ctx context.Context, key string) ([]byte, error)
+}
+
+type artifactStore struct {
+ store objectStore
+ prefix string
+}
+
+func newStore(cfg *Config) (*artifactStore, error) {
+ switch cfg.SourceMapStoreKey {
+ case fileStoreKey:
+ return &artifactStore{store: &fileStore{root: cfg.LocalSourceMaps.Path}}, nil
+ case s3StoreKey:
+ awsCfg, err := awsconfig.LoadDefaultConfig(context.Background(), awsconfig.WithRegion(cfg.S3SourceMaps.Region))
+ if err != nil {
+ return nil, fmt.Errorf("failed to load AWS config: %w", err)
+ }
+ return &artifactStore{
+ store: &s3Store{client: s3.NewFromConfig(awsCfg), bucket: cfg.S3SourceMaps.Bucket},
+ prefix: cfg.S3SourceMaps.Prefix,
+ }, nil
+ case gcsStoreKey:
+ client, err := storage.NewClient(context.Background())
+ if err != nil {
+ return nil, fmt.Errorf("failed to create GCS client: %w", err)
+ }
+ return &artifactStore{
+ store: &gcsStore{bucket: client.Bucket(cfg.GCSSourceMaps.Bucket)},
+ prefix: cfg.GCSSourceMaps.Prefix,
+ }, nil
+ }
+ return nil, fmt.Errorf("unknown source_map_store %q", cfg.SourceMapStoreKey)
+}
+
+func (a *artifactStore) getSourceAndMap(ctx context.Context, frameURL, buildUUID string) ([]byte, []byte, error) {
+ u, err := url.Parse(frameURL)
+ if err != nil {
+ return nil, nil, fmt.Errorf("failed to parse frame url %q: %w", frameURL, err)
+ }
+ base := path.Base(u.Path)
+ if base == "." || base == "/" || base == "" {
+ return nil, nil, fmt.Errorf("frame url %q has no file name", frameURL)
+ }
+
+ sourceKey := a.key(buildUUID, base)
+ var source []byte
+ if u.RawQuery != "" {
+ source, err = a.store.fetch(ctx, sourceKey+"?"+u.RawQuery)
+ }
+ if source == nil || err != nil {
+ if source, err = a.store.fetch(ctx, sourceKey); err != nil {
+ return nil, nil, fmt.Errorf("failed to find source file %q: %w", sourceKey, err)
+ }
+ }
+
+ mapRef := findSourceMappingURL(source)
+ if mapRef == "" {
+ return nil, nil, fmt.Errorf("source file %q has no sourceMappingURL comment", sourceKey)
+ }
+
+ if data, ok := decodeDataURI(mapRef); ok {
+ return source, data, nil
+ }
+
+ if refURL, err := url.Parse(mapRef); err == nil && refURL.IsAbs() {
+ mapRef = path.Base(refURL.Path)
+ }
+ mapKey := path.Join(path.Dir(sourceKey), mapRef)
+ sourceMap, err := a.store.fetch(ctx, mapKey)
+ if err != nil {
+ return nil, nil, fmt.Errorf("failed to find source map %q: %w", mapKey, err)
+ }
+ return source, sourceMap, nil
+}
+
+func (a *artifactStore) key(buildUUID, base string) string {
+ parts := make([]string, 0, 3)
+ if a.prefix != "" {
+ parts = append(parts, a.prefix)
+ }
+ if buildUUID != "" {
+ parts = append(parts, buildUUID)
+ }
+ parts = append(parts, base)
+ return path.Join(parts...)
+}
+
+func findSourceMappingURL(source []byte) string {
+ tail := source
+ if len(tail) > 16384 {
+ tail = tail[len(tail)-16384:]
+ }
+ matches := sourceMappingURLRe.FindAllSubmatch(tail, -1)
+ if len(matches) == 0 {
+ return ""
+ }
+ return string(matches[len(matches)-1][1])
+}
+
+func decodeDataURI(ref string) ([]byte, bool) {
+ if !strings.HasPrefix(ref, "data:") {
+ return nil, false
+ }
+ idx := strings.Index(ref, "base64,")
+ if idx == -1 {
+ return nil, false
+ }
+ data, err := base64.StdEncoding.DecodeString(ref[idx+len("base64,"):])
+ if err != nil {
+ return nil, false
+ }
+ return data, true
+}
+
+type fileStore struct {
+ root string
+}
+
+func (f *fileStore) fetch(_ context.Context, key string) ([]byte, error) {
+ rel := filepath.FromSlash(key)
+ if !filepath.IsLocal(rel) {
+ return nil, fmt.Errorf("invalid key %q", key)
+ }
+ data, err := os.ReadFile(filepath.Join(f.root, rel))
+ if errors.Is(err, os.ErrNotExist) {
+ return nil, errObjectNotFound
+ }
+ return data, err
+}
+
+type s3Store struct {
+ client *s3.Client
+ bucket string
+}
+
+func (s *s3Store) fetch(ctx context.Context, key string) ([]byte, error) {
+ key = strings.TrimPrefix(key, "/")
+ out, err := s.client.GetObject(ctx, &s3.GetObjectInput{Bucket: &s.bucket, Key: &key})
+ if err != nil {
+ var noKey *types.NoSuchKey
+ if errors.As(err, &noKey) {
+ return nil, errObjectNotFound
+ }
+ return nil, err
+ }
+ defer out.Body.Close()
+ return io.ReadAll(out.Body)
+}
+
+type gcsStore struct {
+ bucket *storage.BucketHandle
+}
+
+func (g *gcsStore) fetch(ctx context.Context, key string) ([]byte, error) {
+ key = strings.TrimPrefix(key, "/")
+ r, err := g.bucket.Object(key).NewReader(ctx)
+ if err != nil {
+ if errors.Is(err, storage.ErrObjectNotExist) {
+ return nil, errObjectNotFound
+ }
+ return nil, err
+ }
+ defer r.Close()
+ return io.ReadAll(r)
+}
diff --git a/backend/app/symbolicator/otelprocessor/symbolicate.go b/backend/app/symbolicator/otelprocessor/symbolicate.go
new file mode 100644
index 00000000..63a2b301
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/symbolicate.go
@@ -0,0 +1,285 @@
+package otelprocessor
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "math"
+ "strings"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/jsstack"
+ "go.opentelemetry.io/collector/pdata/pcommon"
+ "go.uber.org/zap"
+)
+
+const (
+ parsingMethodStructured = "structured_stacktrace_attributes"
+ parsingMethodParsed = "processor_parsed"
+)
+
+var errMismatchedLength = errors.New("mismatched stacktrace attribute lengths")
+var errUnparseableStackTrace = errors.New("unable to parse stack trace")
+
+type symbolicatorProcessor struct {
+ cfg *Config
+ store *artifactStore
+ cache *resolverCache
+ logger *zap.Logger
+}
+
+type stackFrame struct {
+ fn string
+ url string
+ line int64
+ col int64
+}
+
+type frameResult struct {
+ fn string
+ url string
+ line int64
+ col int64
+ skipped bool
+ err error
+}
+
+func (p *symbolicatorProcessor) processRecord(ctx context.Context, attrs, resource pcommon.Map) {
+ if !p.languageAllowed(attrs, resource) {
+ return
+ }
+ stackVal, ok := attrs.Get(p.cfg.StackTraceAttributeKey)
+ if !ok {
+ return
+ }
+ originalStack := stackVal.Str()
+
+ buildUUID := ""
+ if v, ok := resource.Get(p.cfg.BuildUUIDAttributeKey); ok {
+ buildUUID = v.Str()
+ }
+
+ frames, structured, parseErr := p.extractFrames(attrs, originalStack)
+ method := parsingMethodParsed
+ if structured {
+ method = parsingMethodStructured
+ }
+ attrs.PutStr(p.cfg.SymbolicatorParsingMethodAttributeKey, method)
+
+ if parseErr != nil {
+ attrs.PutBool(p.cfg.SymbolicatorFailureAttributeKey, true)
+ attrs.PutStr(p.cfg.SymbolicatorErrorAttributeKey, parseErr.Error())
+ return
+ }
+
+ if p.cfg.PreserveStackTrace {
+ attrs.PutStr(p.cfg.OriginalStackTraceAttributeKey, originalStack)
+ if structured {
+ copySlice(attrs, p.cfg.ColumnsAttributeKey, p.cfg.OriginalColumnsAttributeKey)
+ copySlice(attrs, p.cfg.FunctionsAttributeKey, p.cfg.OriginalFunctionsAttributeKey)
+ copySlice(attrs, p.cfg.LinesAttributeKey, p.cfg.OriginalLinesAttributeKey)
+ copySlice(attrs, p.cfg.UrlsAttributeKey, p.cfg.OriginalUrlsAttributeKey)
+ }
+ }
+
+ results := make([]frameResult, len(frames))
+ for i, f := range frames {
+ results[i] = p.symbolicateFrame(ctx, f, buildUUID)
+ }
+
+ var lines []string
+ excType := strAttr(attrs, p.cfg.ExceptionTypeAttributeKey)
+ excMessage := strAttr(attrs, p.cfg.ExceptionMessageAttributeKey)
+ if excType != "" && excMessage != "" {
+ lines = append(lines, excType+": "+excMessage)
+ }
+
+ failed := false
+ var firstErr error
+ for i := range results {
+ r := &results[i]
+ switch {
+ case r.err != nil:
+ failed = true
+ if firstErr == nil {
+ firstErr = r.err
+ }
+ lines = append(lines, fmt.Sprintf("\tFailed to symbolicate %s at %s:%d:%d: %v", frames[i].fn, frames[i].url, frames[i].line, frames[i].col, r.err))
+ case r.skipped:
+ lines = append(lines, fmt.Sprintf(" at %s (%s)", r.fn, r.url))
+ default:
+ lines = append(lines, fmt.Sprintf(" at %s(%s:%d:%d)", r.fn, r.url, r.line, r.col))
+ }
+ }
+
+ attrs.PutStr(p.cfg.StackTraceAttributeKey, strings.Join(lines, "\n"))
+ if structured {
+ p.writeFrameSlices(attrs, frames, results)
+ }
+
+ attrs.PutBool(p.cfg.SymbolicatorFailureAttributeKey, failed)
+ if failed {
+ failures := 0
+ for i := range results {
+ if results[i].err != nil {
+ failures++
+ }
+ }
+ err := firstErr
+ if failures > 1 {
+ err = fmt.Errorf("symbolication failed for some stack frames: %w", firstErr)
+ }
+ attrs.PutStr(p.cfg.SymbolicatorErrorAttributeKey, err.Error())
+ }
+ attrs.PutStr("traceway.processor_type", componentType.String())
+ attrs.PutStr("traceway.processor_version", processorVersion)
+}
+
+func (p *symbolicatorProcessor) languageAllowed(attrs, resource pcommon.Map) bool {
+ if len(p.cfg.AllowedLanguages) == 0 {
+ return true
+ }
+ lang := strAttr(attrs, p.cfg.LanguageAttributeKey)
+ if lang == "" {
+ lang = strAttr(resource, p.cfg.LanguageAttributeKey)
+ }
+ if lang == "" {
+ return false
+ }
+ for _, allowed := range p.cfg.AllowedLanguages {
+ if strings.EqualFold(lang, allowed) {
+ return true
+ }
+ }
+ return false
+}
+
+func (p *symbolicatorProcessor) extractFrames(attrs pcommon.Map, rawStack string) ([]stackFrame, bool, error) {
+ urls, hasUrls := sliceAttr(attrs, p.cfg.UrlsAttributeKey)
+ functions, hasFunctions := sliceAttr(attrs, p.cfg.FunctionsAttributeKey)
+ lines, hasLines := sliceAttr(attrs, p.cfg.LinesAttributeKey)
+ columns, hasColumns := sliceAttr(attrs, p.cfg.ColumnsAttributeKey)
+
+ if hasUrls && hasFunctions && hasLines && hasColumns {
+ n := urls.Len()
+ if functions.Len() != n || lines.Len() != n || columns.Len() != n {
+ return nil, true, errMismatchedLength
+ }
+ frames := make([]stackFrame, n)
+ for i := 0; i < n; i++ {
+ frames[i] = stackFrame{
+ fn: functions.At(i).Str(),
+ url: urls.At(i).Str(),
+ line: lines.At(i).Int(),
+ col: columns.At(i).Int(),
+ }
+ }
+ return frames, true, nil
+ }
+
+ parsed := jsstack.ParseFrames(rawStack)
+ if len(parsed) == 0 {
+ return nil, false, errUnparseableStackTrace
+ }
+ frames := make([]stackFrame, len(parsed))
+ for i, f := range parsed {
+ fn := f.Function
+ if fn == "" {
+ fn = "?"
+ }
+ frames[i] = stackFrame{fn: fn, url: f.URL, line: int64(f.Line), col: int64(f.Col)}
+ }
+ return frames, false, nil
+}
+
+func (p *symbolicatorProcessor) symbolicateFrame(ctx context.Context, f stackFrame, buildUUID string) frameResult {
+ switch f.url {
+ case "", "<anonymous>", "(native)", "[native code]":
+ url := f.url
+ if url == "" {
+ url = "<anonymous>"
+ }
+ return frameResult{fn: f.fn, url: url, skipped: true}
+ }
+ if f.line <= 0 || f.col <= 0 || f.line > math.MaxUint32 || f.col > math.MaxUint32 {
+ return frameResult{err: fmt.Errorf("line/column out of range: %d:%d", f.line, f.col)}
+ }
+
+ resolver, err := p.cache.get(ctx, f.url+"|"+buildUUID, func(ctx context.Context) (*symbolicator.Resolver, error) {
+ fetchCtx, cancel := context.WithTimeout(ctx, p.cfg.Timeout)
+ defer cancel()
+ source, sourceMap, err := p.store.getSourceAndMap(fetchCtx, f.url, buildUUID)
+ if err != nil {
+ return nil, err
+ }
+ return symbolicator.NewResolver(sourceMap, source)
+ })
+ if err != nil {
+ return frameResult{err: err}
+ }
+
+ frame, ok := resolver.Lookup(uint32(f.line-1), uint32(f.col-1))
+ if !ok {
+ return frameResult{err: fmt.Errorf("no mapping at %d:%d", f.line, f.col)}
+ }
+ fn := frame.Fn
+ if fn == "" {
+ fn = f.fn
+ }
+ file := frame.File
+ if file == "" {
+ file = "<unknown>"
+ }
+ return frameResult{fn: fn, url: file, line: int64(frame.Line), col: int64(frame.Col)}
+}
+
+func (p *symbolicatorProcessor) writeFrameSlices(attrs pcommon.Map, frames []stackFrame, results []frameResult) {
+ columns := attrs.PutEmptySlice(p.cfg.ColumnsAttributeKey)
+ functions := attrs.PutEmptySlice(p.cfg.FunctionsAttributeKey)
+ lines := attrs.PutEmptySlice(p.cfg.LinesAttributeKey)
+ urls := attrs.PutEmptySlice(p.cfg.UrlsAttributeKey)
+
+ for i := range results {
+ r := &results[i]
+ switch {
+ case r.err != nil:
+ columns.AppendEmpty().SetInt(-1)
+ functions.AppendEmpty().SetStr("")
+ lines.AppendEmpty().SetInt(-1)
+ urls.AppendEmpty().SetStr("")
+ case r.skipped:
+ columns.AppendEmpty().SetInt(frames[i].col)
+ functions.AppendEmpty().SetStr(frames[i].fn)
+ lines.AppendEmpty().SetInt(frames[i].line)
+ urls.AppendEmpty().SetStr(frames[i].url)
+ default:
+ columns.AppendEmpty().SetInt(r.col)
+ functions.AppendEmpty().SetStr(r.fn)
+ lines.AppendEmpty().SetInt(r.line)
+ urls.AppendEmpty().SetStr(r.url)
+ }
+ }
+}
+
+func strAttr(attrs pcommon.Map, key string) string {
+ if v, ok := attrs.Get(key); ok {
+ return v.Str()
+ }
+ return ""
+}
+
+func sliceAttr(attrs pcommon.Map, key string) (pcommon.Slice, bool) {
+ v, ok := attrs.Get(key)
+ if !ok || v.Type() != pcommon.ValueTypeSlice {
+ return pcommon.Slice{}, false
+ }
+ return v.Slice(), true
+}
+
+func copySlice(attrs pcommon.Map, from, to string) {
+ v, ok := attrs.Get(from)
+ if !ok || v.Type() != pcommon.ValueTypeSlice {
+ return
+ }
+ v.Slice().CopyTo(attrs.PutEmptySlice(to))
+}
diff --git a/backend/app/symbolicator/otelprocessor/testdata/minified.js b/backend/app/symbolicator/otelprocessor/testdata/minified.js
new file mode 100644
index 00000000..46a3417b
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/testdata/minified.js
@@ -0,0 +1 @@
+function t(){}export default t;
\ No newline at end of file
diff --git a/backend/app/symbolicator/otelprocessor/testdata/minified.js.map b/backend/app/symbolicator/otelprocessor/testdata/minified.js.map
new file mode 100644
index 00000000..13ad226e
--- /dev/null
+++ b/backend/app/symbolicator/otelprocessor/testdata/minified.js.map
@@ -0,0 +1 @@
+{"version":3,"names":["abcd"],"sources":["tests/fixtures/simple/original.js"],"sourcesContent":["// ./node_modules/.bin/terser -c -m --module tests/fixtures/simple/original.js --source-map includeSources -o tests/fixtures/simple/minified.js\nfunction abcd() {}\nexport default abcd;\n"],"mappings":"AACA,SAASA,oBACMA"}
\ No newline at end of file
diff --git a/backend/app/symbolicator/oxc_parity_test.go b/backend/app/symbolicator/oxc_parity_test.go
new file mode 100644
index 00000000..da35e4d0
--- /dev/null
+++ b/backend/app/symbolicator/oxc_parity_test.go
@@ -0,0 +1,61 @@
+//go:build oxc && cgo
+
+package symbolicator
+
+import (
+ "testing"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/scopes"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/sourcemap"
+)
+
+func TestOxcGojaLookupEquivalence(t *testing.T) {
+ original := scopes.ActiveParser()
+ defer func() { _ = scopes.SetParser(original) }()
+
+ for _, tc := range parityCases {
+ if tc.minifiedPath == nil {
+ continue
+ }
+ t.Run(tc.name, func(t *testing.T) {
+ mapBytes := mustRead(t, fixture(t, tc.mapPath...))
+ bundle := mustRead(t, fixture(t, tc.minifiedPath...))
+
+ if err := scopes.SetParser("goja"); err != nil {
+ t.Fatal(err)
+ }
+ gojaResolver, err := NewResolver(mapBytes, bundle)
+ if err != nil {
+ t.Fatalf("NewResolver(goja): %v", err)
+ }
+
+ if err := scopes.SetParser("oxc"); err != nil {
+ t.Fatal(err)
+ }
+ oxcResolver, err := NewResolver(mapBytes, bundle)
+ if err != nil {
+ t.Fatalf("NewResolver(oxc): %v", err)
+ }
+
+ parsed, err := sourcemap.Parse(mapBytes)
+ if err != nil {
+ t.Fatalf("parsing source map: %v", err)
+ }
+
+ mismatches := 0
+ for _, token := range parsed.Tokens {
+ gFrame, gOk := gojaResolver.Lookup(token.GenLine, token.GenCol)
+ oFrame, oOk := oxcResolver.Lookup(token.GenLine, token.GenCol)
+ if gOk != oOk || gFrame != oFrame {
+ mismatches++
+ if mismatches <= 10 {
+ t.Errorf("lookup(%d,%d): goja=(%+v,%v) oxc=(%+v,%v)", token.GenLine, token.GenCol, gFrame, gOk, oFrame, oOk)
+ }
+ }
+ }
+ if mismatches > 10 {
+ t.Errorf("%d total mismatches", mismatches)
+ }
+ })
+ }
+}
diff --git a/backend/app/symbolicator/symbolic_parity_test.go b/backend/app/symbolicator/parity_test.go
similarity index 85%
rename from backend/app/symbolicator/symbolic_parity_test.go
rename to backend/app/symbolicator/parity_test.go
index 522c13fe..10e1af9a 100644
--- a/backend/app/symbolicator/symbolic_parity_test.go
+++ b/backend/app/symbolicator/parity_test.go
@@ -4,26 +4,22 @@ import (
"os"
"path/filepath"
"testing"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/scopes"
)
-func fixtureRoot(t *testing.T) string {
+func fixture(t testing.TB, parts ...string) string {
t.Helper()
root, err := filepath.Abs(filepath.Join("..", "..", "..", "..", "symbolic"))
- if err != nil {
- t.Fatal(err)
- }
- if _, err := os.Stat(root); err != nil {
- t.Skipf("symbolic fixture checkout not found at %s", root)
+ if err == nil {
+ if _, statErr := os.Stat(root); statErr == nil {
+ return filepath.Join(append([]string{root, "symbolic-testutils", "fixtures"}, parts...)...)
+ }
}
- return root
-}
-
-func fixture(t *testing.T, parts ...string) string {
- t.Helper()
- return filepath.Join(append([]string{fixtureRoot(t), "symbolic-testutils", "fixtures"}, parts...)...)
+ return filepath.Join(append([]string{"..", "services", "testdata"}, parts...)...)
}
-func mustRead(t *testing.T, path string) []byte {
+func mustRead(t testing.TB, path string) []byte {
t.Helper()
data, err := os.ReadFile(path)
if err != nil {
@@ -32,7 +28,7 @@ func mustRead(t *testing.T, path string) []byte {
return data
}
-func readIfSet(t *testing.T, parts []string) []byte {
+func readIfSet(t testing.TB, parts []string) []byte {
if parts == nil {
return nil
}
@@ -125,6 +121,20 @@ var parityCases = []parityCase{
}
func TestSymbolicParity(t *testing.T) {
+ original := scopes.ActiveParser()
+ defer func() { _ = scopes.SetParser(original) }()
+
+ for _, parserName := range scopes.AvailableParsers() {
+ t.Run(parserName, func(t *testing.T) {
+ if err := scopes.SetParser(parserName); err != nil {
+ t.Fatalf("SetParser(%q): %v", parserName, err)
+ }
+ runParityCases(t)
+ })
+ }
+}
+
+func runParityCases(t *testing.T) {
for _, tc := range parityCases {
t.Run(tc.name, func(t *testing.T) {
mapBytes := mustRead(t, fixture(t, tc.mapPath...))
diff --git a/backend/app/symbolicator/resolver_bench_test.go b/backend/app/symbolicator/resolver_bench_test.go
new file mode 100644
index 00000000..aa4b2b6d
--- /dev/null
+++ b/backend/app/symbolicator/resolver_bench_test.go
@@ -0,0 +1,49 @@
+package symbolicator
+
+import (
+ "testing"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/scopes"
+)
+
+func BenchmarkNewResolver(b *testing.B) {
+ mapBytes := mustRead(b, fixture(b, "sourcemapcache", "preact.module.js.map"))
+ bundle := mustRead(b, fixture(b, "sourcemapcache", "preact.module.js"))
+
+ for _, parserName := range scopes.AvailableParsers() {
+ b.Run("preact/"+parserName, func(b *testing.B) {
+ original := scopes.ActiveParser()
+ defer func() { _ = scopes.SetParser(original) }()
+ if err := scopes.SetParser(parserName); err != nil {
+ b.Skipf("parser %s not available in this build", parserName)
+ }
+ b.SetBytes(int64(len(mapBytes) + len(bundle)))
+ b.ReportAllocs()
+ b.ResetTimer()
+ for b.Loop() {
+ if _, err := NewResolver(mapBytes, bundle); err != nil {
+ b.Fatal(err)
+ }
+ }
+ })
+ }
+}
+
+func BenchmarkOpenTW(b *testing.B) {
+ mapBytes := mustRead(b, fixture(b, "sourcemapcache", "preact.module.js.map"))
+ bundle := mustRead(b, fixture(b, "sourcemapcache", "preact.module.js"))
+ resolver, err := NewResolver(mapBytes, bundle)
+ if err != nil {
+ b.Fatal(err)
+ }
+ tw := resolver.MarshalTW()
+
+ b.SetBytes(int64(len(tw)))
+ b.ReportAllocs()
+ b.ResetTimer()
+ for b.Loop() {
+ if _, err := OpenTW(tw); err != nil {
+ b.Fatal(err)
+ }
+ }
+}
diff --git a/backend/app/symbolicator/scopes/bench_test.go b/backend/app/symbolicator/scopes/bench_test.go
new file mode 100644
index 00000000..380ad612
--- /dev/null
+++ b/backend/app/symbolicator/scopes/bench_test.go
@@ -0,0 +1,94 @@
+package scopes
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+var benchBundles = []struct {
+ name string
+ path []string
+}{
+ {name: "simple", path: []string{"sourcemapcache", "simple", "minified.js"}},
+ {name: "inlining", path: []string{"sourcemapcache", "inlining", "module.js"}},
+ {name: "webpack", path: []string{"sourcemapcache", "webpack", "bundle.js"}},
+ {name: "metro", path: []string{"sourcemapcache", "hermes-metro", "react-native-metro.js"}},
+ {name: "preact", path: []string{"sourcemapcache", "preact.module.js"}},
+}
+
+func benchFixture(t testing.TB, parts ...string) string {
+ t.Helper()
+ root, err := filepath.Abs(filepath.Join("..", "..", "..", "..", "..", "symbolic"))
+ if err == nil {
+ if _, statErr := os.Stat(root); statErr == nil {
+ return filepath.Join(append([]string{root, "symbolic-testutils", "fixtures"}, parts...)...)
+ }
+ }
+ return filepath.Join(append([]string{"..", "..", "services", "testdata"}, parts...)...)
+}
+
+func benchRead(t testing.TB, parts []string) []byte {
+ t.Helper()
+ data, err := os.ReadFile(benchFixture(t, parts...))
+ if err != nil {
+ t.Fatalf("reading fixture: %v", err)
+ }
+ return data
+}
+
+func syntheticBundle(targetBytes int) []byte {
+ var sb strings.Builder
+ sb.Grow(targetBytes + 1024)
+ sb.WriteString("(function(){\"use strict\";")
+ for i := 0; sb.Len() < targetBytes; i++ {
+ fmt.Fprintf(&sb, "function f%d(a,b){return a+b*%d}", i, i)
+ fmt.Fprintf(&sb, "var g%d=(a,b)=>{var c=f%d(a,b);return c?c:b};", i, i)
+ fmt.Fprintf(&sb, "class C%d{constructor(v){this.v=v}m(x){return this.v+x}static s(y){return(()=>y*2)()}}", i)
+ fmt.Fprintf(&sb, "var o%d={k%d:function(){return new C%d(%d)},a%d:async function(p){return await p}};", i, i, i, i, i)
+ }
+ sb.WriteString("})();")
+ return []byte(sb.String())
+}
+
+func benchParser(b *testing.B, parserName string, bundle []byte) {
+ parse, ok := bundleParsers[parserName]
+ if !ok {
+ b.Skipf("parser %s not available in this build", parserName)
+ }
+ if _, err := parse(bundle); err != nil {
+ b.Fatalf("parse: %v", err)
+ }
+ b.SetBytes(int64(len(bundle)))
+ b.ReportAllocs()
+ b.ResetTimer()
+ for b.Loop() {
+ if _, err := parse(bundle); err != nil {
+ b.Fatal(err)
+ }
+ }
+}
+
+func BenchmarkBundleParsers(b *testing.B) {
+ for _, fixture := range benchBundles {
+ bundle := benchRead(b, fixture.path)
+ for _, parserName := range AvailableParsers() {
+ b.Run(fmt.Sprintf("%s/%s", fixture.name, parserName), func(b *testing.B) {
+ benchParser(b, parserName, bundle)
+ })
+ }
+ }
+}
+
+func BenchmarkBundleParsersSynthetic(b *testing.B) {
+ for _, size := range []int{1 << 20, 5 << 20} {
+ bundle := syntheticBundle(size)
+ for _, parserName := range AvailableParsers() {
+ b.Run(fmt.Sprintf("%dMB/%s", size>>20, parserName), func(b *testing.B) {
+ benchParser(b, parserName, bundle)
+ })
+ }
+ }
+}
diff --git a/backend/app/symbolicator/bundle_parser_goja.go b/backend/app/symbolicator/scopes/goja.go
similarity index 66%
rename from backend/app/symbolicator/bundle_parser_goja.go
rename to backend/app/symbolicator/scopes/goja.go
index b1138972..0d618ea1 100644
--- a/backend/app/symbolicator/bundle_parser_goja.go
+++ b/backend/app/symbolicator/scopes/goja.go
@@ -1,16 +1,14 @@
-package symbolicator
+package scopes
import (
"regexp"
- "slices"
- "unicode/utf16"
"github.com/dop251/goja/ast"
"github.com/dop251/goja/file"
"github.com/dop251/goja/parser"
)
-func parseFunctionScopes(bundle []byte) (*functionScopes, error) {
+func parseGoja(bundle []byte) ([]Transition, error) {
src := string(bundle)
prog, err := parser.ParseFile(nil, "", src, 0, parser.WithDisableSourceMaps)
if err != nil {
@@ -27,160 +25,7 @@ func parseFunctionScopes(bundle []byte) (*functionScopes, error) {
c := &scopeCollector{}
c.walk(prog)
-
- offsets := make([]uint32, 0, len(c.raw)*3)
- for _, s := range c.raw {
- offsets = append(offsets, s.start, s.end, s.namePos)
- }
- pos := convertOffsets(src, offsets)
-
- scopes := make([]genScope, len(c.raw))
- for i, s := range c.raw {
- start, end, name := pos[s.start], pos[s.end], pos[s.namePos]
- scopes[i] = genScope{
- startLine: start.line, startCol: start.col,
- endLine: end.line, endCol: end.col,
- nameLine: name.line, nameCol: name.col,
- }
- }
- return &functionScopes{transitions: buildTransitions(scopes)}, nil
-}
-
-type genScope struct {
- startLine, startCol uint32
- endLine, endCol uint32
- nameLine, nameCol uint32
-}
-
-type functionScopes struct {
- transitions []scopeTransition // sorted by generated position
-}
-
-// scopeTransition marks that, from this generated position onward, the
-// innermost enclosing function's name token is at (nameLine, nameCol). has is
-// false when no function encloses the range (global scope).
-type scopeTransition struct {
- line, col uint32
- nameLine, nameCol uint32
- has bool
-}
-
-type scopeEvent struct {
- line, col uint32
- start bool
- scope int
-}
-
-// buildTransitions flattens the well-nested function scopes into a sorted list
-// of transitions in a single sweep, so the resolver can find the enclosing
-// function of any token with a linear merge instead of scanning every scope per
-// token.
-func buildTransitions(scopes []genScope) []scopeTransition {
- events := make([]scopeEvent, 0, len(scopes)*2)
- for i := range scopes {
- s := scopes[i]
- if !less(s.startLine, s.startCol, s.endLine, s.endCol) {
- continue
- }
- events = append(events,
- scopeEvent{line: s.startLine, col: s.startCol, start: true, scope: i},
- scopeEvent{line: s.endLine, col: s.endCol, start: false, scope: i},
- )
- }
- slices.SortFunc(events, func(a, b scopeEvent) int {
- if a.line != b.line {
- return int(a.line) - int(b.line)
- }
- if a.col != b.col {
- return int(a.col) - int(b.col)
- }
- if a.start == b.start {
- return 0
- }
- if !a.start { // a scope ending here closes before another opens
- return -1
- }
- return 1
- })
-
- var transitions []scopeTransition
- stack := make([]int, 0, 16)
- var lastNameLine, lastNameCol uint32
- lastHas, haveLast := false, false
-
- for i := 0; i < len(events); {
- line, col := events[i].line, events[i].col
- for i < len(events) && events[i].line == line && events[i].col == col {
- if events[i].start {
- stack = append(stack, events[i].scope)
- } else {
- stack = removeFromStack(stack, events[i].scope)
- }
- i++
- }
-
- var nameLine, nameCol uint32
- has := false
- if len(stack) > 0 {
- top := scopes[stack[len(stack)-1]]
- nameLine, nameCol, has = top.nameLine, top.nameCol, true
- }
- if !haveLast || has != lastHas || nameLine != lastNameLine || nameCol != lastNameCol {
- transitions = append(transitions, scopeTransition{line: line, col: col, nameLine: nameLine, nameCol: nameCol, has: has})
- lastNameLine, lastNameCol, lastHas, haveLast = nameLine, nameCol, has, true
- }
- }
- return transitions
-}
-
-func removeFromStack(stack []int, scope int) []int {
- for i := len(stack) - 1; i >= 0; i-- {
- if stack[i] == scope {
- return append(stack[:i], stack[i+1:]...)
- }
- }
- return stack
-}
-
-func less(aLine, aCol, bLine, bCol uint32) bool {
- return aLine < bLine || (aLine == bLine && aCol < bCol)
-}
-
-type genPos struct {
- line, col uint32
-}
-
-func convertOffsets(src string, offsets []uint32) map[uint32]genPos {
- sorted := append([]uint32(nil), offsets...)
- slices.Sort(sorted)
-
- out := make(map[uint32]genPos, len(sorted))
- var line, col uint32
- oi := 0
- for i, r := range src {
- for oi < len(sorted) && sorted[oi] == uint32(i) {
- out[sorted[oi]] = genPos{line, col}
- oi++
- }
- if oi >= len(sorted) {
- return out
- }
- if r == '\n' {
- line++
- col = 0
- } else {
- col += uint32(utf16.RuneLen(r))
- }
- }
- for oi < len(sorted) {
- out[sorted[oi]] = genPos{line, col}
- oi++
- }
- return out
-}
-
-type rawScope struct {
- start, end, namePos uint32
+ return scopesFromRaw(src, c.raw), nil
}
type scopeCollector struct {
diff --git a/backend/app/symbolicator/scopes/oxc-shim/Cargo.lock b/backend/app/symbolicator/scopes/oxc-shim/Cargo.lock
new file mode 100644
index 00000000..a67e84eb
--- /dev/null
+++ b/backend/app/symbolicator/scopes/oxc-shim/Cargo.lock
@@ -0,0 +1,567 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "allocator-api2"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
+
+[[package]]
+name = "autocfg"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
+
+[[package]]
+name = "bitflags"
+version = "2.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
+
+[[package]]
+name = "castaway"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a"
+dependencies = [
+ "rustversion",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
+
+[[package]]
+name = "compact_str"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9dfdd1c2274d9aa354115b09dc9a901d6c5576818cdf70d14cae2bdb47df00ab"
+dependencies = [
+ "castaway",
+ "cfg-if",
+ "itoa",
+ "rustversion",
+ "ryu",
+ "static_assertions",
+]
+
+[[package]]
+name = "cow-utils"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "417bef24afe1460300965a25ff4a24b8b45ad011948302ec221e8a0a81eb2c79"
+
+[[package]]
+name = "dragonbox_ecma"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd8e701084c37e7ef62d3f9e453b618130cbc0ef3573847785952a3ac3f746bf"
+
+[[package]]
+name = "fastrand"
+version = "2.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
+
+[[package]]
+name = "hashbrown"
+version = "0.17.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
+dependencies = [
+ "allocator-api2",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
+
+[[package]]
+name = "memchr"
+version = "2.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8"
+
+[[package]]
+name = "nonmax"
+version = "0.5.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "610a5acd306ec67f907abe5567859a3c693fb9886eb1f012ab8f2a47bef3db51"
+
+[[package]]
+name = "num-bigint"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
+dependencies = [
+ "num-integer",
+ "num-traits",
+]
+
+[[package]]
+name = "num-integer"
+version = "0.1.46"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
+dependencies = [
+ "num-traits",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "owo-colors"
+version = "4.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d211803b9b6b570f68772237e415a029d5a50c65d382910b879fb19d3271f94d"
+
+[[package]]
+name = "oxc-miette"
+version = "2.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4356a61f2ed4c9b3610245215fbf48970eb277126919f87db9d0efa93a74245c"
+dependencies = [
+ "cfg-if",
+ "owo-colors",
+ "oxc-miette-derive",
+ "textwrap",
+ "thiserror",
+ "unicode-segmentation",
+ "unicode-width",
+]
+
+[[package]]
+name = "oxc-miette-derive"
+version = "2.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b237422b014f8f8fff75bb9379e697d13f8d57551a22c88bebb39f073c1bf696"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "oxc_allocator"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3d732c2d8df8067a8d7417be81a8a4631e3201ad420ae70aa2426aebf7bc0326"
+dependencies = [
+ "allocator-api2",
+ "hashbrown",
+ "oxc_data_structures",
+ "rustc-hash",
+]
+
+[[package]]
+name = "oxc_ast"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29512a9acf168a734cbead68ae798c07102b9ecb897cdbe17a40d327b5fff2ec"
+dependencies = [
+ "bitflags",
+ "oxc_allocator",
+ "oxc_ast_macros",
+ "oxc_data_structures",
+ "oxc_diagnostics",
+ "oxc_estree",
+ "oxc_regular_expression",
+ "oxc_span",
+ "oxc_str",
+ "oxc_syntax",
+]
+
+[[package]]
+name = "oxc_ast_macros"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06186227ab1f27f214d824030ef8d7abd604fb24cd647d2acfebfe6bbe378dc6"
+dependencies = [
+ "phf",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "oxc_ast_visit"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af8a8771bbedc5904b6536822fb719f76291d00ab2bccbf5f98950d666f0154f"
+dependencies = [
+ "oxc_allocator",
+ "oxc_ast",
+ "oxc_span",
+ "oxc_syntax",
+]
+
+[[package]]
+name = "oxc_data_structures"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "46270ed833a7d2e5f5fbf0c51f970c2d7e1ef09356d40798cf4702f7d2dae30d"
+
+[[package]]
+name = "oxc_diagnostics"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b0ebb338486583af9e603f4d20be123ad3ae52a5415265454995020386d8afe"
+dependencies = [
+ "cow-utils",
+ "oxc-miette",
+ "percent-encoding",
+]
+
+[[package]]
+name = "oxc_ecmascript"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eef5f3e346539b48dbda9d0b618021ba6bb781f7a192476e4bf9b18df7ccaab4"
+dependencies = [
+ "cow-utils",
+ "num-bigint",
+ "num-traits",
+ "oxc_allocator",
+ "oxc_ast",
+ "oxc_regular_expression",
+ "oxc_span",
+ "oxc_syntax",
+]
+
+[[package]]
+name = "oxc_estree"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "816dfd17df8b02a45b122a1f7bb3c1486d4392e0163aea0e6334ad3894a7ea6b"
+
+[[package]]
+name = "oxc_index"
+version = "5.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "191884bee6c3744909a51acc7d78d4ae370d817b25875b10642f632327b6296e"
+dependencies = [
+ "nonmax",
+ "serde",
+]
+
+[[package]]
+name = "oxc_parser"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43cb9af99a1d02989ed53780e3b2b67757226d4501365e65781ae4519be150b6"
+dependencies = [
+ "bitflags",
+ "cow-utils",
+ "memchr",
+ "num-bigint",
+ "num-traits",
+ "oxc_allocator",
+ "oxc_ast",
+ "oxc_data_structures",
+ "oxc_diagnostics",
+ "oxc_ecmascript",
+ "oxc_regular_expression",
+ "oxc_span",
+ "oxc_str",
+ "oxc_syntax",
+ "rustc-hash",
+ "seq-macro",
+]
+
+[[package]]
+name = "oxc_regular_expression"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ecfe28ec0ffa88784155900d5b7ea1f8383f69d80659ed86f1c4a18a6f117488"
+dependencies = [
+ "bitflags",
+ "oxc_allocator",
+ "oxc_ast_macros",
+ "oxc_diagnostics",
+ "oxc_span",
+ "oxc_str",
+ "phf",
+ "rustc-hash",
+ "unicode-id-start",
+]
+
+[[package]]
+name = "oxc_shim"
+version = "0.1.0"
+dependencies = [
+ "oxc_allocator",
+ "oxc_ast",
+ "oxc_ast_visit",
+ "oxc_parser",
+ "oxc_span",
+ "oxc_syntax",
+]
+
+[[package]]
+name = "oxc_span"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2fbd1667674fd9c25e079a0ab84a87b26e2946d1ce86ad6c5827afa0518c493"
+dependencies = [
+ "compact_str",
+ "oxc-miette",
+ "oxc_allocator",
+ "oxc_ast_macros",
+ "oxc_estree",
+ "oxc_str",
+]
+
+[[package]]
+name = "oxc_str"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "887823468316c2b4798275976857edeb0574201a944810f2f94f3d79aaf6187e"
+dependencies = [
+ "compact_str",
+ "hashbrown",
+ "oxc_allocator",
+ "oxc_estree",
+]
+
+[[package]]
+name = "oxc_syntax"
+version = "0.135.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cad8963ea5ad880d3185db2f8a50809e3a10772c2762500518229bca5347be04"
+dependencies = [
+ "bitflags",
+ "cow-utils",
+ "dragonbox_ecma",
+ "nonmax",
+ "oxc_allocator",
+ "oxc_ast_macros",
+ "oxc_estree",
+ "oxc_index",
+ "oxc_span",
+ "oxc_str",
+ "phf",
+ "unicode-id-start",
+]
+
+[[package]]
+name = "percent-encoding"
+version = "2.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
+
+[[package]]
+name = "phf"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf"
+dependencies = [
+ "phf_macros",
+ "phf_shared",
+ "serde",
+]
+
+[[package]]
+name = "phf_generator"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737"
+dependencies = [
+ "fastrand",
+ "phf_shared",
+]
+
+[[package]]
+name = "phf_macros"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef"
+dependencies = [
+ "phf_generator",
+ "phf_shared",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "phf_shared"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266"
+dependencies = [
+ "siphasher",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.106"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "rustc-hash"
+version = "2.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe"
+
+[[package]]
+name = "rustversion"
+version = "1.0.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
+
+[[package]]
+name = "ryu"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
+
+[[package]]
+name = "seq-macro"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
+
+[[package]]
+name = "serde"
+version = "1.0.228"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
+dependencies = [
+ "serde_core",
+]
+
+[[package]]
+name = "serde_core"
+version = "1.0.228"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.228"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "siphasher"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
+
+[[package]]
+name = "smawk"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
+
+[[package]]
+name = "static_assertions"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
+
+[[package]]
+name = "syn"
+version = "2.0.117"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "textwrap"
+version = "0.16.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"
+dependencies = [
+ "smawk",
+ "unicode-linebreak",
+ "unicode-width",
+]
+
+[[package]]
+name = "thiserror"
+version = "2.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "2.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "unicode-id-start"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "81b79ad29b5e19de4260020f8919b443b2ef0277d242ce532ec7b7a2cc8b6007"
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
+
+[[package]]
+name = "unicode-linebreak"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
+
+[[package]]
+name = "unicode-segmentation"
+version = "1.13.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8"
+
+[[package]]
+name = "unicode-width"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
diff --git a/backend/app/symbolicator/scopes/oxc-shim/Cargo.toml b/backend/app/symbolicator/scopes/oxc-shim/Cargo.toml
new file mode 100644
index 00000000..ff956c59
--- /dev/null
+++ b/backend/app/symbolicator/scopes/oxc-shim/Cargo.toml
@@ -0,0 +1,20 @@
+[package]
+name = "oxc_shim"
+version = "0.1.0"
+edition = "2021"
+publish = false
+
+[lib]
+crate-type = ["staticlib"]
+
+[dependencies]
+oxc_allocator = "=0.135.0"
+oxc_ast = "=0.135.0"
+oxc_ast_visit = "=0.135.0"
+oxc_parser = "=0.135.0"
+oxc_span = "=0.135.0"
+oxc_syntax = "=0.135.0"
+
+[profile.release]
+lto = true
+codegen-units = 1
diff --git a/backend/app/symbolicator/scopes/oxc-shim/include/oxc_shim.h b/backend/app/symbolicator/scopes/oxc-shim/include/oxc_shim.h
new file mode 100644
index 00000000..e09ae2b2
--- /dev/null
+++ b/backend/app/symbolicator/scopes/oxc-shim/include/oxc_shim.h
@@ -0,0 +1,18 @@
+#ifndef OXC_SHIM_H
+#define OXC_SHIM_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t oxc_parse_scopes(const char *src, size_t len, uint32_t **out, size_t *out_len);
+void oxc_free_scopes(uint32_t *ptr, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/backend/app/symbolicator/scopes/oxc-shim/src/lib.rs b/backend/app/symbolicator/scopes/oxc-shim/src/lib.rs
new file mode 100644
index 00000000..2e274bcf
--- /dev/null
+++ b/backend/app/symbolicator/scopes/oxc-shim/src/lib.rs
@@ -0,0 +1,93 @@
+use std::os::raw::c_char;
+use std::panic::{catch_unwind, AssertUnwindSafe};
+
+use oxc_allocator::Allocator;
+use oxc_ast::ast::{ArrowFunctionExpression, Class, Function};
+use oxc_ast_visit::{walk, Visit};
+use oxc_parser::Parser;
+use oxc_span::SourceType;
+use oxc_syntax::scope::ScopeFlags;
+
+struct ScopeCollector {
+ out: Vec<u32>,
+}
+
+impl<'a> Visit<'a> for ScopeCollector {
+ fn visit_function(&mut self, it: &Function<'a>, flags: ScopeFlags) {
+ let name = it.id.as_ref().map_or(it.span.start, |id| id.span.start);
+ self.out.extend_from_slice(&[it.span.start, it.span.end, name]);
+ walk::walk_function(self, it, flags);
+ }
+
+ fn visit_arrow_function_expression(&mut self, it: &ArrowFunctionExpression<'a>) {
+ self.out
+ .extend_from_slice(&[it.span.start, it.span.end, it.span.start]);
+ walk::walk_arrow_function_expression(self, it);
+ }
+
+ fn visit_class(&mut self, it: &Class<'a>) {
+ let name = it.id.as_ref().map_or(it.span.start, |id| id.span.start);
+ self.out.extend_from_slice(&[it.span.start, it.span.end, name]);
+ walk::walk_class(self, it);
+ }
+}
+
+fn collect_scopes(src: &str) -> Option<Vec<u32>> {
+ for source_type in [SourceType::mjs(), SourceType::cjs()] {
+ let allocator = Allocator::default();
+ let ret = Parser::new(&allocator, src, source_type).parse();
+ if ret.panicked || !ret.errors.is_empty() {
+ continue;
+ }
+ let mut collector = ScopeCollector { out: Vec::new() };
+ collector.visit_program(&ret.program);
+ return Some(collector.out);
+ }
+ None
+}
+
+const OXC_OK: i32 = 0;
+const OXC_ERR_BAD_ARGS: i32 = 1;
+const OXC_ERR_INVALID_UTF8: i32 = 2;
+const OXC_ERR_PARSE: i32 = 3;
+const OXC_ERR_PANIC: i32 = 4;
+
+#[no_mangle]
+pub extern "C" fn oxc_parse_scopes(
+ src: *const c_char,
+ len: usize,
+ out: *mut *mut u32,
+ out_len: *mut usize,
+) -> i32 {
+ if src.is_null() || out.is_null() || out_len.is_null() {
+ return OXC_ERR_BAD_ARGS;
+ }
+ let bytes = unsafe { std::slice::from_raw_parts(src as *const u8, len) };
+ let text = match std::str::from_utf8(bytes) {
+ Ok(t) => t,
+ Err(_) => return OXC_ERR_INVALID_UTF8,
+ };
+ match catch_unwind(AssertUnwindSafe(|| collect_scopes(text))) {
+ Ok(Some(scopes)) => {
+ let mut boxed = scopes.into_boxed_slice();
+ unsafe {
+ *out = boxed.as_mut_ptr();
+ *out_len = boxed.len();
+ }
+ std::mem::forget(boxed);
+ OXC_OK
+ }
+ Ok(None) => OXC_ERR_PARSE,
+ Err(_) => OXC_ERR_PANIC,
+ }
+}
+
+#[no_mangle]
+pub extern "C" fn oxc_free_scopes(ptr: *mut u32, len: usize) {
+ if ptr.is_null() {
+ return;
+ }
+ unsafe {
+ drop(Vec::from_raw_parts(ptr, len, len));
+ }
+}
diff --git a/backend/app/symbolicator/scopes/oxc.go b/backend/app/symbolicator/scopes/oxc.go
new file mode 100644
index 00000000..d2c4550e
--- /dev/null
+++ b/backend/app/symbolicator/scopes/oxc.go
@@ -0,0 +1,60 @@
+//go:build oxc && cgo
+
+package scopes
+
+/*
+#cgo CFLAGS: -I${SRCDIR}/oxc-shim/include
+#cgo LDFLAGS: ${SRCDIR}/oxc-shim/target/release/liboxc_shim.a
+#cgo linux LDFLAGS: -lm -ldl -lpthread
+#include <oxc_shim.h>
+*/
+import "C"
+
+import (
+ "fmt"
+ "unsafe"
+)
+
+func init() {
+ bundleParsers["oxc"] = parseOxc
+}
+
+var oxcParseErrors = map[int32]string{
+ 1: "bad arguments",
+ 2: "source is not valid utf-8",
+ 3: "parse failed",
+ 4: "parser panicked",
+}
+
+func parseOxc(bundle []byte) ([]Transition, error) {
+ if len(bundle) == 0 {
+ return scopesFromRaw("", nil), nil
+ }
+
+ var out *C.uint32_t
+ var outLen C.size_t
+ rc := int32(C.oxc_parse_scopes(
+ (*C.char)(unsafe.Pointer(&bundle[0])),
+ C.size_t(len(bundle)),
+ &out,
+ &outLen,
+ ))
+ if rc != 0 {
+ msg, ok := oxcParseErrors[rc]
+ if !ok {
+ msg = fmt.Sprintf("unknown error code %d", rc)
+ }
+ return nil, fmt.Errorf("oxc: %s", msg)
+ }
+ defer C.oxc_free_scopes(out, outLen)
+
+ n := int(outLen)
+ raw := make([]rawScope, 0, n/3)
+ if n > 0 {
+ vals := unsafe.Slice((*uint32)(unsafe.Pointer(out)), n)
+ for i := 0; i+2 < n; i += 3 {
+ raw = append(raw, rawScope{start: vals[i], end: vals[i+1], namePos: vals[i+2]})
+ }
+ }
+ return scopesFromRaw(unsafe.String(unsafe.SliceData(bundle), len(bundle)), raw), nil
+}
diff --git a/backend/app/symbolicator/scopes/registry.go b/backend/app/symbolicator/scopes/registry.go
new file mode 100644
index 00000000..8fa13c2b
--- /dev/null
+++ b/backend/app/symbolicator/scopes/registry.go
@@ -0,0 +1,40 @@
+package scopes
+
+import (
+ "fmt"
+ "slices"
+ "strings"
+)
+
+type bundleParser func(bundle []byte) ([]Transition, error)
+
+var bundleParsers = map[string]bundleParser{
+ "goja": parseGoja,
+}
+
+var activeBundleParser = "goja"
+
+func SetParser(name string) error {
+ if _, ok := bundleParsers[name]; !ok {
+ return fmt.Errorf("scopes: unknown bundle parser %q (available: %s)", name, strings.Join(AvailableParsers(), ", "))
+ }
+ activeBundleParser = name
+ return nil
+}
+
+func ActiveParser() string {
+ return activeBundleParser
+}
+
+func AvailableParsers() []string {
+ names := make([]string, 0, len(bundleParsers))
+ for name := range bundleParsers {
+ names = append(names, name)
+ }
+ slices.Sort(names)
+ return names
+}
+
+func Parse(bundle []byte) ([]Transition, error) {
+ return bundleParsers[activeBundleParser](bundle)
+}
diff --git a/backend/app/symbolicator/scopes/scopes.go b/backend/app/symbolicator/scopes/scopes.go
new file mode 100644
index 00000000..d63e0de5
--- /dev/null
+++ b/backend/app/symbolicator/scopes/scopes.go
@@ -0,0 +1,143 @@
+package scopes
+
+import (
+ "slices"
+ "unicode/utf16"
+)
+
+type Transition struct {
+ Line, Col uint32
+ NameLine, NameCol uint32
+ Named bool
+}
+
+type rawScope struct {
+ start, end, namePos uint32
+}
+
+func scopesFromRaw(src string, raw []rawScope) []Transition {
+ offsets := make([]uint32, 0, len(raw)*3)
+ for _, s := range raw {
+ offsets = append(offsets, s.start, s.end, s.namePos)
+ }
+ pos := convertOffsets(src, offsets)
+
+ scopes := make([]genScope, len(raw))
+ for i, s := range raw {
+ start, end, name := pos[s.start], pos[s.end], pos[s.namePos]
+ scopes[i] = genScope{
+ startLine: start.line, startCol: start.col,
+ endLine: end.line, endCol: end.col,
+ nameLine: name.line, nameCol: name.col,
+ }
+ }
+ return buildTransitions(scopes)
+}
+
+type genScope struct {
+ startLine, startCol uint32
+ endLine, endCol uint32
+ nameLine, nameCol uint32
+}
+
+type scopeEvent struct {
+ line, col uint32
+ start bool
+ scope int
+}
+
+func buildTransitions(scopes []genScope) []Transition {
+ events := make([]scopeEvent, 0, len(scopes)*2)
+ for i := range scopes {
+ s := scopes[i]
+ if s.startLine > s.endLine || (s.startLine == s.endLine && s.startCol >= s.endCol) {
+ continue
+ }
+ events = append(events,
+ scopeEvent{line: s.startLine, col: s.startCol, start: true, scope: i},
+ scopeEvent{line: s.endLine, col: s.endCol, start: false, scope: i},
+ )
+ }
+ slices.SortFunc(events, func(a, b scopeEvent) int {
+ if a.line != b.line {
+ return int(a.line) - int(b.line)
+ }
+ if a.col != b.col {
+ return int(a.col) - int(b.col)
+ }
+ if a.start == b.start {
+ return 0
+ }
+ if !a.start {
+ return -1
+ }
+ return 1
+ })
+
+ var transitions []Transition
+ stack := make([]int, 0, 16)
+ var lastNameLine, lastNameCol uint32
+ lastNamed, haveLast := false, false
+
+ for i := 0; i < len(events); {
+ line, col := events[i].line, events[i].col
+ for i < len(events) && events[i].line == line && events[i].col == col {
+ if events[i].start {
+ stack = append(stack, events[i].scope)
+ } else {
+ for j := len(stack) - 1; j >= 0; j-- {
+ if stack[j] == events[i].scope {
+ stack = slices.Delete(stack, j, j+1)
+ break
+ }
+ }
+ }
+ i++
+ }
+
+ var nameLine, nameCol uint32
+ named := false
+ if len(stack) > 0 {
+ top := scopes[stack[len(stack)-1]]
+ nameLine, nameCol, named = top.nameLine, top.nameCol, true
+ }
+ if !haveLast || named != lastNamed || nameLine != lastNameLine || nameCol != lastNameCol {
+ transitions = append(transitions, Transition{Line: line, Col: col, NameLine: nameLine, NameCol: nameCol, Named: named})
+ lastNameLine, lastNameCol, lastNamed, haveLast = nameLine, nameCol, named, true
+ }
+ }
+ return transitions
+}
+
+type genPos struct {
+ line, col uint32
+}
+
+func convertOffsets(src string, offsets []uint32) map[uint32]genPos {
+ sorted := append([]uint32(nil), offsets...)
+ slices.Sort(sorted)
+
+ out := make(map[uint32]genPos, len(sorted))
+ var line, col uint32
+ oi := 0
+ for i, r := range src {
+ for oi < len(sorted) && sorted[oi] == uint32(i) {
+ out[sorted[oi]] = genPos{line, col}
+ oi++
+ }
+ if oi >= len(sorted) {
+ return out
+ }
+ if r == '\n' {
+ line++
+ col = 0
+ } else {
+ col += uint32(utf16.RuneLen(r))
+ }
+ }
+ for oi < len(sorted) {
+ out[sorted[oi]] = genPos{line, col}
+ oi++
+ }
+ return out
+}
diff --git a/backend/app/symbolicator/sourcemap_parser/sourcemap.go b/backend/app/symbolicator/sourcemap/sourcemap.go
similarity index 99%
rename from backend/app/symbolicator/sourcemap_parser/sourcemap.go
rename to backend/app/symbolicator/sourcemap/sourcemap.go
index e843255f..32a87ba8 100644
--- a/backend/app/symbolicator/sourcemap_parser/sourcemap.go
+++ b/backend/app/symbolicator/sourcemap/sourcemap.go
@@ -1,4 +1,4 @@
-package sourcemap_parser
+package sourcemap
import (
"encoding/json"
diff --git a/backend/app/symbolicator/sourcemap_parser/vlq.go b/backend/app/symbolicator/sourcemap/vlq.go
similarity index 76%
rename from backend/app/symbolicator/sourcemap_parser/vlq.go
rename to backend/app/symbolicator/sourcemap/vlq.go
index e885302a..80fe88f7 100644
--- a/backend/app/symbolicator/sourcemap_parser/vlq.go
+++ b/backend/app/symbolicator/sourcemap/vlq.go
@@ -1,4 +1,4 @@
-package sourcemap_parser
+package sourcemap
import "fmt"
@@ -15,6 +15,26 @@ func init() {
}
}
+func AppendVLQ(dst []byte, v int64) []byte {
+ var u uint64
+ if v < 0 {
+ u = uint64(-v)<<1 | 1
+ } else {
+ u = uint64(v) << 1
+ }
+ for {
+ d := u & 31
+ u >>= 5
+ if u != 0 {
+ d |= 32
+ }
+ dst = append(dst, vlqAlphabet[d])
+ if u == 0 {
+ return dst
+ }
+ }
+}
+
func decodeVLQ(seg string, dst []int64) ([]int64, error) {
var cur uint64
var shift uint
diff --git a/backend/app/symbolicator/sourcemap/vlq_test.go b/backend/app/symbolicator/sourcemap/vlq_test.go
new file mode 100644
index 00000000..66faee33
--- /dev/null
+++ b/backend/app/symbolicator/sourcemap/vlq_test.go
@@ -0,0 +1,23 @@
+package sourcemap
+
+import "testing"
+
+func TestVLQRoundTrip(t *testing.T) {
+ values := []int64{0, 1, -1, 15, 16, -16, 31, 32, 1000, -1000, 1 << 20, -(1 << 20), 1<<30 - 1}
+ var encoded []byte
+ for _, v := range values {
+ encoded = AppendVLQ(encoded, v)
+ }
+ decoded, err := decodeVLQ(string(encoded), nil)
+ if err != nil {
+ t.Fatalf("decodeVLQ: %v", err)
+ }
+ if len(decoded) != len(values) {
+ t.Fatalf("decoded %d values, want %d", len(decoded), len(values))
+ }
+ for i, v := range values {
+ if decoded[i] != v {
+ t.Errorf("value %d: got %d, want %d", i, decoded[i], v)
+ }
+ }
+}
diff --git a/backend/app/symbolicator/symbolicator.go b/backend/app/symbolicator/symbolicator.go
index a4a67d91..bcf4fe33 100644
--- a/backend/app/symbolicator/symbolicator.go
+++ b/backend/app/symbolicator/symbolicator.go
@@ -1,9 +1,11 @@
package symbolicator
import (
+ "runtime"
"sort"
- "github.com/tracewayapp/traceway/backend/app/symbolicator/sourcemap_parser"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/scopes"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/sourcemap"
)
type StackTraceFrame struct {
@@ -27,25 +29,21 @@ type Resolver struct {
}
func NewResolver(sourceMap, bundle []byte) (*Resolver, error) {
- m, err := sourcemap_parser.Parse(sourceMap)
+ m, err := sourcemap.Parse(sourceMap)
if err != nil {
return nil, err
}
- var scopes *functionScopes
+ var transitions []scopes.Transition
if len(bundle) > 0 {
- if fs, err := parseFunctionScopes(bundle); err == nil {
- scopes = fs
+ if ts, err := scopes.Parse(bundle); err == nil {
+ transitions = ts
}
}
files := newInterner()
fns := newInterner()
- var transitions []scopeTransition
- if scopes != nil {
- transitions = scopes.transitions
- }
ti := -1
var curFnIdx int32 = -1
curResolved := false
@@ -56,23 +54,27 @@ func NewResolver(sourceMap, bundle []byte) (*Resolver, error) {
// Tokens are sorted by generated position, so the floor transition
// pointer only moves forward across the whole map (linear merge).
- for ti+1 < len(transitions) && !less(t.GenLine, t.GenCol, transitions[ti+1].line, transitions[ti+1].col) {
+ for ti+1 < len(transitions) {
+ next := &transitions[ti+1]
+ if t.GenLine < next.Line || (t.GenLine == next.Line && t.GenCol < next.Col) {
+ break
+ }
ti++
curResolved = false
}
rt := resolvedToken{genLine: t.GenLine, genCol: t.GenCol, fileIdx: -1, fnIdx: -1}
- if t.SrcID != sourcemap_parser.NoID && int(t.SrcID) < len(m.Sources) {
+ if t.SrcID != sourcemap.NoID && int(t.SrcID) < len(m.Sources) {
rt.fileIdx = files.intern(m.Sources[t.SrcID])
rt.srcLine = t.SrcLine + 1
rt.srcCol = t.SrcCol + 1
- if ti >= 0 && transitions[ti].has {
+ if ti >= 0 && transitions[ti].Named {
// Resolve the enclosing function's name once per transition,
// not once per token.
if !curResolved {
curFnIdx = -1
tr := transitions[ti]
- if nt := m.FloorToken(tr.nameLine, tr.nameCol); nt != nil && nt.NameID != sourcemap_parser.NoID {
+ if nt := m.FloorToken(tr.NameLine, tr.NameCol); nt != nil && nt.NameID != sourcemap.NoID {
curFnIdx = fns.intern(m.Names[nt.NameID])
}
curResolved = true
@@ -87,6 +89,7 @@ func NewResolver(sourceMap, bundle []byte) (*Resolver, error) {
}
func (r *Resolver) Lookup(genLine, genCol uint32) (StackTraceFrame, bool) {
+ defer runtime.KeepAlive(r)
toks := r.tokens
idx := sort.Search(len(toks), func(i int) bool {
return toks[i].genLine > genLine || (toks[i].genLine == genLine && toks[i].genCol > genCol)
diff --git a/backend/app/symbolicator/tw.go b/backend/app/symbolicator/tw.go
new file mode 100644
index 00000000..4ccf372b
--- /dev/null
+++ b/backend/app/symbolicator/tw.go
@@ -0,0 +1,161 @@
+package symbolicator
+
+import (
+ "encoding/binary"
+ "errors"
+ "runtime"
+ "unsafe"
+)
+
+const twVersion = 1
+const twHeaderSize = 24
+const twTokenSize = 24
+
+var twMagic = [4]byte{'T', 'W', 'S', 'M'}
+
+var ErrInvalidTW = errors.New("symbolicator: invalid tw data")
+
+var hostLittleEndian = func() bool {
+ var x uint16 = 1
+ return *(*byte)(unsafe.Pointer(&x)) == 1
+}()
+
+func (r *Resolver) MarshalTW() []byte {
+ defer runtime.KeepAlive(r)
+ fileOffsets, fileBlob := encodeStringTable(r.files)
+ fnOffsets, fnBlob := encodeStringTable(r.fns)
+
+ size := twHeaderSize +
+ len(r.tokens)*twTokenSize +
+ len(fileOffsets)*4 + len(fileBlob) +
+ len(fnOffsets)*4 + len(fnBlob)
+
+ out := make([]byte, 0, size)
+ out = append(out, twMagic[:]...)
+ out = binary.LittleEndian.AppendUint32(out, twVersion)
+ out = binary.LittleEndian.AppendUint32(out, uint32(len(r.tokens)))
+ out = binary.LittleEndian.AppendUint32(out, uint32(len(r.files)))
+ out = binary.LittleEndian.AppendUint32(out, uint32(len(r.fns)))
+ out = binary.LittleEndian.AppendUint32(out, 0)
+
+ for i := range r.tokens {
+ t := &r.tokens[i]
+ out = binary.LittleEndian.AppendUint32(out, t.genLine)
+ out = binary.LittleEndian.AppendUint32(out, t.genCol)
+ out = binary.LittleEndian.AppendUint32(out, t.srcLine)
+ out = binary.LittleEndian.AppendUint32(out, t.srcCol)
+ out = binary.LittleEndian.AppendUint32(out, uint32(t.fileIdx))
+ out = binary.LittleEndian.AppendUint32(out, uint32(t.fnIdx))
+ }
+
+ for _, off := range fileOffsets {
+ out = binary.LittleEndian.AppendUint32(out, off)
+ }
+ out = append(out, fileBlob...)
+ for _, off := range fnOffsets {
+ out = binary.LittleEndian.AppendUint32(out, off)
+ }
+ out = append(out, fnBlob...)
+ return out
+}
+
+func encodeStringTable(strs []string) ([]uint32, []byte) {
+ offsets := make([]uint32, len(strs)+1)
+ var blob []byte
+ for i, s := range strs {
+ offsets[i] = uint32(len(blob))
+ blob = append(blob, s...)
+ }
+ offsets[len(strs)] = uint32(len(blob))
+ return offsets, blob
+}
+
+func OpenTW(data []byte) (*Resolver, error) {
+ if len(data) < twHeaderSize || [4]byte(data[:4]) != twMagic {
+ return nil, ErrInvalidTW
+ }
+ if binary.LittleEndian.Uint32(data[4:]) != twVersion {
+ return nil, ErrInvalidTW
+ }
+ tokenCount := int(binary.LittleEndian.Uint32(data[8:]))
+ filesCount := int(binary.LittleEndian.Uint32(data[12:]))
+ fnsCount := int(binary.LittleEndian.Uint32(data[16:]))
+
+ pos := uint64(twHeaderSize)
+ tokensOff := pos
+ pos += uint64(tokenCount) * twTokenSize
+ if pos > uint64(len(data)) {
+ return nil, ErrInvalidTW
+ }
+
+ files, pos, err := decodeStringTable(data, pos, filesCount)
+ if err != nil {
+ return nil, err
+ }
+ fns, pos, err := decodeStringTable(data, pos, fnsCount)
+ if err != nil {
+ return nil, err
+ }
+ if pos != uint64(len(data)) {
+ return nil, ErrInvalidTW
+ }
+
+ r := &Resolver{files: files, fns: fns}
+ if tokenCount > 0 {
+ tokenBytes := data[tokensOff : tokensOff+uint64(tokenCount)*twTokenSize]
+ if hostLittleEndian &&
+ unsafe.Sizeof(resolvedToken{}) == twTokenSize &&
+ uintptr(unsafe.Pointer(&tokenBytes[0]))%unsafe.Alignof(resolvedToken{}) == 0 {
+ r.tokens = unsafe.Slice((*resolvedToken)(unsafe.Pointer(&tokenBytes[0])), tokenCount)
+ } else {
+ r.tokens = decodeTokens(tokenBytes, tokenCount)
+ }
+ }
+ for i := range r.tokens {
+ t := &r.tokens[i]
+ if int(t.fileIdx) >= len(files) || int(t.fnIdx) >= len(fns) {
+ return nil, ErrInvalidTW
+ }
+ }
+ return r, nil
+}
+
+func decodeTokens(b []byte, count int) []resolvedToken {
+ tokens := make([]resolvedToken, count)
+ for i := range tokens {
+ rec := b[i*twTokenSize:]
+ tokens[i] = resolvedToken{
+ genLine: binary.LittleEndian.Uint32(rec),
+ genCol: binary.LittleEndian.Uint32(rec[4:]),
+ srcLine: binary.LittleEndian.Uint32(rec[8:]),
+ srcCol: binary.LittleEndian.Uint32(rec[12:]),
+ fileIdx: int32(binary.LittleEndian.Uint32(rec[16:])),
+ fnIdx: int32(binary.LittleEndian.Uint32(rec[20:])),
+ }
+ }
+ return tokens
+}
+
+func decodeStringTable(data []byte, pos uint64, count int) ([]string, uint64, error) {
+ offsetsEnd := pos + uint64(count+1)*4
+ if count < 0 || offsetsEnd > uint64(len(data)) {
+ return nil, 0, ErrInvalidTW
+ }
+ offsets := make([]uint32, count+1)
+ for i := range offsets {
+ offsets[i] = binary.LittleEndian.Uint32(data[pos+uint64(i)*4:])
+ if i > 0 && offsets[i-1] > offsets[i] {
+ return nil, 0, ErrInvalidTW
+ }
+ }
+ blobStart := offsetsEnd
+ blobEnd := blobStart + uint64(offsets[count])
+ if blobEnd > uint64(len(data)) {
+ return nil, 0, ErrInvalidTW
+ }
+ strs := make([]string, count)
+ for i := range count {
+ strs[i] = string(data[blobStart+uint64(offsets[i]) : blobStart+uint64(offsets[i+1])])
+ }
+ return strs, blobEnd, nil
+}
diff --git a/backend/app/symbolicator/tw_test.go b/backend/app/symbolicator/tw_test.go
new file mode 100644
index 00000000..cec85c61
--- /dev/null
+++ b/backend/app/symbolicator/tw_test.go
@@ -0,0 +1,155 @@
+package symbolicator
+
+import (
+ "encoding/binary"
+ "testing"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/sourcemap"
+)
+
+func TestTWRoundTrip(t *testing.T) {
+ for _, tc := range parityCases {
+ t.Run(tc.name, func(t *testing.T) {
+ mapBytes := mustRead(t, fixture(t, tc.mapPath...))
+ bundle := readIfSet(t, tc.minifiedPath)
+
+ original, err := NewResolver(mapBytes, bundle)
+ if err != nil {
+ t.Fatalf("NewResolver: %v", err)
+ }
+
+ reopened, err := OpenTW(original.MarshalTW())
+ if err != nil {
+ t.Fatalf("OpenTW: %v", err)
+ }
+
+ parsed, err := sourcemap.Parse(mapBytes)
+ if err != nil {
+ t.Fatalf("parsing source map: %v", err)
+ }
+
+ mismatches := 0
+ for _, token := range parsed.Tokens {
+ oFrame, oOk := original.Lookup(token.GenLine, token.GenCol)
+ rFrame, rOk := reopened.Lookup(token.GenLine, token.GenCol)
+ if oOk != rOk || oFrame != rFrame {
+ mismatches++
+ if mismatches <= 10 {
+ t.Errorf("lookup(%d,%d): original=(%+v,%v) reopened=(%+v,%v)", token.GenLine, token.GenCol, oFrame, oOk, rFrame, rOk)
+ }
+ }
+ }
+ if mismatches > 10 {
+ t.Errorf("%d total mismatches", mismatches)
+ }
+
+ for _, exp := range tc.expectations {
+ frame, ok := reopened.Lookup(exp.line, exp.col)
+ if exp.wantNone {
+ if ok {
+ t.Errorf("lookup(%d,%d): got %+v, want no mapping", exp.line, exp.col, frame)
+ }
+ continue
+ }
+ if !ok {
+ t.Errorf("lookup(%d,%d): got no mapping, want a result", exp.line, exp.col)
+ continue
+ }
+ if exp.file != "" && frame.File != exp.file {
+ t.Errorf("lookup(%d,%d) file: got %q, want %q", exp.line, exp.col, frame.File, exp.file)
+ }
+ if frame.Line != exp.srcLine+1 || frame.Col != exp.srcCol+1 {
+ t.Errorf("lookup(%d,%d) pos: got %d:%d, want %d:%d", exp.line, exp.col, frame.Line, frame.Col, exp.srcLine+1, exp.srcCol+1)
+ }
+ if frame.Fn != exp.fn {
+ t.Errorf("lookup(%d,%d) fn: got %q, want %q", exp.line, exp.col, frame.Fn, exp.fn)
+ }
+ }
+ })
+ }
+}
+
+func TestOpenTWRejectsInvalid(t *testing.T) {
+ cases := map[string][]byte{
+ "empty": nil,
+ "short": []byte("TWSM"),
+ "bad_magic": append([]byte("XXXX"), make([]byte, 20)...),
+ "bad_version": append([]byte("TWSM\xff\x00\x00\x00"), make([]byte, 16)...),
+ "truncated": func() []byte { r := &Resolver{}; return r.MarshalTW()[:twHeaderSize-1] }(),
+ "token_overrun": append([]byte("TWSM\x01\x00\x00\x00\xff\xff\xff\x00"), make([]byte, 12)...),
+ }
+ for name, data := range cases {
+ if _, err := OpenTW(data); err == nil {
+ t.Errorf("%s: expected error, got nil", name)
+ }
+ }
+}
+
+func buildTW(t *testing.T, tokens [][6]uint32, fileOffsets []uint32, fileBlob []byte, fnOffsets []uint32, fnBlob []byte) []byte {
+ t.Helper()
+ out := []byte("TWSM")
+ out = binary.LittleEndian.AppendUint32(out, 1)
+ out = binary.LittleEndian.AppendUint32(out, uint32(len(tokens)))
+ out = binary.LittleEndian.AppendUint32(out, uint32(len(fileOffsets)-1))
+ out = binary.LittleEndian.AppendUint32(out, uint32(len(fnOffsets)-1))
+ out = binary.LittleEndian.AppendUint32(out, 0)
+ for _, tok := range tokens {
+ for _, v := range tok {
+ out = binary.LittleEndian.AppendUint32(out, v)
+ }
+ }
+ for _, off := range fileOffsets {
+ out = binary.LittleEndian.AppendUint32(out, off)
+ }
+ out = append(out, fileBlob...)
+ for _, off := range fnOffsets {
+ out = binary.LittleEndian.AppendUint32(out, off)
+ }
+ out = append(out, fnBlob...)
+ return out
+}
+
+func TestOpenTWRejectsCorruptStringOffsets(t *testing.T) {
+ data := buildTW(t, nil, []uint32{0, 1000, 5}, []byte("abcde"), []uint32{0}, nil)
+ if _, err := OpenTW(data); err == nil {
+ t.Fatal("expected error for non-monotonic string offsets, got nil")
+ }
+}
+
+func TestOpenTWRejectsOutOfRangeTokenIndexes(t *testing.T) {
+ cases := map[string][6]uint32{
+ "fileIdx_too_big": {0, 0, 1, 1, 5, 0xFFFFFFFF},
+ "fnIdx_too_big": {0, 0, 1, 1, 0, 7},
+ }
+ for name, tok := range cases {
+ t.Run(name, func(t *testing.T) {
+ data := buildTW(t, [][6]uint32{tok}, []uint32{0, 4}, []byte("a.js"), []uint32{0, 2}, []byte("fn"))
+ if _, err := OpenTW(data); err == nil {
+ t.Fatal("expected error for out-of-range token index, got nil")
+ }
+ })
+ }
+}
+
+func TestOpenTWAcceptsNegativeTokenIndexes(t *testing.T) {
+ noID := uint32(0xFFFFFFFF)
+ data := buildTW(t, [][6]uint32{{0, 0, 1, 1, noID, noID}}, []uint32{0, 4}, []byte("a.js"), []uint32{0, 2}, []byte("fn"))
+ r, err := OpenTW(data)
+ if err != nil {
+ t.Fatalf("OpenTW: %v", err)
+ }
+ if _, ok := r.Lookup(0, 0); ok {
+ t.Fatal("token with fileIdx=-1 should not resolve")
+ }
+}
+
+func TestMarshalTWEmpty(t *testing.T) {
+ r := &Resolver{}
+ reopened, err := OpenTW(r.MarshalTW())
+ if err != nil {
+ t.Fatalf("OpenTW: %v", err)
+ }
+ if _, ok := reopened.Lookup(0, 0); ok {
+ t.Error("empty resolver should not resolve anything")
+ }
+}
diff --git a/backend/app/symbolicator/twcache/mmap_other.go b/backend/app/symbolicator/twcache/mmap_other.go
new file mode 100644
index 00000000..861f959c
--- /dev/null
+++ b/backend/app/symbolicator/twcache/mmap_other.go
@@ -0,0 +1,20 @@
+//go:build !unix
+
+package twcache
+
+import (
+ "errors"
+ "os"
+)
+
+func mmapFile(path string) ([]byte, func(), error) {
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return nil, nil, err
+ }
+ return data, func() {}, nil
+}
+
+func DiskCapacityBytes(dir string) (int64, error) {
+ return 0, errors.New("disk capacity detection is not supported on this platform")
+}
diff --git a/backend/app/symbolicator/twcache/mmap_unix.go b/backend/app/symbolicator/twcache/mmap_unix.go
new file mode 100644
index 00000000..71363f80
--- /dev/null
+++ b/backend/app/symbolicator/twcache/mmap_unix.go
@@ -0,0 +1,39 @@
+//go:build unix
+
+package twcache
+
+import (
+ "os"
+ "syscall"
+)
+
+func mmapFile(path string) ([]byte, func(), error) {
+ f, err := os.Open(path)
+ if err != nil {
+ return nil, nil, err
+ }
+ defer f.Close()
+
+ st, err := f.Stat()
+ if err != nil {
+ return nil, nil, err
+ }
+ size := st.Size()
+ if size == 0 {
+ return nil, func() {}, nil
+ }
+
+ data, err := syscall.Mmap(int(f.Fd()), 0, int(size), syscall.PROT_READ, syscall.MAP_SHARED)
+ if err != nil {
+ return nil, nil, err
+ }
+ return data, func() { _ = syscall.Munmap(data) }, nil
+}
+
+func DiskCapacityBytes(dir string) (int64, error) {
+ var st syscall.Statfs_t
+ if err := syscall.Statfs(dir, &st); err != nil {
+ return 0, err
+ }
+ return int64(uint64(st.Bsize) * st.Blocks), nil
+}
diff --git a/backend/app/symbolicator/twcache/twcache.go b/backend/app/symbolicator/twcache/twcache.go
new file mode 100644
index 00000000..7bb7b1ef
--- /dev/null
+++ b/backend/app/symbolicator/twcache/twcache.go
@@ -0,0 +1,249 @@
+package twcache
+
+import (
+ "container/list"
+ "errors"
+ "fmt"
+ "io/fs"
+ "os"
+ "path/filepath"
+ "runtime"
+ "sort"
+ "strings"
+ "sync"
+ "time"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator"
+)
+
+const mtimeRefreshInterval = 10 * time.Minute
+
+var ErrInvalidName = errors.New("twcache: cache name escapes the cache directory")
+
+type Cache struct {
+ dir string
+ warn func(error)
+
+ mu sync.Mutex
+ files map[string]*list.Element
+ order *list.List
+ maxBytes int64
+ curBytes int64
+ hits uint64
+ evictions uint64
+}
+
+type entry struct {
+ name string
+ size int64
+ touchedAt time.Time
+}
+
+type Stats struct {
+ Entries int
+ Bytes int64
+ MaxBytes int64
+ Hits uint64
+ Evictions uint64
+}
+
+func New(dir string, maxBytes int64, warn func(error)) (*Cache, error) {
+ if maxBytes <= 0 {
+ return nil, errors.New("twcache: maxBytes must be positive")
+ }
+ if err := os.MkdirAll(dir, 0o755); err != nil {
+ return nil, fmt.Errorf("failed to create tw cache dir: %w", err)
+ }
+ c := &Cache{
+ dir: dir,
+ warn: warn,
+ files: make(map[string]*list.Element),
+ order: list.New(),
+ maxBytes: maxBytes,
+ }
+ if err := c.scan(); err != nil {
+ return nil, fmt.Errorf("failed to scan tw cache dir: %w", err)
+ }
+ return c, nil
+}
+
+func (c *Cache) Dir() string {
+ return c.dir
+}
+
+func (c *Cache) path(name string) (string, error) {
+ rel := filepath.FromSlash(name)
+ if !filepath.IsLocal(rel) {
+ return "", ErrInvalidName
+ }
+ return filepath.Join(c.dir, rel), nil
+}
+
+func (c *Cache) scan() error {
+ type scanned struct {
+ name string
+ size int64
+ mtime time.Time
+ }
+ var found []scanned
+ err := filepath.WalkDir(c.dir, func(path string, dirEntry fs.DirEntry, err error) error {
+ if err != nil {
+ if c.warn != nil {
+ c.warn(fmt.Errorf("skipping unreadable tw cache entry (path=%s): %w", path, err))
+ }
+ return nil
+ }
+ if dirEntry.IsDir() || !strings.HasSuffix(path, ".tw") {
+ return nil
+ }
+ info, err := dirEntry.Info()
+ if err != nil {
+ return nil
+ }
+ rel, err := filepath.Rel(c.dir, path)
+ if err != nil {
+ return nil
+ }
+ found = append(found, scanned{name: filepath.ToSlash(rel), size: info.Size(), mtime: info.ModTime()})
+ return nil
+ })
+ if err != nil {
+ return err
+ }
+ sort.Slice(found, func(i, j int) bool { return found[i].mtime.Before(found[j].mtime) })
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ for _, f := range found {
+ el := c.order.PushFront(&entry{name: f.name, size: f.size})
+ c.files[f.name] = el
+ c.curBytes += f.size
+ }
+ c.evictLocked()
+ return nil
+}
+
+// Open mmaps the named .tw file and returns a resolver backed by it. The
+// mapping is released by a runtime cleanup once the resolver is collected.
+// Corrupt files are removed so the caller's rebuild can replace them.
+func (c *Cache) Open(name string) (*symbolicator.Resolver, error) {
+ return c.open(name, true)
+}
+
+func (c *Cache) open(name string, countHit bool) (*symbolicator.Resolver, error) {
+ path, err := c.path(name)
+ if err != nil {
+ return nil, err
+ }
+ data, unmap, err := mmapFile(path)
+ if err != nil {
+ return nil, err
+ }
+ resolver, err := symbolicator.OpenTW(data)
+ if err != nil {
+ unmap()
+ c.Remove(name)
+ return nil, err
+ }
+ runtime.AddCleanup(resolver, func(u func()) { u() }, unmap)
+ c.noteUse(name, int64(len(data)), countHit)
+ return resolver, nil
+}
+
+// Write atomically persists data as the named .tw file and returns a
+// resolver mmapped from it. Write does not count as a cache hit.
+func (c *Cache) Write(name string, data []byte) (*symbolicator.Resolver, error) {
+ path, err := c.path(name)
+ if err != nil {
+ return nil, err
+ }
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ return nil, err
+ }
+ tmp, err := os.CreateTemp(filepath.Dir(path), ".tw-*")
+ if err != nil {
+ return nil, err
+ }
+ if _, err := tmp.Write(data); err != nil {
+ tmp.Close()
+ os.Remove(tmp.Name())
+ return nil, err
+ }
+ if err := tmp.Close(); err != nil {
+ os.Remove(tmp.Name())
+ return nil, err
+ }
+ if err := os.Rename(tmp.Name(), path); err != nil {
+ os.Remove(tmp.Name())
+ return nil, err
+ }
+ return c.open(name, false)
+}
+
+func (c *Cache) noteUse(name string, size int64, countHit bool) {
+ now := time.Now()
+ updateMtime := false
+ c.mu.Lock()
+ if countHit {
+ c.hits++
+ }
+ if el, ok := c.files[name]; ok {
+ e := el.Value.(*entry)
+ c.curBytes += size - e.size
+ e.size = size
+ c.order.MoveToFront(el)
+ if now.Sub(e.touchedAt) > mtimeRefreshInterval {
+ e.touchedAt = now
+ updateMtime = true
+ }
+ } else {
+ c.files[name] = c.order.PushFront(&entry{name: name, size: size, touchedAt: now})
+ c.curBytes += size
+ }
+ c.evictLocked()
+ c.mu.Unlock()
+ if updateMtime {
+ if path, err := c.path(name); err == nil {
+ _ = os.Chtimes(path, now, now)
+ }
+ }
+}
+
+func (c *Cache) Remove(name string) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ if el, ok := c.files[name]; ok {
+ c.dropLocked(el)
+ } else if path, err := c.path(name); err == nil {
+ os.Remove(path)
+ }
+}
+
+func (c *Cache) dropLocked(el *list.Element) {
+ e := c.order.Remove(el).(*entry)
+ delete(c.files, e.name)
+ c.curBytes -= e.size
+ os.Remove(filepath.Join(c.dir, filepath.FromSlash(e.name)))
+}
+
+func (c *Cache) evictLocked() {
+ for c.curBytes > c.maxBytes {
+ back := c.order.Back()
+ if back == nil {
+ break
+ }
+ c.dropLocked(back)
+ c.evictions++
+ }
+}
+
+func (c *Cache) Stats() Stats {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ return Stats{
+ Entries: c.order.Len(),
+ Bytes: c.curBytes,
+ MaxBytes: c.maxBytes,
+ Hits: c.hits,
+ Evictions: c.evictions,
+ }
+}
diff --git a/backend/cmd/run.go b/backend/cmd/run.go
index faabd458..ce2fac15 100644
--- a/backend/cmd/run.go
+++ b/backend/cmd/run.go
@@ -25,6 +25,7 @@ import (
"github.com/tracewayapp/traceway/backend/app/services"
"github.com/tracewayapp/traceway/backend/app/sourcemapbackfill"
"github.com/tracewayapp/traceway/backend/app/storage"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/scopes"
"github.com/tracewayapp/traceway/backend/static"
"github.com/coreos/go-systemd/v22/daemon"
@@ -114,6 +115,25 @@ func Run(opts ...Option) {
parsePositiveInt(cfg.SourceMapCacheMaxEntries, 200),
int64(parsePositiveInt(cfg.SourceMapCacheMaxBytesMB, 500))*1024*1024,
)
+ switch cfg.SourceMapCacheType {
+ case "", "memory":
+ case "disk":
+ dir := cfg.SourceMapDiskCachePath
+ if dir == "" {
+ dir = "./twcache"
+ }
+ maxBytes := int64(parsePositiveInt(cfg.SourceMapDiskCacheMaxMB, 2048)) * 1024 * 1024
+ if err := services.EnableSourceMapDiskCache(dir, maxBytes); err != nil {
+ panic(fmt.Errorf("source map disk cache init failed: %w", err))
+ }
+ default:
+ panic(fmt.Errorf("unknown SOURCEMAP_CACHE_TYPE: %s", cfg.SourceMapCacheType))
+ }
+ if cfg.SymbolicatorParser != "" {
+ if err := scopes.SetParser(cfg.SymbolicatorParser); err != nil {
+ panic(fmt.Errorf("symbolicator parser init failed: %w", err))
+ }
+ }
middleware.InitUseClientAuth()
middleware.InitUseAppAuth()
diff --git a/backend/go.mod b/backend/go.mod
index 861e21ca..5f2313e3 100644
--- a/backend/go.mod
+++ b/backend/go.mod
@@ -3,6 +3,7 @@ module github.com/tracewayapp/traceway/backend
go 1.25.1
require (
+ cloud.google.com/go/storage v1.56.0
github.com/aws/aws-sdk-go-v2 v1.41.1
github.com/aws/aws-sdk-go-v2/config v1.32.7
github.com/aws/aws-sdk-go-v2/credentials v1.19.7
@@ -15,23 +16,77 @@ require (
github.com/lib/pq v1.10.9
github.com/markbates/goth v1.82.0
github.com/tracewayapp/lit/v2 v2.0.2
+ go.opentelemetry.io/collector/component v1.60.0
+ go.opentelemetry.io/collector/component/componenttest v0.154.0
+ go.opentelemetry.io/collector/consumer v1.60.0
+ go.opentelemetry.io/collector/consumer/consumertest v0.154.0
+ go.opentelemetry.io/collector/pdata v1.60.0
+ go.opentelemetry.io/collector/processor v1.60.0
+ go.opentelemetry.io/collector/processor/processorhelper v0.154.0
+ go.opentelemetry.io/collector/processor/processortest v0.154.0
go.tracewayapp.com v1.0.2
go.tracewayapp.com/tracewaygin v1.0.2
+ go.uber.org/zap v1.28.0
modernc.org/sqlite v1.18.1
)
require (
- cloud.google.com/go/compute/metadata v0.8.0 // indirect
+ cel.dev/expr v0.25.1 // indirect
+ cloud.google.com/go v0.121.6 // indirect
+ cloud.google.com/go/auth v0.16.4 // indirect
+ cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
+ cloud.google.com/go/compute/metadata v0.9.0 // indirect
+ cloud.google.com/go/iam v1.5.2 // indirect
+ cloud.google.com/go/monitoring v1.24.2 // indirect
+ github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.31.0 // indirect
+ github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.53.0 // indirect
+ github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.53.0 // indirect
+ github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2 // indirect
+ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
+ github.com/envoyproxy/go-control-plane/envoy v1.37.0 // indirect
+ github.com/envoyproxy/protoc-gen-validate v1.3.3 // indirect
+ github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-chi/chi/v5 v5.2.2 // indirect
+ github.com/go-jose/go-jose/v4 v4.1.4 // indirect
+ github.com/go-logr/logr v1.4.3 // indirect
+ github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
+ github.com/google/s2a-go v0.1.9 // indirect
+ github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
+ github.com/googleapis/gax-go/v2 v2.15.0 // indirect
github.com/gorilla/mux v1.7.4 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
+ github.com/hashicorp/go-version v1.9.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
+ github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
+ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
- golang.org/x/oauth2 v0.30.0 // indirect
- google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
- google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
- google.golang.org/grpc v1.75.1 // indirect
+ github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect
+ github.com/stretchr/testify v1.11.1 // indirect
+ go.opentelemetry.io/auto/sdk v1.2.1 // indirect
+ go.opentelemetry.io/collector/component/componentstatus v0.154.0 // indirect
+ go.opentelemetry.io/collector/consumer/xconsumer v0.154.0 // indirect
+ go.opentelemetry.io/collector/featuregate v1.60.0 // indirect
+ go.opentelemetry.io/collector/internal/componentalias v0.154.0 // indirect
+ go.opentelemetry.io/collector/pdata/pprofile v0.154.0 // indirect
+ go.opentelemetry.io/collector/pdata/testdata v0.154.0 // indirect
+ go.opentelemetry.io/collector/pipeline v1.60.0 // indirect
+ go.opentelemetry.io/collector/processor/xprocessor v0.154.0 // indirect
+ go.opentelemetry.io/contrib/detectors/gcp v1.42.0 // indirect
+ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
+ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
+ go.opentelemetry.io/otel/metric v1.44.0 // indirect
+ go.opentelemetry.io/otel/sdk v1.44.0 // indirect
+ go.opentelemetry.io/otel/sdk/metric v1.44.0 // indirect
+ go.uber.org/multierr v1.11.0 // indirect
+ golang.org/x/oauth2 v0.36.0 // indirect
+ golang.org/x/time v0.12.0 // indirect
+ google.golang.org/api v0.247.0 // indirect
+ google.golang.org/genproto v0.0.0-20250603155806-513f23925822 // indirect
+ google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 // indirect
+ google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 // indirect
+ google.golang.org/grpc v1.81.1 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.36.3 // indirect
modernc.org/ccgo/v3 v3.16.9 // indirect
@@ -79,29 +134,28 @@ require (
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/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
+ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/paulmach/orb v0.12.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.54.0 // indirect
- github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/segmentio/asm v1.2.1 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.0 // indirect
- go.opentelemetry.io/otel v1.39.0 // indirect
- go.opentelemetry.io/otel/trace v1.39.0 // indirect
+ go.opentelemetry.io/otel v1.44.0 // indirect
+ go.opentelemetry.io/otel/trace v1.44.0 // indirect
go.opentelemetry.io/proto/otlp v1.9.0
go.uber.org/mock v0.5.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.20.0 // indirect
- golang.org/x/mod v0.30.0 // indirect
- golang.org/x/net v0.48.0 // indirect
- golang.org/x/sys v0.39.0 // indirect
- golang.org/x/tools v0.39.0 // indirect
- google.golang.org/protobuf v1.36.10
+ golang.org/x/mod v0.35.0 // indirect
+ golang.org/x/net v0.55.0 // indirect
+ golang.org/x/sys v0.45.0 // indirect
+ golang.org/x/tools v0.44.0 // indirect
+ google.golang.org/protobuf v1.36.11
)
require (
@@ -110,7 +164,7 @@ require (
github.com/golang-migrate/migrate/v4 v4.19.1
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
- golang.org/x/crypto v0.46.0
- golang.org/x/sync v0.19.0 // indirect
- golang.org/x/text v0.32.0 // indirect
+ golang.org/x/crypto v0.51.0
+ golang.org/x/sync v0.20.0 // indirect
+ golang.org/x/text v0.37.0 // indirect
)
diff --git a/backend/go.sum b/backend/go.sum
index c6288887..e4cede5a 100644
--- a/backend/go.sum
+++ b/backend/go.sum
@@ -1,5 +1,25 @@
-cloud.google.com/go/compute/metadata v0.8.0 h1:HxMRIbao8w17ZX6wBnjhcDkW6lTFpgcaobyVfZWqRLA=
-cloud.google.com/go/compute/metadata v0.8.0/go.mod h1:sYOGTp851OV9bOFJ9CH7elVvyzopvWQFNNghtDQ/Biw=
+cel.dev/expr v0.25.1 h1:1KrZg61W6TWSxuNZ37Xy49ps13NUovb66QLprthtwi4=
+cel.dev/expr v0.25.1/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4=
+cloud.google.com/go v0.121.6 h1:waZiuajrI28iAf40cWgycWNgaXPO06dupuS+sgibK6c=
+cloud.google.com/go v0.121.6/go.mod h1:coChdst4Ea5vUpiALcYKXEpR1S9ZgXbhEzzMcMR66vI=
+cloud.google.com/go/auth v0.16.4 h1:fXOAIQmkApVvcIn7Pc2+5J8QTMVbUGLscnSVNl11su8=
+cloud.google.com/go/auth v0.16.4/go.mod h1:j10ncYwjX/g3cdX7GpEzsdM+d+ZNsXAbb6qXA7p1Y5M=
+cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc=
+cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c=
+cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs=
+cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10=
+cloud.google.com/go/iam v1.5.2 h1:qgFRAGEmd8z6dJ/qyEchAuL9jpswyODjA2lS+w234g8=
+cloud.google.com/go/iam v1.5.2/go.mod h1:SE1vg0N81zQqLzQEwxL2WI6yhetBdbNQuTvIKCSkUHE=
+cloud.google.com/go/logging v1.13.0 h1:7j0HgAp0B94o1YRDqiqm26w4q1rDMH7XNRU34lJXHYc=
+cloud.google.com/go/logging v1.13.0/go.mod h1:36CoKh6KA/M0PbhPKMq6/qety2DCAErbhXT62TuXALA=
+cloud.google.com/go/longrunning v0.6.7 h1:IGtfDWHhQCgCjwQjV9iiLnUta9LBCo8R9QmAFsS/PrE=
+cloud.google.com/go/longrunning v0.6.7/go.mod h1:EAFV3IZAKmM56TyiE6VAP3VoTzhZzySwI/YI1s/nRsY=
+cloud.google.com/go/monitoring v1.24.2 h1:5OTsoJ1dXYIiMiuL+sYscLc9BumrL3CarVLL7dd7lHM=
+cloud.google.com/go/monitoring v1.24.2/go.mod h1:x7yzPWcgDRnPEv3sI+jJGBkwl5qINf+6qY4eq0I9B4U=
+cloud.google.com/go/storage v1.56.0 h1:iixmq2Fse2tqxMbWhLWC9HfBj1qdxqAmiK8/eqtsLxI=
+cloud.google.com/go/storage v1.56.0/go.mod h1:Tpuj6t4NweCLzlNbw9Z9iwxEkrSem20AetIeH/shgVU=
+cloud.google.com/go/trace v1.11.6 h1:2O2zjPzqPYAHrn3OKl029qlqG6W8ZdYaOWRyr8NgMT4=
+cloud.google.com/go/trace v1.11.6/go.mod h1:GA855OeDEBiBMzcckLPE2kDunIpC72N+Pq8WFieFjnI=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/ClickHouse/ch-go v0.69.0 h1:nO0OJkpxOlN/eaXFj0KzjTz5p7vwP1/y3GN4qc5z/iM=
@@ -10,6 +30,14 @@ github.com/ClickHouse/clickhouse-go/v2 v2.42.0 h1:MdujEfIrpXesQUH0k0AnuVtJQXk6RZ
github.com/ClickHouse/clickhouse-go/v2 v2.42.0/go.mod h1:riWnuo4YMVdajYll0q6FzRBomdyCrXyFY3VXeXczA8s=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
+github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.31.0 h1:DHa2U07rk8syqvCge0QIGMCE1WxGj9njT44GH7zNJLQ=
+github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.31.0/go.mod h1:P4WPRUkOhJC13W//jWpyfJNDAIpvRbAUIYLX/4jtlE0=
+github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.53.0 h1:owcC2UnmsZycprQ5RfRgjydWhuoxg71LUfyiQdijZuM=
+github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.53.0/go.mod h1:ZPpqegjbE99EPKsu3iUWV22A04wzGPcAY/ziSIQEEgs=
+github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.53.0 h1:4LP6hvB4I5ouTbGgWtixJhgED6xdf67twf9PoY96Tbg=
+github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.53.0/go.mod h1:jUZ5LYlw40WMd07qxcQJD5M40aUxrfwqQX1g7zxYnrQ=
+github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.53.0 h1:Ron4zCA/yk6U7WOBXhTJcDpsUBG9npumK6xw2auFltQ=
+github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.53.0/go.mod h1:cSgYe11MCNYunTnRXrKiR/tHc0eoKjICUuWpNZoVCOo=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
@@ -62,6 +90,8 @@ github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
+github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2 h1:aBangftG7EVZoUb69Os8IaYg++6uMOdKK83QtkkvJik=
+github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2/go.mod h1:qwXFYgsP6T7XnJtbKlf1HP8AjxZZyzxMmc+Lq5GjlU4=
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
@@ -87,6 +117,14 @@ github.com/dop251/goja v0.0.0-20260607120635-348e6bea910d/go.mod h1:Sc+QOu1Wruva
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
+github.com/envoyproxy/go-control-plane v0.14.0 h1:hbG2kr4RuFj222B6+7T83thSPqLjwBIfQawTkC++2HA=
+github.com/envoyproxy/go-control-plane v0.14.0/go.mod h1:NcS5X47pLl/hfqxU70yPwL9ZMkUlwlKxtAohpi2wBEU=
+github.com/envoyproxy/go-control-plane/envoy v1.37.0 h1:u3riX6BoYRfF4Dr7dwSOroNfdSbEPe9Yyl09/B6wBrQ=
+github.com/envoyproxy/go-control-plane/envoy v1.37.0/go.mod h1:DReE9MMrmecPy+YvQOAOHNYMALuowAnbjjEMkkWOi6A=
+github.com/envoyproxy/go-control-plane/ratelimit v0.1.0 h1:/G9QYbddjL25KvtKTv3an9lx6VBE2cnb8wp1vEGNYGI=
+github.com/envoyproxy/go-control-plane/ratelimit v0.1.0/go.mod h1:Wk+tMFAFbCXaJPzVVHnPgRKdUdwW/KdbRt94AzgRee4=
+github.com/envoyproxy/protoc-gen-validate v1.3.3 h1:MVQghNeW+LZcmXe7SY1V36Z+WFMDjpqGAGacLe2T0ds=
+github.com/envoyproxy/protoc-gen-validate v1.3.3/go.mod h1:TsndJ/ngyIdQRhMcVVGDDHINPLWB7C82oDArY51KfB0=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
@@ -101,6 +139,9 @@ github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw=
github.com/go-faster/city v1.0.1/go.mod h1:jKcUJId49qdW3L1qKHH/3wPeUstCVpVSXTM6vO3VcTw=
github.com/go-faster/errors v0.7.1 h1:MkJTnDoEdi9pDabt1dpWf7AA8/BaSYZqibYyhZ20AYg=
github.com/go-faster/errors v0.7.1/go.mod h1:5ySTjWFiphBs07IKuiL69nxdfd5+fzh1u7FPGZP2quo=
+github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA=
+github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
+github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
@@ -136,9 +177,17 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc=
+github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0=
+github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0=
+github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
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/googleapis/enterprise-certificate-proxy v0.3.6 h1:GW/XbdyBFQ8Qe+YAmFU9uHLo7OnF5tL52HFAgMmyrf4=
+github.com/googleapis/enterprise-certificate-proxy v0.3.6/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA=
+github.com/googleapis/gax-go/v2 v2.15.0 h1:SyjDc1mGgZU5LncH8gimWo9lW1DtIfPibOG81vgd/bo=
+github.com/googleapis/gax-go/v2 v2.15.0/go.mod h1:zVVkkxAQHa1RQpg9z2AUCMnKhi0Qld9rcmyfL1OZhoc=
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
@@ -147,6 +196,8 @@ github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzq
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
+github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA=
+github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@@ -183,10 +234,12 @@ github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3N
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
-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/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
+github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8=
+github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
@@ -203,6 +256,8 @@ github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=
+github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -218,6 +273,8 @@ github.com/segmentio/asm v1.2.1 h1:DTNbBqs57ioxAD4PrArqftgypG4/qNpXoJx8TVXxPR0=
github.com/segmentio/asm v1.2.1/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
+github.com/spiffe/go-spiffe/v2 v2.6.0 h1:l+DolpxNWYgruGQVV0xsfeya3CsC7m8iBzDnMpsbLuo=
+github.com/spiffe/go-spiffe/v2 v2.6.0/go.mod h1:gm2SeUoMZEtpnzPNs2Csc0D/gX33k1xIx7lEzqblHEs=
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=
@@ -246,26 +303,80 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
+go.opentelemetry.io/collector/component v1.60.0 h1:LpIjHMn7OOjUsFR84ROc2kqPbP1xnKyDCGi7ZVqEaKU=
+go.opentelemetry.io/collector/component v1.60.0/go.mod h1:Rag+NNgiGIkcGYlcTfJtMh2l0T5XS1KNv9Wjw9yofAk=
+go.opentelemetry.io/collector/component/componentstatus v0.154.0 h1:4ifSCy2Y332iZ5AldHt9ujVjY6XKxhVe/hND4TSDarg=
+go.opentelemetry.io/collector/component/componentstatus v0.154.0/go.mod h1:ZsBIax7tvvODn0XqTyhTfKZjm96zVKnLUKvlN8SHFjo=
+go.opentelemetry.io/collector/component/componenttest v0.154.0 h1:uH06tUatG4S45A/f3sFENMMAMzWURmgxKK3MAbVZAUI=
+go.opentelemetry.io/collector/component/componenttest v0.154.0/go.mod h1:SQ1JRosjFAZ7kN2yNHNcNakOliqrP0QxglKcYyUrUpQ=
+go.opentelemetry.io/collector/consumer v1.60.0 h1:SWP/0HvDnWiiy/4S366CiatAZ4gFl410UmggrZEcWVg=
+go.opentelemetry.io/collector/consumer v1.60.0/go.mod h1:nkp1NBtKQzme7WFF7fkgRgDlQLs49VIMOn8rO0jfmYU=
+go.opentelemetry.io/collector/consumer/consumertest v0.154.0 h1:G9gFP86ZsglC3mTLA6cqOrW5lvdcEBJrVgHtThE+Sc4=
+go.opentelemetry.io/collector/consumer/consumertest v0.154.0/go.mod h1:FRLGgy8gFYjm3A+yby1bctz5ZIAn6EUOpuV49KnKbFY=
+go.opentelemetry.io/collector/consumer/xconsumer v0.154.0 h1:I3rB+S5ORE1XLzqopFXvP6UmYrsj5n1tFlcEAPg96Zw=
+go.opentelemetry.io/collector/consumer/xconsumer v0.154.0/go.mod h1:WNT9BoyLE/nE5N6WEL4c1GXcfGcRUmSTCSr6e/tyfO4=
+go.opentelemetry.io/collector/featuregate v1.60.0 h1:/HxHB8hq4N5Fhq5N0C8G6xbXTHxnGcWIryyJzmP7pdc=
+go.opentelemetry.io/collector/featuregate v1.60.0/go.mod h1:4ga1QBMPEejXXmpyJS8lmaRpknJ3Lb9Bvk6e420bUFU=
+go.opentelemetry.io/collector/internal/componentalias v0.154.0 h1:g0y8F/qez9cbsgF5+/uU6YC6l5oXVkccIhsXVHmF3xQ=
+go.opentelemetry.io/collector/internal/componentalias v0.154.0/go.mod h1:F2tudJ/Zcm8w8b768sU65nZc4q2rgY1MhfX5FxDeUgA=
+go.opentelemetry.io/collector/internal/testutil v0.154.0 h1:iUYHOM8+wONW01A4jFnzauanOYGVBGchKWWtm51is6c=
+go.opentelemetry.io/collector/internal/testutil v0.154.0/go.mod h1:Jkjs6rkqs973LqgZ0Fe3zrokQRKULYXPIf4HuqStiEE=
+go.opentelemetry.io/collector/pdata v1.60.0 h1:YcGMHzeJucHen41AoR4mxHro8reUr9SVqt7P0KacKzQ=
+go.opentelemetry.io/collector/pdata v1.60.0/go.mod h1:Ca8VgZX2wOr6wW4nihPWaCpkJVvzeo6Txa7BJ7/WO90=
+go.opentelemetry.io/collector/pdata/pprofile v0.154.0 h1:dWrHnKBzzMhkZXfKmSuFpGVAApSUcrQ+mBFzAsO6/8s=
+go.opentelemetry.io/collector/pdata/pprofile v0.154.0/go.mod h1:BE9oOmAEHVqE+yHRe5Z3qz7co+2SU249DIxVGPRsYf8=
+go.opentelemetry.io/collector/pdata/testdata v0.154.0 h1:PSc3gogHpJoVHenvMhcxkOPTnEKpaykURxtSNyVXYK4=
+go.opentelemetry.io/collector/pdata/testdata v0.154.0/go.mod h1:zIT+sag/xmSM6VAMhv2tnEzlQF9n266OcQm4V6roWdU=
+go.opentelemetry.io/collector/pipeline v1.60.0 h1:ZLk/8K/Xzz+JRBWLmqLlVMwEWVnQvmly6nWeKs+lh6s=
+go.opentelemetry.io/collector/pipeline v1.60.0/go.mod h1:RD90NG3Jbk965Xaqym3JyHkuol4uZJjQVUkD9ddXJIs=
+go.opentelemetry.io/collector/processor v1.60.0 h1:B3YgiKa+4tMuJ6v4bSaKUtTCwNRzugbEDei8j7jiPpI=
+go.opentelemetry.io/collector/processor v1.60.0/go.mod h1:ZRNUW8FHZ+0CW+HoIG0/h+fQq8aYjMz9ccy2w2jguag=
+go.opentelemetry.io/collector/processor/processorhelper v0.154.0 h1:mpH6tnXFYddtfQzRjSY7HQaRM6hAyGZCuoHRudAhTF4=
+go.opentelemetry.io/collector/processor/processorhelper v0.154.0/go.mod h1:N/za6yBZeKPAAPLDn93oHZ1I0mvyWEPMJ40XB1sNSdU=
+go.opentelemetry.io/collector/processor/processortest v0.154.0 h1:2Lu7JGqH3fzg9BE0rmzBwCQB7oRWzM8fs+X5SSZO/4M=
+go.opentelemetry.io/collector/processor/processortest v0.154.0/go.mod h1:E813PIbkBcwgoDnZ9cjuw70MUNmqxAHIvmDC8gOZiP8=
+go.opentelemetry.io/collector/processor/xprocessor v0.154.0 h1:ert+SRk5DPSqIxqpOEnywrwVLYSvqEvXwy60F94VtFE=
+go.opentelemetry.io/collector/processor/xprocessor v0.154.0/go.mod h1:93XyfiqPYokF1i8NQvWsKggt5Si5qZvOcZ2P0l+uxII=
+go.opentelemetry.io/contrib/detectors/gcp v1.42.0 h1:kpt2PEJuOuqYkPcktfJqWWDjTEd/FNgrxcniL7kQrXQ=
+go.opentelemetry.io/contrib/detectors/gcp v1.42.0/go.mod h1:W9zQ439utxymRrXsUOzZbFX4JhLxXU4+ZnCt8GG7yA8=
+go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 h1:q4XOmH/0opmeuJtPsbFNivyl7bCt7yRBbeEm2sC/XtQ=
+go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0/go.mod h1:snMWehoOh2wsEwnvvwtDyFCxVeDAODenXHtn5vzrKjo=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6hwnZ41NSFTO5q4LYDtJRXBf2PD0rNBkeB/lus=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0/go.mod h1:UHB22Z8QsdRDrnAtX4PntOl36ajSxcdUMt1sF7Y6E7Q=
-go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48=
-go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8=
-go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0=
-go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs=
-go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=
-go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=
-go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFhbjxHHspCPc=
-go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps=
-go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI=
-go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
+go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
+go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
+go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.36.0 h1:rixTyDGXFxRy1xzhKrotaHy3/KXdPhlWARrCgK+eqUY=
+go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.36.0/go.mod h1:dowW6UsM9MKbJq5JTz2AMVp3/5iW5I/TStsk8S+CfHw=
+go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
+go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
+go.opentelemetry.io/otel/metric/x v0.66.0 h1:YkCrx1zLOChi9ZcZ6euupOcsgzbVlec7D/xoEU1+cTA=
+go.opentelemetry.io/otel/metric/x v0.66.0/go.mod h1:d1+BDj9t96do0/1LoU1ayfCv79ZgNE41qbhBvnMOBZk=
+go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58=
+go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0=
+go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI=
+go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA=
+go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
+go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
+go.opentelemetry.io/proto/slim/otlp v1.10.0 h1:iR97Vs/ZDR+y9TfuP9b1XBtdPWeC+OMslIBmhcLU7jM=
+go.opentelemetry.io/proto/slim/otlp v1.10.0/go.mod h1:lV9250stpjYLPNA5viFabIgP2QlUGRT1GdTgAf8SIUk=
+go.opentelemetry.io/proto/slim/otlp/collector/profiles/v1development v0.3.0 h1:RUF5rO0hAlgiJt1fzQVzcVs3vZVNHIcMLgOgG4rWNcQ=
+go.opentelemetry.io/proto/slim/otlp/collector/profiles/v1development v0.3.0/go.mod h1:I89cynRj8y+383o7tEQVg2SVA6SRgDVIouWPUVXjx0U=
+go.opentelemetry.io/proto/slim/otlp/profiles/v1development v0.3.0 h1:CQvJSldHRUN6Z8jsUeYv8J0lXRvygALXIzsmAeCcZE0=
+go.opentelemetry.io/proto/slim/otlp/profiles/v1development v0.3.0/go.mod h1:xSQ+mEfJe/GjK1LXEyVOoSI1N9JV9ZI923X5kup43W4=
go.tracewayapp.com v1.0.2 h1:ICMh5V4Sw5WezEPHMQR0roUsU7r9np+fwJWTIdyMhDI=
go.tracewayapp.com v1.0.2/go.mod h1:0eQ/FAOA4VzTxrevTayqfYBhTEQYHEfMTPv/IiZ7F6E=
go.tracewayapp.com/tracewaygin v1.0.2 h1:MRAvtOKz0zceoe1Ee7pl5eciSerc+gIogC7oWJaKQf8=
go.tracewayapp.com/tracewaygin v1.0.2/go.mod h1:p/26TIhpfte86Gp3QJpA8Q72pJShFXX1jogIiKG2LXQ=
+go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
+go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
+go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
+go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
+go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
+go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=
@@ -274,27 +385,27 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
-golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
-golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
+golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
+golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
-golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
+golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
+golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
-golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
-golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
-golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
+golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
+golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
+golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
+golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
-golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
+golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
+golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -305,38 +416,44 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
-golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
+golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
+golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
-golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
-golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
+golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
+golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
+golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
+golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
-golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
-golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
+golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
+golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
-gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
-google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 h1:BIRfGDEjiHRrk0QKZe3Xv2ieMhtgRGeLcZQ0mIVn4EY=
-google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5/go.mod h1:j3QtIyytwqGr1JUDtYXwtMXWPKsEa5LtzIFN1Wn5WvE=
-google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 h1:eaY8u2EuxbRv7c3NiGK0/NedzVsCcV6hDuU5qPX5EGE=
-google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5/go.mod h1:M4/wBTSeyLxupu3W3tJtOgB14jILAS/XWPSSa3TAlJc=
-google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
-google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
+gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
+gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
+google.golang.org/api v0.247.0 h1:tSd/e0QrUlLsrwMKmkbQhYVa109qIintOls2Wh6bngc=
+google.golang.org/api v0.247.0/go.mod h1:r1qZOPmxXffXg6xS5uhx16Fa/UFY8QU/K4bfKrnvovM=
+google.golang.org/genproto v0.0.0-20250603155806-513f23925822 h1:rHWScKit0gvAPuOnu87KpaYtjK5zBMLcULh7gxkCXu4=
+google.golang.org/genproto v0.0.0-20250603155806-513f23925822/go.mod h1:HubltRL7rMh0LfnQPkMH4NPDFEWp0jw3vixw7jEM53s=
+google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 h1:tu/dtnW1o3wfaxCOjSLn5IRX4YDcJrtlpzYkhHhGaC4=
+google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171/go.mod h1:M5krXqk4GhBKvB596udGL3UyjL4I1+cTbK0orROM9ng=
+google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 h1:ggcbiqK8WWh6l1dnltU4BgWGIGo+EVYxCaAPih/zQXQ=
+google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
+google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ=
+google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
-google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
-google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
+google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
+google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
diff --git a/backend/tools/cachebench/corpus.go b/backend/tools/cachebench/corpus.go
new file mode 100644
index 00000000..d304543a
--- /dev/null
+++ b/backend/tools/cachebench/corpus.go
@@ -0,0 +1,150 @@
+package main
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+ "sync"
+ "sync/atomic"
+
+ "github.com/tracewayapp/traceway/backend/app/services"
+ "github.com/tracewayapp/traceway/backend/app/storage"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/sourcemap"
+
+ "github.com/google/uuid"
+)
+
+const bundleFileFmt = "bundle-%06d.min.js"
+const sourcePoolSize = 200
+const namePoolSize = 500
+
+type corpusManifest struct {
+ Entries int `json:"entries"`
+ Tokens int `json:"tokens"`
+ BundleBytes int `json:"bundleBytes"`
+ MapBytes int `json:"mapBytes"`
+ TwBytes int `json:"twBytes"`
+ ResolverBytes int64 `json:"resolverBytes"`
+}
+
+func loadManifest(corpusDir string) (*corpusManifest, error) {
+ data, err := os.ReadFile(filepath.Join(corpusDir, "corpus-manifest.json"))
+ if err != nil {
+ return nil, err
+ }
+ var m corpusManifest
+ if err := json.Unmarshal(data, &m); err != nil {
+ return nil, err
+ }
+ return &m, nil
+}
+
+func buildCanonical(tokens int) (bundle, mapJSON []byte) {
+ var b strings.Builder
+ b.Grow(tokens * 40)
+ cols := make([]int, tokens)
+ for i := range tokens {
+ cols[i] = b.Len()
+ fmt.Fprintf(&b, "function f%d(a,b){return a+b*3};", i)
+ }
+ bundle = []byte(b.String())
+
+ sources := make([]string, sourcePoolSize)
+ for i := range sources {
+ sources[i] = fmt.Sprintf("src/module-%03d.js", i)
+ }
+ names := make([]string, namePoolSize)
+ for i := range names {
+ names[i] = fmt.Sprintf("origFn%d", i)
+ }
+
+ mappings := make([]byte, 0, tokens*10)
+ prevCol, prevSrc, prevLine, prevSrcCol, prevName := 0, 0, 0, 0, 0
+ for i := range tokens {
+ if i > 0 {
+ mappings = append(mappings, ',')
+ }
+ src := i % sourcePoolSize
+ line := i % 1000
+ srcCol := i % 80
+ name := i % namePoolSize
+ mappings = sourcemap.AppendVLQ(mappings, int64(cols[i]-prevCol))
+ mappings = sourcemap.AppendVLQ(mappings, int64(src-prevSrc))
+ mappings = sourcemap.AppendVLQ(mappings, int64(line-prevLine))
+ mappings = sourcemap.AppendVLQ(mappings, int64(srcCol-prevSrcCol))
+ mappings = sourcemap.AppendVLQ(mappings, int64(name-prevName))
+ prevCol, prevSrc, prevLine, prevSrcCol, prevName = cols[i], src, line, srcCol, name
+ }
+
+ m := map[string]any{
+ "version": 3,
+ "sources": sources,
+ "names": names,
+ "mappings": string(mappings),
+ }
+ mapJSON, err := json.Marshal(m)
+ if err != nil {
+ panic(err)
+ }
+ return bundle, mapJSON
+}
+
+func generateCorpus(ctx context.Context, corpusDir string, projectId uuid.UUID, entries, tokens, workers int) error {
+ bundle, mapJSON := buildCanonical(tokens)
+
+ resolver, err := symbolicator.NewResolver(mapJSON, bundle)
+ if err != nil {
+ return fmt.Errorf("building canonical resolver: %w", err)
+ }
+ tw := resolver.MarshalTW()
+
+ if frame, ok := resolver.Lookup(0, 10); !ok || !strings.HasPrefix(frame.File, "src/module-") {
+ return fmt.Errorf("canonical resolver sanity check failed: %+v ok=%v", frame, ok)
+ }
+
+ var idx atomic.Int64
+ var firstErr atomic.Value
+ var wg sync.WaitGroup
+ for range workers {
+ wg.Go(func() {
+ for {
+ i := idx.Add(1) - 1
+ if int(i) >= entries || firstErr.Load() != nil {
+ return
+ }
+ base := services.SourceMapStorageKey(projectId, fmt.Sprintf(bundleFileFmt, i))
+ for suffix, data := range map[string][]byte{"": bundle, ".map": mapJSON, ".tw": tw} {
+ if err := storage.Store.Write(ctx, base+suffix, data); err != nil {
+ firstErr.CompareAndSwap(nil, fmt.Errorf("writing %s%s: %w", base, suffix, err))
+ return
+ }
+ }
+ if i > 0 && i%1000 == 0 {
+ fmt.Fprintf(os.Stderr, "generated %d/%d entries\n", i, entries)
+ }
+ }
+ })
+ }
+ wg.Wait()
+ if err := firstErr.Load(); err != nil {
+ return err.(error)
+ }
+
+ manifest := corpusManifest{
+ Entries: entries,
+ Tokens: tokens,
+ BundleBytes: len(bundle),
+ MapBytes: len(mapJSON),
+ TwBytes: len(tw),
+ ResolverBytes: resolver.ApproxSize(),
+ }
+ data, err := json.MarshalIndent(manifest, "", " ")
+ if err != nil {
+ return err
+ }
+ return os.WriteFile(filepath.Join(corpusDir, "corpus-manifest.json"), data, 0o644)
+}
diff --git a/backend/tools/cachebench/main.go b/backend/tools/cachebench/main.go
new file mode 100644
index 00000000..196282ea
--- /dev/null
+++ b/backend/tools/cachebench/main.go
@@ -0,0 +1,128 @@
+package main
+
+import (
+ "context"
+ "flag"
+ "fmt"
+ "os"
+ "runtime"
+ "time"
+
+ "github.com/tracewayapp/traceway/backend/app/config"
+ "github.com/tracewayapp/traceway/backend/app/storage"
+
+ "github.com/google/uuid"
+)
+
+const defaultProjectId = "00000000-0000-4000-8000-000000000001"
+
+func main() {
+ if len(os.Args) < 2 {
+ fmt.Fprintln(os.Stderr, "usage: cachebench <generate|run|table> [flags]")
+ os.Exit(2)
+ }
+ var err error
+ switch os.Args[1] {
+ case "generate":
+ err = cmdGenerate(os.Args[2:])
+ case "run":
+ err = cmdRun(os.Args[2:])
+ case "table":
+ err = cmdTable(os.Args[2:])
+ default:
+ err = fmt.Errorf("unknown subcommand %q", os.Args[1])
+ }
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "cachebench:", err)
+ os.Exit(1)
+ }
+}
+
+func cmdGenerate(args []string) error {
+ fs := flag.NewFlagSet("generate", flag.ExitOnError)
+ corpusDir := fs.String("corpus-dir", "", "directory holding the generated corpus (acts as local storage root)")
+ projectId := fs.String("project-id", defaultProjectId, "project uuid used in storage keys")
+ entries := fs.Int("entries", 1000, "number of bundle+map+tw triples to generate")
+ tokens := fs.Int("tokens", 40000, "source map tokens per bundle (drives resolver size)")
+ workers := fs.Int("workers", runtime.NumCPU()*2, "concurrent writers")
+ if err := fs.Parse(args); err != nil {
+ return err
+ }
+ if *corpusDir == "" {
+ return fmt.Errorf("--corpus-dir is required")
+ }
+ pid, err := uuid.Parse(*projectId)
+ if err != nil {
+ return err
+ }
+ config.Init(&config.Cfg{StorageType: "local", StoragePath: *corpusDir})
+ if err := storage.Init(); err != nil {
+ return err
+ }
+ start := time.Now()
+ if err := generateCorpus(context.Background(), *corpusDir, pid, *entries, *tokens, *workers); err != nil {
+ return err
+ }
+ fmt.Fprintf(os.Stderr, "generated %d entries in %s\n", *entries, time.Since(start).Round(time.Second))
+ return nil
+}
+
+func cmdRun(args []string) error {
+ fs := flag.NewFlagSet("run", flag.ExitOnError)
+ cfg := runConfig{}
+ fs.StringVar(&cfg.corpusDir, "corpus-dir", "", "corpus directory from generate")
+ fs.StringVar(&cfg.projectId, "project-id", defaultProjectId, "project uuid used in storage keys")
+ fs.StringVar(&cfg.label, "label", "", "label for this cell in the results table (defaults to mode)")
+ fs.StringVar(&cfg.mode, "mode", "memory", "cache mode: memory or disk")
+ fs.IntVar(&cfg.entries, "entries", 1000, "corpus entries the workload draws from")
+ fs.IntVar(&cfg.hot, "hot", 30, "distinct bundles in the hot rotation")
+ fs.Float64Var(&cfg.coldRatio, "cold-ratio", 0.05, "fraction of lookups hitting a uniformly random bundle")
+ fs.DurationVar(&cfg.duration, "duration", 60*time.Second, "measured duration")
+ fs.DurationVar(&cfg.warmup, "warmup", 10*time.Second, "warmup excluded from stats")
+ fs.IntVar(&cfg.concurrency, "concurrency", 16, "concurrent resolver workers")
+ fs.IntVar(&cfg.memCacheMB, "mem-cache-mb", 0, "memory mode resolver cache budget in MB (0 = unbounded)")
+ fs.IntVar(&cfg.openEntries, "open-entries", 512, "disk mode: max open mmap resolvers")
+ fs.IntVar(&cfg.openMB, "open-mb", 1024, "disk mode: byte budget of the open-resolver layer in MB")
+ fs.StringVar(&cfg.diskDir, "disk-cache-dir", "", "disk mode: local tw cache dir (wiped at start)")
+ fs.IntVar(&cfg.diskMB, "disk-cache-mb", 16384, "disk mode: tw cache capacity in MB")
+ fs.StringVar(&cfg.tier, "tier", "local", "instance label embedded in results")
+ fs.StringVar(&cfg.out, "out", "-", "result JSON path (- for stdout)")
+ if err := fs.Parse(args); err != nil {
+ return err
+ }
+ if cfg.corpusDir == "" {
+ return fmt.Errorf("--corpus-dir is required")
+ }
+ if cfg.mode == "disk" && cfg.diskDir == "" {
+ return fmt.Errorf("--disk-cache-dir is required in disk mode")
+ }
+ if cfg.label == "" {
+ cfg.label = cfg.mode
+ }
+ config.Init(&config.Cfg{StorageType: "local", StoragePath: cfg.corpusDir})
+ if err := storage.Init(); err != nil {
+ return err
+ }
+ return runBench(cfg)
+}
+
+func cmdTable(args []string) error {
+ fs := flag.NewFlagSet("table", flag.ExitOnError)
+ resultsDir := fs.String("results-dir", "", "directory of run result JSON files")
+ out := fs.String("out", "-", "markdown output path (- for stdout)")
+ if err := fs.Parse(args); err != nil {
+ return err
+ }
+ if *resultsDir == "" {
+ return fmt.Errorf("--results-dir is required")
+ }
+ table, err := renderTable(*resultsDir)
+ if err != nil {
+ return err
+ }
+ if *out == "" || *out == "-" {
+ _, err = os.Stdout.WriteString(table)
+ return err
+ }
+ return os.WriteFile(*out, []byte(table), 0o644)
+}
diff --git a/backend/tools/cachebench/run.go b/backend/tools/cachebench/run.go
new file mode 100644
index 00000000..2369ffa3
--- /dev/null
+++ b/backend/tools/cachebench/run.go
@@ -0,0 +1,302 @@
+package main
+
+import (
+ "cmp"
+ "context"
+ "encoding/json"
+ "fmt"
+ "math/rand"
+ "os"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "strconv"
+ "strings"
+ "sync"
+ "sync/atomic"
+ "time"
+
+ "github.com/tracewayapp/traceway/backend/app/monitoring"
+ "github.com/tracewayapp/traceway/backend/app/services"
+
+ "github.com/google/uuid"
+)
+
+const latencyReservoirSize = 200000
+
+type runConfig struct {
+ corpusDir string
+ projectId string
+ label string
+ mode string
+ entries int
+ hot int
+ coldRatio float64
+ duration time.Duration
+ warmup time.Duration
+ concurrency int
+ memCacheMB int
+ openEntries int
+ openMB int
+ diskDir string
+ diskMB int
+ tier string
+ out string
+}
+
+type runResult struct {
+ Status string `json:"status"`
+ Tier string `json:"tier"`
+ Label string `json:"label"`
+ Mode string `json:"mode"`
+ Entries int `json:"entries"`
+ Hot int `json:"hot"`
+ ColdRatio float64 `json:"coldRatio"`
+ CorpusGB float64 `json:"corpusGB"`
+ DurationSec float64 `json:"durationSec"`
+ Concurrency int `json:"concurrency"`
+ Resolves int64 `json:"resolves"`
+ RPS float64 `json:"rps"`
+ P50Us float64 `json:"p50Us"`
+ P95Us float64 `json:"p95Us"`
+ P99Us float64 `json:"p99Us"`
+ MaxUs float64 `json:"maxUs"`
+ UnresolvedFrm int64 `json:"unresolvedFrames"`
+ RSSPeakMB float64 `json:"rssPeakMB"`
+ HeapAllocMB float64 `json:"heapAllocMB"`
+ NumGC uint32 `json:"numGC"`
+ GCPauseMs float64 `json:"gcPauseMs"`
+ CacheHits uint64 `json:"cacheHits"`
+ CacheMisses uint64 `json:"cacheMisses"`
+ CacheEvict uint64 `json:"cacheEvictions"`
+ DiskHits uint64 `json:"diskHits"`
+ StoreHits uint64 `json:"storeHits"`
+ Builds uint64 `json:"builds"`
+ DiskEvict uint64 `json:"diskEvictions"`
+ DiskBytesMB float64 `json:"diskBytesMB"`
+ ExitCode int `json:"exitCode,omitempty"`
+}
+
+type latencyReservoir struct {
+ samples []int64
+ seen int64
+ rng *rand.Rand
+}
+
+func (r *latencyReservoir) record(ns int64) {
+ r.seen++
+ if len(r.samples) < latencyReservoirSize {
+ r.samples = append(r.samples, ns)
+ return
+ }
+ if i := r.rng.Int63n(r.seen); i < latencyReservoirSize {
+ r.samples[i] = ns
+ }
+}
+
+func runBench(cfg runConfig) error {
+ manifest, err := loadManifest(cfg.corpusDir)
+ if err != nil {
+ return fmt.Errorf("loading corpus manifest (run generate first): %w", err)
+ }
+ if cfg.entries > manifest.Entries {
+ return fmt.Errorf("requested %d entries but corpus has %d", cfg.entries, manifest.Entries)
+ }
+
+ switch cfg.mode {
+ case "memory":
+ maxBytes := int64(cfg.memCacheMB) << 20
+ if cfg.memCacheMB == 0 {
+ maxBytes = 1 << 60
+ }
+ services.InitSourceMapCache(cfg.entries*2+cfg.hot, maxBytes)
+ case "disk":
+ services.InitSourceMapCache(cfg.openEntries, int64(cfg.openMB)<<20)
+ if err := os.RemoveAll(cfg.diskDir); err != nil {
+ return err
+ }
+ if err := services.EnableSourceMapDiskCache(cfg.diskDir, int64(cfg.diskMB)<<20); err != nil {
+ return err
+ }
+ default:
+ return fmt.Errorf("unknown mode %q (memory or disk)", cfg.mode)
+ }
+
+ projectId, err := uuid.Parse(cfg.projectId)
+ if err != nil {
+ return err
+ }
+
+ hotSet := make([]int, cfg.hot)
+ for i := range hotSet {
+ hotSet[i] = i * cfg.entries / cfg.hot
+ }
+ fileNames := make([]string, cfg.entries)
+ for i := range fileNames {
+ fileNames[i] = fmt.Sprintf(bundleFileFmt, i)
+ }
+
+ var rssPeak atomic.Uint64
+ rssCtx, rssCancel := context.WithCancel(context.Background())
+ defer rssCancel()
+ go func() {
+ ticker := time.NewTicker(200 * time.Millisecond)
+ defer ticker.Stop()
+ for {
+ select {
+ case <-rssCtx.Done():
+ return
+ case <-ticker.C:
+ if rss, ok := monitoring.ReadRSSBytes(); ok && rss > rssPeak.Load() {
+ rssPeak.Store(rss)
+ }
+ }
+ }
+ }()
+
+ var measuring atomic.Bool
+ var resolves atomic.Int64
+ var unresolved atomic.Int64
+ reservoirs := make([]*latencyReservoir, cfg.concurrency)
+
+ workCtx, workCancel := context.WithCancel(context.Background())
+ var wg sync.WaitGroup
+ for w := range cfg.concurrency {
+ reservoirs[w] = &latencyReservoir{rng: rand.New(rand.NewSource(int64(w) + 42))}
+ wg.Add(1)
+ go func(res *latencyReservoir, seed int64) {
+ defer wg.Done()
+ rng := rand.New(rand.NewSource(seed))
+ for workCtx.Err() == nil {
+ var idx int
+ if cfg.coldRatio > 0 && rng.Float64() < cfg.coldRatio {
+ idx = rng.Intn(cfg.entries)
+ } else {
+ idx = hotSet[rng.Intn(len(hotSet))]
+ }
+ trace := buildTrace(fileNames[idx], manifest.BundleBytes, rng)
+ start := time.Now()
+ out := services.ResolveStackTrace(workCtx, projectId, trace, nil)
+ elapsed := time.Since(start)
+ if measuring.Load() {
+ res.record(elapsed.Nanoseconds())
+ resolves.Add(1)
+ if n := int64(3 - strings.Count(out, "src/module-")); n > 0 {
+ unresolved.Add(n)
+ }
+ }
+ }
+ }(reservoirs[w], int64(w)+1000)
+ }
+
+ time.Sleep(cfg.warmup)
+ measuring.Store(true)
+ measureStart := time.Now()
+ time.Sleep(cfg.duration)
+ measuring.Store(false)
+ measuredFor := time.Since(measureStart)
+ workCancel()
+ wg.Wait()
+ rssCancel()
+
+ type weightedSample struct {
+ ns int64
+ w float64
+ }
+ var all []weightedSample
+ var totalWeight float64
+ for _, r := range reservoirs {
+ if len(r.samples) == 0 {
+ continue
+ }
+ w := float64(r.seen) / float64(len(r.samples))
+ for _, ns := range r.samples {
+ all = append(all, weightedSample{ns: ns, w: w})
+ }
+ totalWeight += float64(r.seen)
+ }
+ slices.SortFunc(all, func(a, b weightedSample) int {
+ return cmp.Compare(a.ns, b.ns)
+ })
+ maxUs := 0.0
+ if len(all) > 0 {
+ maxUs = float64(all[len(all)-1].ns) / 1e3
+ }
+ percentileUs := func(p float64) float64 {
+ if len(all) == 0 {
+ return 0
+ }
+ threshold := p * totalWeight
+ cum := 0.0
+ for _, s := range all {
+ cum += s.w
+ if cum >= threshold {
+ return float64(s.ns) / 1e3
+ }
+ }
+ return maxUs
+ }
+
+ var memStats runtime.MemStats
+ runtime.ReadMemStats(&memStats)
+ smStats := services.SourceMapStats()
+
+ result := runResult{
+ Status: "ok",
+ Tier: cfg.tier,
+ Label: cfg.label,
+ Mode: cfg.mode,
+ Entries: cfg.entries,
+ Hot: cfg.hot,
+ ColdRatio: cfg.coldRatio,
+ CorpusGB: float64(cfg.entries) * float64(manifest.ResolverBytes) / (1 << 30),
+ DurationSec: measuredFor.Seconds(),
+ Concurrency: cfg.concurrency,
+ Resolves: resolves.Load(),
+ RPS: float64(resolves.Load()) / measuredFor.Seconds(),
+ P50Us: percentileUs(0.50),
+ P95Us: percentileUs(0.95),
+ P99Us: percentileUs(0.99),
+ MaxUs: maxUs,
+ UnresolvedFrm: unresolved.Load(),
+ RSSPeakMB: float64(rssPeak.Load()) / (1 << 20),
+ HeapAllocMB: float64(memStats.HeapAlloc) / (1 << 20),
+ NumGC: memStats.NumGC,
+ GCPauseMs: float64(memStats.PauseTotalNs) / 1e6,
+ CacheHits: smStats.Hits,
+ CacheMisses: smStats.Misses,
+ CacheEvict: smStats.Evictions,
+ DiskHits: smStats.DiskHits,
+ StoreHits: smStats.StoreHits,
+ Builds: smStats.Builds,
+ DiskEvict: smStats.DiskEvictions,
+ DiskBytesMB: float64(smStats.DiskBytes) / (1 << 20),
+ }
+
+ data, err := json.MarshalIndent(result, "", " ")
+ if err != nil {
+ return err
+ }
+ if cfg.out == "" || cfg.out == "-" {
+ _, err = os.Stdout.Write(append(data, '\n'))
+ return err
+ }
+ if err := os.MkdirAll(filepath.Dir(cfg.out), 0o755); err != nil {
+ return err
+ }
+ return os.WriteFile(cfg.out, append(data, '\n'), 0o644)
+}
+
+func buildTrace(file string, bundleLen int, rng *rand.Rand) string {
+ var sb strings.Builder
+ sb.Grow(64 + 3*(len(file)+32))
+ sb.WriteString("Error: bench\n")
+ for range 3 {
+ sb.WriteString("anonymous()\n ")
+ sb.WriteString(file)
+ sb.WriteString(":1:")
+ sb.WriteString(strconv.Itoa(1 + rng.Intn(bundleLen)))
+ sb.WriteByte('\n')
+ }
+ return sb.String()
+}
diff --git a/backend/tools/cachebench/table.go b/backend/tools/cachebench/table.go
new file mode 100644
index 00000000..687cb660
--- /dev/null
+++ b/backend/tools/cachebench/table.go
@@ -0,0 +1,152 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "maps"
+ "os"
+ "path/filepath"
+ "slices"
+ "strings"
+)
+
+func renderTable(resultsDir string) (string, error) {
+ files, err := filepath.Glob(filepath.Join(resultsDir, "*.json"))
+ if err != nil {
+ return "", err
+ }
+ var rows []runResult
+ for _, f := range files {
+ data, err := os.ReadFile(f)
+ if err != nil {
+ return "", err
+ }
+ var r runResult
+ if err := json.Unmarshal(data, &r); err != nil {
+ return "", fmt.Errorf("parsing %s: %w", f, err)
+ }
+ rows = append(rows, r)
+ }
+ if len(rows) == 0 {
+ return "", fmt.Errorf("no result files in %s", resultsDir)
+ }
+
+ cells := make(map[float64]map[int]map[string]*runResult)
+ var labels []string
+ for i := range rows {
+ r := &rows[i]
+ if cells[r.ColdRatio] == nil {
+ cells[r.ColdRatio] = make(map[int]map[string]*runResult)
+ }
+ if cells[r.ColdRatio][r.Entries] == nil {
+ cells[r.ColdRatio][r.Entries] = make(map[string]*runResult)
+ }
+ cells[r.ColdRatio][r.Entries][r.Label] = r
+ if !slices.Contains(labels, r.Label) {
+ labels = append(labels, r.Label)
+ }
+ }
+ slices.Sort(labels)
+ if i := slices.Index(labels, "memory"); i > 0 {
+ labels = append([]string{"memory"}, slices.Delete(labels, i, i+1)...)
+ }
+ ratios := slices.Sorted(maps.Keys(cells))
+
+ var sb strings.Builder
+ fmt.Fprintf(&sb, "# Symbolicator cache benchmark: in-memory vs mmap disk cache\n\n")
+ fmt.Fprintf(&sb, "Instance: %s. Hot set: %d bundles. Workload: %d concurrent resolvers, 3 frames per stack trace.\n\n",
+ rows[0].Tier, rows[0].Hot, rows[0].Concurrency)
+ sb.WriteString("Peak RSS is the benchmark process's maximum resident memory over the whole cell (sampled every 200ms), so it captures the worst-case RAM cost of each cache design under that load.\n\n")
+
+ for _, ratio := range ratios {
+ fmt.Fprintf(&sb, "## Cold traffic ratio %.0f%% (share of lookups hitting a uniformly random bundle outside the hot set)\n\n", ratio*100)
+ entrySizes := slices.Sorted(maps.Keys(cells[ratio]))
+
+ ratioLabels := make([]string, 0, len(labels))
+ for _, l := range labels {
+ for _, entries := range entrySizes {
+ if cells[ratio][entries][l] != nil {
+ ratioLabels = append(ratioLabels, l)
+ break
+ }
+ }
+ }
+
+ sb.WriteString("| Bundles | Resolver corpus |")
+ for _, l := range ratioLabels {
+ fmt.Fprintf(&sb, " %s rps | %s p99 ms | %s peak RSS MB |", l, l, l)
+ }
+ sb.WriteString(" Winner |\n")
+ sb.WriteString("|---|---|")
+ for range ratioLabels {
+ sb.WriteString("---|---|---|")
+ }
+ sb.WriteString("---|\n")
+
+ crossover := -1
+ broken := -1
+ for _, entries := range entrySizes {
+ row := cells[ratio][entries]
+ corpusGB := 0.0
+ for _, c := range row {
+ if c.CorpusGB > 0 {
+ corpusGB = c.CorpusGB
+ }
+ }
+ fmt.Fprintf(&sb, "| %d | %.2f GB |", entries, corpusGB)
+
+ bestLabel, bestRPS := "", -1.0
+ for _, l := range ratioLabels {
+ c := row[l]
+ if c == nil {
+ sb.WriteString(" - | - | - |")
+ continue
+ }
+ if c.Status != "ok" {
+ fmt.Fprintf(&sb, " **BREAK (%s)** | - | - |", strings.ToUpper(c.Status))
+ if c.Status == "oom" && strings.HasPrefix(l, "memory") && broken == -1 {
+ broken = entries
+ }
+ continue
+ }
+ fmt.Fprintf(&sb, " %.0f | %.2f | %.0f |", c.RPS, c.P99Us/1000, c.RSSPeakMB)
+ if c.RPS > bestRPS {
+ bestRPS, bestLabel = c.RPS, l
+ }
+ }
+ fmt.Fprintf(&sb, " %s |\n", bestLabel)
+
+ if crossover == -1 && bestLabel == "disk" {
+ if m := row["memory"]; m != nil && m.Status == "ok" {
+ crossover = entries
+ }
+ }
+ }
+ sb.WriteString("\n")
+ if crossover != -1 {
+ fmt.Fprintf(&sb, "Disk cache becomes cheaper than the in-memory cache at **%d bundles** for this cold ratio.\n", crossover)
+ }
+ if broken != -1 {
+ fmt.Fprintf(&sb, "The in-memory cache breaks at **%d bundles**; beyond this point the file-based cache is the only option.\n", broken)
+ }
+ if crossover != -1 || broken != -1 {
+ sb.WriteString("\n")
+ }
+
+ sb.WriteString("<details><summary>Cache internals per cell</summary>\n\n")
+ sb.WriteString("| Bundles | Label | Hits | Misses | Builds | Disk hits | Store hits | Disk evictions | Unresolved frames | GC pause ms |\n")
+ sb.WriteString("|---|---|---|---|---|---|---|---|---|---|\n")
+ for _, entries := range entrySizes {
+ for _, l := range ratioLabels {
+ r := cells[ratio][entries][l]
+ if r == nil || r.Status != "ok" {
+ continue
+ }
+ fmt.Fprintf(&sb, "| %d | %s | %d | %d | %d | %d | %d | %d | %d | %.0f |\n",
+ entries, l, r.CacheHits, r.CacheMisses, r.Builds, r.DiskHits, r.StoreHits, r.DiskEvict, r.UnresolvedFrm, r.GCPauseMs)
+ }
+ }
+ sb.WriteString("\n</details>\n\n")
+ }
+ return sb.String(), nil
+}
diff --git a/benchmarks/README.md b/benchmarks/README.md
index 26dc039c..bd8e4c83 100644
--- a/benchmarks/README.md
+++ b/benchmarks/README.md
@@ -348,6 +348,84 @@ they're missing.
ingest path. Read-probe surfaces the cluster's read scaling, which is what
you actually buy from a managed offering.
+## Symbolicator benchmarks
+
+Two additional workflows benchmark the JS symbolicator. They answer different
+questions and run on different infrastructure:
+
+| Workflow | What it measures | Where it runs | Cost |
+|---|---|---|---|
+| `benchmark-symbolicator` | Bundle parser throughput: goja vs oxc (`go test -bench`) | GitHub runner | free, ~10 min |
+| `benchmark-symbolicator-cache` | Resolver cache architecture: in-memory LRU vs mmap disk cache | One Hetzner box | under 1 EUR, ~2 h |
+
+Both are `workflow_dispatch` only. The workflow file must exist on `main` to be
+dispatchable; select the feature branch in the run dropdown to execute that
+branch's scripts and code.
+
+### Parser benchmark
+
+`scripts/benchmark-symbolicator.sh` (repo root `scripts/`, not this folder)
+builds the oxc Rust shim, runs the symbolicator test suite as a gate, then runs
+`BenchmarkBundleParsers` over the bundler fixtures (simple, inlining, webpack,
+metro, preact) plus 1MB/5MB synthetic bundles, with both parsers. Results land
+in the job step summary. Expected shape: oxc 2-4.5x faster than goja with
+roughly 99% fewer allocations; `BenchmarkOpenTW` in the hundreds of
+nanoseconds.
+
+### Cache benchmark (cachebench)
+
+> With a corpus of **N** uploaded bundles (more than RAM can hold), a hot set
+> of ~30 active exceptions, and **R**% of lookups hitting the long tail, which
+> resolver cache is cheaper: parsed-in-memory or mmap'd `.tw` files on disk,
+> and at what corpus size does one break?
+
+The harness is `backend/tools/cachebench` (it imports backend internals, so it
+lives in the backend module): `generate` writes a corpus of synthetic
+bundle + VLQ source map + `.tw` triples, `run` executes one cell
+(mode x entries x cold-ratio) in a fresh process and emits a JSON row with
+throughput (rps), weighted p50/p95/p99 latency, peak RSS sampled at 200ms, GC
+totals, and cache internals (hits, builds, disk hits, store hits, evictions),
+`table` merges the rows into a markdown summary that marks the crossover
+corpus size and any OOM break point.
+
+Run it three ways:
+
+```bash
+# Locally, no Hetzner (small corpus; RSS reads 0 on macOS, Linux is the real measurement)
+./benchmarks/scripts/cachebench-local.sh
+
+# From a laptop against Hetzner (same env vars as the hardware benchmark)
+export HCLOUD_TOKEN=... BENCHMARK_SSH_KEY=~/.ssh/benchmark-key
+SMOKE=1 ./benchmarks/scripts/cachebench-entry.sh # ~5 min pipeline check
+./benchmarks/scripts/cachebench-entry.sh # full sweep
+
+# From GitHub Actions: dispatch benchmark-symbolicator-cache, smoke=true first
+```
+
+Defaults: ccx13 (2 vCPU / 8 GB), corpus 1000 to 12000 bundles (~1 MB resolver
+each against a 5.6 GB bounded memory budget, 70% of RAM), cold ratios
+0 / 0.05 / 0.25, plus an unbounded in-memory variant per cell to find the OOM
+break point. Each cell gets a wiped tw-cache and dropped page caches. A cell
+killed by the OOM killer is recorded as `BREAK (OOM)` instead of failing the
+sweep; ssh drops and timeouts are recorded as `ERROR`/`TIMEOUT` so they cannot
+masquerade as cache conclusions.
+
+What to expect in the summary table (one section per cold ratio):
+
+- **Cold 0%:** memory wins or ties every row; with only the hot set in play
+ nothing ever misses. Baseline sanity.
+- **Cold 5% / 25%:** memory wins while the corpus fits its budget, then
+ degrades once it does not (every cold lookup pulls the `.tw` artifact from
+ storage into the heap, churning the LRU and the GC) while disk holds sub-ms
+ p99 via mmap re-opens. The table prints the crossover row.
+- **memory-unbounded:** RSS climbs with corpus size until `BREAK (OOM)`,
+ producing the "file-based is the only option beyond here" line. Disk RSS
+ stays flat (only hot pages resident).
+
+Results are not committed back to the repo: every dispatch uploads
+`benchmarks/results-cachebench/` (per-cell JSON plus `summary.md`) as a run
+artifact, and the summary table is rendered in the job step summary.
+
## Layout
```
@@ -378,9 +456,13 @@ benchmarks/
loadgen-bootstrap.sh # Cross-compiles + runs loadgen
seed-project.sh # /api/register -> JWT + project token JSON
chart.py # matplotlib renderer (throughput + read-probe charts)
- _ssh.sh # Shared ssh/rsync helpers
+ _ssh.sh # Shared ssh/rsync helpers + retry_eof
+ cachebench-local.sh # Symbolicator cache sweep on this machine
+ cachebench-entry.sh # Symbolicator cache sweep on one Hetzner box
+ _cachebench.sh # Shared matrix/stub helpers for the two above
results-throughput/ # Committed throughput results (wiped per dispatch)
results-probe/ # Committed read-probe results (wiped per dispatch)
+ results-cachebench/ # Symbolicator cache results; CI uploads these as a run artifact, never committed
results/ # Historical dated folders (not written to anymore)
charts.md # Reading guide for every chart chart.py emits
```
diff --git a/benchmarks/scripts/_cachebench.sh b/benchmarks/scripts/_cachebench.sh
new file mode 100755
index 00000000..0a6abfb6
--- /dev/null
+++ b/benchmarks/scripts/_cachebench.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+# Shared matrix helpers for the symbolicator cache benchmark drivers. Source
+# this after setting ENTRIES/COLD_RATIOS/UNBOUNDED and defining a
+# run_cell <label> <mode> <entries> <ratio> function for the transport
+# (local exec in cachebench-local.sh, ssh in cachebench-entry.sh).
+
+parse_matrix() {
+ IFS=',' read -ra entries_list <<< "${ENTRIES}"
+ IFS=',' read -ra ratios_list <<< "${COLD_RATIOS}"
+ max_entries=0
+ local n
+ for n in "${entries_list[@]}"; do
+ (( n > max_entries )) && max_entries=$n
+ done
+}
+
+write_stub() {
+ local out="$1" tier="$2" label="$3" mode="$4" n="$5" hot="$6" ratio="$7" rc="$8"
+ local status="error"
+ case "${rc}" in
+ 137) status="oom" ;;
+ 124) status="timeout" ;;
+ esac
+ printf '{"status":"%s","tier":"%s","label":"%s","mode":"%s","entries":%s,"hot":%s,"coldRatio":%s,"exitCode":%s}\n' \
+ "${status}" "${tier}" "${label}" "${mode}" "${n}" "${hot}" "${ratio}" "${rc}" > "${out}"
+}
+
+run_sweep() {
+ local ratio n
+ for ratio in "${ratios_list[@]}"; do
+ for n in "${entries_list[@]}"; do
+ run_cell memory memory "${n}" "${ratio}"
+ run_cell disk disk "${n}" "${ratio}"
+ if [[ "${UNBOUNDED}" == "1" && "${ratio}" != "0" ]]; then
+ run_cell memory-unbounded memory "${n}" "${ratio}"
+ fi
+ done
+ done
+}
diff --git a/benchmarks/scripts/_ssh.sh b/benchmarks/scripts/_ssh.sh
index 198b75d1..a36702ad 100755
--- a/benchmarks/scripts/_ssh.sh
+++ b/benchmarks/scripts/_ssh.sh
@@ -45,3 +45,37 @@ wait_for_ssh() {
echo "ssh to ${host} not ready after ${timeout}s" >&2
return 1
}
+
+# retry_eof: run an `hcloud` command, capturing stderr. If the command exits
+# non-zero AND its stderr contains "EOF", wait 5 seconds and retry — up to 3
+# attempts total. Hetzner's API occasionally drops its keep-alive TCP
+# connection mid-action-poll, so hcloud surfaces an EOF even though the
+# server-side operation actually succeeded. On any retry attempt, an
+# "already exists" error is treated as success because it means the original
+# (EOF'd) call did go through. All other failure modes propagate immediately.
+retry_eof() {
+ local attempt=1 max=3 delay=5 errfile rc
+ errfile="$(mktemp)"
+ while true; do
+ "$@" 2>"${errfile}" && rc=0 || rc=$?
+ cat "${errfile}" >&2
+ if [[ $rc -eq 0 ]]; then
+ rm -f "${errfile}"
+ return 0
+ fi
+ if [[ ${attempt} -gt 1 ]] && grep -qiE "already (exists|in use)|name .* not unique" "${errfile}"; then
+ echo " ↳ resource already exists from earlier attempt; treating as success" >&2
+ rm -f "${errfile}"
+ return 0
+ fi
+ if grep -q "EOF" "${errfile}" && [[ $attempt -lt $max ]]; then
+ echo " ↳ hcloud hit EOF, sleeping ${delay}s and retrying (attempt $((attempt+1))/${max})" >&2
+ sleep $delay
+ attempt=$((attempt + 1))
+ : > "${errfile}"
+ continue
+ fi
+ rm -f "${errfile}"
+ return $rc
+ done
+}
diff --git a/benchmarks/scripts/cachebench-entry.sh b/benchmarks/scripts/cachebench-entry.sh
new file mode 100755
index 00000000..1eb12b06
--- /dev/null
+++ b/benchmarks/scripts/cachebench-entry.sh
@@ -0,0 +1,118 @@
+#!/bin/bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
+source "${SCRIPT_DIR}/_ssh.sh"
+source "${SCRIPT_DIR}/_cachebench.sh"
+
+TIER="${TIER:-ccx13}"
+LOCATION="${LOCATION:-nbg1}"
+IMAGE="${BENCH_IMAGE:-debian-12}"
+OUT_DIR="${OUT_DIR:-${REPO_ROOT}/benchmarks/results-cachebench}"
+
+ENTRIES="${ENTRIES:-1000,2000,4000,6000,8000,12000}"
+COLD_RATIOS="${COLD_RATIOS:-0,0.05,0.25}"
+DURATION="${DURATION:-60s}"
+WARMUP="${WARMUP:-10s}"
+HOT="${HOT:-30}"
+TOKENS="${TOKENS:-40000}"
+CONCURRENCY="${CONCURRENCY:-16}"
+UNBOUNDED="${UNBOUNDED:-1}"
+DISK_CACHE_MB="${DISK_CACHE_MB:-16384}"
+
+if [[ "${SMOKE:-0}" == "1" ]]; then
+ ENTRIES="200"
+ COLD_RATIOS="0.1"
+ DURATION="10s"
+ WARMUP="3s"
+ TOKENS="4000"
+ UNBOUNDED="0"
+fi
+
+for tool in hcloud go ssh scp; do
+ command -v "${tool}" >/dev/null || { echo "missing required tool: ${tool}" >&2; exit 1; }
+done
+[[ -n "${HCLOUD_TOKEN:-}" ]] || { echo "HCLOUD_TOKEN is required" >&2; exit 1; }
+
+RUN_ID="${RUN_ID:-$(date -u +%Y%m%d-%H%M%S)-cachebench-${TIER}-$RANDOM}"
+SERVER_NAME="bench-cachebench-${RUN_ID}"
+
+cleanup() {
+ local rc=$?
+ echo "--- teardown for ${RUN_ID} (exit=${rc}) ---" >&2
+ hcloud server delete "${SERVER_NAME}" >/dev/null 2>&1 || true
+ exit "${rc}"
+}
+trap cleanup EXIT INT TERM
+
+if ! hcloud server describe "${SERVER_NAME}" >/dev/null 2>&1; then
+ echo "creating server ${SERVER_NAME} (${TIER}) in ${LOCATION}" >&2
+ retry_eof hcloud server create \
+ --name "${SERVER_NAME}" --type "${TIER}" --image "${IMAGE}" \
+ --location "${LOCATION}" --ssh-key benchmark-key \
+ --label "bench=true,run=${RUN_ID}" >/dev/null
+fi
+SUT_IP="$(hcloud server ip "${SERVER_NAME}")"
+echo "server up at ${SUT_IP}" >&2
+
+wait_for_ssh "${SUT_IP}"
+
+ARCH="$(bench_ssh "${SUT_IP}" "uname -m")"
+case "${ARCH}" in
+ x86_64) GOARCH=amd64 ;;
+ aarch64) GOARCH=arm64 ;;
+ *) echo "unsupported SUT arch ${ARCH}" >&2; exit 1 ;;
+esac
+
+(cd "${REPO_ROOT}/backend" && GOOS=linux GOARCH="${GOARCH}" CGO_ENABLED=0 go build -o "/tmp/cachebench-linux-${GOARCH}" ./tools/cachebench)
+bench_ssh "${SUT_IP}" "mkdir -p /root/cachebench/results"
+bench_scp "/tmp/cachebench-linux-${GOARCH}" "root@${SUT_IP}:/root/cachebench/cachebench"
+bench_ssh "${SUT_IP}" "chmod +x /root/cachebench/cachebench"
+
+parse_matrix
+
+echo "generating corpus: ${max_entries} entries, ${TOKENS} tokens each" >&2
+bench_ssh "${SUT_IP}" "/root/cachebench/cachebench generate --corpus-dir /root/cachebench/corpus --entries ${max_entries} --tokens ${TOKENS}"
+
+MEM_TOTAL_MB="$(bench_ssh "${SUT_IP}" "awk '/MemTotal/{print int(\$2/1024)}' /proc/meminfo")"
+MEM_BUDGET_MB="${MEM_BUDGET_MB:-$(( MEM_TOTAL_MB * 70 / 100 ))}"
+echo "box has ${MEM_TOTAL_MB} MB RAM, bounded memory cache budget ${MEM_BUDGET_MB} MB" >&2
+
+mkdir -p "${OUT_DIR}"
+rm -f "${OUT_DIR}"/*.json "${OUT_DIR}/summary.md" 2>/dev/null || true
+
+TIMEOUT_CMD="$(command -v timeout || command -v gtimeout || true)"
+dur_s="$(( $(echo "${DURATION}" | sed 's/s$//') + $(echo "${WARMUP}" | sed 's/s$//') + 300 ))"
+
+run_cell() {
+ local label="$1" mode="$2" n="$3" ratio="$4"
+ local extra=""
+ case "${label}" in
+ memory) extra="--mem-cache-mb ${MEM_BUDGET_MB}" ;;
+ memory-unbounded) extra="--mem-cache-mb 0" ;;
+ disk) extra="--disk-cache-dir /root/cachebench/twcache --disk-cache-mb ${DISK_CACHE_MB}" ;;
+ esac
+ local cell="${TIER}-${label}-n${n}-cold${ratio}"
+ local remote_out="/root/cachebench/results/${cell}.json"
+ local local_out="${OUT_DIR}/${cell}.json"
+ echo "--- cell: ${cell} ---" >&2
+ bench_ssh "${SUT_IP}" "rm -rf /root/cachebench/twcache && sync && echo 3 > /proc/sys/vm/drop_caches"
+ local rc=0
+ ${TIMEOUT_CMD:+${TIMEOUT_CMD} ${dur_s}} ssh "${ssh_opts[@]}" "root@${SUT_IP}" \
+ "/root/cachebench/cachebench run --corpus-dir /root/cachebench/corpus --mode ${mode} --label ${label} --entries ${n} --hot ${HOT} --cold-ratio ${ratio} --duration ${DURATION} --warmup ${WARMUP} --concurrency ${CONCURRENCY} --tier ${TIER} --out ${remote_out} ${extra}" || rc=$?
+ if [[ ${rc} -ne 0 ]]; then
+ echo "cell ${cell} exited with ${rc}, recording break" >&2
+ write_stub "${local_out}" "${TIER}" "${label}" "${mode}" "${n}" "${HOT}" "${ratio}" "${rc}"
+ wait_for_ssh "${SUT_IP}" 300
+ return 0
+ fi
+ bench_scp "root@${SUT_IP}:${remote_out}" "${local_out}"
+}
+
+run_sweep
+
+(cd "${REPO_ROOT}/backend" && go build -o /tmp/cachebench-host ./tools/cachebench)
+/tmp/cachebench-host table --results-dir "${OUT_DIR}" --out "${OUT_DIR}/summary.md"
+cat "${OUT_DIR}/summary.md"
+echo "results in ${OUT_DIR}" >&2
diff --git a/benchmarks/scripts/cachebench-local.sh b/benchmarks/scripts/cachebench-local.sh
new file mode 100755
index 00000000..61ba3f50
--- /dev/null
+++ b/benchmarks/scripts/cachebench-local.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
+source "${SCRIPT_DIR}/_cachebench.sh"
+
+ENTRIES="${ENTRIES:-100,300}"
+COLD_RATIOS="${COLD_RATIOS:-0,0.2}"
+DURATION="${DURATION:-5s}"
+WARMUP="${WARMUP:-2s}"
+HOT="${HOT:-10}"
+TOKENS="${TOKENS:-4000}"
+CONCURRENCY="${CONCURRENCY:-8}"
+UNBOUNDED="${UNBOUNDED:-0}"
+MEM_BUDGET_MB="${MEM_BUDGET_MB:-256}"
+WORK_DIR="${WORK_DIR:-/tmp/cachebench-local}"
+
+BIN="${WORK_DIR}/cachebench"
+CORPUS="${WORK_DIR}/corpus"
+RESULTS="${WORK_DIR}/results"
+TWCACHE="${WORK_DIR}/twcache"
+
+mkdir -p "${WORK_DIR}"
+rm -rf "${RESULTS}"
+mkdir -p "${RESULTS}"
+
+(cd "${REPO_ROOT}/backend" && go build -o "${BIN}" ./tools/cachebench)
+
+parse_matrix
+"${BIN}" generate --corpus-dir "${CORPUS}" --entries "${max_entries}" --tokens "${TOKENS}"
+
+run_cell() {
+ local label="$1" mode="$2" n="$3" ratio="$4"
+ local extra=()
+ case "${label}" in
+ memory) extra=(--mem-cache-mb "${MEM_BUDGET_MB}") ;;
+ memory-unbounded) extra=(--mem-cache-mb 0) ;;
+ disk) rm -rf "${TWCACHE}"; extra=(--disk-cache-dir "${TWCACHE}") ;;
+ esac
+ local out="${RESULTS}/local-${label}-n${n}-cold${ratio}.json"
+ echo "--- cell: ${label} entries=${n} cold=${ratio} ---" >&2
+ local rc=0
+ "${BIN}" run \
+ --corpus-dir "${CORPUS}" --mode "${mode}" --label "${label}" \
+ --entries "${n}" --hot "${HOT}" --cold-ratio "${ratio}" \
+ --duration "${DURATION}" --warmup "${WARMUP}" --concurrency "${CONCURRENCY}" \
+ --tier local --out "${out}" "${extra[@]}" || rc=$?
+ if [[ ${rc} -ne 0 ]]; then
+ echo "cell exited with ${rc}, recording break" >&2
+ write_stub "${out}" local "${label}" "${mode}" "${n}" "${HOT}" "${ratio}" "${rc}"
+ fi
+}
+
+run_sweep
+
+"${BIN}" table --results-dir "${RESULTS}" --out "${RESULTS}/summary.md"
+cat "${RESULTS}/summary.md"
+echo "results in ${RESULTS}" >&2
diff --git a/benchmarks/scripts/hetzner-up.sh b/benchmarks/scripts/hetzner-up.sh
index 2efadfcc..6a9e8d67 100755
--- a/benchmarks/scripts/hetzner-up.sh
+++ b/benchmarks/scripts/hetzner-up.sh
@@ -12,6 +12,8 @@
# {"sutPublicIp":"...","sutPrivateIp":"...","loadgenPublicIp":"...","loadgenPrivateIp":"...","networkId":"...","runId":"..."}
set -euo pipefail
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/_ssh.sh"
+
if [[ $# -lt 2 ]]; then
echo "usage: $0 <tier> <run-id> [location]" >&2
exit 2
@@ -58,40 +60,6 @@ case "${LOCATION}" in
;;
esac
-# retry_eof: run an `hcloud` command, capturing stderr. If the command exits
-# non-zero AND its stderr contains "EOF", wait 5 seconds and retry — up to 3
-# attempts total. Hetzner's API occasionally drops its keep-alive TCP
-# connection mid-action-poll, so hcloud surfaces an EOF even though the
-# server-side operation actually succeeded. On any retry attempt, an
-# "already exists" error is treated as success because it means the original
-# (EOF'd) call did go through. All other failure modes propagate immediately.
-retry_eof() {
- local attempt=1 max=3 delay=5 errfile rc
- errfile="$(mktemp)"
- while true; do
- "$@" 2>"${errfile}" && rc=0 || rc=$?
- cat "${errfile}" >&2
- if [[ $rc -eq 0 ]]; then
- rm -f "${errfile}"
- return 0
- fi
- if [[ ${attempt} -gt 1 ]] && grep -qiE "already (exists|in use)|name .* not unique" "${errfile}"; then
- echo " ↳ resource already exists from earlier attempt; treating as success" >&2
- rm -f "${errfile}"
- return 0
- fi
- if grep -q "EOF" "${errfile}" && [[ $attempt -lt $max ]]; then
- echo " ↳ hcloud hit EOF, sleeping ${delay}s and retrying (attempt $((attempt+1))/${max})" >&2
- sleep $delay
- attempt=$((attempt + 1))
- : > "${errfile}"
- continue
- fi
- rm -f "${errfile}"
- return $rc
- done
-}
-
# Create a /24 private network so SUT and loadgen can talk over 10.0.0.x.
if ! hcloud network describe "${NET_NAME}" >/dev/null 2>&1; then
echo "creating network ${NET_NAME} in zone ${NETWORK_ZONE}" >&2
diff --git a/docs/pages/client/js-sdk/_meta.json b/docs/pages/client/js-sdk/_meta.json
index af7b0b1f..517cd6d2 100644
--- a/docs/pages/client/js-sdk/_meta.json
+++ b/docs/pages/client/js-sdk/_meta.json
@@ -6,5 +6,6 @@
"distributed-tracing": "Distributed Tracing",
"flush": "Flush & Lifecycle",
"sourcemap-upload": "Source Maps",
+ "debug-ids": "Debug IDs",
"session-replay": "Session Replay"
}
diff --git a/docs/pages/client/js-sdk/debug-ids.mdx b/docs/pages/client/js-sdk/debug-ids.mdx
new file mode 100644
index 00000000..f62479b4
--- /dev/null
+++ b/docs/pages/client/js-sdk/debug-ids.mdx
@@ -0,0 +1,97 @@
+# Debug IDs
+
+Debug IDs tie a deployed bundle to the exact source map produced by the same build. At build time, `@tracewayapp/bundler-plugin` embeds a unique 128-bit ID (UUID format) into both the bundle and its `.map` file. At runtime the SDK reports the IDs of the bundles involved in each exception, and the backend uses them to pick the matching map: content-addressed, with no dependence on filenames, URLs, versions, or deploy timing.
+
+This is the same mechanism Sentry pioneered and the [ECMA-426 source map specification's Debug ID proposal](https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md) standardizes: a `debugId` field in the source map JSON and a `//# debugId=<uuid>` comment in the generated file. Traceway emits and consumes exactly that format, so artifacts are interoperable with other ECMA-426 tooling, and Traceway accepts artifacts produced by other debug-ID-aware tools (Sentry's bundler plugins, `sentry-cli sourcemaps inject`, Rollup's `output.sourcemapDebugIds`, Bun).
+
+Without debug IDs, maps are matched by filename, which works with content-hashed bundle names but breaks down with stable names like `app.js` served from multiple concurrent deploys. See [How Maps Are Matched](/client/js-sdk/sourcemap-upload#how-maps-are-matched).
+
+## Installation
+
+```bash
+npm install -D @tracewayapp/bundler-plugin
+```
+
+## Vite
+
+```ts
+// vite.config.ts
+import { defineConfig } from "vite";
+import { tracewayDebugIds } from "@tracewayapp/bundler-plugin/vite";
+
+export default defineConfig({
+ build: {
+ sourcemap: true,
+ },
+ plugins: [tracewayDebugIds()],
+});
+```
+
+## Rollup
+
+```js
+// rollup.config.js
+import { tracewayDebugIds } from "@tracewayapp/bundler-plugin/rollup";
+
+export default {
+ output: {
+ sourcemap: true,
+ },
+ plugins: [tracewayDebugIds()],
+};
+```
+
+## webpack
+
+```js
+// webpack.config.js
+const {
+ TracewayDebugIdsWebpackPlugin,
+} = require("@tracewayapp/bundler-plugin/webpack");
+
+module.exports = {
+ devtool: "source-map",
+ plugins: [new TracewayDebugIdsWebpackPlugin()],
+};
+```
+
+Requires webpack 5.
+
+## Upload As Usual
+
+The upload step is unchanged; the backend detects debug IDs in the uploaded files automatically:
+
+```bash
+npx traceway-sourcemaps \
+ --url https://your-traceway-instance.com \
+ --token your-sourcemap-token \
+ --directory ./dist
+```
+
+## How It Works
+
+For every emitted JS chunk, the plugin:
+
+1. Derives a deterministic debug ID from the chunk's content (a SHA-256 hash formatted as a UUID), so rebuilding identical input yields the identical ID.
+2. Injects a small self-executing snippet at the top of the chunk (after any shebang and `"use strict"` directive) that registers the ID in a `_tracewayDebugIds` global, keyed by the stack of a synthetic error, which is how the SDK later discovers the runtime URL each bundle was loaded from. Source maps are adjusted for the insertion, so resolved positions are unaffected.
+3. Appends a `//# debugId=<uuid>` comment to the chunk, above the `//# sourceMappingURL=` comment.
+4. Writes the ID into the source map JSON as `debugId` (and `debug_id` for compatibility with Sentry-era tooling).
+
+When an exception is captured, the SDK reads `_tracewayDebugIds` (and `_sentryDebugIds`, so bundles processed by Sentry tooling work too), maps each bundle filename in the stack trace to its debug ID, and sends that mapping with the exception. At ingest, the backend resolves each frame against the map uploaded with that exact debug ID, falling back to filename matching when no debug-ID artifact exists. Uploaded artifacts carrying a debug ID are stored under both their filename and a `by-debug-id/` key, so old SDK versions and frames without IDs keep resolving.
+
+## Node and OpenTelemetry
+
+Debug IDs work the same way for server-side bundles: the injected snippet detects `globalThis`/`global`, and Node stack traces carry the bundle path just like browser ones. If you bundle a Node service with Vite, Rollup, or webpack, the same plugin applies.
+
+OpenTelemetry currently has **no debug ID convention**: there is no semantic-conventions attribute for source map linkage, and the JS SDKs do not collect anything like it. Traceway therefore carries debug IDs in its own report payload (a `debugIds` filename-to-ID map on each exception). Because the build artifacts follow the ECMA-426 format rather than anything Traceway-specific, a future Node/OTel integration can adopt the same uploads without rebuilding anything.
+
+## Interoperability Notes
+
+- **Rollup/Vite native IDs**: Rollup's `output.sourcemapDebugIds: true` emits the comment and map field but no runtime registry, so the SDK cannot report IDs at runtime from that alone. The Traceway plugin is a superset; you do not need both.
+- **Sentry tooling**: bundles processed by `@sentry/vite-plugin`, `@sentry/webpack-plugin`, or `sentry-cli sourcemaps inject` register `_sentryDebugIds`, which the Traceway SDK also reads. Maps carrying only the legacy `debug_id` field are accepted on upload.
+- **esbuild**: the Traceway plugin does not cover esbuild, and esbuild emits no debug IDs natively. Bundles processed by `@sentry/esbuild-plugin` (or a post-build `sentry-cli sourcemaps inject`) get `_sentryDebugIds` injected, which the SDK reads as described above, so esbuild apps can still get exact debug-ID matching through that tooling; without it they fall back to filename matching.
+
+## Next Steps
+
+- [Source Maps](/client/js-sdk/sourcemap-upload): the upload CLI
+- [Symbolication](/learn/symbolication-js): the full resolution pipeline
diff --git a/docs/pages/client/js-sdk/sourcemap-upload.mdx b/docs/pages/client/js-sdk/sourcemap-upload.mdx
index faf1c30c..9f243d8c 100644
--- a/docs/pages/client/js-sdk/sourcemap-upload.mdx
+++ b/docs/pages/client/js-sdk/sourcemap-upload.mdx
@@ -92,7 +92,10 @@ Make sure `TRACEWAY_URL` and `TRACEWAY_SOURCEMAP_TOKEN` are set in your environm
## How Maps Are Matched
-There is nothing to configure at runtime. When an exception is captured, Traceway takes each minified frame's filename and looks up the map you uploaded under that same name, deobfuscating the frame. The most recent upload of each filename wins, so content-hashed bundle names (the default in Vite, Next, Angular, and most bundlers) keep every build's maps distinct automatically.
+There is nothing to configure at runtime. When an exception is captured, Traceway resolves each minified frame in two steps:
+
+1. **By debug ID**, when the exception carries one for the frame's file. If your build uses [`@tracewayapp/bundler-plugin`](/client/js-sdk/debug-ids), every bundle and its map share an embedded unique ID, and the backend picks the map uploaded with that exact ID, immune to filename collisions and concurrent deploys. The upload endpoint detects debug IDs in uploaded files automatically; no CLI flags involved.
+2. **By filename** otherwise: the map you uploaded under the frame's filename is used. The most recent upload of each filename wins, so content-hashed bundle names (the default in Vite, Next, Angular, and most bundlers) keep every build's maps distinct automatically.
Uploads take effect immediately: the backend evicts any cached state for the uploaded filenames, so exceptions arriving right after a deploy resolve against the new maps. See [Symbolication](/learn/symbolication-js) for the full resolution pipeline.
@@ -100,5 +103,6 @@ The SDK's `version` option is unrelated to source maps: it is plain metadata sho
## Next Steps
+- [Debug IDs](/client/js-sdk/debug-ids) — exact build-to-map matching with the bundler plugin
- [Exceptions](/client/js-sdk/exceptions) — capturing errors with the JS SDK
- [Initialization](/client/js-sdk/initialization) — configuring the SDK `version` option
diff --git a/docs/pages/learn/_meta.json b/docs/pages/learn/_meta.json
index fb7bbee0..a50fd369 100644
--- a/docs/pages/learn/_meta.json
+++ b/docs/pages/learn/_meta.json
@@ -5,6 +5,8 @@
"ai-tracing": "AI Tracing",
"issues": "Issues",
"symbolication-js": "Symbolication (JS)",
+ "symbolicator-library": "Symbolicator as a Library",
+ "collector-symbolicator": "Collector Symbolicator",
"sessions": "Sessions",
"attributes": "Attributes",
"spans": "Spans",
diff --git a/docs/pages/learn/collector-symbolicator.mdx b/docs/pages/learn/collector-symbolicator.mdx
new file mode 100644
index 00000000..aafa39eb
--- /dev/null
+++ b/docs/pages/learn/collector-symbolicator.mdx
@@ -0,0 +1,215 @@
+# Symbolicator for the OTel Collector
+
+import { Callout, Steps } from "nextra/components";
+
+Traceway's symbolicator also ships as a standalone OpenTelemetry Collector processor, `source_map_symbolicator`. Add it to your collector pipeline and minified JavaScript stack traces in spans, span events, and log records are rewritten to original files, lines, columns, and function names before they reach any backend, Traceway or otherwise.
+
+It is a drop-in replacement for [Honeycomb's `source_map_symbolicator` processor](https://github.com/honeycombio/opentelemetry-collector-symbolicator): same component type, same attribute contract, same store layout, same configuration keys. Existing pipelines and instrumentation (for example `@honeycombio/opentelemetry-web` with `GlobalErrorsInstrumentation`) work unchanged. What you gain by swapping:
+
+- **A cache bounded by disk, not RAM.** Maps and bundles compile once into the [`.tw` resolver format](/learn/symbolication-js#the-tw-resolver-format) and are memory-mapped from a local cache directory with an LRU byte cap. Resident memory tracks the hot set, restarts warm from disk.
+- **Pure Go, no cgo.** No glibc base image requirement; runs in `scratch`.
+- **Function names via bundle scope analysis**, the same approach Sentry's symbolic uses.
+
+If you want to call the engine from your own Go code instead of a collector, see [Symbolicator as a Go Library](/learn/symbolicator-library).
+
+## Building a Collector With the Processor
+
+The processor is a public package of the published `github.com/tracewayapp/traceway/backend` module, exposing the standard `NewFactory()` entry point, so it plugs into the [OpenTelemetry Collector Builder](https://opentelemetry.io/docs/collector/custom-collector/) like any other component. Because the package is not at the module root, the manifest entry carries an `import` line alongside `gomod`.
+
+<Steps>
+
+### Install the builder
+
+```bash
+go install go.opentelemetry.io/collector/cmd/builder@latest
+```
+
+### Write the builder manifest
+
+`builder-config.yaml`, with the Traceway processor next to whatever receivers and exporters you need:
+
+```yaml
+dist:
+ name: otelcol-symbolicator
+ description: OTel Collector with Traceway source map symbolication
+ output_path: ./dist
+
+receivers:
+ - gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.154.0
+
+processors:
+ - gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.154.0
+ - gomod: github.com/tracewayapp/traceway/backend v1.8.0
+ import: github.com/tracewayapp/traceway/backend/app/symbolicator/otelprocessor
+
+exporters:
+ - gomod: go.opentelemetry.io/collector/exporter/otlphttpexporter v0.154.0
+```
+
+<Callout type="info">
+ The processor first ships in `v1.8.0`; use that tag or any newer one, and
+ keep the collector component versions aligned with each other as usual for
+ OCB manifests.
+</Callout>
+
+### Build it
+
+```bash
+builder --config builder-config.yaml
+```
+
+This produces `./dist/otelcol-symbolicator`, a self-contained collector binary.
+
+### Configure the pipeline
+
+`collector.yaml`:
+
+```yaml
+receivers:
+ otlp:
+ protocols:
+ http:
+ endpoint: 0.0.0.0:4318
+
+processors:
+ source_map_symbolicator:
+ source_map_store: file_store
+ local_source_maps:
+ path: /sourcemaps
+ cache_dir: /var/cache/symbolicator
+ cache_max_mb: 2048
+ batch:
+
+exporters:
+ otlphttp:
+ endpoint: https://otel.example.com
+ headers:
+ Authorization: Bearer <token>
+
+service:
+ pipelines:
+ traces:
+ receivers: [otlp]
+ processors: [source_map_symbolicator, batch]
+ exporters: [otlphttp]
+ logs:
+ receivers: [otlp]
+ processors: [source_map_symbolicator, batch]
+ exporters: [otlphttp]
+```
+
+To forward to Traceway, point the exporter at your Traceway server's OTLP base path and use a project token:
+
+```yaml
+exporters:
+ otlphttp:
+ endpoint: https://traceway.example.com/api/otel
+ headers:
+ Authorization: Bearer <project token>
+```
+
+### Run it
+
+```bash
+./dist/otelcol-symbolicator --config collector.yaml
+```
+
+</Steps>
+
+## Registering the Factory Programmatically
+
+When you assemble a collector in Go instead of using the builder, register the factory like any other processor factory:
+
+```go
+import "github.com/tracewayapp/traceway/backend/app/symbolicator/otelprocessor"
+
+factory := otelprocessor.NewFactory()
+factories.Processors[factory.Type()] = factory
+```
+
+The component type is `source_map_symbolicator`, with traces and logs support at alpha stability.
+
+## Populating the Source Map Store
+
+The store holds your build output as-is: minified bundles next to their `.map` files, addressed by URL basename. Upload (or mount) the files your bundler emitted; no manifest or renaming is needed.
+
+1. A frame URL like `https://cdn.example.com/assets/app-3f9c.js:1:13337` is looked up in the store as `app-3f9c.js`.
+2. The bundle's `//# sourceMappingURL=` comment is followed to find the map (inline `data:` URIs are supported).
+3. Both compile into one resolver, cached thereafter.
+
+Content-hashed filenames from different deploys coexist naturally. For stable filenames (`app.js`), either accept last-upload-wins or set the `app.debug.source_map_uuid` resource attribute in your web SDK; the processor then prefixes store lookups with that uuid, isolating each build under its own directory:
+
+```
+/sourcemaps/
+ 9c1d2b3a-.../(app.js, app.js.map) # build A
+ 4e5f6a7b-.../(app.js, app.js.map) # build B
+```
+
+Three store backends are built in:
+
+```yaml
+# Local directory (default)
+source_map_store: file_store
+local_source_maps:
+ path: /sourcemaps
+
+# S3, credentials from the default AWS chain
+source_map_store: s3_store
+s3_source_maps:
+ region: eu-central-1
+ bucket: my-sourcemaps
+ prefix: production
+
+# GCS, credentials from Application Default Credentials
+source_map_store: gcs_store
+gcs_source_maps:
+ bucket: my-sourcemaps
+ prefix: production
+```
+
+## What the Processor Reads and Writes
+
+For each span, span event, or log record carrying an exception:
+
+| Attribute | Direction | Meaning |
+| --------- | --------- | ------- |
+| `exception.stacktrace` | read + rewritten | Raw stack in, symbolicated stack out |
+| `exception.structured_stacktrace.{urls,functions,lines,columns}` | read + rewritten | Structured parallel arrays, preferred over string parsing when present |
+| `exception.type`, `exception.message` | read | Used for the rewritten header line |
+| `app.debug.source_map_uuid` | read (resource) | Optional store key prefix per build |
+| `exception.stacktrace.original` and `.original` array variants | written | Originals, kept when `preserve_stack_trace: true` |
+| `exception.symbolicator.failed` | written | `true` when any frame failed |
+| `exception.symbolicator.error` | written | First failure, with a count hint when several frames failed |
+| `exception.symbolicator.parsing_method` | written | `structured_stacktrace_attributes` or `processor_parsed` |
+| `traceway.processor_type`, `traceway.processor_version` | written | Provenance stamps |
+
+Raw string parsing handles the stack formats browsers produce: V8 (including `async`, `new`, `[as alias]`, and `eval` frames) and Firefox.
+
+## Configuration Reference
+
+| Key | Default | Description |
+| --- | ------- | ----------- |
+| `source_map_store` | `file_store` | `file_store`, `s3_store`, or `gcs_store` |
+| `local_source_maps.path` | `.` | Root directory for `file_store` |
+| `s3_source_maps.region` / `.bucket` / `.prefix` | | S3 location |
+| `gcs_source_maps.bucket` / `.prefix` | | GCS location |
+| `timeout` | `5s` | Per-fetch budget for store reads |
+| `cache_dir` | `""` | Directory for the `.tw` disk cache; empty disables the disk tier |
+| `cache_max_mb` | `2048` | Byte cap for the disk cache, LRU-evicted |
+| `cache_max_disk_pct` | `0` | Cap as a percentage of the cache directory's filesystem; when both caps are set, the smaller wins |
+| `source_map_cache_size` | `128` | Max resolvers held in memory (cheap mmap handles when the disk tier is on) |
+| `preserve_stack_trace` | `true` | Keep originals under the `.original` keys |
+| `build_uuid_attribute_key` | `app.debug.source_map_uuid` | Resource attribute used as a store key prefix |
+| `language_attribute_key` | `telemetry.sdk.language` | Attribute checked against `allowed_languages` |
+| `allowed_languages` | `[]` | When set, only records with a matching language are processed |
+
+Every attribute key from the table above is remappable (`stack_trace_attribute_key`, `urls_attribute_key`, `symbolicator_failure_attribute_key`, and so on), with the same configuration keys and defaults as Honeycomb's processor.
+
+Failed fetches are negative-cached for one minute per bundle, so a missing upload cannot turn an error storm into a store-request storm.
+
+## Sizing the Cache
+
+- `cache_dir` unset: every resolver is rebuilt from the store on demand and held only in the in-memory LRU (`source_map_cache_size` entries). Fine for small corpora.
+- `cache_dir` set: each map+bundle compiles to a `.tw` file once; subsequent loads are mmaps measured in microseconds. Budget with `cache_max_mb`, or `cache_max_disk_pct: 50` to track the filesystem size. `.tw` files are typically a small multiple of the map's `mappings` field, far smaller than the parsed-in-RAM representation.
+
+For the full engine internals (resolver format, scope analysis, cache policy), see [Symbolication (JS)](/learn/symbolication-js).
diff --git a/docs/pages/learn/symbolication-js.mdx b/docs/pages/learn/symbolication-js.mdx
index 7a032e67..3769b25b 100644
--- a/docs/pages/learn/symbolication-js.mdx
+++ b/docs/pages/learn/symbolication-js.mdx
@@ -1,11 +1,5 @@
# Symbolication (JS)
-import { Callout } from "nextra/components";
-
-<Callout type="info">
- **This is actively being worked on.** If you have ideas or suggestions for how symbolication should evolve, we want to hear them: reach out on [Discord](https://discord.gg/RZq9NT62nc) or open an issue on [GitHub](https://github.com/tracewayapp/traceway).
-</Callout>
-
Symbolication is the process of translating minified production stack traces back into the original source locations your team actually wrote. Browsers report errors against the shipped bundle, so without symbolication an exception looks like this:
```
@@ -28,11 +22,13 @@ handleClick()
This page explains exactly how that translation works today, what is cached and when, how the pipeline is observable through metrics, where the current limits are, and how we verify the output. For how to upload source maps in the first place, see [Source Maps](/client/js-sdk/sourcemap-upload).
+The engine described here is also usable outside Traceway's ingest: as an importable Go package ([Symbolicator as a Library](/learn/symbolicator-library)) and as a standalone OpenTelemetry Collector processor ([Collector Symbolicator](/learn/collector-symbolicator)).
+
## When Symbolication Runs
Symbolication happens **once, at ingest**, inside `POST /api/report`:
-1. The report arrives from the JS SDK. If the project is a JS framework, each frame is resolved directly against object storage at `sourcemaps/{projectId}/{filename}`: the map is addressed by the frame's filename, with no version and no database lookup. The most recent upload of each filename wins.
+1. The report arrives from the JS SDK. If the project is a JS framework, each frame is resolved directly against object storage, with no version and no database lookup. When the exception carries a [debug ID](/client/js-sdk/debug-ids) for the frame's file, the map is addressed at `sourcemaps/{projectId}/by-debug-id/{debugId}.js.map`; otherwise it is addressed by the frame's filename at `sourcemaps/{projectId}/{filename}.map`, where the most recent upload of each filename wins.
2. Each stack trace in the report is resolved frame by frame.
3. The **resolved** trace is what gets hashed for grouping and stored in ClickHouse.
@@ -63,7 +59,9 @@ For each location line, in order:
### 1. Find the right source map
-The frame's file name is reduced to its basename (any query string or fragment stripped first), and the map is addressed in object storage at a deterministic key:
+**By debug ID first.** If the exception payload carries a `debugIds` entry for the frame's file (injected at build time by [`@tracewayapp/bundler-plugin`](/client/js-sdk/debug-ids)), the map is addressed at `sourcemaps/{projectId}/by-debug-id/{debugId}.js.map` and the bundle at the same key without `.map`. This is content-addressed matching: the ID was embedded into the bundle and its map by the build, so the frame can never resolve against a map from a different build, regardless of filenames, CDNs, or concurrent deploys. If no artifact with that debug ID was uploaded, resolution falls back to filename matching below.
+
+**By filename otherwise.** The frame's file name is reduced to its basename (any query string or fragment stripped first), and the map is addressed in object storage at a deterministic key:
| Frame file | Storage key |
|---|---|
@@ -77,7 +75,7 @@ No map in storage: the line passes through unchanged, and that filename enters a
### 2. Get the resolver
-The parsed lookup structure comes from the in-memory cache described below. First use pays a storage read plus a parse; everything after is a memory lookup.
+The parsed lookup structure comes from the in-memory cache described below, optionally backed by a disk tier of precompiled [`.tw` files](#the-tw-resolver-format). First use pays a storage read plus a parse (or a memory-mapped `.tw` open, which skips the parse); everything after is a memory lookup.
### 3. Look up the position
@@ -175,7 +173,7 @@ One consequence to be aware of: a trace that fails symbolication (storage outage
## What Is Cached, How, and When
-Source maps for real applications are large (a 20 MB `.map` is unremarkable), and the compiled lookup structure is what actually serves frames. Traceway keeps **one in-memory cache** of built resolvers, keyed by the map's storage key.
+Source maps for real applications are large (a 20 MB `.map` is unremarkable), and the compiled lookup structure is what actually serves frames. Traceway keeps **one in-memory cache** of built resolvers, keyed by the map's storage key, optionally backed by a **disk tier** of precompiled [`.tw` files](#the-tw-resolver-format) (see [Cache backends](#cache-backends-memory-and-disk)).
### What a cache entry contains
@@ -193,7 +191,7 @@ Everything else is discarded: the raw map and bundle bytes, `sourcesContent`, th
| Property | Value |
|---|---|
-| Keying | map storage key, one entry per bundle filename per project |
+| Keying | map storage key: one entry per bundle filename per project, plus one per debug ID for [debug-ID artifacts](/client/js-sdk/debug-ids) |
| Capacity | `SOURCEMAP_CACHE_MAX_ENTRIES` (default 200) and `SOURCEMAP_CACHE_MAX_BYTES_MB` (default 500, estimated resolver size) |
| Eviction | least recently used, whenever either cap is exceeded |
| Loading | deduplicated (singleflight): concurrent requests for the same map share one storage read and one build |
@@ -223,6 +221,87 @@ If the map does not exist, the read times out, storage errors, or the map fails
- Within a single trace, a failed map is attempted **once**, not once per frame, so a 50-frame trace cannot stack fifty timeouts.
- Traceway self-reports the failure into its own monitoring project, throttled to one exception per minute with a count of suppressed occurrences.
+## Cache Backends: Memory and Disk
+
+The in-memory cache described above is the default and always present. In both modes, a memory miss first checks object storage for a precompiled [`.tw` resolver](#the-tw-resolver-format) before rebuilding, and every rebuild writes the finished `.tw` back to object storage, so a given map is rebuilt once cluster-wide and every other instance (and every restart) downloads the compiled artifact instead of re-parsing. `SOURCEMAP_CACHE_TYPE=disk` adds a local cache of those `.tw` files in between, which changes what a *memory miss* costs. The full lookup order:
+
+1. **In-memory LRU.** Both modes. A hit is a pure memory lookup.
+2. **Local `.tw` file** under `SOURCEMAP_DISK_CACHE_PATH` (disk mode only). The file is memory-mapped and the resolver opens with validation only; on little-endian hosts (amd64, arm64) the token table is used directly from the mapped pages with zero copying or decoding. Counted in `disk.hits`.
+3. **`.tw` from object storage.** Both modes. In disk mode it is written to the local directory (atomically, via temp file and rename) and then opened as in step 2; in memory mode it is opened on the heap. Counted in `store_hits`.
+4. **Full rebuild** from the `.map` and bundle. Both modes. The finished resolver is serialized to `.tw` and written back to object storage (and, in disk mode, to the local directory). Counted in `builds`.
+
+The local directory is itself an LRU bounded by bytes (`SOURCEMAP_DISK_CACHE_MAX_MB`, default 2048): least recently used `.tw` files are deleted when the cap is exceeded. The directory is scanned at startup, so the cache survives restarts with its recency order approximated from file mtimes; mtimes are refreshed on use at most once per 10 minutes to keep that approximation current without constant metadata writes. A `.tw` file that fails validation (truncated, corrupt, or written by an older format version) is deleted and rebuilt from the original artifacts; this is a recovery path, not an error.
+
+Uploads warm the cache proactively in both modes: after `/api/sourcemaps/upload` stores the files, a background task deletes the stale `.tw` from object storage, evicts the cached resolver, and rebuilds it, so the first exception after a deploy finds a hot cache instead of paying the build.
+
+When to enable it: the memory-only default is right for most deployments. The disk tier pays off when the set of actively-resolving maps is much larger than the memory cap (high eviction traffic): a re-entry becomes a local mmap open measured in microseconds instead of an object storage download, and the token tables live in page cache rather than on the process heap, so resident memory tracks the hot set instead of the cap.
+
+## The `.tw` Resolver Format
+
+Building a resolver is the expensive part of symbolication: parse the `.map` JSON, decode the VLQ `mappings`, parse the bundle, run scope analysis, pre-resolve every enclosing function name. `.tw` is the binary serialization of the *finished* resolver, so opening one skips all of that. It is designed to be memory-mapped and used in place.
+
+All integers are little-endian. The layout:
+
+```
+offset size field
+0 4 magic "TWSM"
+4 4 format version (currently 1)
+8 4 token count (N)
+12 4 file name count (F)
+16 4 function name count (G)
+20 4 reserved (0)
+24 24 × N token table
+... 4 × (F+1) file name offsets
+... var file name blob (concatenated UTF-8)
+... 4 × (G+1) function name offsets
+... var function name blob (concatenated UTF-8)
+```
+
+**Token table.** One 24-byte record per source map mapping, six 32-bit fields each: generated line, generated column, original line, original column, file name index, function name index. Lines and columns are stored exactly as the resolver uses them (original line/column already 1-based, generated 0-based), so no arithmetic happens at lookup time. The two indices are signed; `-1` means "no original file" (an unmapped segment) or "no enclosing function". Tokens are sorted by generated position, which is what makes a frame lookup a single binary search over the mapped file. Function names being materialized per token is the key property: scope analysis ran once, at build time, and its output is just an index into the name table.
+
+**String tables.** Each table is `count + 1` offsets followed by one concatenated UTF-8 blob; string `i` spans `blob[offsets[i]:offsets[i+1]]`. Offsets must be monotonically non-decreasing. The names are interned, so a file referenced by ten thousand tokens is stored once.
+
+**Opening.** `OpenTW` validates and does nothing else: magic and version match, every section lies within the file, offsets are monotonic, every token index is in range, and no trailing bytes follow the last table. On a little-endian host where the in-memory token struct matches the on-disk record layout (true on amd64 and arm64), the token table is reinterpreted directly from the mapped bytes: zero copies, zero decoding, and the OS page cache shares it across anything else mapping the same file. The only allocations are the interned strings. On other hosts the tokens are decoded record by record into a fresh slice.
+
+**Versioning.** The format is versioned by a single integer with no migration path, deliberately: a `.tw` is a cache artifact, never the source of truth. Bumping the version makes every existing file fail validation, after which each is lazily rebuilt from its `.map` and bundle.
+
+**Placement.** A `.tw` lives at the map's storage key with the `.map` suffix replaced by `.tw`: `sourcemaps/{projectId}/app.bundle.js.map` compiles to `sourcemaps/{projectId}/app.bundle.js.tw`, and debug-ID artifacts to `sourcemaps/{projectId}/by-debug-id/{debugId}.js.tw`. The local disk cache mirrors the same relative paths under `SOURCEMAP_DISK_CACHE_PATH`.
+
+## Bundle Parsers
+
+Function name resolution (the scope analysis above) requires parsing the minified bundle into an AST. Two parsers are available:
+
+| Parser | Availability | Implementation |
+|---|---|---|
+| `goja` | always (default) | pure Go, via the [goja](https://github.com/dop251/goja) parser |
+| `oxc` | opt-in build | Rust, via the [oxc](https://oxc.rs) parser behind a small C FFI shim |
+
+`goja` ships in every build and needs nothing. It parses the bundle as a script and, when that fails on ESM syntax, neutralizes the module syntax and retries.
+
+`oxc` is substantially faster on large bundles but requires a Rust toolchain at *build* time (the resulting binary is self-contained):
+
+```bash
+./scripts/build-oxc-shim.sh # cargo build --release of the FFI shim
+cd backend && go build -tags oxc . # links the static library in
+```
+
+Select the parser at runtime with `SYMBOLICATOR_PARSER=oxc` (or `goja`). Selecting a parser that was not compiled in fails startup with the list of available parsers, rather than silently falling back.
+
+The parser choice affects **build speed only, never output**: both parsers must produce identical scope transitions, and a parity test asserts oxc against goja across the fixture suite. Since parsing happens only when a resolver is built (and the result is cached, including into `.tw`), the parser matters most for deployments with heavy map churn or with the disk cache disabled. `scripts/benchmark-symbolicator.sh` benchmarks the two side by side.
+
+## Configuration Reference
+
+| Variable | Default | Description |
+|----------|---------|-------------|
+| `SYMBOLICATOR_PARSER` | `goja` | Bundle parser for function name resolution: `goja` or `oxc` (the latter only in `-tags oxc` builds) |
+| `SOURCEMAP_CACHE_TYPE` | `memory` | `memory` for the in-memory LRU only, `disk` to add the local `.tw` tier |
+| `SOURCEMAP_DISK_CACHE_PATH` | `./twcache` | Directory for local `.tw` files (disk mode only) |
+| `SOURCEMAP_DISK_CACHE_MAX_MB` | `2048` | Byte cap for the local `.tw` directory, LRU-evicted (disk mode only) |
+| `SOURCEMAP_CACHE_MAX_ENTRIES` | `200` | Max built resolvers held in memory |
+| `SOURCEMAP_CACHE_MAX_BYTES_MB` | `500` | Max estimated in-memory size of all resolvers |
+
+See [Capacity & Self-Monitoring](/server/capacity-monitoring) for sizing guidance.
+
## Observability
The backend self-reports cache metrics every 30 seconds (see [Capacity Monitoring](/server/capacity-monitoring) for the full operations view):
@@ -239,6 +318,11 @@ The backend self-reports cache metrics every 30 seconds (see [Capacity Monitorin
| `traceway.sourcemap.not_found.delta` | lookups that found no uploaded map for the frame's filename since the last tick |
| `traceway.sourcemap.negative_hits.delta` | frame lookups skipped by an active cooldown since the last tick |
| `traceway.sourcemap.parse_ms` | duration of the most recent resolver build |
+| `traceway.sourcemap.store_hits.delta` | memory misses served by a `.tw` fetched from object storage since the last tick (both cache modes) |
+| `traceway.sourcemap.builds.delta` | memory misses that required a full rebuild from `.map` + bundle since the last tick (both cache modes) |
+| `traceway.sourcemap.disk.entries` / `disk.bytes` | local `.tw` files currently cached and their total size (disk tier only) |
+| `traceway.sourcemap.disk.hits.delta` | memory misses served by a local `.tw` file since the last tick (disk tier only) |
+| `traceway.sourcemap.disk.evictions.delta` | local `.tw` files evicted by the byte cap since the last tick (disk tier only) |
What healthy looks like: `misses.delta` near zero in steady state (every miss is a storage read plus a rebuild), `load_failures.delta` at zero (anything above zero means minified traces are reaching your issues), and `bytes` comfortably under the cap. A useful alert is `load_failures.delta` max greater than 0 over 5 minutes.
@@ -250,7 +334,7 @@ Honest list, in rough order of impact:
1. **Function names require the bundle.** The current upload CLI sends it automatically, but map-only uploads (older CLI versions, or maps whose sibling bundle was not in the build output) resolve locations without names.
2. **Symbolication is ingest-only.** Maps uploaded after an event arrived do not improve that event.
-3. **Maps are matched by basename.** Two bundles with the same filename in different directories collide, and the most recent upload wins. Content-hashed bundle names (the default in Vite, Next, Angular, and most bundlers) avoid this entirely; stable names like `app.js` shared across concurrently deployed versions resolve against the latest upload only.
+3. **Filename matching collides on stable names.** Without debug IDs, two bundles with the same filename in different directories collide, and the most recent upload wins. Content-hashed bundle names (the default in Vite, Next, Angular, and most bundlers) avoid this in practice, and [debug IDs](/client/js-sdk/debug-ids) eliminate it entirely by addressing maps by build content instead of by name.
4. **The 5 second load budget trades completeness for latency.** A map that takes longer to fetch produces an unsymbolicated trace (recorded in `load_failures.delta`) rather than a slow ingest.
5. **Failure cooldowns can delay recovery on other instances.** Uploading a map clears its cooldown instantly on the instance that handled the upload; in multi-instance deployments, the rest retry within their remaining cooldown, at most 15 minutes.
6. **Outages split grouping transiently.** Unsymbolicated and symbolicated versions of the same error hash differently.
@@ -264,6 +348,8 @@ The resolver is tested for parity against [getsentry/symbolic](https://github.co
All frames match symbolic on **location**. With scope analysis, names now match too for frames inside a function, including the cases the old text-scanning heuristic got wrong (preact's `createElement` and `assign` among them). The remaining name gap is module-level code, where symbolic reports `<global>` and Traceway reports no name (limitation 9 above).
+Two more invariants are tested directly: the `.tw` format round-trips (a resolver serialized and reopened answers every lookup identically, including from a memory-mapped file), and the `oxc` parser produces scope output identical to `goja` across the fixture suite, so the parser choice can never change symbolication results.
+
## Related Pages
- [Source Maps](/client/js-sdk/sourcemap-upload): uploading maps from CI
diff --git a/docs/pages/learn/symbolicator-library.mdx b/docs/pages/learn/symbolicator-library.mdx
new file mode 100644
index 00000000..328cdb76
--- /dev/null
+++ b/docs/pages/learn/symbolicator-library.mdx
@@ -0,0 +1,201 @@
+# Symbolicator as a Go Library
+
+import { Callout } from "nextra/components";
+
+Traceway's JS symbolicator is an importable Go library. Everything the ingest pipeline uses to turn minified stack traces back into source locations (source map parsing, bundle scope analysis for function names, the `.tw` resolver format, and the mmap-backed disk cache) lives in public packages of the backend module, so you can use the engine in your own tooling without running Traceway at all.
+
+It is pure Go by default: no cgo, no C libraries, works in a `scratch` image.
+
+If you want this functionality inside an OpenTelemetry Collector pipeline instead of your own code, use the prebuilt [collector processor](/learn/collector-symbolicator). For how the engine works internally, see [Symbolication (JS)](/learn/symbolication-js).
+
+## Installation
+
+```bash
+go get github.com/tracewayapp/traceway/backend@latest
+```
+
+<Callout type="info">
+ The symbolicator packages first ship in backend release `v1.8.0`, so
+ `@latest` resolves to a version that has them. The import paths below are
+ stable public packages; everything under `backend/app/symbolicator` is
+ importable.
+</Callout>
+
+| Package | Import path | Purpose |
+| ------- | ----------- | ------- |
+| `symbolicator` | `github.com/tracewayapp/traceway/backend/app/symbolicator` | The resolver: source map + bundle in, original locations out |
+| `jsstack` | `github.com/tracewayapp/traceway/backend/app/symbolicator/jsstack` | Browser stack trace parsing (V8, Firefox, Safari formats) |
+| `scopes` | `github.com/tracewayapp/traceway/backend/app/symbolicator/scopes` | Bundle parser selection (goja default, oxc optional) |
+| `twcache` | `github.com/tracewayapp/traceway/backend/app/symbolicator/twcache` | Mmap-backed disk cache of compiled `.tw` resolvers |
+| `otelprocessor` | `github.com/tracewayapp/traceway/backend/app/symbolicator/otelprocessor` | The [OTel Collector processor](/learn/collector-symbolicator) wrapping the engine |
+
+## Resolving a Single Frame
+
+Build a resolver from a source map and (optionally) its minified bundle, then look positions up. The bundle is what enables function names through scope analysis; pass `nil` and you still get files, lines, and columns.
+
+```go
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator"
+)
+
+func main() {
+ mapBytes, err := os.ReadFile("dist/app.min.js.map")
+ if err != nil {
+ panic(err)
+ }
+ bundleBytes, _ := os.ReadFile("dist/app.min.js") // optional, enables function names
+
+ resolver, err := symbolicator.NewResolver(mapBytes, bundleBytes)
+ if err != nil {
+ panic(err)
+ }
+
+ // Lookup takes zero-based generated positions. A browser frame like
+ // "app.min.js:1:13337" is line 0, column 13336 here.
+ frame, ok := resolver.Lookup(0, 13336)
+ if !ok {
+ fmt.Println("no mapping at this position")
+ return
+ }
+ fmt.Printf("%s:%d:%d", frame.File, frame.Line, frame.Col) // src/render.ts:42:7
+ if frame.Fn != "" {
+ fmt.Printf(" in %s()", frame.Fn)
+ }
+ fmt.Println()
+}
+```
+
+The coordinate conventions, precisely:
+
+- `Lookup(genLine, genCol uint32)` takes **zero-based** positions, matching the source map spec's internal encoding.
+- Browser stack traces print **one-based** positions, so subtract 1 from each before calling `Lookup`.
+- The returned `StackTraceFrame` carries **one-based** `Line` and `Col`, ready to print.
+- `Fn` is the enclosing original function name, or `""` when the bundle was not provided or the position is not inside a known scope.
+
+## Symbolicating a Whole Stack Trace
+
+`jsstack.ParseFrames` parses the raw `error.stack` formats browsers actually produce: V8 (`at fn (url:line:col)`, including `async`, `new`, `[as alias]`, and `eval` frames), Firefox, and Safari (`fn@url:line:col`). It returns frames with the one-based positions as printed.
+
+```go
+package main
+
+import (
+ "fmt"
+
+ "github.com/tracewayapp/traceway/backend/app/symbolicator"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/jsstack"
+)
+
+func symbolicateStack(rawStack string, resolverFor func(url string) *symbolicator.Resolver) {
+ for _, f := range jsstack.ParseFrames(rawStack) {
+ r := resolverFor(f.URL)
+ if r == nil {
+ continue
+ }
+ frame, ok := r.Lookup(f.Line-1, f.Col-1)
+ if !ok {
+ continue
+ }
+ fmt.Printf("%s at %s:%d:%d\n", f.Function, frame.File, frame.Line, frame.Col)
+ }
+}
+```
+
+`resolverFor` is yours to implement: typically a map from bundle URL basename to the resolver built from that bundle's artifacts.
+
+If you need Traceway's canonical frame format (function name on one line, ` file:line:col` on the next, the format described in [Symbolication (JS)](/learn/symbolication-js#the-frame-format)), use `jsstack.Canonicalize`:
+
+```go
+canonical, converted := jsstack.Canonicalize(rawStack)
+```
+
+It returns the input unchanged (`converted == false`) when the trace is not a recognizable browser stack, so it is safe to call on arbitrary text, including Go panics and already-canonical traces.
+
+## Caching Compiled Resolvers: the `.tw` Format
+
+Parsing a large source map and analyzing its bundle takes time you do not want to spend twice. A resolver serializes to Traceway's compact binary `.tw` format ([format details](/learn/symbolication-js#the-tw-resolver-format)) and loads back without reparsing anything:
+
+```go
+data := resolver.MarshalTW()
+// persist data wherever you like, then later:
+resolver2, err := symbolicator.OpenTW(data)
+```
+
+`OpenTW` validates the input fully and, when the byte slice is memory-mapped, resolves lookups directly against the mapping with zero copying. That is exactly what `twcache` does for you:
+
+```go
+package main
+
+import (
+ "github.com/tracewayapp/traceway/backend/app/symbolicator"
+ "github.com/tracewayapp/traceway/backend/app/symbolicator/twcache"
+)
+
+// 2 GiB LRU of .tw files under /var/cache/tw; least recently used evicted first.
+func newCache() (*twcache.Cache, error) {
+ return twcache.New("/var/cache/tw", 2<<30, nil)
+}
+
+func cachedResolver(cache *twcache.Cache, name string, mapBytes, bundleBytes []byte) (*symbolicator.Resolver, error) {
+ if r, err := cache.Open(name); err == nil {
+ return r, nil // mmap hit
+ }
+ built, err := symbolicator.NewResolver(mapBytes, bundleBytes)
+ if err != nil {
+ return nil, err
+ }
+ if r, err := cache.Write(name, built.MarshalTW()); err == nil {
+ return r, nil // persisted and mmapped
+ }
+ return built, nil // disk failed, serve the in-memory resolver
+}
+```
+
+What `twcache` handles for you:
+
+- Names are slash-separated paths relative to the cache directory and must stay inside it; subdirectories are fine (`project-a/app.min.js.tw`).
+- Writes are atomic (temp file + rename), so a crash never leaves a partial `.tw` behind.
+- Corrupt files are deleted on `Open` so your rebuild path replaces them.
+- The LRU survives restarts: the directory is scanned on `New` and ordered by file mtime.
+- `Remove(name)` invalidates after a re-deploy; `Stats()` reports entries, bytes, hits, and evictions.
+- Resolvers stay valid after eviction deletes their file; the mapping is released only when the resolver is garbage collected.
+
+`resolver.ApproxSize()` reports the retained footprint if you want to bound an in-memory cache on top.
+
+## Choosing the Bundle Parser
+
+Function-name resolution parses the minified bundle into scopes. Two parsers produce identical output (a parity test asserts this across the fixture suite, see [Bundle Parsers](/learn/symbolication-js#bundle-parsers)):
+
+- **goja** (default): pure Go, zero setup.
+- **oxc**: a Rust parser behind cgo, several times faster on large bundles. The `-tags oxc` build links a static library from the `scopes` package's own source directory (`oxc-shim/target/release/liboxc_shim.a`), which the read-only module cache that `go get` populates never contains. To enable it, build against a writable checkout: clone the repo, run `scripts/build-oxc-shim.sh` once, add a `replace github.com/tracewayapp/traceway/backend => /path/to/traceway/backend` directive to your `go.mod` (or vendor the module and build the shim inside `vendor/`), then compile with `-tags oxc`.
+
+```go
+import "github.com/tracewayapp/traceway/backend/app/symbolicator/scopes"
+
+if err := scopes.SetParser("oxc"); err != nil {
+ // not compiled in; still on goja
+}
+```
+
+`scopes.AvailableParsers()` lists what your binary was built with. The parser affects resolver build speed only, never output, so `.tw` files are interchangeable between the two.
+
+## API Summary
+
+| Symbol | Signature | Notes |
+| ------ | --------- | ----- |
+| `symbolicator.NewResolver` | `(sourceMap, bundle []byte) (*Resolver, error)` | `bundle` may be `nil` (no function names) |
+| `(*Resolver).Lookup` | `(genLine, genCol uint32) (StackTraceFrame, bool)` | zero-based in, one-based out |
+| `symbolicator.StackTraceFrame` | `{File string; Line, Col uint32; Fn string}` | `Fn` may be empty |
+| `(*Resolver).MarshalTW` | `() []byte` | serialize to `.tw` |
+| `symbolicator.OpenTW` | `(data []byte) (*Resolver, error)` | validates fully; zero-copy over mmapped data |
+| `(*Resolver).ApproxSize` | `() int64` | retained footprint for cache accounting |
+| `jsstack.ParseFrames` | `(trace string) []Frame` | `Frame{Function, URL string; Line, Col uint32}`, one-based |
+| `jsstack.Canonicalize` | `(trace string) (string, bool)` | passthrough on non-browser input |
+| `scopes.SetParser` | `(name string) error` | `"goja"` or `"oxc"` (with `-tags oxc`) |
+| `twcache.New` | `(dir string, maxBytes int64, warn func(error)) (*Cache, error)` | scans `dir`, LRU bounded by `maxBytes` |
+| `(*twcache.Cache).Open` / `.Write` / `.Remove` / `.Stats` | | mmap-backed `.tw` files by relative name |
diff --git a/docs/pages/server/capacity-monitoring.mdx b/docs/pages/server/capacity-monitoring.mdx
index ed75c804..2523aa64 100644
--- a/docs/pages/server/capacity-monitoring.mdx
+++ b/docs/pages/server/capacity-monitoring.mdx
@@ -83,6 +83,9 @@ Not emitted in SQLite mode.
| `traceway.sourcemap.not_found.delta` | Lookups since the last tick where no map was uploaded for the frame's filename; sustained nonzero for a project that should symbolicate usually means a missing CI upload step |
| `traceway.sourcemap.negative_hits.delta` | Frame lookups skipped by an active cooldown since the last tick; high values are normal for JS projects that do not upload maps |
| `traceway.sourcemap.parse_ms` | Duration of the most recent resolver build |
+| `traceway.sourcemap.store_hits.delta` / `builds.delta` | Memory misses served by a precompiled `.tw` from object storage vs. full rebuilds from `.map` + bundle; reported in both cache modes, since the `.tw` store tier is always active |
+| `traceway.sourcemap.disk.entries` / `disk.bytes` | Local `.tw` files cached on disk and their total size (only reported when `SOURCEMAP_CACHE_TYPE=disk`) |
+| `traceway.sourcemap.disk.hits.delta` / `disk.evictions.delta` | Memory misses served by a local `.tw` file, and local files evicted by the byte cap, since the last tick |
## Source map cache sizing
@@ -92,16 +95,23 @@ Lookups that find no map (or fail to load one) are negative-cached per filename
Upgrading from 1.7? The flat storage layout is new in 1.8 and existing maps are migrated automatically at startup; see [Upgrading to 1.8](/server/upgrade-1-8).
+In both modes, a memory miss first tries a precompiled `.tw` resolver from object storage before re-parsing the map and bundle, and rebuilds happen once cluster-wide because the resulting `.tw` is written back to storage. Optionally, `SOURCEMAP_CACHE_TYPE=disk` adds a local disk tier of those `.tw` files between the memory cache and object storage, so a miss becomes a local mmap open instead of a storage download. See [the `.tw` format](/learn/symbolication-js#the-tw-resolver-format) and [cache backends](/learn/symbolication-js#cache-backends-memory-and-disk) for the mechanics.
+
| Variable | Default | Description |
|----------|---------|-------------|
| `SOURCEMAP_CACHE_MAX_ENTRIES` | `200` | Max built resolvers kept in memory |
| `SOURCEMAP_CACHE_MAX_BYTES_MB` | `500` | Max estimated in-memory size of all resolvers |
+| `SOURCEMAP_CACHE_TYPE` | `memory` | `disk` adds the local `.tw` tier |
+| `SOURCEMAP_DISK_CACHE_PATH` | `./twcache` | Directory for local `.tw` files (disk mode only) |
+| `SOURCEMAP_DISK_CACHE_MAX_MB` | `2048` | Byte cap for the local `.tw` directory, LRU-evicted (disk mode only) |
+| `SYMBOLICATOR_PARSER` | `goja` | Bundle parser for function name resolution; `oxc` is faster on large bundles but requires a `-tags oxc` build (see [Bundle parsers](/learn/symbolication-js#bundle-parsers)) |
Sizing guidance:
- **Small box (1-2 GB RAM):** `SOURCEMAP_CACHE_MAX_BYTES_MB=100`.
- **Plenty of RAM, many active source maps:** raise `SOURCEMAP_CACHE_MAX_BYTES_MB` until `traceway.sourcemap.misses.delta` stays near zero in steady state; every miss is a storage read plus a rebuild, which burns CPU and briefly doubles that map's memory footprint.
-- Watch `traceway.proc.rss_mb` against your host RAM; if it climbs during exception ingest with stack traces, the source map cache is the usual suspect.
+- **More active maps than the memory cap can hold, or multiple backend instances:** enable the disk tier. Watch `traceway.sourcemap.builds.delta` (full rebuilds) shrink toward zero while `disk.hits.delta` and `store_hits.delta` absorb the misses; give `SOURCEMAP_DISK_CACHE_MAX_MB` enough room that `disk.evictions.delta` stays near zero.
+- Watch `traceway.proc.rss_mb` against your host RAM; if it climbs during exception ingest with stack traces, the source map cache is the usual suspect. With the disk tier, `.tw` token tables are memory-mapped and show up as page cache rather than process heap.
## Alerting on these metrics
diff --git a/examples/devtesting-embedded/go.mod b/examples/devtesting-embedded/go.mod
index 96455a10..1f17c539 100644
--- a/examples/devtesting-embedded/go.mod
+++ b/examples/devtesting-embedded/go.mod
@@ -7,13 +7,13 @@ require (
github.com/google/uuid v1.6.0
github.com/tracewayapp/traceway/backend v1.5.2
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.68.0
- go.opentelemetry.io/otel v1.43.0
+ go.opentelemetry.io/otel v1.44.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0
go.opentelemetry.io/otel/log v0.19.0
- go.opentelemetry.io/otel/sdk v1.43.0
+ go.opentelemetry.io/otel/sdk v1.44.0
go.opentelemetry.io/otel/sdk/log v0.19.0
- go.opentelemetry.io/otel/trace v1.43.0
+ go.opentelemetry.io/otel/trace v1.44.0
)
require (
@@ -77,7 +77,7 @@ require (
github.com/markbates/goth v1.82.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
- github.com/modern-go/reflect2 v1.0.2 // indirect
+ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/paulmach/orb v0.12.0 // indirect
github.com/pelletier/go-toml/v2 v2.3.0 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
@@ -92,23 +92,23 @@ require (
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 // indirect
- go.opentelemetry.io/otel/metric v1.43.0 // indirect
+ go.opentelemetry.io/otel/metric v1.44.0 // indirect
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
go.tracewayapp.com v1.0.3 // indirect
go.tracewayapp.com/tracewaygin v1.0.2 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.25.0 // indirect
- golang.org/x/crypto v0.49.0 // indirect
- golang.org/x/mod v0.33.0 // indirect
- golang.org/x/net v0.52.0 // indirect
- golang.org/x/oauth2 v0.35.0 // indirect
+ golang.org/x/crypto v0.51.0 // indirect
+ golang.org/x/mod v0.35.0 // indirect
+ golang.org/x/net v0.55.0 // indirect
+ golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sync v0.20.0 // indirect
- golang.org/x/sys v0.42.0 // indirect
- golang.org/x/text v0.35.0 // indirect
- golang.org/x/tools v0.42.0 // indirect
+ golang.org/x/sys v0.45.0 // indirect
+ golang.org/x/text v0.37.0 // indirect
+ golang.org/x/tools v0.44.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect
- google.golang.org/grpc v1.80.0 // indirect
+ google.golang.org/grpc v1.81.1 // indirect
google.golang.org/protobuf v1.36.11 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.36.3 // indirect
diff --git a/examples/devtesting-embedded/go.sum b/examples/devtesting-embedded/go.sum
index 112647ef..b1ba1322 100644
--- a/examples/devtesting-embedded/go.sum
+++ b/examples/devtesting-embedded/go.sum
@@ -191,8 +191,9 @@ github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/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/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8=
+github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
@@ -262,8 +263,8 @@ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6h
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0/go.mod h1:UHB22Z8QsdRDrnAtX4PntOl36ajSxcdUMt1sF7Y6E7Q=
go.opentelemetry.io/contrib/propagators/b3 v1.43.0 h1:CETqV3QLLPTy5yNrqyMr41VnAOOD4lsRved7n4QG00A=
go.opentelemetry.io/contrib/propagators/b3 v1.43.0/go.mod h1:Q4mCiCdziYzpNR0g+6UqVotAlCDZdzz6L8jwY4knOrw=
-go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
-go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
+go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
+go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0 h1:HIBTQ3VO5aupLKjC90JgMqpezVXwFuq6Ryjn0/izoag=
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0/go.mod h1:ji9vId85hMxqfvICA0Jt8JqEdrXaAkcpkI9HPXya0ro=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 h1:88Y4s2C8oTui1LGM6bTWkw0ICGcOLCAI5l6zsD1j20k=
@@ -274,18 +275,18 @@ go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0 h1:mS47AX77OtFfKG4
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0/go.mod h1:PJnsC41lAGncJlPUniSwM81gc80GkgWJWr3cu2nKEtU=
go.opentelemetry.io/otel/log v0.19.0 h1:KUZs/GOsw79TBBMfDWsXS+KZ4g2Ckzksd1ymzsIEbo4=
go.opentelemetry.io/otel/log v0.19.0/go.mod h1:5DQYeGmxVIr4n0/BcJvF4upsraHjg6vudJJpnkL6Ipk=
-go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
-go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
-go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
-go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg=
+go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
+go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
+go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58=
+go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0=
go.opentelemetry.io/otel/sdk/log v0.19.0 h1:scYVLqT22D2gqXItnWiocLUKGH9yvkkeql5dBDiXyko=
go.opentelemetry.io/otel/sdk/log v0.19.0/go.mod h1:vFBowwXGLlW9AvpuF7bMgnNI95LiW10szrOdvzBHlAg=
go.opentelemetry.io/otel/sdk/log/logtest v0.19.0 h1:BEbF7ZBB6qQloV/Ub1+3NQoOUnVtcGkU3XX4Ws3GQfk=
go.opentelemetry.io/otel/sdk/log/logtest v0.19.0/go.mod h1:Lua81/3yM0wOmoHTokLj9y9ADeA02v1naRrVrkAZuKk=
-go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw=
-go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A=
-go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
-go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
+go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI=
+go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA=
+go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
+go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g=
go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
@@ -300,21 +301,21 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
-golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4=
-golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA=
+golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
+golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
-golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
+golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
+golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
-golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
-golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ=
-golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
+golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
+golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
+golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
+golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -331,22 +332,22 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
-golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
+golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
+golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
-golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
-golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
+golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
+golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
-golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
-golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
+golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
+golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -357,8 +358,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 h1:
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:7QBABkRtR8z+TEnmXTqIqwJLlzrZKVfAUm7tY3yGv0M=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 h1:m8qni9SQFH0tJc1X0vmnpw/0t+AImlSvp30sEupozUg=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
-google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM=
-google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4=
+google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ=
+google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
diff --git a/scripts/benchmark-symbolicator.sh b/scripts/benchmark-symbolicator.sh
new file mode 100755
index 00000000..2b969f92
--- /dev/null
+++ b/scripts/benchmark-symbolicator.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT_DIR="$(dirname "$SCRIPT_DIR")"
+
+BENCHTIME="${BENCHTIME:-2s}"
+COUNT="${COUNT:-6}"
+OUT="${OUT:-$ROOT_DIR/symbolicator-bench.txt}"
+
+"$SCRIPT_DIR/build-oxc-shim.sh"
+
+cd "$ROOT_DIR/backend"
+
+go test -tags oxc ./app/symbolicator/... -count=1
+
+go test -tags oxc ./app/symbolicator/... \
+ -run '^$' \
+ -bench 'BenchmarkBundleParsers|BenchmarkNewResolver|BenchmarkOpenTW' \
+ -benchtime "$BENCHTIME" \
+ -count "$COUNT" \
+ -timeout 60m \
+ | tee "$OUT"
+
+echo
+echo "Results written to $OUT"
diff --git a/scripts/build-oxc-shim.sh b/scripts/build-oxc-shim.sh
new file mode 100755
index 00000000..5e177448
--- /dev/null
+++ b/scripts/build-oxc-shim.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT_DIR="$(dirname "$SCRIPT_DIR")"
+
+if ! command -v cargo &> /dev/null; then
+ echo "cargo not found - install Rust (https://rustup.rs) to build the oxc shim"
+ exit 1
+fi
+
+cd "$ROOT_DIR/backend/app/symbolicator/scopes/oxc-shim"
+cargo build --release
+
+echo "Built liboxc_shim.a"
+echo "Build the backend with the oxc parser enabled:"
+echo " cd backend && go build -tags oxc ."
+echo "Select it at runtime with SYMBOLICATOR_PARSER=oxc"