Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
153 changes: 153 additions & 0 deletions bundle/phases/telemetry_scrub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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 at least two components
// (e.g., C:\foo\bar, D:/projects/myapp).
windowsAbsPathRegexp = 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, windowsAbsPathRegexp, "[REDACTED_PATH]", 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