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
chore: added sampling in analytics
Ankit Nayan99c0c97c1e93
diff --git a/pkg/query-service/app/server.go b/pkg/query-service/app/server.goindex dd00aea804..a34bb0b477 100644--- a/pkg/query-service/app/server.go+++ b/pkg/query-service/app/server.go@@ -232,9 +232,10 @@ func (s *Server) analyticsMiddleware(next http.Handler) http.Handler {next.ServeHTTP(lrw, r)data := map[string]interface{}{"path": path, "statusCode": lrw.statusCode}-- if _, ok := telemetry.IgnoredPaths()[path]; !ok {- telemetry.GetInstance().SendEvent(telemetry.TELEMETRY_EVENT_PATH, data)+ if telemetry.GetInstance().IsSampled() {+ if _, ok := telemetry.IgnoredPaths()[path]; !ok {+ telemetry.GetInstance().SendEvent(telemetry.TELEMETRY_EVENT_PATH, data)+ }}})diff --git a/pkg/query-service/telemetry/telemetry.go b/pkg/query-service/telemetry/telemetry.goindex 0774b7bb91..1d2fa5429e 100644--- a/pkg/query-service/telemetry/telemetry.go+++ b/pkg/query-service/telemetry/telemetry.go@@ -3,6 +3,7 @@ package telemetryimport ("context""io/ioutil"+ "math/rand""net/http""os""strings"@@ -23,6 +24,7 @@ const (TELEMETRY_EVENT_NUMBER_OF_SERVICES = "Number of Services"TELEMETRY_EVENT_HEART_BEAT = "Heart Beat"TELEMETRY_EVENT_ORG_SETTINGS = "Org Settings"+ DEFAULT_SAMPLING = 0.1)const api_key = "4Gmoa4ixJAUHx2BpJxsjwA1bEfnwEeRz"@@ -35,6 +37,18 @@ const HEART_BEAT_DURATION = 6 * time.Hourvar telemetry *Telemetryvar once sync.Once+func (a *Telemetry) IsSampled() bool {++ number := a.minRandInt + rand.Intn(a.maxRandInt-a.minRandInt)++ if (number % a.maxRandInt) == 0 {+ return true+ } else {+ return false+ }++}+type Telemetry struct {operator analytics.ClientipAddress string@@ -43,6 +57,8 @@ type Telemetry struct {distinctId stringreader interfaces.ReadercompanyDomain string+ minRandInt int+ maxRandInt int}func createTelemetry() {@@ -50,6 +66,10 @@ func createTelemetry() {operator: analytics.New(api_key),ipAddress: getOutboundIP(),}+ telemetry.minRandInt = 0+ telemetry.maxRandInt = int(1 / DEFAULT_SAMPLING)++ rand.Seed(time.Now().UnixNano())data := map[string]interface{}{}