@@ -8,6 +8,13 @@ import { extractDatabaseId, isValidServername } from './servername.ts'
88import { getTls , setSecureContext } from './tls.ts'
99import { createStartupMessage } from './create-message.ts'
1010import { extractIP } from './extract-ip.ts'
11+ import {
12+ DatabaseShared ,
13+ DatabaseUnshared ,
14+ logEvent ,
15+ UserConnected ,
16+ UserDisconnected ,
17+ } from './telemetry.ts'
1118
1219const debug = makeDebug ( 'browser-proxy' )
1320
@@ -59,6 +66,8 @@ websocketServer.on('connection', (socket, request) => {
5966
6067 websocketConnections . set ( databaseId , socket )
6168
69+ logEvent ( new DatabaseShared ( { databaseId } ) )
70+
6271 socket . on ( 'message' , ( data : Buffer ) => {
6372 debug ( 'websocket message' , data . toString ( 'hex' ) )
6473 const tcpConnection = tcpConnections . get ( databaseId )
@@ -67,6 +76,7 @@ websocketServer.on('connection', (socket, request) => {
6776
6877 socket . on ( 'close' , ( ) => {
6978 websocketConnections . delete ( databaseId )
79+ logEvent ( new DatabaseUnshared ( { databaseId } ) )
7080 } )
7181} )
7282
@@ -112,6 +122,7 @@ tcpServer.on('connection', async (socket) => {
112122 // only set the databaseId after we've verified the connection
113123 databaseId = _databaseId
114124 tcpConnections . set ( databaseId ! , connection )
125+ logEvent ( new UserConnected ( { databaseId } ) )
115126 } ,
116127 serverVersion ( ) {
117128 return '16.3'
@@ -158,6 +169,7 @@ tcpServer.on('connection', async (socket) => {
158169 socket . on ( 'close' , ( ) => {
159170 if ( databaseId ) {
160171 tcpConnections . delete ( databaseId )
172+ logEvent ( new UserDisconnected ( { databaseId } ) )
161173 const websocket = websocketConnections . get ( databaseId )
162174 websocket ?. send ( createStartupMessage ( 'postgres' , 'postgres' , { client_ip : '' } ) )
163175 }
0 commit comments