The only tool you need to know what is happening and how to fix it.
Go alertingexception-trackerissue-trackinglogsmetricsmonitoringobservability-platformopen-telemetryotelsession-replaytelemetrytraces
feat: perf improvement for clickhouse - bounding all lookups by time (#216)
narrow-adventure2a9a3846c74a
diff --git a/backend/app/controllers/ai_trace.controller.go b/backend/app/controllers/ai_trace.controller.goindex 7fbf5398..d5ba0e2d 100644--- a/backend/app/controllers/ai_trace.controller.go+++ b/backend/app/controllers/ai_trace.controller.go@@ -17,6 +17,10 @@ import (type aiTraceController struct{}+type aiTraceDetailRequest struct {+ RecordedAt *time.Time `json:"recordedAt"`+}+type AiTraceSearchRequest struct {FromDate time.Time `json:"fromDate"`ToDate time.Time `json:"toDate"`@@ -136,7 +140,13 @@ func (a aiTraceController) GetAiTraceDetail(c *gin.Context) {return}- aiTrace, err := repositories.AiTraceRepository.FindById(c, projectId, traceId)+ var request aiTraceDetailRequest+ _ = c.ShouldBindJSON(&request)++ aiTrace, err := repositories.AiTraceRepository.FindById(c, projectId, traceId, request.RecordedAt)+ if aiTrace == nil && err == nil && request.RecordedAt != nil {+ aiTrace, err = repositories.AiTraceRepository.FindById(c, projectId, traceId, nil)+ }if err != nil {c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("error loading ai trace: %w", err))returndiff --git a/backend/app/controllers/distributed_trace.controller.go b/backend/app/controllers/distributed_trace.controller.goindex 43cbfcb4..9841713f 100644--- a/backend/app/controllers/distributed_trace.controller.go+++ b/backend/app/controllers/distributed_trace.controller.go@@ -4,6 +4,7 @@ import ("context""database/sql""net/http"+ "time""github.com/tracewayapp/traceway/backend/app/db""github.com/tracewayapp/traceway/backend/app/middleware"@@ -17,6 +18,10 @@ import (type distributedTraceController struct{}+type distributedTraceRequest struct {+ RecordedAt *time.Time `json:"recordedAt"`+}+type DistributedTraceNode struct {ProjectId uuid.UUID `json:"projectId"`ProjectName string `json:"projectName"`@@ -41,6 +46,9 @@ func (d distributedTraceController) GetDistributedTrace(c *gin.Context) {return}+ var request distributedTraceRequest+ _ = c.ShouldBindJSON(&request)+userId := middleware.GetUserId(c)projects, err := db.ExecuteTransaction(func(tx *sql.Tx) ([]*models.Project, error) {@@ -68,25 +76,25 @@ func (d distributedTraceController) GetDistributedTrace(c *gin.Context) {ctx := context.Background()- endpoints, err := repositories.EndpointRepository.FindByDistributedTraceId(ctx, distributedTraceId, projectIds)+ endpoints, err := repositories.EndpointRepository.FindByDistributedTraceId(ctx, distributedTraceId, projectIds, request.RecordedAt)if err != nil {c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to query endpoints: %w", err))return}- tasks, err := repositories.TaskRepository.FindByDistributedTraceId(ctx, distributedTraceId, projectIds)+ tasks, err := repositories.TaskRepository.FindByDistributedTraceId(ctx, distributedTraceId, projectIds, request.RecordedAt)if err != nil {c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to query tasks: %w", err))return}- aiTraces, err := repositories.AiTraceRepository.FindByDistributedTraceId(ctx, distributedTraceId, projectIds)+ aiTraces, err := repositories.AiTraceRepository.FindByDistributedTraceId(ctx, distributedTraceId, projectIds, request.RecordedAt)if err != nil {c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to query ai traces: %w", err))return}- exceptions, err := repositories.ExceptionStackTraceRepository.FindByDistributedTraceId(ctx, distributedTraceId, projectIds)+ exceptions, err := repositories.ExceptionStackTraceRepository.FindByDistributedTraceId(ctx, distributedTraceId, projectIds, request.RecordedAt)if err != nil {c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to query exceptions: %w", err))returndiff --git a/backend/app/controllers/endpoint_detail.controller.go b/backend/app/controllers/endpoint_detail.controller.goindex 249e6041..5ec5585e 100644--- a/backend/app/controllers/endpoint_detail.controller.go+++ b/backend/app/controllers/endpoint_detail.controller.go@@ -2,6 +2,7 @@ package controllersimport ("net/http"+ "time""github.com/tracewayapp/traceway/backend/app/middleware""github.com/tracewayapp/traceway/backend/app/models"@@ -14,6 +15,10 @@ import (type endpointDetailController struct{}+type endpointDetailRequest struct {+ RecordedAt *time.Time `json:"recordedAt"`+}+type EndpointExceptionInfo struct {ExceptionHash string `json:"exceptionHash"`StackTrace string `json:"stackTrace"`@@ -49,9 +54,15 @@ func (t endpointDetailController) GetEndpointDetail(c *gin.Context) {return}+ var request endpointDetailRequest+ _ = c.ShouldBindJSON(&request)+// Get endpointspan := traceway.StartSpan(c, "loading endpoint")- endpoint, err := repositories.EndpointRepository.FindById(c, projectId, endpointId)+ endpoint, err := repositories.EndpointRepository.FindById(c, projectId, endpointId, request.RecordedAt)+ if endpoint == nil && err == nil && request.RecordedAt != nil {+ endpoint, err = repositories.EndpointRepository.FindById(c, projectId, endpointId, nil)+ }span.End()if err != nil {c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("error loading endpoint: %w", err))@@ -62,9 +73,11 @@ func (t endpointDetailController) GetEndpointDetail(c *gin.Context) {return}+ recordedAt := endpoint.RecordedAt+// Get spans (flat list ordered by start_time)span = traceway.StartSpan(c, "loading spans")- spans, err := repositories.SpanRepository.FindByTraceId(c, projectId, endpointId)+ spans, err := repositories.SpanRepository.FindByTraceId(c, projectId, endpointId, &recordedAt)span.End()if err != nil {c.AbortWithError(500, traceway.NewStackTraceErrorf("error loading spans: %w", err))@@ -76,7 +89,7 @@ func (t endpointDetailController) GetEndpointDetail(c *gin.Context) {var messages []EndpointMessageInfospan = traceway.StartSpan(c, "loading exceptions")- allExceptions, err := repositories.ExceptionStackTraceRepository.FindAllByTraceId(c, projectId, endpointId)+ allExceptions, err := repositories.ExceptionStackTraceRepository.FindAllByTraceId(c, projectId, endpointId, &recordedAt)span.End()if err != nil {c.AbortWithError(500, traceway.NewStackTraceErrorf("error loading all exceptions: %w", err))diff --git a/backend/app/controllers/exception_stack_trace.controller.go b/backend/app/controllers/exception_stack_trace.controller.goindex d6cc0567..97c16696 100644--- a/backend/app/controllers/exception_stack_trace.controller.go+++ b/backend/app/controllers/exception_stack_trace.controller.go@@ -259,6 +259,10 @@ func (e exceptionStackTraceController) UnarchiveExceptions(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"unarchived": len(request.Hashes)})}+type exceptionByIdRequest struct {+ RecordedAt *time.Time `json:"recordedAt"`+}+func (e exceptionStackTraceController) FindById(c *gin.Context) {projectId, err := middleware.GetProjectId(c)if err != nil {@@ -272,8 +276,14 @@ func (e exceptionStackTraceController) FindById(c *gin.Context) {return}+ var request exceptionByIdRequest+ _ = c.ShouldBindJSON(&request)+span := traceway.StartSpan(c, "loading exception by id")- exception, err := repositories.ExceptionStackTraceRepository.FindById(c, projectId, exceptionId)+ exception, err := repositories.ExceptionStackTraceRepository.FindById(c, projectId, exceptionId, request.RecordedAt)+ if exception == nil && err == nil && request.RecordedAt != nil {+ exception, err = repositories.ExceptionStackTraceRepository.FindById(c, projectId, exceptionId, nil)+ }span.End()if err != nil {c.AbortWithError(500, traceway.NewStackTraceErrorf("error loading the exception: %w", err))diff --git a/backend/app/controllers/log.controller.go b/backend/app/controllers/log.controller.goindex 537d6bae..bf17cf17 100644--- a/backend/app/controllers/log.controller.go+++ b/backend/app/controllers/log.controller.go@@ -158,15 +158,15 @@ func (l logController) List(c *gin.Context) {func (l logController) resolveDistributedTraceIds(ctx context.Context, dtid uuid.UUID, projectId uuid.UUID, excludeTraceHex string) ([]string, error) {projectIds := []uuid.UUID{projectId}- endpoints, err := repositories.EndpointRepository.FindByDistributedTraceId(ctx, dtid, projectIds)+ endpoints, err := repositories.EndpointRepository.FindByDistributedTraceId(ctx, dtid, projectIds, nil)if err != nil {return nil, err}- tasks, err := repositories.TaskRepository.FindByDistributedTraceId(ctx, dtid, projectIds)+ tasks, err := repositories.TaskRepository.FindByDistributedTraceId(ctx, dtid, projectIds, nil)if err != nil {return nil, err}- aiTraces, err := repositories.AiTraceRepository.FindByDistributedTraceId(ctx, dtid, projectIds)+ aiTraces, err := repositories.AiTraceRepository.FindByDistributedTraceId(ctx, dtid, projectIds, nil)if err != nil {return nil, err}diff --git a/backend/app/controllers/task_detail.controller.go b/backend/app/controllers/task_detail.controller.goindex 608f77bb..7f906d61 100644--- a/backend/app/controllers/task_detail.controller.go+++ b/backend/app/controllers/task_detail.controller.go@@ -2,6 +2,7 @@ package controllersimport ("net/http"+ "time""github.com/tracewayapp/traceway/backend/app/middleware""github.com/tracewayapp/traceway/backend/app/models"@@ -14,6 +15,10 @@ import (type taskDetailController struct{}+type taskDetailRequest struct {+ RecordedAt *time.Time `json:"recordedAt"`+}+type TaskExceptionInfo struct {ExceptionHash string `json:"exceptionHash"`StackTrace string `json:"stackTrace"`@@ -49,18 +54,26 @@ func (t taskDetailController) GetTaskDetail(c *gin.Context) {return}+ var request taskDetailRequest+ _ = c.ShouldBindJSON(&request)+// Get taskspan := traceway.StartSpan(c, "loading task")- task, err := repositories.TaskRepository.FindById(c, projectId, taskId)+ task, err := repositories.TaskRepository.FindById(c, projectId, taskId, request.RecordedAt)+ if task == nil && err == nil && request.RecordedAt != nil {+ task, err = repositories.TaskRepository.FindById(c, projectId, taskId, nil)+ }span.End()- if err != nil {+ if err != nil || task == nil {c.JSON(http.StatusNotFound, gin.H{"error": "Task not found"})return}+ recordedAt := task.RecordedAt+// Get spans (flat list ordered by start_time)span = traceway.StartSpan(c, "loading spans")- spans, err := repositories.SpanRepository.FindByTraceId(c, projectId, taskId)+ spans, err := repositories.SpanRepository.FindByTraceId(c, projectId, taskId, &recordedAt)span.End()if err != nil {c.AbortWithError(500, traceway.NewStackTraceErrorf("error loading spans: %w", err))@@ -72,7 +85,7 @@ func (t taskDetailController) GetTaskDetail(c *gin.Context) {var messages []TaskMessageInfospan = traceway.StartSpan(c, "loading exceptions")- allExceptions, err := repositories.ExceptionStackTraceRepository.FindAllByTraceId(c, projectId, taskId)+ allExceptions, err := repositories.ExceptionStackTraceRepository.FindAllByTraceId(c, projectId, taskId, &recordedAt)span.End()if err != nil {c.AbortWithError(500, traceway.NewStackTraceErrorf("error loading allExceptions: %w", err))diff --git a/backend/app/notifications/evaluator_event.go b/backend/app/notifications/evaluator_event.goindex 26034195..b9eb294e 100644--- a/backend/app/notifications/evaluator_event.go+++ b/backend/app/notifications/evaluator_event.go@@ -124,7 +124,7 @@ func getExceptionDetails(ctx context.Context, projectId uuid.UUID, hash string)details.ServerName = serverNamedetails.RecordedAt = recordedAtdetails.TraceType = traceType- details.TraceName = resolveTraceName(ctx, projectId, traceId, traceType)+ details.TraceName = resolveTraceName(ctx, projectId, traceId, traceType, &details.RecordedAt)if attributesJSON != "" && attributesJSON != "{}" {attrs := make(map[string]string)diff --git a/backend/app/notifications/evaluator_event_sqlite.go b/backend/app/notifications/evaluator_event_sqlite.goindex 4f56c9a5..f278dd37 100644--- a/backend/app/notifications/evaluator_event_sqlite.go+++ b/backend/app/notifications/evaluator_event_sqlite.go@@ -133,7 +133,7 @@ func getExceptionDetails(ctx context.Context, projectId uuid.UUID, hash string)traceId = &parsed}}- details.TraceName = resolveTraceName(ctx, projectId, traceId, traceType)+ details.TraceName = resolveTraceName(ctx, projectId, traceId, traceType, &details.RecordedAt)if attributesJSON != "" && attributesJSON != "{}" {attrs := make(map[string]string)diff --git a/backend/app/notifications/evaluator_helpers.go b/backend/app/notifications/evaluator_helpers.goindex d4c8643a..c71ef783 100644--- a/backend/app/notifications/evaluator_helpers.go+++ b/backend/app/notifications/evaluator_helpers.go@@ -120,13 +120,16 @@ func extractErrorType(stackTrace string) string {return "Unknown Error"}-func resolveTraceName(ctx context.Context, projectId uuid.UUID, traceId *uuid.UUID, traceType string) string {+func resolveTraceName(ctx context.Context, projectId uuid.UUID, traceId *uuid.UUID, traceType string, recordedAt *time.Time) string {if traceId == nil {return ""}switch traceType {case "task":- task, err := repositories.TaskRepository.FindById(ctx, projectId, *traceId)+ task, err := repositories.TaskRepository.FindById(ctx, projectId, *traceId, recordedAt)+ if task == nil && err == nil && recordedAt != nil {+ task, err = repositories.TaskRepository.FindById(ctx, projectId, *traceId, nil)+ }if err != nil {traceway.CaptureException(fmt.Errorf("failed to resolve task name for notification: %w", err))return ""@@ -136,7 +139,10 @@ func resolveTraceName(ctx context.Context, projectId uuid.UUID, traceId *uuid.UU}return task.TaskNamecase "ai_trace":- trace, err := repositories.AiTraceRepository.FindById(ctx, projectId, *traceId)+ trace, err := repositories.AiTraceRepository.FindById(ctx, projectId, *traceId, recordedAt)+ if trace == nil && err == nil && recordedAt != nil {+ trace, err = repositories.AiTraceRepository.FindById(ctx, projectId, *traceId, nil)+ }if err != nil {traceway.CaptureException(fmt.Errorf("failed to resolve ai trace name for notification: %w", err))return ""@@ -146,7 +152,10 @@ func resolveTraceName(ctx context.Context, projectId uuid.UUID, traceId *uuid.UU}return trace.TraceNamedefault:- endpoint, err := repositories.EndpointRepository.FindById(ctx, projectId, *traceId)+ endpoint, err := repositories.EndpointRepository.FindById(ctx, projectId, *traceId, recordedAt)+ if endpoint == nil && err == nil && recordedAt != nil {+ endpoint, err = repositories.EndpointRepository.FindById(ctx, projectId, *traceId, nil)+ }if err != nil {traceway.CaptureException(fmt.Errorf("failed to resolve endpoint name for notification: %w", err))return ""diff --git a/backend/app/repositories/ai_trace.repository.go b/backend/app/repositories/ai_trace.repository.goindex ab1e7c7e..ae84df36 100644--- a/backend/app/repositories/ai_trace.repository.go+++ b/backend/app/repositories/ai_trace.repository.go@@ -245,7 +245,7 @@ func (r *aiTraceRepository) GetTraceNameStats(ctx context.Context, projectId uuireturn &stats, nil}-func (r *aiTraceRepository) FindById(ctx context.Context, projectId, traceId uuid.UUID) (*models.AiTrace, error) {+func (r *aiTraceRepository) FindById(ctx context.Context, projectId, traceId uuid.UUID, recordedAt *time.Time) (*models.AiTrace, error) {query := `SELECT id, project_id, recorded_at, duration, status_code,model, response_model, provider, operation,input_tokens, output_tokens, total_tokens, cached_tokens, reasoning_tokens,@@ -253,14 +253,20 @@ func (r *aiTraceRepository) FindById(ctx context.Context, projectId, traceId uuitrace_name, user_id, finish_reason, server_name, app_version,storage_key, attributes, distributed_trace_id, is_rootFROM ai_traces- WHERE project_id = ? AND id = ?- LIMIT 1`+ WHERE project_id = ? AND id = ?`+ args := []any{projectId, traceId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` LIMIT 1`var t models.AiTracevar attributesJSON stringvar isRoot uint8- err := chdb.Conn.QueryRow(ctx, query, projectId, traceId).Scan(+ err := chdb.Conn.QueryRow(ctx, query, args...).Scan(&t.Id, &t.ProjectId, &t.RecordedAt, &t.Duration, &t.StatusCode,&t.Model, &t.ResponseModel, &t.Provider, &t.Operation,&t.InputTokens, &t.OutputTokens, &t.TotalTokens, &t.CachedTokens, &t.ReasoningTokens,@@ -285,7 +291,7 @@ func (r *aiTraceRepository) FindById(ctx context.Context, projectId, traceId uuireturn &t, nil}-func (r *aiTraceRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID) ([]models.AiTrace, error) {+func (r *aiTraceRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID, recordedAt *time.Time) ([]models.AiTrace, error) {if len(projectIds) == 0 {return nil, nil}@@ -303,8 +309,13 @@ func (r *aiTraceRepository) FindByDistributedTraceId(ctx context.Context, distritrace_name, user_id, finish_reason, server_name, app_version,storage_key, attributes, distributed_trace_id, is_rootFROM ai_traces- WHERE distributed_trace_id = ? AND project_id IN (` + strings.Join(placeholders, ",") + `)- ORDER BY recorded_at ASC`+ WHERE distributed_trace_id = ? AND project_id IN (` + strings.Join(placeholders, ",") + `)`+ if recordedAt != nil {+ from, to := distributedTraceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` ORDER BY recorded_at ASC`rows, err := chdb.Conn.Query(ctx, query, args...)if err != nil {diff --git a/backend/app/repositories/ai_trace.repository_sqlite.go b/backend/app/repositories/ai_trace.repository_sqlite.goindex 7d4c6cc9..85323ea8 100644--- a/backend/app/repositories/ai_trace.repository_sqlite.go+++ b/backend/app/repositories/ai_trace.repository_sqlite.go@@ -382,18 +382,25 @@ func (r *aiTraceRepository) GetTraceNameStats(ctx context.Context, projectId uuireturn stats, nil}-func (r *aiTraceRepository) FindById(ctx context.Context, projectId, traceId uuid.UUID) (*models.AiTrace, error) {- row, err := lit.SelectSingleNamed[aiTraceRow](db.TelemetryDB,- `SELECT id, project_id, recorded_at, duration, status_code,+func (r *aiTraceRepository) FindById(ctx context.Context, projectId, traceId uuid.UUID, recordedAt *time.Time) (*models.AiTrace, error) {+ query := `SELECT id, project_id, recorded_at, duration, status_code,model, response_model, provider, operation,input_tokens, output_tokens, total_tokens, cached_tokens, reasoning_tokens,input_cost, output_cost, total_cost,trace_name, user_id, finish_reason, server_name, app_version,storage_key, attributes, distributed_trace_id, is_rootFROM ai_traces- WHERE project_id = :project_id AND id = :id- LIMIT 1`,- lit.P{"project_id": projectId, "id": traceId})+ WHERE project_id = :project_id AND id = :id`+ params := lit.P{"project_id": projectId, "id": traceId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` LIMIT 1`++ row, err := lit.SelectSingleNamed[aiTraceRow](db.TelemetryDB, query, params)if err != nil {return nil, err}@@ -404,7 +411,7 @@ func (r *aiTraceRepository) FindById(ctx context.Context, projectId, traceId uuireturn &result, nil}-func (r *aiTraceRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID) ([]models.AiTrace, error) {+func (r *aiTraceRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID, recordedAt *time.Time) ([]models.AiTrace, error) {if len(projectIds) == 0 {return nil, nil}@@ -421,8 +428,14 @@ func (r *aiTraceRepository) FindByDistributedTraceId(ctx context.Context, distriinput_cost, output_cost, total_cost,trace_name, user_id, finish_reason, server_name, app_version,storage_key, attributes, distributed_trace_id, is_root- FROM ai_traces WHERE distributed_trace_id = :trace_id AND project_id IN (` + strings.Join(placeholders, ",") + `)- ORDER BY recorded_at ASC`+ FROM ai_traces WHERE distributed_trace_id = :trace_id AND project_id IN (` + strings.Join(placeholders, ",") + `)`+ if recordedAt != nil {+ from, to := distributedTraceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` ORDER BY recorded_at ASC`parsedQuery, args, err := lit.ParseNamedQuery(db.Driver, query, params)if err != nil {diff --git a/backend/app/repositories/endpoint.repository.go b/backend/app/repositories/endpoint.repository.goindex c76caa7a..37fdc9db 100644--- a/backend/app/repositories/endpoint.repository.go+++ b/backend/app/repositories/endpoint.repository.go@@ -336,17 +336,23 @@ func (e *endpointRepository) FindByEndpoint(ctx context.Context, projectId uuid.}// FindById returns a single endpoint by ID-func (e *endpointRepository) FindById(ctx context.Context, projectId, endpointId uuid.UUID) (*models.Endpoint, error) {+func (e *endpointRepository) FindById(ctx context.Context, projectId, endpointId uuid.UUID, recordedAt *time.Time) (*models.Endpoint, error) {query := `SELECT id, project_id, endpoint, duration, recorded_at, status_code, body_size, client_ip, attributes, app_version, server_name, distributed_trace_id, span_id, is_rootFROM endpoints- WHERE project_id = ? AND id = ?- LIMIT 1`+ WHERE project_id = ? AND id = ?`+ args := []any{projectId, endpointId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` LIMIT 1`var t models.Endpointvar attributesJSON stringvar isRoot uint8- err := chdb.Conn.QueryRow(ctx, query, projectId, endpointId).Scan(+ err := chdb.Conn.QueryRow(ctx, query, args...).Scan(&t.Id, &t.ProjectId, &t.Endpoint, &t.Duration, &t.RecordedAt,&t.StatusCode, &t.BodySize, &t.ClientIP, &attributesJSON, &t.AppVersion, &t.ServerName, &t.DistributedTraceId, &t.SpanId, &isRoot)t.IsRoot = isRoot == 1@@ -843,13 +849,19 @@ func (e *endpointRepository) UpsertSlowEndpoint(ctx context.Context, projectId ureturn batch.Send()}-func (e *endpointRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID) ([]models.Endpoint, error) {+func (e *endpointRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID, recordedAt *time.Time) ([]models.Endpoint, error) {query := `SELECT id, project_id, endpoint, duration, recorded_at, status_code, body_size, client_ip, attributes, app_version, server_name, distributed_trace_idFROM endpoints- WHERE distributed_trace_id = ? AND project_id IN (?)- ORDER BY recorded_at ASC`+ WHERE distributed_trace_id = ? AND project_id IN (?)`+ args := []any{distributedTraceId, projectIds}+ if recordedAt != nil {+ from, to := distributedTraceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` ORDER BY recorded_at ASC`- rows, err := chdb.Conn.Query(ctx, query, distributedTraceId, projectIds)+ rows, err := chdb.Conn.Query(ctx, query, args...)if err != nil {return nil, err}diff --git a/backend/app/repositories/endpoint.repository_sqlite.go b/backend/app/repositories/endpoint.repository_sqlite.goindex d854422f..fd2cd1c1 100644--- a/backend/app/repositories/endpoint.repository_sqlite.go+++ b/backend/app/repositories/endpoint.repository_sqlite.go@@ -392,11 +392,19 @@ func (e *endpointRepository) FindByEndpoint(ctx context.Context, projectId uuid.return endpoints, count, nil}-func (e *endpointRepository) FindById(ctx context.Context, projectId, endpointId uuid.UUID) (*models.Endpoint, error) {- row, err := lit.SelectSingleNamed[endpoint](db.TelemetryDB,- `SELECT id, project_id, endpoint, duration, recorded_at, status_code, body_size, client_ip, attributes, app_version, server_name, distributed_trace_id, span_id- FROM endpoints WHERE project_id = :project_id AND id = :id LIMIT 1`,- lit.P{"project_id": projectId, "id": endpointId})+func (e *endpointRepository) FindById(ctx context.Context, projectId, endpointId uuid.UUID, recordedAt *time.Time) (*models.Endpoint, error) {+ query := `SELECT id, project_id, endpoint, duration, recorded_at, status_code, body_size, client_ip, attributes, app_version, server_name, distributed_trace_id, span_id+ FROM endpoints WHERE project_id = :project_id AND id = :id`+ params := lit.P{"project_id": projectId, "id": endpointId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` LIMIT 1`++ row, err := lit.SelectSingleNamed[endpoint](db.TelemetryDB, query, params)if err != nil {return nil, err}@@ -1006,7 +1014,7 @@ func getTopEndpointsByMetric(ctx context.Context, projectId uuid.UUID, from, toreturn result, nil}-func (e *endpointRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID) ([]models.Endpoint, error) {+func (e *endpointRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID, recordedAt *time.Time) ([]models.Endpoint, error) {if len(projectIds) == 0 {return nil, nil}@@ -1018,8 +1026,14 @@ func (e *endpointRepository) FindByDistributedTraceId(ctx context.Context, distrparams[key] = pid}query := `SELECT id, project_id, endpoint, duration, recorded_at, status_code, body_size, client_ip, attributes, app_version, server_name, distributed_trace_id- FROM endpoints WHERE distributed_trace_id = :trace_id AND project_id IN (` + strings.Join(placeholders, ",") + `)- ORDER BY recorded_at ASC`+ FROM endpoints WHERE distributed_trace_id = :trace_id AND project_id IN (` + strings.Join(placeholders, ",") + `)`+ if recordedAt != nil {+ from, to := distributedTraceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` ORDER BY recorded_at ASC`parsedQuery, args, err := lit.ParseNamedQuery(db.Driver, query, params)if err != nil {diff --git a/backend/app/repositories/endpoint_repository_test.go b/backend/app/repositories/endpoint_repository_test.goindex 05d63651..b0601d12 100644--- a/backend/app/repositories/endpoint_repository_test.go+++ b/backend/app/repositories/endpoint_repository_test.go@@ -232,7 +232,7 @@ func TestEndpointRepository_FindById(t *testing.T) {t.Fatalf("InsertAsync failed: %v", err)}- found, err := EndpointRepository.FindById(ctx, projectId, ep.Id)+ found, err := EndpointRepository.FindById(ctx, projectId, ep.Id, nil)if err != nil {t.Fatalf("FindById failed: %v", err)}@@ -251,7 +251,7 @@ func TestEndpointRepository_FindById_NotFound(t *testing.T) {setupTestDB(t)ctx := context.Background()- found, err := EndpointRepository.FindById(ctx, uuid.New(), uuid.New())+ found, err := EndpointRepository.FindById(ctx, uuid.New(), uuid.New(), nil)if err != nil {t.Fatalf("FindById failed: %v", err)}diff --git a/backend/app/repositories/exception_repository_test.go b/backend/app/repositories/exception_repository_test.goindex 3ad62411..be834c98 100644--- a/backend/app/repositories/exception_repository_test.go+++ b/backend/app/repositories/exception_repository_test.go@@ -263,7 +263,7 @@ func TestExceptionRepository_FindById(t *testing.T) {t.Fatalf("InsertAsync failed: %v", err)}- found, err := ExceptionStackTraceRepository.FindById(ctx, projectId, exc.Id)+ found, err := ExceptionStackTraceRepository.FindById(ctx, projectId, exc.Id, nil)if err != nil {t.Fatalf("FindById failed: %v", err)}@@ -279,7 +279,7 @@ func TestExceptionRepository_FindById_NotFound(t *testing.T) {setupTestDB(t)ctx := context.Background()- found, err := ExceptionStackTraceRepository.FindById(ctx, uuid.New(), uuid.New())+ found, err := ExceptionStackTraceRepository.FindById(ctx, uuid.New(), uuid.New(), nil)if err != nil {t.Fatalf("FindById failed: %v", err)}diff --git a/backend/app/repositories/exception_stack_trace.repository.go b/backend/app/repositories/exception_stack_trace.repository.goindex 9a3fd9c2..06919c79 100644--- a/backend/app/repositories/exception_stack_trace.repository.go+++ b/backend/app/repositories/exception_stack_trace.repository.go@@ -400,13 +400,19 @@ func (e *exceptionStackTraceRepository) FindExceptionByTraceId(ctx context.Conte}// FindAllByTraceId returns all exceptions and messages associated with a specific trace-func (e *exceptionStackTraceRepository) FindAllByTraceId(ctx context.Context, projectId uuid.UUID, traceId uuid.UUID) ([]models.ExceptionStackTrace, error) {- rows, err := chdb.Conn.Query(ctx,- `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_id+func (e *exceptionStackTraceRepository) FindAllByTraceId(ctx context.Context, projectId uuid.UUID, traceId uuid.UUID, recordedAt *time.Time) ([]models.ExceptionStackTrace, error) {+ query := `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_idFROM exception_stack_traces- WHERE project_id = ? AND trace_id = ?- ORDER BY recorded_at ASC`,- projectId, traceId)+ WHERE project_id = ? AND trace_id = ?`+ args := []any{projectId, traceId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` ORDER BY recorded_at ASC`++ rows, err := chdb.Conn.Query(ctx, query, args...)if err != nil {return nil, err@@ -437,17 +443,23 @@ func (e *exceptionStackTraceRepository) FindAllByTraceId(ctx context.Context, pr}// FindById returns a single exception by its ID-func (e *exceptionStackTraceRepository) FindById(ctx context.Context, projectId uuid.UUID, id uuid.UUID) (*models.ExceptionStackTrace, error) {+func (e *exceptionStackTraceRepository) FindById(ctx context.Context, projectId uuid.UUID, id uuid.UUID, recordedAt *time.Time) (*models.ExceptionStackTrace, error) {var est models.ExceptionStackTracevar attributesJSON stringvar isMessage uint8- err := chdb.Conn.QueryRow(ctx,- `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_id+ query := `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_idFROM exception_stack_traces- WHERE project_id = ? AND id = ?- LIMIT 1`,- projectId, id).Scan(+ WHERE project_id = ? AND id = ?`+ args := []any{projectId, id}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` LIMIT 1`++ err := chdb.Conn.QueryRow(ctx, query, args...).Scan(&est.Id, &est.ProjectId, &est.TraceId, &est.TraceType, &est.ExceptionHash, &est.StackTrace,&est.RecordedAt, &attributesJSON, &est.AppVersion, &est.ServerName, &isMessage, &est.DistributedTraceId)@@ -468,13 +480,19 @@ func (e *exceptionStackTraceRepository) FindById(ctx context.Context, projectIdreturn &est, nil}-func (e *exceptionStackTraceRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID) ([]models.ExceptionStackTrace, error) {+func (e *exceptionStackTraceRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID, recordedAt *time.Time) ([]models.ExceptionStackTrace, error) {query := `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_idFROM exception_stack_traces- WHERE distributed_trace_id = ? AND project_id IN (?) AND is_message = false- ORDER BY recorded_at ASC`+ WHERE distributed_trace_id = ? AND project_id IN (?) AND is_message = false`+ args := []any{distributedTraceId, projectIds}+ if recordedAt != nil {+ from, to := distributedTraceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` ORDER BY recorded_at ASC`- rows, err := chdb.Conn.Query(ctx, query, distributedTraceId, projectIds)+ rows, err := chdb.Conn.Query(ctx, query, args...)if err != nil {return nil, err}diff --git a/backend/app/repositories/exception_stack_trace.repository_sqlite.go b/backend/app/repositories/exception_stack_trace.repository_sqlite.goindex 50538e78..8eb169fd 100644--- a/backend/app/repositories/exception_stack_trace.repository_sqlite.go+++ b/backend/app/repositories/exception_stack_trace.repository_sqlite.go@@ -402,11 +402,19 @@ func (e *exceptionStackTraceRepository) FindExceptionByTraceId(ctx context.Contereturn &est, nil}-func (e *exceptionStackTraceRepository) FindAllByTraceId(ctx context.Context, projectId uuid.UUID, traceId uuid.UUID) ([]models.ExceptionStackTrace, error) {- rows, err := lit.SelectNamed[exceptionRow](db.TelemetryDB,- `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_id, session_id- FROM exception_stack_traces WHERE project_id = :project_id AND trace_id = :trace_id ORDER BY recorded_at ASC`,- lit.P{"project_id": projectId, "trace_id": traceId})+func (e *exceptionStackTraceRepository) FindAllByTraceId(ctx context.Context, projectId uuid.UUID, traceId uuid.UUID, recordedAt *time.Time) ([]models.ExceptionStackTrace, error) {+ query := `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_id, session_id+ FROM exception_stack_traces WHERE project_id = :project_id AND trace_id = :trace_id`+ params := lit.P{"project_id": projectId, "trace_id": traceId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` ORDER BY recorded_at ASC`++ rows, err := lit.SelectNamed[exceptionRow](db.TelemetryDB, query, params)if err != nil {return nil, err}@@ -418,11 +426,19 @@ func (e *exceptionStackTraceRepository) FindAllByTraceId(ctx context.Context, prreturn results, nil}-func (e *exceptionStackTraceRepository) FindById(ctx context.Context, projectId uuid.UUID, id uuid.UUID) (*models.ExceptionStackTrace, error) {- row, err := lit.SelectSingleNamed[exceptionRow](db.TelemetryDB,- `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_id, session_id- FROM exception_stack_traces WHERE project_id = :project_id AND id = :id LIMIT 1`,- lit.P{"project_id": projectId, "id": id})+func (e *exceptionStackTraceRepository) FindById(ctx context.Context, projectId uuid.UUID, id uuid.UUID, recordedAt *time.Time) (*models.ExceptionStackTrace, error) {+ query := `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_id, session_id+ FROM exception_stack_traces WHERE project_id = :project_id AND id = :id`+ params := lit.P{"project_id": projectId, "id": id}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` LIMIT 1`++ row, err := lit.SelectSingleNamed[exceptionRow](db.TelemetryDB, query, params)if err != nil {return nil, err}@@ -433,7 +449,7 @@ func (e *exceptionStackTraceRepository) FindById(ctx context.Context, projectIdreturn &est, nil}-func (e *exceptionStackTraceRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID) ([]models.ExceptionStackTrace, error) {+func (e *exceptionStackTraceRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID, recordedAt *time.Time) ([]models.ExceptionStackTrace, error) {if len(projectIds) == 0 {return nil, nil}@@ -446,8 +462,14 @@ func (e *exceptionStackTraceRepository) FindByDistributedTraceId(ctx context.Con}query := `SELECT id, project_id, trace_id, trace_type, exception_hash, stack_trace, recorded_at, attributes, app_version, server_name, is_message, distributed_trace_id, session_id- FROM exception_stack_traces WHERE distributed_trace_id = :trace_id AND project_id IN (` + strings.Join(placeholders, ",") + `) AND is_message = 0- ORDER BY recorded_at ASC`+ FROM exception_stack_traces WHERE distributed_trace_id = :trace_id AND project_id IN (` + strings.Join(placeholders, ",") + `) AND is_message = 0`+ if recordedAt != nil {+ from, to := distributedTraceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` ORDER BY recorded_at ASC`parsedQuery, args, err := lit.ParseNamedQuery(db.Driver, query, params)if err != nil {diff --git a/backend/app/repositories/span.repository.go b/backend/app/repositories/span.repository.goindex 22eebb53..775d01d6 100644--- a/backend/app/repositories/span.repository.go+++ b/backend/app/repositories/span.repository.go@@ -5,6 +5,7 @@ package repositoriesimport ("context""encoding/json"+ "time""github.com/tracewayapp/traceway/backend/app/chdb""github.com/tracewayapp/traceway/backend/app/models"@@ -50,14 +51,20 @@ func (r *spanRepository) InsertAsync(ctx context.Context, spans []models.Span) ereturn batch.Send()}-func (r *spanRepository) FindByTraceId(ctx context.Context, projectId, traceId uuid.UUID) ([]models.Span, error) {+func (r *spanRepository) FindByTraceId(ctx context.Context, projectId, traceId uuid.UUID, recordedAt *time.Time) ([]models.Span, error) {query := `SELECTid, trace_id, project_id, name, start_time, duration, recorded_at, parent_span_id, attributesFROM spans- WHERE project_id = ? AND trace_id = ?- ORDER BY start_time ASC`+ WHERE project_id = ? AND trace_id = ?`+ args := []any{projectId, traceId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` ORDER BY start_time ASC`- rows, err := chdb.Conn.Query(ctx, query, projectId, traceId)+ rows, err := chdb.Conn.Query(ctx, query, args...)if err != nil {return nil, err}diff --git a/backend/app/repositories/span.repository_sqlite.go b/backend/app/repositories/span.repository_sqlite.goindex 35c4633f..e5063b73 100644--- a/backend/app/repositories/span.repository_sqlite.go+++ b/backend/app/repositories/span.repository_sqlite.go@@ -84,13 +84,20 @@ func (r *spanRepository) InsertAsync(ctx context.Context, spans []models.Span) ereturn tx.Commit()}-func (r *spanRepository) FindByTraceId(ctx context.Context, projectId, traceId uuid.UUID) ([]models.Span, error) {- rows, err := lit.SelectNamed[span](db.TelemetryDB,- `SELECT id, trace_id, project_id, name, start_time, duration, recorded_at, parent_span_id, attributes+func (r *spanRepository) FindByTraceId(ctx context.Context, projectId, traceId uuid.UUID, recordedAt *time.Time) ([]models.Span, error) {+ query := `SELECT id, trace_id, project_id, name, start_time, duration, recorded_at, parent_span_id, attributesFROM spans- WHERE project_id = :project_id AND trace_id = :trace_id- ORDER BY start_time ASC`,- lit.P{"project_id": projectId, "trace_id": traceId})+ WHERE project_id = :project_id AND trace_id = :trace_id`+ params := lit.P{"project_id": projectId, "trace_id": traceId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` ORDER BY start_time ASC`++ rows, err := lit.SelectNamed[span](db.TelemetryDB, query, params)if err != nil {return nil, err}diff --git a/backend/app/repositories/span_repository_test.go b/backend/app/repositories/span_repository_test.goindex 4e1157e3..cc2d73bf 100644--- a/backend/app/repositories/span_repository_test.go+++ b/backend/app/repositories/span_repository_test.go@@ -25,7 +25,7 @@ func TestSpanRepository_InsertAndFindByTraceId(t *testing.T) {t.Fatalf("InsertAsync failed: %v", err)}- found, err := SpanRepository.FindByTraceId(ctx, projectId, traceId)+ found, err := SpanRepository.FindByTraceId(ctx, projectId, traceId, nil)if err != nil {t.Fatalf("FindByTraceId failed: %v", err)}@@ -68,7 +68,7 @@ func TestSpanRepository_AttributesRoundTrip(t *testing.T) {t.Fatalf("InsertAsync failed: %v", err)}- found, err := SpanRepository.FindByTraceId(ctx, projectId, traceId)+ found, err := SpanRepository.FindByTraceId(ctx, projectId, traceId, nil)if err != nil {t.Fatalf("FindByTraceId failed: %v", err)}@@ -91,7 +91,7 @@ func TestSpanRepository_FindByTraceId_Empty(t *testing.T) {setupTestDB(t)ctx := context.Background()- found, err := SpanRepository.FindByTraceId(ctx, uuid.New(), uuid.New())+ found, err := SpanRepository.FindByTraceId(ctx, uuid.New(), uuid.New(), nil)if err != nil {t.Fatalf("FindByTraceId failed: %v", err)}@@ -126,7 +126,7 @@ func TestSpanRepository_ProjectIsolation(t *testing.T) {t.Fatalf("InsertAsync failed: %v", err)}- found, err := SpanRepository.FindByTraceId(ctx, project1, traceId)+ found, err := SpanRepository.FindByTraceId(ctx, project1, traceId, nil)if err != nil {t.Fatalf("FindByTraceId failed: %v", err)}diff --git a/backend/app/repositories/task.repository.go b/backend/app/repositories/task.repository.goindex 048e65d2..1acbb7d6 100644--- a/backend/app/repositories/task.repository.go+++ b/backend/app/repositories/task.repository.go@@ -222,17 +222,23 @@ func (e *taskRepository) FindByTaskName(ctx context.Context, projectId uuid.UUID}// FindById returns a single task by ID-func (e *taskRepository) FindById(ctx context.Context, projectId, taskId uuid.UUID) (*models.Task, error) {+func (e *taskRepository) FindById(ctx context.Context, projectId, taskId uuid.UUID, recordedAt *time.Time) (*models.Task, error) {query := `SELECT id, project_id, task_name, duration, recorded_at, client_ip, attributes, app_version, server_name, distributed_trace_id, span_id, is_rootFROM tasks- WHERE project_id = ? AND id = ?- LIMIT 1`+ WHERE project_id = ? AND id = ?`+ args := []any{projectId, taskId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` LIMIT 1`var t models.Taskvar attributesJSON stringvar isRoot uint8- err := chdb.Conn.QueryRow(ctx, query, projectId, taskId).Scan(+ err := chdb.Conn.QueryRow(ctx, query, args...).Scan(&t.Id, &t.ProjectId, &t.TaskName, &t.Duration, &t.RecordedAt,&t.ClientIP, &attributesJSON, &t.AppVersion, &t.ServerName, &t.DistributedTraceId, &t.SpanId, &isRoot)t.IsRoot = isRoot == 1@@ -440,13 +446,19 @@ func (e *taskRepository) GetTaskStats(ctx context.Context, projectId uuid.UUID,return &stats, nil}-func (e *taskRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID) ([]models.Task, error) {+func (e *taskRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID, recordedAt *time.Time) ([]models.Task, error) {query := `SELECT id, project_id, task_name, duration, recorded_at, client_ip, attributes, app_version, server_name, distributed_trace_idFROM tasks- WHERE distributed_trace_id = ? AND project_id IN (?)- ORDER BY recorded_at ASC`+ WHERE distributed_trace_id = ? AND project_id IN (?)`+ args := []any{distributedTraceId, projectIds}+ if recordedAt != nil {+ from, to := distributedTraceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= ? AND recorded_at <= ?`+ args = append(args, from, to)+ }+ query += ` ORDER BY recorded_at ASC`- rows, err := chdb.Conn.Query(ctx, query, distributedTraceId, projectIds)+ rows, err := chdb.Conn.Query(ctx, query, args...)if err != nil {return nil, err}diff --git a/backend/app/repositories/task.repository_sqlite.go b/backend/app/repositories/task.repository_sqlite.goindex 72170eaa..c7462be4 100644--- a/backend/app/repositories/task.repository_sqlite.go+++ b/backend/app/repositories/task.repository_sqlite.go@@ -330,11 +330,19 @@ func (e *taskRepository) FindByTaskName(ctx context.Context, projectId uuid.UUIDreturn tasks, count, nil}-func (e *taskRepository) FindById(ctx context.Context, projectId, taskId uuid.UUID) (*models.Task, error) {- row, err := lit.SelectSingleNamed[task](db.TelemetryDB,- `SELECT id, project_id, task_name, duration, recorded_at, client_ip, attributes, app_version, server_name, distributed_trace_id, span_id, is_root- FROM tasks WHERE project_id = :project_id AND id = :id LIMIT 1`,- lit.P{"project_id": projectId, "id": taskId})+func (e *taskRepository) FindById(ctx context.Context, projectId, taskId uuid.UUID, recordedAt *time.Time) (*models.Task, error) {+ query := `SELECT id, project_id, task_name, duration, recorded_at, client_ip, attributes, app_version, server_name, distributed_trace_id, span_id, is_root+ FROM tasks WHERE project_id = :project_id AND id = :id`+ params := lit.P{"project_id": projectId, "id": taskId}+ if recordedAt != nil {+ from, to := traceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` LIMIT 1`++ row, err := lit.SelectSingleNamed[task](db.TelemetryDB, query, params)if err != nil {return nil, err}@@ -472,7 +480,7 @@ func (e *taskRepository) GetTaskStats(ctx context.Context, projectId uuid.UUID,}, nil}-func (e *taskRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID) ([]models.Task, error) {+func (e *taskRepository) FindByDistributedTraceId(ctx context.Context, distributedTraceId uuid.UUID, projectIds []uuid.UUID, recordedAt *time.Time) ([]models.Task, error) {if len(projectIds) == 0 {return nil, nil}@@ -484,8 +492,14 @@ func (e *taskRepository) FindByDistributedTraceId(ctx context.Context, distributparams[key] = pid}query := `SELECT id, project_id, task_name, duration, recorded_at, client_ip, attributes, app_version, server_name, distributed_trace_id- FROM tasks WHERE distributed_trace_id = :trace_id AND project_id IN (` + strings.Join(placeholders, ",") + `)- ORDER BY recorded_at ASC`+ FROM tasks WHERE distributed_trace_id = :trace_id AND project_id IN (` + strings.Join(placeholders, ",") + `)`+ if recordedAt != nil {+ from, to := distributedTraceWindowBounds(*recordedAt)+ query += ` AND recorded_at >= :from AND recorded_at <= :to`+ params["from"] = NewSQLiteTime(from)+ params["to"] = NewSQLiteTime(to)+ }+ query += ` ORDER BY recorded_at ASC`parsedQuery, args, err := lit.ParseNamedQuery(db.Driver, query, params)if err != nil {diff --git a/backend/app/repositories/task_repository_test.go b/backend/app/repositories/task_repository_test.goindex f68e8bdb..cfe807c4 100644--- a/backend/app/repositories/task_repository_test.go+++ b/backend/app/repositories/task_repository_test.go@@ -257,7 +257,7 @@ func TestTaskRepository_FindById(t *testing.T) {t.Fatalf("InsertAsync failed: %v", err)}- found, err := TaskRepository.FindById(ctx, projectId, task.Id)+ found, err := TaskRepository.FindById(ctx, projectId, task.Id, nil)if err != nil {t.Fatalf("FindById failed: %v", err)}@@ -276,7 +276,7 @@ func TestTaskRepository_FindById_NotFound(t *testing.T) {setupTestDB(t)ctx := context.Background()- found, err := TaskRepository.FindById(ctx, uuid.New(), uuid.New())+ found, err := TaskRepository.FindById(ctx, uuid.New(), uuid.New(), nil)if err != nil {t.Fatalf("FindById failed: %v", err)}diff --git a/backend/app/repositories/trace_window.go b/backend/app/repositories/trace_window.gonew file mode 100644index 00000000..7d9fa538--- /dev/null+++ b/backend/app/repositories/trace_window.go@@ -0,0 +1,15 @@+package repositories++import "time"++const traceLookupWindow = 24 * time.Hour++const distributedTraceLookupWindow = 48 * time.Hour++func traceWindowBounds(recordedAt time.Time) (time.Time, time.Time) {+ return recordedAt.Add(-traceLookupWindow), recordedAt.Add(traceLookupWindow)+}++func distributedTraceWindowBounds(recordedAt time.Time) (time.Time, time.Time) {+ return recordedAt.Add(-distributedTraceLookupWindow), recordedAt.Add(distributedTraceLookupWindow)+}diff --git a/frontend/src/lib/components/distributed-trace/distributed-trace-card.svelte b/frontend/src/lib/components/distributed-trace/distributed-trace-card.svelteindex 0a4ba3a1..8079f681 100644--- a/frontend/src/lib/components/distributed-trace/distributed-trace-card.svelte+++ b/frontend/src/lib/components/distributed-trace/distributed-trace-card.svelte@@ -15,9 +15,10 @@interface Props {distributedTraceId: string;currentExceptionHash?: string;+ recordedAt?: string;}- let { distributedTraceId, currentExceptionHash }: Props = $props();+ let { distributedTraceId, currentExceptionHash, recordedAt }: Props = $props();const timezone = $derived(getTimezone());@@ -31,7 +32,7 @@try {response = (await api.post(`/distributed-traces/${distributedTraceId}`,- {}+ recordedAt ? { recordedAt } : {})) as DistributedTraceResponse;} catch (e: any) {error = e.message || 'Failed to load distributed trace';diff --git a/frontend/src/lib/components/issues/event-card.svelte b/frontend/src/lib/components/issues/event-card.svelteindex 07ddf01d..b75da000 100644--- a/frontend/src/lib/components/issues/event-card.svelte+++ b/frontend/src/lib/components/issues/event-card.svelte@@ -254,5 +254,5 @@</Card.Root>{#if linkedTrace?.distributedTraceId || occurrence.distributedTraceId}- <DistributedTraceCard distributedTraceId={(linkedTrace?.distributedTraceId ?? occurrence.distributedTraceId)!} currentExceptionHash={occurrence.exceptionHash} />+ <DistributedTraceCard distributedTraceId={(linkedTrace?.distributedTraceId ?? occurrence.distributedTraceId)!} currentExceptionHash={occurrence.exceptionHash} recordedAt={linkedTrace?.recordedAt ?? occurrence.recordedAt} />{/if}diff --git a/frontend/src/lib/components/issues/events-table.svelte b/frontend/src/lib/components/issues/events-table.svelteindex 1e08c5cc..d9bde4b4 100644--- a/frontend/src/lib/components/issues/events-table.svelte+++ b/frontend/src/lib/components/issues/events-table.svelte@@ -38,7 +38,7 @@);function getRowUrl(occurrence: ExceptionOccurrence): string {- return `/issues/${exceptionHash}/${occurrence.id}`;+ return `/issues/${exceptionHash}/${occurrence.id}?t=${encodeURIComponent(occurrence.recordedAt)}`;}function isCurrentEvent(occurrence: ExceptionOccurrence): boolean {diff --git a/frontend/src/routes/ai-traces/[traceName]/+page.svelte b/frontend/src/routes/ai-traces/[traceName]/+page.svelteindex 2be11229..40b0d169 100644--- a/frontend/src/routes/ai-traces/[traceName]/+page.svelte+++ b/frontend/src/routes/ai-traces/[traceName]/+page.svelte@@ -351,7 +351,7 @@<Table.Rowclass="cursor-pointer hover:bg-muted/50"onclick={createRowClickHandler(- `/ai-traces/${encodeURIComponent(decodeURIComponent(data.traceName))}/${trace.id}`,+ `/ai-traces/${encodeURIComponent(decodeURIComponent(data.traceName))}/${trace.id}?t=${encodeURIComponent(trace.recordedAt)}`,'preset','from','to'diff --git a/frontend/src/routes/ai-traces/[traceName]/[traceId]/+page.svelte b/frontend/src/routes/ai-traces/[traceName]/[traceId]/+page.svelteindex abd8b058..6cb92844 100644--- a/frontend/src/routes/ai-traces/[traceName]/[traceId]/+page.svelte+++ b/frontend/src/routes/ai-traces/[traceName]/[traceId]/+page.svelte@@ -182,7 +182,7 @@try {const result = await api.post(`/ai-traces/${data.traceId}`,- {},+ data.recordedAt ? { recordedAt: data.recordedAt } : {},{ projectId: projectsState.currentProjectId ?? undefined });response = result;diff --git a/frontend/src/routes/ai-traces/[traceName]/[traceId]/+page.ts b/frontend/src/routes/ai-traces/[traceName]/[traceId]/+page.tsindex fba1ca02..78233431 100644--- a/frontend/src/routes/ai-traces/[traceName]/[traceId]/+page.ts+++ b/frontend/src/routes/ai-traces/[traceName]/[traceId]/+page.ts@@ -4,13 +4,14 @@ import type { PageLoad } from './$types';export const prerender = false;-export const load: PageLoad = ({ params }) => {+export const load: PageLoad = ({ params, url }) => {if (!authState.isAuthenticated) {throw redirect(302, '/login');}return {traceName: params.traceName,- traceId: params.traceId+ traceId: params.traceId,+ recordedAt: url.searchParams.get('t')};};diff --git a/frontend/src/routes/endpoints/[endpoint]/+page.svelte b/frontend/src/routes/endpoints/[endpoint]/+page.svelteindex 6a05e0a1..982c3791 100644--- a/frontend/src/routes/endpoints/[endpoint]/+page.svelte+++ b/frontend/src/routes/endpoints/[endpoint]/+page.svelte@@ -538,7 +538,7 @@<Table.Rowclass="cursor-pointer hover:bg-muted/50"onclick={createRowClickHandler(- `/endpoints/${encodeURIComponent(decodeURIComponent(data.endpoint))}/${transaction.id}`,+ `/endpoints/${encodeURIComponent(decodeURIComponent(data.endpoint))}/${transaction.id}?t=${encodeURIComponent(transaction.recordedAt)}`,'preset','from','to'diff --git a/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.svelte b/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.svelteindex 91df27d3..b357186b 100644--- a/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.svelte+++ b/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.svelte@@ -40,7 +40,7 @@try {const result = await api.post(`/endpoints/${data.endpointId}`,- {},+ data.recordedAt ? { recordedAt: data.recordedAt } : {},{ projectId: projectsState.currentProjectId ?? undefined });response = result;@@ -282,7 +282,10 @@/>{#if response.endpoint.distributedTraceId}- <DistributedTraceCard distributedTraceId={response.endpoint.distributedTraceId} />+ <DistributedTraceCard+ distributedTraceId={response.endpoint.distributedTraceId}+ recordedAt={response.endpoint.recordedAt}+ />{/if}{/if}</div>diff --git a/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.ts b/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.tsindex 17f47097..1b3385e7 100644--- a/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.ts+++ b/frontend/src/routes/endpoints/[endpoint]/[endpointId]/+page.ts@@ -12,6 +12,7 @@ export const load: PageLoad = ({ params, url }) => {return {endpoint: params.endpoint,endpointId: params.endpointId,+ recordedAt: url.searchParams.get('t'),preset: url.searchParams.get('preset') || null,from: url.searchParams.get('from') || null,to: url.searchParams.get('to') || nulldiff --git a/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.svelte b/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.svelteindex c35d1a4c..7dbead0a 100644--- a/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.svelte+++ b/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.svelte@@ -56,7 +56,7 @@try {// Load the specific exception by ID- const exceptionResponse = await api.post(`/exception-stack-traces/by-id/${data.exceptionId}`, {}, { projectId: projectsState.currentProjectId ?? undefined });+ const exceptionResponse = await api.post(`/exception-stack-traces/by-id/${data.exceptionId}`, data.recordedAt ? { recordedAt: data.recordedAt } : {}, { projectId: projectsState.currentProjectId ?? undefined });occurrence = exceptionResponse.exception;sessionRecording = exceptionResponse.sessionRecording ?? null;sessionId = exceptionResponse.sessionId ?? null;diff --git a/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.ts b/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.tsindex 63838e46..fd9c1c69 100644--- a/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.ts+++ b/frontend/src/routes/issues/[exceptionHash]/[exceptionId]/+page.ts@@ -1,8 +1,9 @@export const prerender = false;-export function load({ params }) {+export function load({ params, url }) {return {exceptionHash: params.exceptionHash,- exceptionId: params.exceptionId+ exceptionId: params.exceptionId,+ recordedAt: url.searchParams.get('t')};}diff --git a/frontend/src/routes/tasks/[task]/+page.svelte b/frontend/src/routes/tasks/[task]/+page.svelteindex 482c3886..2c63cca3 100644--- a/frontend/src/routes/tasks/[task]/+page.svelte+++ b/frontend/src/routes/tasks/[task]/+page.svelte@@ -344,7 +344,7 @@<Table.Rowclass="cursor-pointer hover:bg-muted/50"onclick={createRowClickHandler(- `/tasks/${encodeURIComponent(decodeURIComponent(data.task))}/${task.id}`,+ `/tasks/${encodeURIComponent(decodeURIComponent(data.task))}/${task.id}?t=${encodeURIComponent(task.recordedAt)}`,'preset','from','to'diff --git a/frontend/src/routes/tasks/[task]/[taskId]/+page.svelte b/frontend/src/routes/tasks/[task]/[taskId]/+page.svelteindex bc5ea546..04ecdba1 100644--- a/frontend/src/routes/tasks/[task]/[taskId]/+page.svelte+++ b/frontend/src/routes/tasks/[task]/[taskId]/+page.svelte@@ -67,7 +67,7 @@try {const result = await api.post(`/tasks/${data.taskId}`,- {},+ data.recordedAt ? { recordedAt: data.recordedAt } : {},{ projectId: projectsState.currentProjectId ?? undefined });response = result;@@ -281,7 +281,10 @@/>{#if response.task.distributedTraceId}- <DistributedTraceCard distributedTraceId={response.task.distributedTraceId} />+ <DistributedTraceCard+ distributedTraceId={response.task.distributedTraceId}+ recordedAt={response.task.recordedAt}+ />{/if}{/if}</div>diff --git a/frontend/src/routes/tasks/[task]/[taskId]/+page.ts b/frontend/src/routes/tasks/[task]/[taskId]/+page.tsindex cea16c7e..1ef80830 100644--- a/frontend/src/routes/tasks/[task]/[taskId]/+page.ts+++ b/frontend/src/routes/tasks/[task]/[taskId]/+page.ts@@ -12,6 +12,7 @@ export const load: PageLoad = ({ params, url }) => {return {task: params.task,taskId: params.taskId,+ recordedAt: url.searchParams.get('t'),preset: url.searchParams.get('preset') || null,from: url.searchParams.get('from') || null,to: url.searchParams.get('to') || null