Skip to content

Commit

Permalink
fix: do not send state update telemetry events (#861)
Browse files Browse the repository at this point in the history
Also, added a remote profile boolean flag to API requests

Signed-off-by: Toma Puljak <toma.puljak@hotmail.com>
  • Loading branch information
Tpuljak authored Jul 30, 2024
1 parent dda3c27 commit ce500c6
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions pkg/api/middlewares/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package middlewares

import (
"context"
"strings"
"time"

"github.com/daytonaio/daytona/internal"
Expand All @@ -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 {
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit ce500c6

Please sign in to comment.