Skip to content

Commit 09cde19

Browse files
samikshya-dbclaude
andcommitted
Fix telemetry proto field mapping
Correct issue where Operation.Type values were incorrectly placed in statement_type field. Per proto definition: - statement_type expects Statement.Type (QUERY, SQL, UPDATE, METADATA, VOLUME) - operation_type goes in operation_detail.operation_type and uses Operation.Type Changes: - Connection metrics: Set sql_operation.operation_detail.operation_type to CREATE_SESSION or DELETE_SESSION - Statement metrics: Set both statement_type (QUERY or METADATA based on operation) and operation_detail.operation_type (EXECUTE_STATEMENT, etc.) - Added mapOperationToStatementType() to convert Operation.Type to Statement.Type This ensures telemetry payloads match the OssSqlDriverTelemetryLog proto structure correctly. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent adb70bc commit 09cde19

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

lib/telemetry/DatabricksTelemetryExporter.ts

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,41 @@ export default class DatabricksTelemetryExporter {
252252
}
253253
}
254254

255+
/**
256+
* Map Operation.Type to Statement.Type for statement_type field.
257+
* Operation.Type (EXECUTE_STATEMENT, LIST_CATALOGS, etc.) maps to Statement.Type (QUERY, METADATA, etc.)
258+
*/
259+
private mapOperationToStatementType(operationType?: string): string {
260+
if (!operationType) {
261+
return 'TYPE_UNSPECIFIED';
262+
}
263+
264+
// Metadata operations map to METADATA
265+
if (
266+
operationType === 'LIST_TYPE_INFO' ||
267+
operationType === 'LIST_CATALOGS' ||
268+
operationType === 'LIST_SCHEMAS' ||
269+
operationType === 'LIST_TABLES' ||
270+
operationType === 'LIST_TABLE_TYPES' ||
271+
operationType === 'LIST_COLUMNS' ||
272+
operationType === 'LIST_FUNCTIONS' ||
273+
operationType === 'LIST_PRIMARY_KEYS' ||
274+
operationType === 'LIST_IMPORTED_KEYS' ||
275+
operationType === 'LIST_EXPORTED_KEYS' ||
276+
operationType === 'LIST_CROSS_REFERENCES'
277+
) {
278+
return 'METADATA';
279+
}
280+
281+
// EXECUTE_STATEMENT maps to QUERY
282+
if (operationType === 'EXECUTE_STATEMENT') {
283+
return 'QUERY';
284+
}
285+
286+
// Default to TYPE_UNSPECIFIED
287+
return 'TYPE_UNSPECIFIED';
288+
}
289+
255290
/**
256291
* Convert TelemetryMetric to Databricks telemetry log format.
257292
*/
@@ -324,10 +359,12 @@ export default class DatabricksTelemetryExporter {
324359
log.entry.sql_driver_log.operation_latency_ms = metric.latencyMs;
325360
}
326361

327-
// Include operation type (CREATE_SESSION or DELETE_SESSION)
362+
// Include operation type in operation_detail (CREATE_SESSION or DELETE_SESSION)
328363
if (metric.operationType) {
329364
log.entry.sql_driver_log.sql_operation = {
330-
statement_type: metric.operationType,
365+
operation_detail: {
366+
operation_type: metric.operationType,
367+
},
331368
};
332369
}
333370
} else if (metric.metricType === 'statement') {
@@ -336,9 +373,16 @@ export default class DatabricksTelemetryExporter {
336373
// Only create sql_operation if we have any fields to include
337374
if (metric.operationType || metric.compressed !== undefined || metric.resultFormat || metric.chunkCount) {
338375
log.entry.sql_driver_log.sql_operation = {
339-
statement_type: metric.operationType,
376+
// Map operationType to statement_type (Statement.Type enum)
377+
statement_type: this.mapOperationToStatementType(metric.operationType),
340378
...(metric.compressed !== undefined && { is_compressed: metric.compressed }),
341379
...(metric.resultFormat && { execution_result: metric.resultFormat }),
380+
// Include operation_type in operation_detail
381+
...(metric.operationType && {
382+
operation_detail: {
383+
operation_type: metric.operationType,
384+
},
385+
}),
342386
};
343387

344388
if (metric.chunkCount && metric.chunkCount > 0) {

0 commit comments

Comments
 (0)