Skip to content

Commit cb59f1d

Browse files
Add error_message field to bundle deploy telemetry
Track the first error diagnostic summary encountered during bundle deploy in telemetry. Move telemetry logging into a defer so it's always captured, even when deploy fails. Co-authored-by: Isaac
1 parent 1560aae commit cb59f1d

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

bundle/phases/deploy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func uploadLibraries(ctx context.Context, b *bundle.Bundle, libs map[string][]li
139139
// The deploy phase deploys artifacts and resources.
140140
// If readPlanPath is provided, the plan is loaded from that file instead of being calculated.
141141
func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHandler, engine engine.EngineType, libs map[string][]libraries.LocationToUpdate, plan *deployplan.Plan) {
142+
// Always log deploy telemetry, even on error.
143+
defer logDeployTelemetry(ctx, b)
144+
142145
log.Info(ctx, "Phase: deploy")
143146

144147
// Core mutators that CRUD resources and modify deployment state. These
@@ -208,7 +211,6 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
208211
return
209212
}
210213

211-
logDeployTelemetry(ctx, b)
212214
bundle.ApplyContext(ctx, b, scripts.Execute(config.ScriptPostDeploy))
213215
}
214216

bundle/phases/telemetry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/databricks/cli/bundle/libraries"
1111
"github.com/databricks/cli/libs/dyn"
1212
"github.com/databricks/cli/libs/log"
13+
"github.com/databricks/cli/libs/logdiag"
1314
"github.com/databricks/cli/libs/telemetry"
1415
"github.com/databricks/cli/libs/telemetry/protos"
1516
)
@@ -149,6 +150,7 @@ func logDeployTelemetry(ctx context.Context, b *bundle.Bundle) {
149150
BundleDeployEvent: &protos.BundleDeployEvent{
150151
BundleUuid: bundleUuid,
151152
DeploymentId: b.Metrics.DeploymentId.String(),
153+
ErrorMessage: logdiag.GetFirstErrorSummary(ctx),
152154

153155
ResourceCount: resourcesCount,
154156
ResourceJobCount: int64(len(b.Config.Resources.Jobs)),

libs/logdiag/logdiag.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type LogDiagData struct {
3030
// If Collect is true, diagnostics are appended to Collected. Use SetCollected() to set.
3131
Collect bool
3232
Collected []diag.Diagnostic
33+
34+
// Summary of the first error diagnostic logged, if any.
35+
FirstErrorSummary string
3336
}
3437

3538
// IsSetup returns whether InitContext() was already called.
@@ -117,6 +120,16 @@ func FlushCollected(ctx context.Context) diag.Diagnostics {
117120
return result
118121
}
119122

123+
// GetFirstErrorSummary returns the summary of the first error diagnostic
124+
// logged, or an empty string if no errors have been logged.
125+
func GetFirstErrorSummary(ctx context.Context) string {
126+
val := read(ctx)
127+
val.mu.Lock()
128+
defer val.mu.Unlock()
129+
130+
return val.FirstErrorSummary
131+
}
132+
120133
func LogDiag(ctx context.Context, d diag.Diagnostic) {
121134
val := read(ctx)
122135
val.mu.Lock()
@@ -125,6 +138,9 @@ func LogDiag(ctx context.Context, d diag.Diagnostic) {
125138
switch d.Severity {
126139
case diag.Error:
127140
val.Errors += 1
141+
if val.FirstErrorSummary == "" {
142+
val.FirstErrorSummary = d.Summary
143+
}
128144
case diag.Warning:
129145
val.Warnings += 1
130146
case diag.Recommendation:

libs/telemetry/protos/bundle_deploy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ type BundleDeployEvent struct {
77
// UUID associated with the deployment.
88
DeploymentId string `json:"deployment_id,omitempty"`
99

10+
// Error message encountered during the bundle deploy command, if any.
11+
ErrorMessage string `json:"error_message,omitempty"`
12+
1013
ResourceCount int64 `json:"resource_count"`
1114
ResourceJobCount int64 `json:"resource_job_count"`
1215
ResourcePipelineCount int64 `json:"resource_pipeline_count"`

0 commit comments

Comments
 (0)