@@ -25,6 +25,7 @@ import { CreateSSHKeyPairRequest } from '@gitpod/supervisor-api-grpcweb/lib/cont
2525import * as ssh2 from 'ssh2' ;
2626import { ParsedKey } from 'ssh2-streams' ;
2727import { isPortUsed } from '../../common/ports' ;
28+ import { WrapError } from '../../common/utils' ;
2829
2930const phaseMap : Record < WorkspaceInstanceStatus_Phase , WorkspaceInstancePhase | undefined > = {
3031 [ WorkspaceInstanceStatus_Phase . CREATING ] : 'pending' ,
@@ -74,6 +75,8 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
7475 }
7576
7677 async getWorkspaceAuthInfo ( request : GetWorkspaceAuthInfoRequest , _context : CallContext ) : Promise < GetWorkspaceAuthInfoResponse > {
78+ let userId : string | undefined ;
79+ let instanceId : string | undefined ;
7780 try {
7881 if ( new URL ( this . hostService . gitpodHost ) . host !== new URL ( request . gitpodHost ) . host ) {
7982 this . logService . error ( `gitpod host mismatch, actual: ${ this . hostService . gitpodHost } target: ${ request . gitpodHost } ` ) ;
@@ -83,7 +86,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
8386 if ( ! accessToken ) {
8487 throw new ServerError ( Status . INTERNAL , 'no access token found' ) ;
8588 }
86- const userId = this . sessionService . getUserId ( ) ;
89+ userId = this . sessionService . getUserId ( ) ;
8790 const workspaceId = request . workspaceId ;
8891 // TODO(lssh): Get auth info according to `request.gitpodHost`
8992 const gitpodHost = this . hostService . gitpodHost ;
@@ -101,7 +104,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
101104 }
102105 const url = new URL ( ideUrl ) ;
103106 const workspaceHost = url . host . substring ( url . host . indexOf ( '.' ) + 1 ) ;
104- const instanceId = ( usePublicApi ? ( workspace as Workspace ) . status ?. instance ?. instanceId : ( workspace as WorkspaceInfo ) . latestInstance ?. id ) as string ;
107+ instanceId = ( usePublicApi ? ( workspace as Workspace ) . status ?. instance ?. instanceId : ( workspace as WorkspaceInfo ) . latestInstance ?. id ) as string ;
105108
106109 const sshkey = phase === 'running' ? ( await this . getWorkspaceSSHKey ( ownerToken , workspaceId , workspaceHost ) ) : '' ;
107110
@@ -116,11 +119,20 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
116119 phase : phase ?? 'unknown' ,
117120 } ;
118121 } catch ( e ) {
119- this . logService . error ( e , 'failed to get workspace auth info' ) ;
120- if ( e instanceof ServerError ) {
121- throw e ;
122+ let code = Status . INTERNAL ;
123+ if ( e instanceof WrapError && typeof e . grpcCode === 'number' ) {
124+ code = e . grpcCode
122125 }
123- throw new ServerError ( Status . UNAVAILABLE , e . toString ( ) ) ;
126+ const wrapErr = new WrapError ( 'failed to get workspace auth info' , e ) ;
127+ this . logService . error ( wrapErr ) ;
128+ this . telemetryService . sendTelemetryException ( wrapErr , {
129+ gitpodHost : request . gitpodHost ,
130+ workspaceId : request . workspaceId ,
131+ instanceId,
132+ userId,
133+ } ) ;
134+
135+ throw new ServerError ( code , wrapErr . toString ( ) ) ;
124136 }
125137 }
126138
0 commit comments