@@ -31,23 +31,6 @@ type telemetryMetric struct {
3131 tags map [string ]interface {}
3232}
3333
34- // telemetryPayload is the JSON structure sent to Databricks.
35- type telemetryPayload struct {
36- Metrics []* exportedMetric `json:"metrics"`
37- }
38-
39- // exportedMetric is a single metric in the payload.
40- type exportedMetric struct {
41- MetricType string `json:"metric_type"`
42- Timestamp string `json:"timestamp"` // RFC3339
43- WorkspaceID string `json:"workspace_id,omitempty"`
44- SessionID string `json:"session_id,omitempty"`
45- StatementID string `json:"statement_id,omitempty"`
46- LatencyMs int64 `json:"latency_ms,omitempty"`
47- ErrorType string `json:"error_type,omitempty"`
48- Tags map [string ]interface {} `json:"tags,omitempty"`
49- }
50-
5134// newTelemetryExporter creates a new exporter.
5235func newTelemetryExporter (host string , driverVersion string , httpClient * http.Client , cfg * Config ) * telemetryExporter {
5336 return & telemetryExporter {
@@ -88,23 +71,21 @@ func (e *telemetryExporter) export(ctx context.Context, metrics []*telemetryMetr
8871
8972// doExport performs the actual export with retries and exponential backoff.
9073func (e * telemetryExporter ) doExport (ctx context.Context , metrics []* telemetryMetric ) error {
91- // Convert metrics to exported format with tag filtering
92- exportedMetrics := make ([]* exportedMetric , 0 , len (metrics ))
93- for _ , m := range metrics {
94- exportedMetrics = append (exportedMetrics , m .toExportedMetric ())
95- }
96-
97- // Create payload
98- payload := & telemetryPayload {
99- Metrics : exportedMetrics ,
74+ // Create telemetry request with protoLogs format (matches JDBC/Node.js)
75+ payload , err := createTelemetryRequest (metrics , e .driverVersion )
76+ if err != nil {
77+ return fmt .Errorf ("failed to create telemetry request: %w" , err )
10078 }
10179
102- // Serialize metrics
80+ // Serialize request
10381 data , err := json .Marshal (payload )
10482 if err != nil {
105- return fmt .Errorf ("failed to marshal metrics : %w" , err )
83+ return fmt .Errorf ("failed to marshal telemetry request : %w" , err )
10684 }
10785
86+ // TODO: Remove debug logging
87+ fmt .Printf ("[TELEMETRY DEBUG] Payload: %s\n " , string (data ))
88+
10889 // Determine endpoint
10990 // Support both plain hosts and full URLs (for testing)
11091 var endpoint string
@@ -114,6 +95,10 @@ func (e *telemetryExporter) doExport(ctx context.Context, metrics []*telemetryMe
11495 endpoint = fmt .Sprintf ("https://%s/telemetry-ext" , e .host )
11596 }
11697
98+ // TODO: Remove debug logging
99+ fmt .Printf ("[TELEMETRY DEBUG] Exporting %d metrics to %s\n " , len (metrics ), endpoint )
100+ fmt .Printf ("[TELEMETRY DEBUG] ProtoLogs count: %d\n " , len (payload .ProtoLogs ))
101+
117102 // Retry logic with exponential backoff
118103 maxRetries := e .cfg .MaxRetries
119104 for attempt := 0 ; attempt <= maxRetries ; attempt ++ {
@@ -150,9 +135,14 @@ func (e *telemetryExporter) doExport(ctx context.Context, metrics []*telemetryMe
150135
151136 // Check status code
152137 if resp .StatusCode >= 200 && resp .StatusCode < 300 {
138+ // TODO: Remove debug logging
139+ fmt .Printf ("[TELEMETRY DEBUG] Export successful: %d metrics sent, HTTP %d\n " , len (metrics ), resp .StatusCode )
153140 return nil // Success
154141 }
155142
143+ // TODO: Remove debug logging
144+ fmt .Printf ("[TELEMETRY DEBUG] Export failed: HTTP %d (attempt %d/%d)\n " , resp .StatusCode , attempt + 1 , maxRetries + 1 )
145+
156146 // Check if retryable
157147 if ! isRetryableStatus (resp .StatusCode ) {
158148 return fmt .Errorf ("non-retryable status: %d" , resp .StatusCode )
@@ -166,28 +156,6 @@ func (e *telemetryExporter) doExport(ctx context.Context, metrics []*telemetryMe
166156 return nil
167157}
168158
169- // toExportedMetric converts internal metric to exported format with tag filtering.
170- func (m * telemetryMetric ) toExportedMetric () * exportedMetric {
171- // Filter tags based on export scope
172- filteredTags := make (map [string ]interface {})
173- for k , v := range m .tags {
174- if shouldExportToDatabricks (m .metricType , k ) {
175- filteredTags [k ] = v
176- }
177- }
178-
179- return & exportedMetric {
180- MetricType : m .metricType ,
181- Timestamp : m .timestamp .Format (time .RFC3339 ),
182- WorkspaceID : m .workspaceID ,
183- SessionID : m .sessionID ,
184- StatementID : m .statementID ,
185- LatencyMs : m .latencyMs ,
186- ErrorType : m .errorType ,
187- Tags : filteredTags ,
188- }
189- }
190-
191159// isRetryableStatus returns true if HTTP status is retryable.
192160// Retryable statuses: 429 (Too Many Requests), 503 (Service Unavailable), 5xx (Server Errors)
193161func isRetryableStatus (status int ) bool {
0 commit comments