SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix: instrumentation changes to capture query duration properly (#10362)
Nityananda Gohain2792e20aa2fa
diff --git a/pkg/telemetrystore/clickhousetelemetrystore/provider.go b/pkg/telemetrystore/clickhousetelemetrystore/provider.goindex 5e7ca0e9d5..db5844904a 100644--- a/pkg/telemetrystore/clickhousetelemetrystore/provider.go+++ b/pkg/telemetrystore/clickhousetelemetrystore/provider.go@@ -40,7 +40,6 @@ func New(ctx context.Context, providerSettings factory.ProviderSettings, configreturn nil, err}-hooks := make([]telemetrystore.TelemetryStoreHook, len(hookFactories))for i, hookFactory := range hookFactories {hook, err := hookFactory.New(ctx, providerSettings, config)@@ -83,11 +82,18 @@ func (p *provider) Query(ctx context.Context, query string, args ...interface{})ctx = telemetrystore.WrapBeforeQuery(p.hooks, ctx, event)rows, err := p.clickHouseConn.Query(ctx, query, args...)+ if err != nil {+ event.Err = err+ telemetrystore.WrapAfterQuery(p.hooks, ctx, event)+ return nil, err+ }- event.Err = err- telemetrystore.WrapAfterQuery(p.hooks, ctx, event)-- return rows, err+ return &rowsWithHooks{+ Rows: rows,+ ctx: ctx,+ event: event,+ onClose: func() { telemetrystore.WrapAfterQuery(p.hooks, ctx, event) },+ }, nil}func (p *provider) QueryRow(ctx context.Context, query string, args ...interface{}) driver.Row {diff --git a/pkg/telemetrystore/clickhousetelemetrystore/rows.go b/pkg/telemetrystore/clickhousetelemetrystore/rows.gonew file mode 100644index 0000000000..a27a4f4fc6--- /dev/null+++ b/pkg/telemetrystore/clickhousetelemetrystore/rows.go@@ -0,0 +1,37 @@+package clickhousetelemetrystore++import (+ "context"++ "github.com/ClickHouse/clickhouse-go/v2/lib/driver"+ "github.com/SigNoz/signoz/pkg/telemetrystore"+)++// rowsWithHooks wraps driver.Rows and defers AfterQuery hooks until Close(),+// so the instrumentation span covers the full query lifecycle including row consumption.+type rowsWithHooks struct {+ driver.Rows+ ctx context.Context+ event *telemetrystore.QueryEvent+ onClose func()+ closed bool+}++func (r *rowsWithHooks) Close() error {+ // delegate to the original rows.Close() if already closed+ if r.closed {+ return r.Rows.Close()+ }++ // mark as closed and run the onClose hook+ r.closed = true+ if err := r.Rows.Err(); err != nil {+ r.event.Err = err+ }+ closeErr := r.Rows.Close()+ if closeErr != nil {+ r.event.Err = closeErr+ }+ r.onClose()+ return closeErr+}