@@ -21,6 +21,7 @@ import { ConnectionCredentialsProvider } from '../auth/providers/connectionCrede
2121import { DataZoneConnection } from './client/datazoneClient'
2222import { createDZClientBaseOnDomainMode } from '../explorer/nodes/utils'
2323
24+ const notSet = 'not-set'
2425/**
2526 * Records space telemetry
2627 */
@@ -30,37 +31,46 @@ export async function recordSpaceTelemetry(
3031) {
3132 const logger = getLogger ( 'smus' )
3233
34+ const parent = node . resource . getParent ( ) as SageMakerUnifiedStudioSpacesParentNode
35+ const authProvider = SmusAuthenticationProvider . fromContext ( )
36+ const projectId = parent ?. getProjectId ( )
37+ const domainId = parent ?. getAuthProvider ( ) ?. getDomainId ( )
38+
39+ span . record ( {
40+ smusAuthMode : authProvider . activeConnection ?. type ,
41+ smusSpaceKey : node . resource . DomainSpaceKey ,
42+ smusDomainRegion : node . resource . regionCode ,
43+ smusDomainId : domainId ,
44+ smusProjectId : projectId ,
45+ } )
46+
3347 try {
34- const parent = node . resource . getParent ( ) as SageMakerUnifiedStudioSpacesParentNode
35- const authProvider = SmusAuthenticationProvider . fromContext ( )
3648 const accountId = await authProvider . getDomainAccountId ( )
37- const projectId = parent ?. getProjectId ( )
38-
39- // Get project account ID and region
40- let projectAccountId : string | undefined
41- let projectRegion : string | undefined
49+ span . record ( { smusDomainAccountId : accountId } )
50+ } catch ( err ) {
51+ span . record ( { smusDomainAccountId : notSet } )
52+ logger . warn ( `Failed to record domain account Id for telemetry in domain ${ domainId } : ${ ( err as Error ) . message } ` )
53+ }
4254
43- if ( projectId ) {
44- projectAccountId = await authProvider . getProjectAccountId ( projectId )
55+ if ( projectId ) {
56+ try {
57+ const projectAccountId = await authProvider . getProjectAccountId ( projectId )
58+ span . record ( { smusProjectAccountId : projectAccountId } )
59+ } catch ( err ) {
60+ span . record ( { smusProjectAccountId : notSet } )
61+ logger . warn (
62+ `Failed to record project account Id for telemetry in domain ${ domainId } : ${ ( err as Error ) . message } `
63+ )
64+ }
4565
46- // Get project region from tooling environment
66+ try {
4767 const dzClient = await createDZClientBaseOnDomainMode ( authProvider )
4868 const toolingEnv = await dzClient . getToolingEnvironment ( projectId )
49- projectRegion = toolingEnv . awsAccountRegion
69+ span . record ( { smusProjectRegion : toolingEnv . awsAccountRegion } )
70+ } catch ( err ) {
71+ span . record ( { smusProjectRegion : notSet } )
72+ logger . warn ( `Failed to get project region for telemetry: ${ ( err as Error ) . message } ` )
5073 }
51-
52- span . record ( {
53- smusAuthMode : authProvider . activeConnection ?. type ,
54- smusSpaceKey : node . resource . DomainSpaceKey ,
55- smusDomainRegion : node . resource . regionCode ,
56- smusDomainId : parent ?. getAuthProvider ( ) ?. getDomainId ( ) ,
57- smusDomainAccountId : accountId ,
58- smusProjectId : projectId ,
59- smusProjectAccountId : projectAccountId ,
60- smusProjectRegion : projectRegion ,
61- } )
62- } catch ( err ) {
63- logger . error ( `Failed to record space telemetry: ${ ( err as Error ) . message } ` )
6474 }
6575}
6676
@@ -90,6 +100,7 @@ export async function recordAuthTelemetry(
90100 smusDomainAccountId : accountId ,
91101 } )
92102 } catch ( err ) {
103+ span . record ( { smusDomainAccountId : notSet } )
93104 logger . error (
94105 `Failed to record Domain AccountId in data connection telemetry for domain ${ domainId } in region ${ region } : ${ err } `
95106 )
@@ -106,23 +117,25 @@ export async function recordDataConnectionTelemetry(
106117) {
107118 const logger = getLogger ( 'smus' )
108119
120+ const isInSmusSpace = getContext ( 'aws.smus.inSmusSpaceEnvironment' )
121+ const authProvider = SmusAuthenticationProvider . fromContext ( )
122+
123+ span . record ( {
124+ smusAuthMode : authProvider . activeConnection ?. type ,
125+ smusToolkitEnv : isInSmusSpace ? 'smus_space' : 'local' ,
126+ smusDomainId : connection . domainId ,
127+ smusProjectId : connection . projectId ,
128+ smusConnectionId : connection . connectionId ,
129+ smusConnectionType : connection . type ,
130+ smusProjectRegion : connection . location ?. awsRegion ,
131+ smusProjectAccountId : connection . location ?. awsAccountId ,
132+ } )
133+
109134 try {
110- const isInSmusSpace = getContext ( 'aws.smus.inSmusSpaceEnvironment' )
111- const authProvider = SmusAuthenticationProvider . fromContext ( )
112135 const accountId = await connectionCredentialsProvider . getDomainAccountId ( )
113-
114- span . record ( {
115- smusAuthMode : authProvider . activeConnection ?. type ,
116- smusToolkitEnv : isInSmusSpace ? 'smus_space' : 'local' ,
117- smusDomainId : connection . domainId ,
118- smusDomainAccountId : accountId ,
119- smusProjectId : connection . projectId ,
120- smusConnectionId : connection . connectionId ,
121- smusConnectionType : connection . type ,
122- smusProjectRegion : connection . location ?. awsRegion ,
123- smusProjectAccountId : connection . location ?. awsAccountId ,
124- } )
136+ span . record ( { smusDomainAccountId : accountId } )
125137 } catch ( err ) {
126- logger . error ( `Failed to record data connection telemetry: ${ ( err as Error ) . message } ` )
138+ span . record ( { smusDomainAccountId : notSet } )
139+ logger . warn ( `Failed to record domain account ID for data connection telemetry: ${ ( err as Error ) . message } ` )
127140 }
128141}
0 commit comments