From ce500c64f71dd95b21e972e1ce0507db946648d9 Mon Sep 17 00:00:00 2001 From: Toma Puljak Date: Tue, 30 Jul 2024 10:58:54 +0200 Subject: [PATCH] fix: do not send state update telemetry events (#861) Also, added a remote profile boolean flag to API requests Signed-off-by: Toma Puljak --- pkg/api/middlewares/telemetry.go | 33 +++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pkg/api/middlewares/telemetry.go b/pkg/api/middlewares/telemetry.go index 72ee956dd3..b987ced390 100644 --- a/pkg/api/middlewares/telemetry.go +++ b/pkg/api/middlewares/telemetry.go @@ -5,6 +5,7 @@ package middlewares import ( "context" + "strings" "time" "github.com/daytonaio/daytona/internal" @@ -15,6 +16,12 @@ import ( log "github.com/sirupsen/logrus" ) +var ignorePaths = map[string]bool{ + "/health": true, + "/workspace/:workspaceId/:projectId/state": true, + "/server/network-key": true, +} + func TelemetryMiddleware(telemetryService telemetry.TelemetryService) gin.HandlerFunc { return func(ctx *gin.Context) { if telemetryService == nil { @@ -27,6 +34,12 @@ func TelemetryMiddleware(telemetryService telemetry.TelemetryService) gin.Handle return } + reqUri := ctx.FullPath() + if ignorePaths[reqUri] { + ctx.Next() + return + } + clientId := ctx.GetHeader(telemetry.CLIENT_ID_HEADER) if clientId == "" { clientId = uuid.NewString() @@ -49,17 +62,22 @@ func TelemetryMiddleware(telemetryService telemetry.TelemetryService) gin.Handle source := ctx.GetHeader(telemetry.SOURCE_HEADER) reqMethod := ctx.Request.Method - reqUri := ctx.FullPath() query := ctx.Request.URL.RawQuery + remoteProfile := false + if source == string(telemetry.CLI_SOURCE) && !strings.Contains(ctx.Request.Host, "localhost") { + remoteProfile = true + } + err := telemetryService.TrackServerEvent(telemetry.ServerEventApiRequestStarted, clientId, map[string]interface{}{ - "method": reqMethod, - "URI": reqUri, - "query": query, - "source": source, - "server_id": server.Id, - "session_id": sessionId, + "method": reqMethod, + "URI": reqUri, + "query": query, + "source": source, + "server_id": server.Id, + "session_id": sessionId, + "remote_profile": remoteProfile, }) if err != nil { log.Trace(err) @@ -80,6 +98,7 @@ func TelemetryMiddleware(telemetryService telemetry.TelemetryService) gin.Handle "exec time (µs)": execTime.Microseconds(), "server_id": server.Id, "session_id": sessionId, + "remote_profile": remoteProfile, } if len(ctx.Errors) > 0 {