Skip to content

Commit ee78dec

Browse files
samikshya-dbclaude
andcommitted
Add operation_detail field to telemetry interface and enhance test
- Added operation_detail field to DatabricksTelemetryLog interface - Enhanced telemetry-local.test.ts to capture and display actual payloads - Verified all three telemetry events (CONNECTION_OPEN, STATEMENT_COMPLETE, CONNECTION_CLOSE) - Confirmed statement_type and operation_detail.operation_type are properly populated Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 09cde19 commit ee78dec

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

lib/telemetry/DatabricksTelemetryExporter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ interface DatabricksTelemetryLog {
6565
statement_type?: string;
6666
is_compressed?: boolean;
6767
execution_result?: string;
68+
operation_detail?: {
69+
operation_type?: string;
70+
};
6871
chunk_details?: {
6972
total_chunks_present?: number;
7073
total_chunks_iterated?: number;

tests/e2e/telemetry-local.test.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import { DBSQLClient, LogLevel } from '../../lib';
1414
import IDBSQLLogger from '../../lib/contracts/IDBSQLLogger';
15+
import sinon from 'sinon';
16+
import * as nodeFetch from 'node-fetch';
1517

1618
// Custom logger to capture telemetry debug logs
1719
class DebugLogger implements IDBSQLLogger {
@@ -29,6 +31,8 @@ class DebugLogger implements IDBSQLLogger {
2931
}
3032

3133
describe('Telemetry E2E Test (Local Only)', () => {
34+
let fetchStub: sinon.SinonStub;
35+
3236
it('should send telemetry for SELECT 1 query', async function () {
3337
this.timeout(30000);
3438

@@ -51,6 +55,33 @@ describe('Telemetry E2E Test (Local Only)', () => {
5155
console.log('TELEMETRY E2E TEST');
5256
console.log('='.repeat(60));
5357

58+
// Stub fetch to capture telemetry payloads
59+
const originalFetch = nodeFetch.default;
60+
fetchStub = sinon.stub(nodeFetch, 'default').callsFake(async (url: any, options?: any) => {
61+
// Capture and log telemetry requests
62+
if (typeof url === 'string' && (url.includes('/telemetry-ext') || url.includes('/telemetry-unauth'))) {
63+
const body = options?.body ? JSON.parse(options.body) : null;
64+
65+
console.log('\n' + '='.repeat(60));
66+
console.log('📊 TELEMETRY REQUEST CAPTURED');
67+
console.log('='.repeat(60));
68+
console.log('URL:', url);
69+
70+
if (body && body.protoLogs) {
71+
console.log(`\nProtoLogs count: ${body.protoLogs.length}`);
72+
body.protoLogs.forEach((log: string, index: number) => {
73+
const parsed = JSON.parse(log);
74+
console.log(`\n--- ProtoLog ${index + 1} ---`);
75+
console.log(JSON.stringify(parsed, null, 2));
76+
});
77+
}
78+
console.log('='.repeat(60) + '\n');
79+
}
80+
81+
// Call original fetch
82+
return originalFetch(url, options);
83+
});
84+
5485
const client = new DBSQLClient({
5586
logger: new DebugLogger(),
5687
});
@@ -100,10 +131,15 @@ describe('Telemetry E2E Test (Local Only)', () => {
100131
console.log('\n' + '='.repeat(60));
101132
console.log('TEST COMPLETE');
102133
console.log('='.repeat(60));
103-
console.log('\nCheck the logs above for telemetry-related messages (shown in cyan)');
104-
console.log('Look for:');
105-
console.log(' - "Exporting N telemetry metrics"');
106-
console.log(' - "Successfully exported N telemetry metrics"');
107-
console.log(' - "Feature flag enabled: true"\n');
134+
console.log('\nCheck the logs above for captured telemetry payloads');
135+
console.log('Should see 3 ProtoLogs:');
136+
console.log(' 1. CONNECTION_OPEN (CREATE_SESSION)');
137+
console.log(' 2. STATEMENT_COMPLETE (EXECUTE_STATEMENT)');
138+
console.log(' 3. CONNECTION_CLOSE (DELETE_SESSION)\n');
139+
140+
// Restore fetch stub
141+
if (fetchStub) {
142+
fetchStub.restore();
143+
}
108144
});
109145
});

0 commit comments

Comments
 (0)