Skip to content

Commit 085db30

Browse files
fix(smus): Configure SMUS loggers to use prefix (#2302)
## Problem - manual addition of SMUS to logger ## Solution - Added 'smus' to LogTopic type in logger.ts - Updated all SMUS-related files to use getLogger('smus') instead of getLogger() - Removed manual 'SMUS:' prefixes from all log messages - Logger now automatically prepends 'smus:' to all SMUS log messages verified Changes ``` 2025-11-17 09:12:55.014 [info] auth: Handling validation error of connection: 77fd26fb-ec96-4e54-8171-703530254b3f 2025-11-17 09:12:55.014 [info] auth: Updating connection state of 77fd26fb-ec96-4e54-8171-703530254b3f to invalid 2025-11-17 09:12:55.023 [info] smus: SMUS Connection: Clearing all cached clients 2025-11-17 09:12:55.029 [info] smus: Not in SageMaker Unified Studio remote environment, skipping user activity monitoring 2025-11-17 09:12:55.033 [info] secondaryAuth: connectionId=77fd26fb-ec96-4e54-8171-703530254b3f, connectionStatus=invalid ``` --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 067ed85 commit 085db30

34 files changed

+273
-272
lines changed

packages/core/src/sagemakerunifiedstudio/auth/authenticationOrchestrator.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export type SmusAuthenticationResult =
3232
* Orchestrates SMUS authentication flows
3333
*/
3434
export class SmusAuthenticationOrchestrator {
35-
private static readonly logger = getLogger()
35+
private static readonly logger = getLogger('smus')
3636

3737
/**
3838
* Handles IAM authentication flow
@@ -57,7 +57,7 @@ export class SmusAuthenticationOrchestrator {
5757
// If profile and region are provided, skip profile selection (re-authentication case)
5858
if (existingProfileName && existingRegion) {
5959
logger.debug(
60-
`SMUS Auth: Re-authenticating with existing profile: ${existingProfileName}, region: ${existingRegion}`
60+
`Auth: Re-authenticating with existing profile: ${existingProfileName}, region: ${existingRegion}`
6161
)
6262
profileSelection = {
6363
profileName: existingProfileName,
@@ -71,31 +71,29 @@ export class SmusAuthenticationOrchestrator {
7171
// Handle different result types
7272
if ('isBack' in profileSelection) {
7373
// User chose to go back to authentication method selection
74-
logger.debug('SMUS Auth: User chose to go back to authentication method selection')
74+
logger.debug('User chose to go back to authentication method selection')
7575
return { status: 'BACK' }
7676
}
7777

7878
if ('isEditing' in profileSelection) {
7979
// User chose to edit credentials or is in editing mode
80-
logger.debug('SMUS Auth: User is editing credentials')
80+
logger.debug('User is editing credentials')
8181
return { status: 'EDITING' }
8282
}
8383

8484
// At this point, we have a profile selected
85-
logger.debug(
86-
`SMUS Auth: Selected profile: ${profileSelection.profileName}, region: ${profileSelection.region}`
87-
)
85+
logger.debug(`Selected profile: ${profileSelection.profileName}, region: ${profileSelection.region}`)
8886

8987
// Validate the selected profile
9088
const validation = await authProvider.validateIamProfile(profileSelection.profileName)
9189
if (!validation.isValid) {
92-
logger.debug(`SMUS Auth: Profile validation failed: ${validation.error}`)
90+
logger.debug(`Profile validation failed: ${validation.error}`)
9391
return { status: 'INVALID_PROFILE', error: validation.error || 'Profile validation failed' }
9492
}
9593

9694
// Discover IAM-based domain using IAM credential. If IAM-based domain is not present, we should throw an appropriate error
9795
// and exit
98-
logger.debug('SMUS Auth: Discovering IAM-based domain using IAM credentials')
96+
logger.debug('Discovering IAM-based domain using IAM credentials')
9997

10098
const domainUrl = await this.findSmusIamDomain(
10199
authProvider,
@@ -124,7 +122,7 @@ export class SmusAuthenticationOrchestrator {
124122
}
125123

126124
logger.info(
127-
`SMUS Auth: Successfully connected with IAM profile ${profileSelection.profileName} in region ${profileSelection.region} to IAM-based domain`
125+
`Successfully connected with IAM profile ${profileSelection.profileName} in region ${profileSelection.region} to IAM-based domain`
128126
)
129127

130128
// Extract domain ID and region for telemetry logging
@@ -142,7 +140,7 @@ export class SmusAuthenticationOrchestrator {
142140
}
143141

144142
// After successful IAM authentication (IAM mode), automatically open project picker
145-
logger.debug('SMUS Auth: IAM authentication successful, opening project picker')
143+
logger.debug('IAM authentication successful, opening project picker')
146144
try {
147145
await vscode.commands.executeCommand('aws.smus.switchProject')
148146
} catch (pickerErr) {
@@ -179,12 +177,12 @@ export class SmusAuthenticationOrchestrator {
179177
context: vscode.ExtensionContext
180178
): Promise<SmusAuthenticationResult> {
181179
const logger = this.logger
182-
logger.debug('SMUS Auth: Starting SSO authentication flow')
180+
logger.debug('Starting SSO authentication flow')
183181

184182
// Show domain URL input dialog with back button support
185183
const domainUrl = await SmusSsoAuthenticationUI.showDomainUrlInput()
186184

187-
logger.debug(`SMUS Auth: Domain URL input result: ${domainUrl ? 'provided' : 'cancelled or back'}`)
185+
logger.debug(`Domain URL input result: ${domainUrl ? 'provided' : 'cancelled or back'}`)
188186

189187
if (domainUrl === 'BACK') {
190188
// User wants to go back to authentication method selection
@@ -261,13 +259,13 @@ export class SmusAuthenticationOrchestrator {
261259
)
262260

263261
if (result === 'Yes') {
264-
logger.debug(`SMUS Auth: Saving user preference: ${method}`)
262+
logger.debug(`Saving user preference: ${method}`)
265263
await SmusAuthenticationPreferencesManager.setPreferredMethod(context, method, true)
266-
logger.debug(`SMUS Auth: Preference saved successfully`)
264+
logger.debug(`Preference saved successfully`)
267265
}
268266
} catch (error) {
269267
// Not a hard failure, so not throwing error
270-
logger.warn('SMUS Auth: Error asking to remember auth method: %s', error)
268+
logger.warn('Error asking to remember auth method: %s', error)
271269
}
272270
}
273271

@@ -286,7 +284,7 @@ export class SmusAuthenticationOrchestrator {
286284
const logger = this.logger
287285

288286
try {
289-
logger.debug(`SMUS Auth: Finding IAM-based domain in region ${region} using profile ${profileName}`)
287+
logger.debug(`Finding IAM-based domain in region ${region} using profile ${profileName}`)
290288

291289
// Get DataZoneCustomClientHelper instance
292290
const datazoneCustomClientHelper = DataZoneCustomClientHelper.getInstance(
@@ -298,19 +296,19 @@ export class SmusAuthenticationOrchestrator {
298296
const iamDomain = await datazoneCustomClientHelper.getIamDomain()
299297

300298
if (!iamDomain) {
301-
logger.warn(`SMUS Auth: No IAM-based domain found in region ${region}`)
299+
logger.warn(`No IAM-based domain found in region ${region}`)
302300
return undefined
303301
}
304302

305-
logger.debug(`SMUS Auth: Found IAM-based domain: ${iamDomain.name} (${iamDomain.id})`)
303+
logger.debug(`Found IAM-based domain: ${iamDomain.name} (${iamDomain.id})`)
306304

307305
// Construct domain URL from the IAM-based domain
308306
const domainUrl = iamDomain.portalUrl || `https://${iamDomain.id}.sagemaker.${region}.on.aws/`
309-
logger.info(`SMUS Auth: Discovered IAM-based domain URL: ${domainUrl}`)
307+
logger.info(`Discovered IAM-based domain URL: ${domainUrl}`)
310308

311309
return domainUrl
312310
} catch (error) {
313-
logger.error(`SMUS Auth: Failed to find IAM-based domain: %s`, error)
311+
logger.error(`Failed to find IAM-based domain: %s`, error)
314312
throw new ToolkitError(`Failed to find IAM-based domain: ${(error as Error).message}`, {
315313
code: SmusErrorCodes.ApiTimeout,
316314
cause: error instanceof Error ? error : undefined,

packages/core/src/sagemakerunifiedstudio/auth/credentialExpiryHandler.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function showIamCredentialExpiryOptions(
3939
connection: any,
4040
extensionContext: vscode.ExtensionContext
4141
): Promise<IamCredentialExpiryResult> {
42-
const logger = getLogger()
42+
const logger = getLogger('smus')
4343

4444
type QuickPickItemWithAction = vscode.QuickPickItem & { action: IamCredentialExpiryAction }
4545
const options: QuickPickItemWithAction[] = [
@@ -119,7 +119,7 @@ export async function showIamCredentialExpiryOptions(
119119
break
120120
}
121121
case IamCredentialExpiryAction.EditCredentials: {
122-
logger.debug('SMUS: Opening AWS credentials and config files for editing')
122+
logger.debug('Opening AWS credentials and config files for editing')
123123
// Open both credentials and config files like AWS Explorer does
124124
const credentialsPath = getCredentialsFilename()
125125
const configPath = getConfigFilename()
@@ -144,13 +144,13 @@ export async function showIamCredentialExpiryOptions(
144144
break
145145
}
146146
case IamCredentialExpiryAction.SwitchProfile: {
147-
logger.debug('SMUS: Switching to another IAM profile')
147+
logger.debug('Switching to another IAM profile')
148148
try {
149149
const profileSelection = await SmusIamProfileSelector.showIamProfileSelection()
150150

151151
// Handle back navigation - show the credential expiry menu again
152152
if ('isBack' in profileSelection) {
153-
logger.debug('SMUS: User clicked back, showing credential expiry options again')
153+
logger.debug('User clicked back, showing credential expiry options again')
154154
// Recursively show the credential expiry options menu
155155
const result = await showIamCredentialExpiryOptions(
156156
authProvider,
@@ -163,7 +163,7 @@ export async function showIamCredentialExpiryOptions(
163163

164164
// Handle editing mode - This is if user picks edit during the profile selection
165165
if ('isEditing' in profileSelection) {
166-
logger.debug('SMUS: User is editing credentials')
166+
logger.debug('User is editing credentials')
167167
resolve({ action: IamCredentialExpiryAction.EditCredentials })
168168
return
169169
}
@@ -197,20 +197,20 @@ export async function showIamCredentialExpiryOptions(
197197
switchError instanceof ToolkitError &&
198198
switchError.code === SmusErrorCodes.UserCancelled
199199
) {
200-
logger.debug('SMUS: Profile switch cancelled by user')
200+
logger.debug('Profile switch cancelled by user')
201201
resolve({ action: IamCredentialExpiryAction.Cancelled })
202202
} else {
203203
// Show error message for actual failures
204204
const errorMsg = (switchError as Error).message
205205
void vscode.window.showErrorMessage(`Failed to switch profile: ${errorMsg}`)
206-
logger.error('SMUS: Profile switch failed: %s', switchError)
206+
logger.error('Profile switch failed: %s', switchError)
207207
resolve({ action: IamCredentialExpiryAction.SwitchProfile })
208208
}
209209
}
210210
break
211211
}
212212
case IamCredentialExpiryAction.SignOut: {
213-
logger.debug('SMUS: Signing out from connection')
213+
logger.debug('Signing out from connection')
214214
// Use the provider's signOut method which properly handles metadata cleanup
215215
await authProvider.signOut()
216216
void vscode.window.showInformationMessage('Successfully signed out')
@@ -219,7 +219,7 @@ export async function showIamCredentialExpiryOptions(
219219
}
220220
}
221221
} catch (error) {
222-
logger.error('SMUS: Failed to handle credential expiry action: %s', error)
222+
logger.error('Failed to handle credential expiry action: %s', error)
223223
// Only show error for non-reauthenticate cases (reauthenticate handles its own errors)
224224
if (itemWithAction.action !== IamCredentialExpiryAction.Reauthenticate) {
225225
void vscode.window.showErrorMessage(`Failed to complete action: ${(error as Error).message}`)
@@ -231,7 +231,7 @@ export async function showIamCredentialExpiryOptions(
231231
quickPick.onDidHide(() => {
232232
if (!isCompleted) {
233233
quickPick.dispose()
234-
logger.debug('SMUS: Credential expiry options cancelled by user')
234+
logger.debug('Credential expiry options cancelled by user')
235235
resolve({ action: IamCredentialExpiryAction.Cancelled })
236236
}
237237
})

packages/core/src/sagemakerunifiedstudio/auth/preferences/authenticationPreferences.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface SmusAuthenticationPreferences {
3232
* Manager for SMUS authentication preferences
3333
*/
3434
export class SmusAuthenticationPreferencesManager {
35-
private static readonly logger = getLogger()
35+
private static readonly logger = getLogger('smus')
3636
// eslint-disable-next-line @typescript-eslint/naming-convention
3737
private static readonly PREFERENCES_KEY = 'aws.smus.authenticationPreferences'
3838

@@ -145,7 +145,7 @@ export class SmusAuthenticationPreferencesManager {
145145
*/
146146
public static async clearPreferences(context?: vscode.ExtensionContext): Promise<void> {
147147
const logger = this.logger
148-
logger.debug('SMUS Auth: Clearing authentication preferences')
148+
logger.debug('Clearing authentication preferences')
149149

150150
await globals.globalState.update(this.PREFERENCES_KEY, undefined)
151151
}
@@ -156,7 +156,7 @@ export class SmusAuthenticationPreferencesManager {
156156
*/
157157
public static async clearConnectionPreferences(context?: vscode.ExtensionContext): Promise<void> {
158158
const logger = this.logger
159-
logger.debug('SMUS Auth: Clearing connection-specific preferences (preserving auth method preference)')
159+
logger.debug('Clearing connection-specific preferences (preserving auth method preference)')
160160

161161
const currentPrefs = this.getPreferences()
162162

@@ -182,7 +182,7 @@ export class SmusAuthenticationPreferencesManager {
182182
newMethod: SmusAuthenticationMethod
183183
): Promise<void> {
184184
const logger = this.logger
185-
logger.debug(`SMUS Auth: Switching authentication method to: ${newMethod}`)
185+
logger.debug(`Switching authentication method to: ${newMethod}`)
186186

187187
await this.updatePreferences(context, {
188188
preferredMethod: newMethod,

packages/core/src/sagemakerunifiedstudio/auth/providers/connectionCredentialsProvider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { getContext } from '../../../shared/vscode/setContext'
2020
* This provider implements independent caching with 10-minute expiry
2121
*/
2222
export class ConnectionCredentialsProvider implements CredentialsProvider {
23-
private readonly logger = getLogger()
23+
private readonly logger = getLogger('smus')
2424
private credentialCache?: {
2525
credentials: AWS.Credentials
2626
expiresAt: Date
@@ -108,7 +108,7 @@ export class ConnectionCredentialsProvider implements CredentialsProvider {
108108
try {
109109
return this.smusAuthProvider.isConnected()
110110
} catch (err) {
111-
this.logger.error('SMUS Connection: Error checking if auth provider is connected: %s', err)
111+
this.logger.error('Error checking if auth provider is connected: %s', err)
112112
return false
113113
}
114114
}
@@ -118,7 +118,7 @@ export class ConnectionCredentialsProvider implements CredentialsProvider {
118118
* @returns Promise resolving to credentials
119119
*/
120120
public async getCredentials(): Promise<AWS.Credentials> {
121-
this.logger.debug(`SMUS Connection: Getting credentials for connection ${this.connectionId}`)
121+
this.logger.debug(`Getting credentials for connection ${this.connectionId}`)
122122

123123
// Check cache first (10-minute expiry)
124124
if (this.credentialCache && this.credentialCache.expiresAt > new Date()) {
@@ -147,7 +147,7 @@ export class ConnectionCredentialsProvider implements CredentialsProvider {
147147
withSecret: true,
148148
})
149149

150-
this.logger.debug(`SMUS Connection: Successfully retrieved connection details for ${this.connectionId}`)
150+
this.logger.debug(`Successfully retrieved connection details for ${this.connectionId}`)
151151

152152
// Extract connection credentials
153153
const connectionCredentials = getConnectionResponse.connectionCredentials
@@ -228,7 +228,7 @@ export class ConnectionCredentialsProvider implements CredentialsProvider {
228228
* Clears the internal cache without fetching new credentials
229229
*/
230230
public invalidate(): void {
231-
this.logger.debug(`SMUS Connection: Invalidating cached credentials for connection ${this.connectionId}`)
231+
this.logger.debug(`Invalidating cached credentials for connection ${this.connectionId}`)
232232
// Clear cache to force fresh fetch on next getCredentials() call
233233
this.credentialCache = undefined
234234
this.logger.debug(

0 commit comments

Comments
 (0)