The only tool you need to know what is happening and how to fix it.
Go alertingexception-trackerissue-trackinglogsmetricsmonitoringobservability-platformopen-telemetryotelsession-replaytelemetrytraces
embeded progress
dduxb685c9a56cc3
diff --git a/backend/app/chdb/chdb.go b/backend/app/chdb/chdb.goindex dca9141f..b021f978 100644--- a/backend/app/chdb/chdb.go+++ b/backend/app/chdb/chdb.go@@ -1,10 +1,11 @@package chdbimport (+ "backend/app/config""context""crypto/tls"+ "database/sql""fmt"- "os""strings""time"@@ -20,23 +21,24 @@ type ChConn interface {}var Conn ChConn+var EmbeddedDB *sql.DBfunc Init() error {- chType := os.Getenv("CLICKHOUSE_TYPE")- if chType == "embedded" {+ if config.Config.ClickhouseType == "embedded" {return initEmbedded()}return initExternal()}func initExternal() error {+ cfg := config.ConfigtlsConfig := &tls.Config{}- clickhouseServer := os.Getenv("CLICKHOUSE_SERVER")- clickhouseDatabase := os.Getenv("CLICKHOUSE_DATABASE")- clickhouseUsername := os.Getenv("CLICKHOUSE_USERNAME")- clickhousePassword := os.Getenv("CLICKHOUSE_PASSWORD")- clickhouseTls := os.Getenv("CLICKHOUSE_TLS")+ clickhouseServer := cfg.ClickhouseServer+ clickhouseDatabase := cfg.ClickhouseDatabase+ clickhouseUsername := cfg.ClickhouseUsername+ clickhousePassword := cfg.ClickhousePassword+ clickhouseTls := cfg.ClickhouseTLSif clickhouseTls == "false" {tlsConfig = nildiff --git a/backend/app/chdb/embedded.go b/backend/app/chdb/embedded.goindex 9ae973d7..d6367c32 100644--- a/backend/app/chdb/embedded.go+++ b/backend/app/chdb/embedded.go@@ -1,11 +1,13 @@+//go:build chdb+package chdbimport (+ "backend/app/config""context""database/sql""fmt""log"- "os""strings""time"@@ -15,14 +17,12 @@ import ("github.com/google/uuid")-var EmbeddedDB *sql.DB-type embeddedConn struct {db *sql.DB}func initEmbedded() error {- path := os.Getenv("CLICKHOUSE_PATH")+ path := config.Config.ClickhousePathdsn := ""if path != "" {dsn = "session=" + path@@ -38,7 +38,7 @@ func initEmbedded() error {}func (c *embeddedConn) Query(ctx context.Context, query string, args ...any) (driver.Rows, error) {- rows, err := c.db.QueryContext(ctx, query, args...)+ rows, err := c.db.QueryContext(ctx, query, sanitizeArgs(args)...)if err != nil {return nil, err}@@ -46,7 +46,7 @@ func (c *embeddedConn) Query(ctx context.Context, query string, args ...any) (dr}func (c *embeddedConn) QueryRow(ctx context.Context, query string, args ...any) driver.Row {- row := c.db.QueryRowContext(ctx, query, args...)+ row := c.db.QueryRowContext(ctx, query, sanitizeArgs(args)...)return &embeddedRow{row: row}}@@ -55,10 +55,23 @@ func (c *embeddedConn) PrepareBatch(ctx context.Context, query string, opts ...d}func (c *embeddedConn) Exec(ctx context.Context, query string, args ...any) error {- _, err := c.db.ExecContext(ctx, query, args...)+ _, err := c.db.ExecContext(ctx, query, sanitizeArgs(args)...)return err}+func sanitizeArgs(args []any) []any {+ out := make([]any, len(args))+ for i, arg := range args {+ switch v := arg.(type) {+ case time.Time:+ out[i] = v.UTC().Format("2006-01-02 15:04:05")+ default:+ out[i] = arg+ }+ }+ return out+}+// --- Rows adapter ---type embeddedRows struct {diff --git a/backend/app/chdb/embedded_stub.go b/backend/app/chdb/embedded_stub.gonew file mode 100644index 00000000..782a5665--- /dev/null+++ b/backend/app/chdb/embedded_stub.go@@ -0,0 +1,9 @@+//go:build !chdb++package chdb++import "fmt"++func initEmbedded() error {+ return fmt.Errorf("embedded ClickHouse not available — rebuild with: go build -tags chdb")+}diff --git a/backend/app/config/config.go b/backend/app/config/config.gonew file mode 100644index 00000000..26126760--- /dev/null+++ b/backend/app/config/config.go@@ -0,0 +1,95 @@+package config++import "os"++type Cfg struct {+ JWTSecret string++ DBType string+ PostgresHost string+ PostgresPort string+ PostgresDatabase string+ PostgresUsername string+ PostgresPassword string+ PostgresSSLMode string+ SQLitePath string++ ClickhouseType string+ ClickhouseServer string+ ClickhouseDatabase string+ ClickhouseUsername string+ ClickhousePassword string+ ClickhouseTLS string+ ClickhousePath string++ StorageType string+ StoragePath string+ S3Bucket string+ S3Region string+ S3AccessKey string+ S3SecretKey string+ S3Endpoint string++ SMTPEnabled string+ SMTPHost string+ SMTPPort string+ SMTPUsername string+ SMTPPassword string+ SMTPFrom string++ AppBaseURL string+ CloudMode string+ MonitoringTracewayURL string+ APIOnly string+ Ports string+ TurnstileSecretKey string+}++var Config *Cfg++func Init(c *Cfg) { Config = c }++func LoadFromEnv() *Cfg {+ return &Cfg{+ JWTSecret: os.Getenv("JWT_SECRET"),++ DBType: os.Getenv("DB_TYPE"),+ PostgresHost: os.Getenv("POSTGRES_HOST"),+ PostgresPort: os.Getenv("POSTGRES_PORT"),+ PostgresDatabase: os.Getenv("POSTGRES_DATABASE"),+ PostgresUsername: os.Getenv("POSTGRES_USERNAME"),+ PostgresPassword: os.Getenv("POSTGRES_PASSWORD"),+ PostgresSSLMode: os.Getenv("POSTGRES_SSLMODE"),+ SQLitePath: os.Getenv("SQLITE_PATH"),++ ClickhouseType: os.Getenv("CLICKHOUSE_TYPE"),+ ClickhouseServer: os.Getenv("CLICKHOUSE_SERVER"),+ ClickhouseDatabase: os.Getenv("CLICKHOUSE_DATABASE"),+ ClickhouseUsername: os.Getenv("CLICKHOUSE_USERNAME"),+ ClickhousePassword: os.Getenv("CLICKHOUSE_PASSWORD"),+ ClickhouseTLS: os.Getenv("CLICKHOUSE_TLS"),+ ClickhousePath: os.Getenv("CLICKHOUSE_PATH"),++ StorageType: os.Getenv("STORAGE_TYPE"),+ StoragePath: os.Getenv("STORAGE_PATH"),+ S3Bucket: os.Getenv("S3_BUCKET"),+ S3Region: os.Getenv("S3_REGION"),+ S3AccessKey: os.Getenv("S3_ACCESS_KEY"),+ S3SecretKey: os.Getenv("S3_SECRET_KEY"),+ S3Endpoint: os.Getenv("S3_ENDPOINT"),++ SMTPEnabled: os.Getenv("SMTP_ENABLED"),+ SMTPHost: os.Getenv("SMTP_HOST"),+ SMTPPort: os.Getenv("SMTP_PORT"),+ SMTPUsername: os.Getenv("SMTP_USERNAME"),+ SMTPPassword: os.Getenv("SMTP_PASSWORD"),+ SMTPFrom: os.Getenv("SMTP_FROM"),++ AppBaseURL: os.Getenv("APP_BASE_URL"),+ CloudMode: os.Getenv("CLOUD_MODE"),+ MonitoringTracewayURL: os.Getenv("MONITORING_TRACEWAY_URL"),+ APIOnly: os.Getenv("API_ONLY"),+ Ports: os.Getenv("PORTS"),+ TurnstileSecretKey: os.Getenv("TURNSTILE_SECRET_KEY"),+ }+}diff --git a/backend/app/controllers/auth.controller.go b/backend/app/controllers/auth.controller.goindex 2b2957b6..2f9ebb23 100644--- a/backend/app/controllers/auth.controller.go+++ b/backend/app/controllers/auth.controller.go@@ -2,13 +2,13 @@ package controllersimport ("backend/app/cache"+ "backend/app/config""backend/app/middleware""backend/app/models""backend/app/repositories""backend/app/services""database/sql""net/http"- "os""github.com/gin-gonic/gin"traceway "go.tracewayapp.com"@@ -97,7 +97,7 @@ func (a authController) Register(c *gin.Context) {tx := middleware.GetTx(c)// if we're not in the cloud mode only a single organization is allowed- if os.Getenv("CLOUD_MODE") != "true" {+ if config.Config.CloudMode != "true" {hasOrganizations, err := repositories.OrganizationRepository.HasOrganizations(tx)if err != nil {diff --git a/backend/app/controllers/routes.go b/backend/app/controllers/routes.goindex 5781d34f..47d032e3 100644--- a/backend/app/controllers/routes.go+++ b/backend/app/controllers/routes.go@@ -1,10 +1,10 @@package controllersimport (+ "backend/app/config""backend/app/controllers/clientcontrollers""backend/app/controllers/otelcontrollers""backend/app/middleware"- "os""github.com/gin-gonic/gin")@@ -96,7 +96,7 @@ func RegisterControllers(router *gin.RouterGroup) {router.POST("/login", middleware.Transactional, AuthController.Login)router.POST("/register", middleware.Transactional, AuthController.Register)- if os.Getenv("CLOUD_MODE") != "true" {+ if config.Config.CloudMode != "true" {router.GET("/has-organizations", middleware.Transactional, AuthController.HasOrganizations)}diff --git a/backend/app/db/db.go b/backend/app/db/db.goindex 7252c10a..b8cd7b36 100644--- a/backend/app/db/db.go+++ b/backend/app/db/db.go@@ -1,10 +1,10 @@package dbimport (+ "backend/app/config""database/sql""fmt""log"- "os"_ "github.com/lib/pq""github.com/tracewayapp/go-lightning/lit"@@ -19,20 +19,22 @@ func IsSQLite() bool {}func Init() error {- dbType := os.Getenv("DB_TYPE")- if dbType == "sqlite" {+ cfg := config.Config+ if cfg.DBType == "sqlite" {return initSQLite()}return initPostgres()}func initPostgres() error {- host := os.Getenv("POSTGRES_HOST")- port := os.Getenv("POSTGRES_PORT")- database := os.Getenv("POSTGRES_DATABASE")- username := os.Getenv("POSTGRES_USERNAME")- password := os.Getenv("POSTGRES_PASSWORD")- sslMode := os.Getenv("POSTGRES_SSLMODE")+ cfg := config.Config++ host := cfg.PostgresHost+ port := cfg.PostgresPort+ database := cfg.PostgresDatabase+ username := cfg.PostgresUsername+ password := cfg.PostgresPassword+ sslMode := cfg.PostgresSSLModeif sslMode == "" {sslMode = "disable"@@ -65,7 +67,7 @@ func initPostgres() error {}func initSQLite() error {- path := os.Getenv("SQLITE_PATH")+ path := config.Config.SQLitePathif path == "" {path = "./traceway.db"}diff --git a/backend/app/migrations/migrations.go b/backend/app/migrations/migrations.goindex 421c95c1..45612a74 100644--- a/backend/app/migrations/migrations.go+++ b/backend/app/migrations/migrations.go@@ -2,13 +2,13 @@ package migrationsimport ("backend/app/chdb"+ "backend/app/config""backend/app/db""database/sql""embed""fmt""log""net/url"- "os""sort""strings"@@ -257,25 +257,20 @@ func runMigrationsEmbeddedClickhouse(chDB *sql.DB) error {}func Run(dbType string) error {+ cfg := config.Config+// Run ClickHouse migrations- chType := os.Getenv("CLICKHOUSE_TYPE")- if chType == "embedded" {+ if cfg.ClickhouseType == "embedded" {if err := runMigrationsEmbeddedClickhouse(chdb.EmbeddedDB); err != nil {return fmt.Errorf("embedded clickhouse migrations failed: %w", err)}} else {- clickhouseServer := os.Getenv("CLICKHOUSE_SERVER")- clickhouseDatabase := os.Getenv("CLICKHOUSE_DATABASE")- clickhouseUsername := os.Getenv("CLICKHOUSE_USERNAME")- clickhousePassword := os.Getenv("CLICKHOUSE_PASSWORD")- clickhouseTls := os.Getenv("CLICKHOUSE_TLS")-tlsConfig := "&secure=true"- if clickhouseTls == "false" {+ if cfg.ClickhouseTLS == "false" {tlsConfig = ""}- err := runMigrationsClickhouse(fmt.Sprintf(`clickhouse://%s?username=%s&password=%s&database=%s%s`, clickhouseServer, url.QueryEscape(clickhouseUsername), url.QueryEscape(clickhousePassword), clickhouseDatabase, tlsConfig))+ err := runMigrationsClickhouse(fmt.Sprintf(`clickhouse://%s?username=%s&password=%s&database=%s%s`, cfg.ClickhouseServer, url.QueryEscape(cfg.ClickhouseUsername), url.QueryEscape(cfg.ClickhousePassword), cfg.ClickhouseDatabase, tlsConfig))if err != nil {return fmt.Errorf("clickhouse migrations failed: %w", err)}@@ -294,12 +289,8 @@ func Run(dbType string) error {}// Run PostgreSQL migrations- pgHost := os.Getenv("POSTGRES_HOST")- pgPort := os.Getenv("POSTGRES_PORT")- pgDatabase := os.Getenv("POSTGRES_DATABASE")- pgUsername := os.Getenv("POSTGRES_USERNAME")- pgPassword := os.Getenv("POSTGRES_PASSWORD")- pgSSLMode := os.Getenv("POSTGRES_SSLMODE")+ pgPort := cfg.PostgresPort+ pgSSLMode := cfg.PostgresSSLModeif pgSSLMode == "" {pgSSLMode = "disable"@@ -309,7 +300,7 @@ func Run(dbType string) error {}pgConnStr := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s",- url.QueryEscape(pgUsername), url.QueryEscape(pgPassword), pgHost, pgPort, pgDatabase, pgSSLMode)+ url.QueryEscape(cfg.PostgresUsername), url.QueryEscape(cfg.PostgresPassword), cfg.PostgresHost, pgPort, cfg.PostgresDatabase, pgSSLMode)if err := runMigrationsPostgres(pgConnStr); err != nil {return fmt.Errorf("postgres migrations failed: %w", err)diff --git a/backend/app/models/project.model.go b/backend/app/models/project.model.goindex 2e6275eb..4ba0adb9 100644--- a/backend/app/models/project.model.go+++ b/backend/app/models/project.model.go@@ -1,7 +1,7 @@package modelsimport (- "os"+ "backend/app/config""time""github.com/google/uuid"@@ -22,7 +22,7 @@ func (p Project) ToProjectWithBackendUrl() *ProjectWithBackendUrl {}func getBackendUrl() string {- if url := os.Getenv("APP_BASE_URL"); url != "" {+ if url := config.Config.AppBaseURL; url != "" {return url}return "https://cloud.tracewayapp.com"diff --git a/backend/app/services/email.service.go b/backend/app/services/email.service.goindex faec687b..62d997ee 100644--- a/backend/app/services/email.service.go+++ b/backend/app/services/email.service.go@@ -1,10 +1,10 @@package servicesimport (+ "backend/app/config""fmt""log""net/smtp"- "os""strconv")@@ -21,24 +21,26 @@ type emailService struct {var EmailService *emailServicefunc InitEmail() {- enabled := os.Getenv("SMTP_ENABLED") == "true"- port, _ := strconv.Atoi(os.Getenv("SMTP_PORT"))+ cfg := config.Config++ enabled := cfg.SMTPEnabled == "true"+ port, _ := strconv.Atoi(cfg.SMTPPort)if port == 0 {port = 587}- baseUrl := os.Getenv("APP_BASE_URL")+ baseUrl := cfg.AppBaseURLif baseUrl == "" {baseUrl = "http://localhost:5173"}EmailService = &emailService{enabled: enabled,- host: os.Getenv("SMTP_HOST"),+ host: cfg.SMTPHost,port: port,- username: os.Getenv("SMTP_USERNAME"),- password: os.Getenv("SMTP_PASSWORD"),- from: os.Getenv("SMTP_FROM"),+ username: cfg.SMTPUsername,+ password: cfg.SMTPPassword,+ from: cfg.SMTPFrom,baseUrl: baseUrl,}diff --git a/backend/app/services/jwt.service.go b/backend/app/services/jwt.service.goindex 9084a716..7210e923 100644--- a/backend/app/services/jwt.service.go+++ b/backend/app/services/jwt.service.go@@ -1,9 +1,9 @@package servicesimport (+ "backend/app/config""errors""fmt"- "os""time""github.com/golang-jwt/jwt/v5"@@ -18,7 +18,7 @@ type JWTClaims struct {}func InitJWT() error {- secret := os.Getenv("JWT_SECRET")+ secret := config.Config.JWTSecretif secret == "" {return errors.New("JWT_SECRET environment variable is not set")}diff --git a/backend/app/services/turnstile.service.go b/backend/app/services/turnstile.service.goindex c0780ded..84e16b58 100644--- a/backend/app/services/turnstile.service.go+++ b/backend/app/services/turnstile.service.go@@ -1,11 +1,11 @@package servicesimport (+ "backend/app/config""encoding/json""errors""net/http""net/url"- "os""time")@@ -21,9 +21,13 @@ type turnstileResponse struct {Hostname string `json:"hostname"`}-var TurnstileService = &turnstileService{- secretKey: os.Getenv("TURNSTILE_SECRET_KEY"),- client: &http.Client{Timeout: 10 * time.Second},+var TurnstileService *turnstileService++func InitTurnstile() {+ TurnstileService = &turnstileService{+ secretKey: config.Config.TurnstileSecretKey,+ client: &http.Client{Timeout: 10 * time.Second},+ }}func (s *turnstileService) IsEnabled() bool {diff --git a/backend/app/storage/storage.go b/backend/app/storage/storage.goindex 7c5694bf..a3232173 100644--- a/backend/app/storage/storage.go+++ b/backend/app/storage/storage.go@@ -1,9 +1,9 @@package storageimport (+ "backend/app/config""context""fmt"- "os")type Storage interface {@@ -14,14 +14,16 @@ type Storage interface {var Store Storagefunc Init() error {- storageType := os.Getenv("STORAGE_TYPE")+ cfg := config.Config++ storageType := cfg.StorageTypeif storageType == "" {storageType = "local"}switch storageType {case "local":- path := os.Getenv("STORAGE_PATH")+ path := cfg.StoragePathif path == "" {path = "./storage"}@@ -31,15 +33,15 @@ func Init() error {}Store = scase "s3":- bucket := os.Getenv("S3_BUCKET")+ bucket := cfg.S3Bucketif bucket == "" {return fmt.Errorf("S3_BUCKET is required when STORAGE_TYPE=s3")}- region := os.Getenv("S3_REGION")+ region := cfg.S3Regionif region == "" {return fmt.Errorf("S3_REGION is required when STORAGE_TYPE=s3")}- s, err := NewS3Storage(bucket, region, os.Getenv("S3_ACCESS_KEY"), os.Getenv("S3_SECRET_KEY"), os.Getenv("S3_ENDPOINT"))+ s, err := NewS3Storage(bucket, region, cfg.S3AccessKey, cfg.S3SecretKey, cfg.S3Endpoint)if err != nil {return fmt.Errorf("failed to create S3 storage: %w", err)}diff --git a/backend/backend b/backend/backendindex 4969dff7..3c38ebfc 100755Binary files a/backend/backend and b/backend/backend differdiff --git a/backend/cmd/options.go b/backend/cmd/options.gonew file mode 100644index 00000000..c3cecbc3--- /dev/null+++ b/backend/cmd/options.go@@ -0,0 +1,61 @@+package cmd++type options struct {+ sqlitePath string+ clickhousePath string+ port int+ serverURL string+ defaultUser *defaultUserOpts+ defaultProjects []defaultProjectOpts+}++type defaultUserOpts struct {+ email string+ password string+}++type defaultProjectOpts struct {+ name string+ framework string+ token string+}++type Option func(*options)++func WithSQLitePath(path string) Option {+ return func(o *options) {+ o.sqlitePath = path+ }+}++func WithClickhousePath(path string) Option {+ return func(o *options) {+ o.clickhousePath = path+ }+}++func WithPort(port int) Option {+ return func(o *options) {+ o.port = port+ }+}++func WithServerURL(url string) Option {+ return func(o *options) {+ o.serverURL = url+ }+}++func WithDefaultUser(email, password string) Option {+ return func(o *options) {+ o.defaultUser = &defaultUserOpts{email: email, password: password}+ }+}++func WithDefaultProject(name, framework, token string) Option {+ return func(o *options) {+ o.defaultProjects = append(o.defaultProjects, defaultProjectOpts{+ name: name, framework: framework, token: token,+ })+ }+}diff --git a/backend/cmd/run.go b/backend/cmd/run.goindex bd29a062..9287a615 100644--- a/backend/cmd/run.go+++ b/backend/cmd/run.go@@ -3,11 +3,12 @@ package cmdimport ("backend/app/cache""backend/app/chdb"+ "backend/app/config""backend/app/controllers"+ "backend/app/db""backend/app/middleware""backend/app/migrations""backend/app/models"- "backend/app/db""backend/app/services""backend/app/storage""backend/static"@@ -16,7 +17,6 @@ import ("io/fs""log""net/http"- "os""strings""time"@@ -28,8 +28,39 @@ import (var PostStartupHooks []func(ctx context.Context)-func Run() {- godotenv.Load()+func Run(opts ...Option) {+ var cfg *config.Cfg+ var o *options++ if len(opts) == 0 {+ godotenv.Load()+ cfg = config.LoadFromEnv()+ } else {+ o = &options{sqlitePath: ":memory:"}+ for _, opt := range opts {+ opt(o)+ }+ port := o.port+ if port == 0 {+ port = 8082+ }+ cfg = &config.Cfg{+ JWTSecret: "traceway-dev-secret-key-min-32-chars!",+ DBType: "sqlite",+ SQLitePath: o.sqlitePath,+ ClickhouseType: "embedded",+ ClickhousePath: o.clickhousePath,+ StorageType: "local",+ StoragePath: "./storage",+ APIOnly: "false",+ Ports: fmt.Sprintf("%d", port),+ }+ if o.serverURL == "" {+ o.serverURL = fmt.Sprintf("http://localhost:%d", port)+ }+ cfg.AppBaseURL = o.serverURL+ }+ config.Init(cfg)if err := services.InitJWT(); err != nil {panic(fmt.Errorf("failed to initialize JWT: %w", err))@@ -51,12 +82,17 @@ func Run() {panic(fmt.Errorf("failed to initialize storage: %w", err))}- dbType := os.Getenv("DB_TYPE")- err = migrations.Run(dbType)+ err = migrations.Run(cfg.DBType)if err != nil {panic(fmt.Errorf("migrations run failed: %w", err))}+ if o != nil {+ if err := seed(o); err != nil {+ panic(fmt.Errorf("seeding failed: %w", err))+ }+ }+ctx := context.Background()if err := cache.ProjectCache.Init(ctx); err != nil {panic(fmt.Errorf("projects cache could not be initialized: %w", err))@@ -71,6 +107,7 @@ func Run() {middleware.InitUseSourceMapAuth()services.InitEmail()+ services.InitTurnstile()for _, hook := range PostStartupHooks {hook(ctx)@@ -78,7 +115,7 @@ func Run() {router := gin.Default()- if monitoringTracewayUrl := os.Getenv("MONITORING_TRACEWAY_URL"); monitoringTracewayUrl != "" {+ if monitoringTracewayUrl := cfg.MonitoringTracewayURL; monitoringTracewayUrl != "" {router.Use(tracewaygin.New(monitoringTracewayUrl,tracewaygin.WithOnErrorRecording(tracewaygin.RecordingQuery|tracewaygin.RecordingBody|tracewaygin.RecordingHeader|tracewaygin.RecordingUrl),@@ -96,7 +133,7 @@ func Run() {ctx.JSON(200, gin.H{"version": "0.0.1"})})- apiOnly := os.Getenv("API_ONLY") == "true"+ apiOnly := cfg.APIOnly == "true"if apiOnly {router.NoRoute(func(c *gin.Context) {@@ -119,7 +156,7 @@ func Run() {router.NoRoute(createSPAHandler(staticFS))}- ports := os.Getenv("PORTS")+ ports := cfg.Portsif ports == "" {ports = "80,8082"}diff --git a/backend/cmd/seed.go b/backend/cmd/seed.gonew file mode 100644index 00000000..bd2e59ce--- /dev/null+++ b/backend/cmd/seed.go@@ -0,0 +1,71 @@+package cmd++import (+ "backend/app/db"+ "backend/app/models"+ "backend/app/repositories"+ "backend/app/services"+ "database/sql"+ "log"+ "time"++ "github.com/google/uuid"+ "github.com/tracewayapp/go-lightning/lit"+)++func seed(opts *options) error {+ if opts.defaultUser == nil {+ return nil+ }++ _, err := db.ExecuteTransaction(func(tx *sql.Tx) (struct{}, error) {+ existing, err := repositories.UserRepository.FindByEmail(tx, opts.defaultUser.email)+ if err != nil {+ return struct{}{}, err+ }+ if existing != nil {+ log.Printf("Seed: user %s already exists, skipping", opts.defaultUser.email)+ return struct{}{}, nil+ }++ hash, err := services.HashPassword(opts.defaultUser.password)+ if err != nil {+ return struct{}{}, err+ }++ user, err := repositories.UserRepository.Create(tx, opts.defaultUser.email, "Admin", hash)+ if err != nil {+ return struct{}{}, err+ }++ org, err := repositories.OrganizationRepository.Create(tx, "Default", "UTC")+ if err != nil {+ return struct{}{}, err+ }++ _, err = repositories.OrganizationRepository.AddUser(tx, org.Id, user.Id, "owner")+ if err != nil {+ return struct{}{}, err+ }++ for _, p := range opts.defaultProjects {+ project := &models.Project{+ Id: uuid.New(),+ Name: p.name,+ Token: p.token,+ Framework: p.framework,+ OrganizationId: &org.Id,+ CreatedAt: time.Now().UTC(),+ }+ if err := lit.InsertExistingUuid(tx, project); err != nil {+ return struct{}{}, err+ }+ log.Printf("Seed: project %q connection string: %s@%s/api/report", project.Name, project.Token, opts.serverURL)+ }++ log.Printf("Seed: created user %s, org %q", user.Email, org.Name)+ return struct{}{}, nil+ })++ return err+}diff --git a/docs/pages/learn/_meta.json b/docs/pages/learn/_meta.jsonindex a673cadd..a684e8f0 100644--- a/docs/pages/learn/_meta.json+++ b/docs/pages/learn/_meta.json@@ -5,5 +5,6 @@"issues": "Issues","attributes": "Attributes","spans": "Spans",- "metrics": "Metrics"+ "metrics": "Metrics",+ "embedded-mode": "Embedded Mode"}diff --git a/docs/pages/learn/embedded-mode.mdx b/docs/pages/learn/embedded-mode.mdxnew file mode 100644index 00000000..76590355--- /dev/null+++ b/docs/pages/learn/embedded-mode.mdx@@ -0,0 +1,45 @@+# Embedded Mode++Traceway supports running ClickHouse **in-process** using [chdb](https://github.com/chdb-io/chdb) — no external ClickHouse server required.++This is useful for:++- **Local development** — get started without installing ClickHouse+- **Testing** — spin up an isolated instance per test run+- **Single-node deploys** — run everything in one binary++## Install libchdb++The embedded driver requires `libchdb` to be installed on the system. Run the official installer (supports macOS and Linux):++```bash+curl -sL https://lib.chdb.io | bash+```++## Building with the tag++The embedded ClickHouse driver is behind a build tag so it doesn't affect normal builds. Pass `-tags chdb` to include it:++```bash+go build -tags chdb ./...+```++To run directly during development:++```bash+go run -tags chdb .+```++Without the tag, the binary compiles normally and attempting to use embedded mode returns a clear error.++## How it works++The `chdb` build tag controls whether the `chdb-go` driver is compiled into the binary. When the tag is present, `embedded.go` is included — it imports the chdb driver and provides the `initEmbedded()` implementation. When the tag is absent, a stub returns an error if embedded mode is requested.++To use embedded mode at runtime, set the `CLICKHOUSE_TYPE` environment variable:++```bash+CLICKHOUSE_TYPE=embedded go run -tags chdb .+```++Optionally set `CLICKHOUSE_PATH` to persist data to a directory. Without it, chdb uses an in-memory session.