Skip to content

Commit 6bda425

Browse files
committed
Add debug logging for SPOG x-databricks-org-id header extraction
Mirrors equivalent logging added to OSS JDBC and pysql. Emits at DEBUG level in three paths of extractSpogHeaders: 1. Malformed query string in httpPath — log and skip. 2. httpPath has "?" but no ?o= param — log and skip. 3. Injection happens — log the extracted workspace ID so customers diagnosing SPOG routing can confirm the header was added. Also adds a detailed docstring explaining the role this header plays: Thrift routing stays URL-driven via ?o= in httpPath; only the separate endpoints (telemetry, feature flags) need the header for account-level routing on SPOG hosts. Helps with customer support: when a customer reports "SPOG isn't routing correctly", they can enable DEBUG logging and immediately see whether the driver saw their ?o= value. Signed-off-by: Madhavendra Rathore Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
1 parent 0ec7e06 commit 6bda425

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

connector.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ func NewConnector(options ...ConnOption) (driver.Connector, error) {
125125

126126
// extractSpogHeaders extracts ?o=<workspaceId> from httpPath and returns
127127
// an x-databricks-org-id header for SPOG routing.
128+
//
129+
// On SPOG (Custom URL) workspaces, httpPath is of the form
130+
// /sql/1.0/warehouses/<id>?o=<workspaceId>. The ?o= parameter keeps Thrift
131+
// requests routed to the correct workspace via the URL itself, but other
132+
// endpoints (telemetry, feature flags) run on separate hosts and need the
133+
// x-databricks-org-id header. This function extracts ?o= from httpPath once
134+
// and returns it so those paths can inject it as an HTTP header.
135+
//
136+
// Returns nil if:
137+
// - httpPath has no query string ("?"), or
138+
// - the query string is malformed and can't be parsed, or
139+
// - the ?o= parameter is missing or empty.
128140
func extractSpogHeaders(httpPath string) map[string]string {
129141
if !strings.Contains(httpPath, "?") {
130142
return nil
@@ -133,12 +145,21 @@ func extractSpogHeaders(httpPath string) map[string]string {
133145
parts := strings.SplitN(httpPath, "?", 2)
134146
params, err := url.ParseQuery(parts[1])
135147
if err != nil {
148+
logger.Debug().Msgf(
149+
"SPOG header extraction: malformed query string in httpPath, skipping org-id extraction: %s",
150+
err)
136151
return nil
137152
}
138153
orgID := params.Get("o")
139154
if orgID == "" {
155+
logger.Debug().Msg(
156+
"SPOG header extraction: httpPath has query string but no ?o= param, " +
157+
"skipping x-databricks-org-id injection")
140158
return nil
141159
}
160+
logger.Debug().Msgf(
161+
"SPOG header extraction: injecting x-databricks-org-id=%s (extracted from ?o= in httpPath)",
162+
orgID)
142163
return map[string]string{"x-databricks-org-id": orgID}
143164
}
144165

0 commit comments

Comments
 (0)