Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
1a8ff40
Add error_message field to bundle deploy telemetry
shreyas-goenka Mar 19, 2026
3bc2436
Merge remote-tracking branch 'origin' into bundle-deploy-error-message
shreyas-goenka Mar 26, 2026
5b39bf3
Fix CI failures in deploy telemetry
shreyas-goenka Mar 26, 2026
c70dbb1
Cap error message length in deploy telemetry to 500 chars
shreyas-goenka Mar 26, 2026
a2fb5dd
Add acceptance test for deploy telemetry error message
shreyas-goenka Mar 26, 2026
ca229c4
Scrub sensitive paths and emails from deploy telemetry error messages
shreyas-goenka Mar 26, 2026
c5b0903
Simplify telemetry scrubber: remove home-specific code, add workspace…
shreyas-goenka Mar 26, 2026
8cc26b3
Fix Windows drive letter case sensitivity and add Windows bundle root…
shreyas-goenka Mar 26, 2026
34b5228
Remove replacePath; let regex patterns handle all path scrubbing
shreyas-goenka Mar 26, 2026
0242d30
Move tilde home path (~/) to absolute path regex
shreyas-goenka Mar 26, 2026
947e545
Retain known file extensions in redacted paths
shreyas-goenka Mar 26, 2026
e4197a8
Add more known file extensions to telemetry scrubber
shreyas-goenka Mar 26, 2026
8d680a8
Add web/app and doc file extensions to telemetry scrubber
shreyas-goenka Mar 26, 2026
968e9fb
Expand known extensions to cover all plausible error message paths
shreyas-goenka Mar 26, 2026
4a0b8d9
Document boundary character choice in path regexes
shreyas-goenka Mar 27, 2026
4919773
Update comment wording for known extensions
shreyas-goenka Mar 27, 2026
45d027b
Distinguish Windows backslash and forward-slash paths in telemetry sc…
shreyas-goenka Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bundle:
name: test-bundle

variables:
myvar:
description: a required variable

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions acceptance/bundle/telemetry/deploy-error-message/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

>>> [CLI] bundle deploy
Error: no value assigned to required variable myvar. Variables are usually assigned in databricks.yml, and they can be overridden using "--var", the BUNDLE_VAR_myvar environment variable, or .databricks/bundle/<target>/variable-overrides.json


Exit code: 1

>>> cat out.requests.txt
no value assigned to required variable myvar. Variables are usually assigned in databricks.yml, and they can be overridden using "--var", the BUNDLE_VAR_myvar environment variable, or [REDACTED_REL_PATH](json)
5 changes: 5 additions & 0 deletions acceptance/bundle/telemetry/deploy-error-message/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
errcode trace $CLI bundle deploy

trace cat out.requests.txt | jq -r 'select(has("path") and .path == "/telemetry-ext") | .body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_deploy_event.error_message'

rm out.requests.txt
1 change: 0 additions & 1 deletion bundle/phases/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
return
}

logDeployTelemetry(ctx, b)
bundle.ApplyContext(ctx, b, scripts.Execute(config.ScriptPostDeploy))
}

Expand Down
13 changes: 12 additions & 1 deletion bundle/phases/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ func getExecutionTimes(b *bundle.Bundle) []protos.IntMapEntry {
return executionTimes
}

func logDeployTelemetry(ctx context.Context, b *bundle.Bundle) {
// Maximum length of the error message included in telemetry.
const maxErrorMessageLength = 500

// LogDeployTelemetry logs a telemetry event for a bundle deploy command.
func LogDeployTelemetry(ctx context.Context, b *bundle.Bundle, errMsg string) {
errMsg = scrubForTelemetry(errMsg)

if len(errMsg) > maxErrorMessageLength {
errMsg = errMsg[:maxErrorMessageLength]
}

resourcesCount := int64(0)
_, err := dyn.MapByPattern(b.Config.Value(), dyn.NewPattern(dyn.Key("resources"), dyn.AnyKey(), dyn.AnyKey()), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
resourcesCount++
Expand Down Expand Up @@ -149,6 +159,7 @@ func logDeployTelemetry(ctx context.Context, b *bundle.Bundle) {
BundleDeployEvent: &protos.BundleDeployEvent{
BundleUuid: bundleUuid,
DeploymentId: b.Metrics.DeploymentId.String(),
ErrorMessage: errMsg,

ResourceCount: resourcesCount,
ResourceJobCount: int64(len(b.Config.Resources.Jobs)),
Expand Down
158 changes: 158 additions & 0 deletions bundle/phases/telemetry_scrub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package phases

import (
"path"
"regexp"
"strings"
)

// Scrub sensitive information from error messages before sending to telemetry.
// Inspired by VS Code's telemetry path scrubbing and Sentry's @userpath pattern.
//
// Path regexes use [\s:,"'] as boundary characters to delimit where a path
// ends. While these characters are technically valid in file paths, in error
// messages they act as delimiters (e.g. "error: /path/to/file: not found",
// or "failed to read '/some/path', skipping"). This is a practical tradeoff:
// paths containing colons, commas, or quotes are extremely rare, and without
// these boundaries the regexes would over-match into surrounding message text.
//
// References:
// - VS Code: https://github.com/microsoft/vscode/blob/main/src/vs/platform/telemetry/common/telemetryUtils.ts
// - Sentry: https://github.com/getsentry/relay (PII rule: @userpath)
var (
// Matches Windows absolute paths with backslashes and at least two components
// (e.g., C:\foo\bar, D:\Users\project).
windowsBackslashPathRegexp = regexp.MustCompile(`[A-Za-z]:\\[^\s:,"'/\\]+\\[^\s:,"']+`)

// Matches Windows absolute paths with forward slashes and at least two components
// (e.g., C:/foo/bar, D:/Users/project).
windowsFwdslashPathRegexp = regexp.MustCompile(`[A-Za-z]:/[^\s:,"'/\\]+/[^\s:,"']+`)

// Matches Databricks workspace paths (/Workspace/...).
workspacePathRegexp = regexp.MustCompile(`(^|[\s:,"'])(/Workspace/[^\s:,"']+)`)

// Matches absolute Unix paths with at least two components
// (e.g., /home/user/..., /tmp/foo, ~/.config/databricks).
absPathRegexp = regexp.MustCompile(`(^|[\s:,"'])(~?/[^\s:,"'/]+/[^\s:,"']+)`)

// Matches relative paths:
// - Explicit: ./foo, ../foo
// - Dot-prefixed directories: .databricks/bundle/..., .cache/foo
explicitRelPathRegexp = regexp.MustCompile(`(^|[\s:,"'])((?:\.\.?|\.[a-zA-Z][^\s:,"'/]*)/[^\s:,"']+)`)

// Matches implicit relative paths: at least two path components where
// the last component has a file extension (e.g., "resources/job.yml",
// "bundle/dev/state.json").
implicitRelPathRegexp = regexp.MustCompile(`(^|[\s:,"'])([a-zA-Z0-9_][^\s:,"']*/[^\s:,"']*\.[a-zA-Z][^\s:,"']*)`)

// Matches email addresses. Workspace paths in Databricks often contain
// emails (e.g., /Workspace/Users/user@example.com/.bundle/dev).
emailRegexp = regexp.MustCompile(`[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}`)
)

// Known file extensions that are safe to retain in redacted paths.
// These help understand usage patterns without capturing sensitive information.
var knownExtensions = map[string]bool{
// Configuration and data formats
".yml": true,
".yaml": true,
".json": true,
".toml": true,
".cfg": true,
".ini": true,
".env": true,
".xml": true,
".properties": true,
".conf": true,

// Notebook and script languages
".py": true,
".r": true,
".scala": true,
".sql": true,
".ipynb": true,
".sh": true,

// Web / Apps
".js": true,
".ts": true,
".jsx": true,
".tsx": true,
".html": true,
".css": true,

// Terraform
".tf": true,
".hcl": true,
".tfstate": true,
".tfvars": true,

// Build artifacts and archives
".whl": true,
".jar": true,
".egg": true,
".zip": true,
".tar": true,
".gz": true,
".tgz": true,
".dbc": true,

// Data formats
".txt": true,
".csv": true,
".md": true,
".parquet": true,
".avro": true,

// Logs and locks
".log": true,
".lock": true,

// Certificates and keys
".pem": true,
".crt": true,
}

// scrubForTelemetry is a best-effort scrubber that removes sensitive path and
// PII information from error messages before they are sent to telemetry.
// The error message is treated as PII by the logging infrastructure but we
// scrub to avoid collecting more information than necessary.
func scrubForTelemetry(msg string) string {
// Redact absolute paths.
msg = replacePathRegexp(msg, windowsBackslashPathRegexp, "[REDACTED_WIN_PATH]", false)
msg = replacePathRegexp(msg, windowsFwdslashPathRegexp, "[REDACTED_WIN_FPATH]", false)
msg = replacePathRegexp(msg, workspacePathRegexp, "[REDACTED_WORKSPACE_PATH]", true)
msg = replacePathRegexp(msg, absPathRegexp, "[REDACTED_PATH]", true)

// Redact relative paths.
msg = replacePathRegexp(msg, explicitRelPathRegexp, "[REDACTED_REL_PATH]", true)
msg = replacePathRegexp(msg, implicitRelPathRegexp, "[REDACTED_REL_PATH]", true)

// Redact email addresses.
msg = emailRegexp.ReplaceAllString(msg, "[REDACTED_EMAIL]")

return msg
}

// replacePathRegexp replaces path matches with the given label, retaining
// known file extensions. When hasDelimiterGroup is true, the first character
// of the match is preserved as a delimiter prefix.
func replacePathRegexp(msg string, re *regexp.Regexp, label string, hasDelimiterGroup bool) string {
return re.ReplaceAllStringFunc(msg, func(match string) string {
prefix := ""
p := match
if hasDelimiterGroup && len(match) > 0 {
first := match[0]
if strings.ContainsRune(" \t\n:,\"'", rune(first)) {
prefix = match[:1]
p = match[1:]
}
}

ext := path.Ext(p)
if knownExtensions[ext] {
return prefix + label + "(" + ext[1:] + ")"
}
return prefix + label
})
}
Loading
Loading