Skip to content

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

async inserts

ddux8ebdb8a71aee
diff --git a/backend/app/repositories/exception_stack_trace.repository.go b/backend/app/repositories/exception_stack_trace.repository.go
index 858da060..f745eb61 100644
--- a/backend/app/repositories/exception_stack_trace.repository.go
+++ b/backend/app/repositories/exception_stack_trace.repository.go
@@ -7,6 +7,8 @@ import (
"encoding/json"
"errors"
"time"
+
+ "github.com/ClickHouse/clickhouse-go/v2"
)
var ErrExceptionNotFound = errors.New("exception not found")
@@ -14,13 +16,13 @@ var ErrExceptionNotFound = errors.New("exception not found")
type exceptionStackTraceRepository struct{}
func (e *exceptionStackTraceRepository) InsertAsync(ctx context.Context, lines []models.ExceptionStackTrace) error {
- batch, err := (*chdb.Conn).PrepareBatch(ctx, "INSERT INTO exception_stack_traces (project_id, transaction_id, exception_hash, stack_trace, recorded_at, scope, app_version, server_name, is_message)")
+ batch, err := (*chdb.Conn).PrepareBatch(clickhouse.Context(context.Background(), clickhouse.WithAsync(false)), "INSERT INTO exception_stack_traces (project_id, transaction_id, exception_hash, stack_trace, recorded_at, scope, app_version, server_name, is_message)")
if err != nil {
return err
}
for _, est := range lines {
scopeJSON := "{}"
- if est.Scope != nil {
+ if len(est.Scope) != 0 {
if scopeBytes, err := json.Marshal(est.Scope); err == nil {
scopeJSON = string(scopeBytes)
}
diff --git a/backend/app/repositories/metric_record.repository.go b/backend/app/repositories/metric_record.repository.go
index a8b8ae48..0a356156 100644
--- a/backend/app/repositories/metric_record.repository.go
+++ b/backend/app/repositories/metric_record.repository.go
@@ -5,12 +5,14 @@ import (
"backend/app/models"
"context"
"time"
+
+ "github.com/ClickHouse/clickhouse-go/v2"
)
type metricRecordRepository struct{}
func (e *metricRecordRepository) InsertAsync(ctx context.Context, lines []models.MetricRecord) error {
- batch, err := (*chdb.Conn).PrepareBatch(ctx, "INSERT INTO metric_records (project_id, name, value, recorded_at, server_name)")
+ batch, err := (*chdb.Conn).PrepareBatch(clickhouse.Context(context.Background(), clickhouse.WithAsync(false)), "INSERT INTO metric_records (project_id, name, value, recorded_at, server_name)")
if err != nil {
return err
}
diff --git a/backend/app/repositories/segment.repository.go b/backend/app/repositories/segment.repository.go
index e1928bff..fda356e4 100644
--- a/backend/app/repositories/segment.repository.go
+++ b/backend/app/repositories/segment.repository.go
@@ -4,6 +4,8 @@ import (
"backend/app/chdb"
"backend/app/models"
"context"
+
+ "github.com/ClickHouse/clickhouse-go/v2"
)
type segmentRepository struct{}
@@ -13,7 +15,7 @@ func (r *segmentRepository) InsertAsync(ctx context.Context, segments []models.S
return nil
}
- batch, err := (*chdb.Conn).PrepareBatch(ctx,
+ batch, err := (*chdb.Conn).PrepareBatch(clickhouse.Context(context.Background(), clickhouse.WithAsync(false)),
"INSERT INTO segments (id, transaction_id, project_id, name, start_time, duration, recorded_at)")
if err != nil {
return err
diff --git a/backend/app/repositories/transaction.repository.go b/backend/app/repositories/transaction.repository.go
index 99871f21..7ecac828 100644
--- a/backend/app/repositories/transaction.repository.go
+++ b/backend/app/repositories/transaction.repository.go
@@ -6,18 +6,20 @@ import (
"context"
"encoding/json"
"time"
+
+ "github.com/ClickHouse/clickhouse-go/v2"
)
type transactionRepository struct{}
func (e *transactionRepository) InsertAsync(ctx context.Context, lines []models.Transaction) error {
- batch, err := (*chdb.Conn).PrepareBatch(ctx, "INSERT INTO transactions (id, project_id, endpoint, duration, recorded_at, status_code, body_size, client_ip, scope, app_version, server_name)")
+ batch, err := (*chdb.Conn).PrepareBatch(clickhouse.Context(context.Background(), clickhouse.WithAsync(false)), "INSERT INTO transactions (id, project_id, endpoint, duration, recorded_at, status_code, body_size, client_ip, scope, app_version, server_name)")
if err != nil {
return err
}
for _, t := range lines {
scopeJSON := "{}"
- if t.Scope != nil {
+ if len(t.Scope) != 0 {
if scopeBytes, err := json.Marshal(t.Scope); err == nil {
scopeJSON = string(scopeBytes)
}
diff --git a/testing/devtesting/devtesting.go b/testing/devtesting/devtesting.go
index 27aaa482..438a5da1 100644
--- a/testing/devtesting/devtesting.go
+++ b/testing/devtesting/devtesting.go
@@ -4,10 +4,11 @@ import (
"errors"
"math/rand/v2"
"os"
+ "strconv"
"time"
- "go.tracewayapp.com"
- "go.tracewayapp.com/traceway_gin"
+ traceway "go.tracewayapp.com"
+ tracewaygin "go.tracewayapp.com/traceway_gin"
"github.com/gin-gonic/gin"
)
@@ -29,6 +30,12 @@ func testGin() {
traceway.WithDebug(true),
))
+ router.GET("/test-50k", func(ctx *gin.Context) {
+ for i := range 50_000 {
+ traceway.CaptureMessage("I:" + strconv.Itoa(i))
+ }
+ })
+
router.GET("/test-exception", func(ctx *gin.Context) {
time.Sleep(time.Duration(rand.IntN(2000)) * time.Millisecond)
panic("Cool")
diff --git a/testing/devtesting/go.mod b/testing/devtesting/go.mod
index 09be64a6..394f5beb 100644
--- a/testing/devtesting/go.mod
+++ b/testing/devtesting/go.mod
@@ -42,4 +42,4 @@ require (
google.golang.org/protobuf v1.36.9 // indirect
)
-replace go.tracewayapp.com => ../../clients/go-client
+replace go.tracewayapp.com => ../../../go-client