Skip to content

Commit ffd62ca

Browse files
committed
telemetry on disconnect
1 parent 67898fd commit ffd62ca

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

cli/ssh.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ func (r *RootCmd) ssh() *serpent.Command {
437437
}
438438

439439
err = sshSession.Wait()
440+
conn.SendDisconnectedTelemetry("ssh")
440441
if err != nil {
441442
if exitErr := (&gossh.ExitError{}); errors.As(err, &exitErr) {
442443
// Clear the error since it's not useful beyond

codersdk/workspacesdk/agentconn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,7 @@ func (c *AgentConn) apiClient() *http.Client {
380380
func (c *AgentConn) GetPeerDiagnostics() tailnet.PeerDiagnostics {
381381
return c.Conn.GetPeerDiagnostics(c.opts.AgentID)
382382
}
383+
384+
func (c *AgentConn) SendDisconnectedTelemetry(application string) {
385+
c.Conn.SendDisconnectedTelemetry(c.agentAddress(), application)
386+
}

tailnet/conn.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,24 @@ func (c *Conn) SendConnectedTelemetry(ip netip.Addr, application string) {
727727
}()
728728
}
729729

730+
func (c *Conn) SendDisconnectedTelemetry(ip netip.Addr, application string) {
731+
if c.telemetrySink == nil {
732+
return
733+
}
734+
e := c.newTelemetryEvent()
735+
e.Status = proto.TelemetryEvent_DISCONNECTED
736+
e.Application = application
737+
pip, ok := c.wireguardEngine.PeerForIP(ip)
738+
if ok {
739+
e.NodeIdRemote = uint64(pip.Node.ID)
740+
}
741+
c.telemetryWg.Add(1)
742+
go func() {
743+
defer c.telemetryWg.Done()
744+
c.telemetrySink.SendTelemetryEvent(e)
745+
}()
746+
}
747+
730748
func (c *Conn) SendSpeedtestTelemetry(throughputMbits float64) {
731749
if c.telemetrySink == nil {
732750
return

0 commit comments

Comments
 (0)