Skip to content

Commit f69d8a7

Browse files
chore(api): log reason for failing to connect, resume sandboxes on state change (#2145)
* log reason for failing to connect, resume sandboxes on state change
1 parent 029a122 commit f69d8a7

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

packages/api/internal/handlers/sandbox_connect.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func (a *APIStore) PostSandboxesSandboxIDConnect(c *gin.Context, sandboxID api.S
8080
// Sandbox exists but isn't running → check which transitional state.
8181
var notRunningErr *sandbox.NotRunningError
8282
if !errors.As(apiErr.Err, &notRunningErr) {
83+
telemetry.ReportErrorByCode(ctx, apiErr.Code, "error keeping sandbox alive", apiErr.Err,
84+
telemetry.WithSandboxID(sandboxID),
85+
telemetry.WithTeamID(teamID.String()),
86+
)
8387
a.sendAPIStoreError(c, apiErr.Code, apiErr.ClientMsg)
8488

8589
return
@@ -99,6 +103,10 @@ func (a *APIStore) PostSandboxesSandboxIDConnect(c *gin.Context, sandboxID api.S
99103

100104
err = a.orchestrator.WaitForStateChange(ctx, teamID, sandboxID)
101105
if err != nil {
106+
telemetry.ReportCriticalError(ctx, "error waiting for sandbox state change", err,
107+
telemetry.WithSandboxID(sandboxID),
108+
telemetry.WithTeamID(teamID.String()),
109+
)
102110
a.sendAPIStoreError(c, http.StatusInternalServerError,
103111
"Error waiting for sandbox state change")
104112

@@ -118,7 +126,7 @@ func (a *APIStore) PostSandboxesSandboxIDConnect(c *gin.Context, sandboxID api.S
118126
return
119127
}
120128

121-
logger.L().Error(ctx, "Error getting last snapshot", logger.WithSandboxID(sandboxID), zap.Error(err))
129+
telemetry.ReportCriticalError(ctx, "Error getting last snapshot", err, telemetry.WithSandboxID(sandboxID), telemetry.WithTeamID(teamID.String()))
122130
a.sendAPIStoreError(c, http.StatusInternalServerError, "Error when getting snapshot")
123131

124132
return
@@ -152,7 +160,12 @@ func (a *APIStore) PostSandboxesSandboxIDConnect(c *gin.Context, sandboxID api.S
152160
if snap.EnvSecure {
153161
accessToken, tokenErr := a.getEnvdAccessToken(build.EnvdVersion, sandboxID)
154162
if tokenErr != nil {
155-
logger.L().Error(ctx, "Secure envd access token error", zap.Error(tokenErr.Err), logger.WithTemplateID(snap.EnvID), logger.WithBuildID(build.ID.String()), logger.WithSandboxID(sandboxID))
163+
telemetry.ReportErrorByCode(ctx, tokenErr.Code, "Secure envd access token error", tokenErr.Err,
164+
telemetry.WithTemplateID(snap.EnvID),
165+
telemetry.WithBuildID(build.ID.String()),
166+
telemetry.WithSandboxID(sandboxID),
167+
telemetry.WithTeamID(teamID.String()),
168+
)
156169
a.sendAPIStoreError(c, tokenErr.Code, tokenErr.ClientMsg)
157170

158171
return

packages/api/internal/handlers/sandbox_resume.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func (a *APIStore) PostSandboxesSandboxIDResume(c *gin.Context, sandboxID api.Sa
7979
logger.L().Debug(ctx, "Waiting for sandbox to pause", logger.WithSandboxID(sandboxID))
8080
err = a.orchestrator.WaitForStateChange(ctx, teamID, sandboxID)
8181
if err != nil {
82+
telemetry.ReportCriticalError(ctx, "error waiting for sandbox to pause", err,
83+
telemetry.WithSandboxID(sandboxID),
84+
telemetry.WithTeamID(teamID.String()),
85+
)
8286
a.sendAPIStoreError(c, http.StatusInternalServerError, "Error waiting for sandbox to pause")
8387

8488
return
@@ -104,7 +108,10 @@ func (a *APIStore) PostSandboxesSandboxIDResume(c *gin.Context, sandboxID api.Sa
104108

105109
return
106110
default:
107-
logger.L().Error(ctx, "Sandbox is in an unknown state", logger.WithSandboxID(sandboxID), zap.String("state", string(sandboxData.State)))
111+
telemetry.ReportCriticalError(ctx, "Sandbox is in an unknown state", fmt.Errorf("state: %s", sandboxData.State),
112+
telemetry.WithSandboxID(sandboxID),
113+
telemetry.WithTeamID(teamID.String()),
114+
)
108115
a.sendAPIStoreError(c, http.StatusInternalServerError, "Sandbox is in an unknown state")
109116

110117
return
@@ -121,7 +128,10 @@ func (a *APIStore) PostSandboxesSandboxIDResume(c *gin.Context, sandboxID api.Sa
121128
return
122129
}
123130

124-
logger.L().Error(ctx, "Error getting last snapshot", logger.WithSandboxID(sandboxID), zap.Error(err))
131+
telemetry.ReportCriticalError(ctx, "Error getting last snapshot", err,
132+
telemetry.WithSandboxID(sandboxID),
133+
telemetry.WithTeamID(teamID.String()),
134+
)
125135
a.sendAPIStoreError(c, http.StatusInternalServerError, "Error when getting snapshot")
126136

127137
return
@@ -158,7 +168,12 @@ func (a *APIStore) PostSandboxesSandboxIDResume(c *gin.Context, sandboxID api.Sa
158168
if snap.EnvSecure {
159169
accessToken, tokenErr := a.getEnvdAccessToken(build.EnvdVersion, sandboxID)
160170
if tokenErr != nil {
161-
logger.L().Error(ctx, "Secure envd access token error", zap.Error(tokenErr.Err), logger.WithTemplateID(snap.EnvID), logger.WithBuildID(build.ID.String()), logger.WithSandboxID(sandboxID))
171+
telemetry.ReportErrorByCode(ctx, tokenErr.Code, "Secure envd access token error", tokenErr.Err,
172+
telemetry.WithTemplateID(snap.EnvID),
173+
telemetry.WithBuildID(build.ID.String()),
174+
telemetry.WithSandboxID(sandboxID),
175+
telemetry.WithTeamID(teamID.String()),
176+
)
162177
a.sendAPIStoreError(c, tokenErr.Code, tokenErr.ClientMsg)
163178

164179
return

0 commit comments

Comments
 (0)