Skip to content

Commit c6e31ff

Browse files
committed
feat(notifications): improve rule logging
1 parent ae7e7e7 commit c6e31ff

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

packages/core/src/notifications/panelNode.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { openUrl } from '../shared/utilities/vsCodeUtils'
1818
import { telemetry } from '../shared/telemetry/telemetry'
1919
import { globals } from '../shared'
2020

21+
const logger = getLogger('notifications')
22+
2123
/**
2224
* Controls the "Notifications" side panel/tree in each extension. It takes purely UX actions
2325
* and does not determine what notifications to dispaly or how to fetch and store them.
@@ -133,23 +135,23 @@ export class NotificationsNode implements TreeNode {
133135
switch (notification.uiRenderInstructions.onClick.type) {
134136
case 'modal':
135137
// Render blocking modal
136-
getLogger('notifications').verbose(`rendering modal for notificaiton: ${notification.id} ...`)
138+
logger.verbose(`rendering modal for notificaiton: ${notification.id} ...`)
137139
await this.showInformationWindow(notification, 'modal', false)
138140
break
139141
case 'openUrl':
140142
// Show open url option
141143
if (!notification.uiRenderInstructions.onClick.url) {
142144
throw new ToolkitError('No url provided for onclick open url')
143145
}
144-
getLogger('notifications').verbose(`opening url for notification: ${notification.id} ...`)
146+
logger.verbose(`opening url for notification: ${notification.id} ...`)
145147
await openUrl(
146148
vscode.Uri.parse(notification.uiRenderInstructions.onClick.url),
147149
getNotificationTelemetryId(notification)
148150
)
149151
break
150152
case 'openTextDocument':
151153
// Display read-only txt document
152-
getLogger('notifications').verbose(`showing txt document for notification: ${notification.id} ...`)
154+
logger.verbose(`showing txt document for notification: ${notification.id} ...`)
153155
await telemetry.toolkit_invokeAction.run(async () => {
154156
telemetry.record({ source: getNotificationTelemetryId(notification), action: 'openTxt' })
155157
await readonlyDocument.show(
@@ -236,7 +238,7 @@ export class NotificationsNode implements TreeNode {
236238
}
237239

238240
private async updateAndReload(id: string) {
239-
getLogger('notifications').verbose('Updating and reloading the extension...')
241+
logger.verbose('Updating and reloading the extension...')
240242
await vscode.commands.executeCommand('workbench.extensions.installExtension', id)
241243
await vscode.commands.executeCommand('workbench.action.reloadWindow')
242244
}

packages/core/src/notifications/rules.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { getComputeEnvType, getOperatingSystem } from '../shared/telemetry/util'
1111
import { AuthFormId } from '../login/webview/vue/types'
1212
import { getLogger } from '../shared/logger/logger'
1313

14+
const logger = getLogger('notifications')
1415
/**
1516
* Evaluates if a given version fits into the parameters specified by a notification, e.g:
1617
*
@@ -72,31 +73,51 @@ export class RuleEngine {
7273
constructor(private readonly context: RuleContext) {}
7374

7475
public shouldDisplayNotification(payload: ToolkitNotification) {
75-
return this.evaluate(payload.displayIf)
76+
return this.evaluate(payload.id, payload.displayIf)
7677
}
7778

78-
private evaluate(condition: DisplayIf): boolean {
79+
private evaluate(id: string, condition: DisplayIf): boolean {
7980
const currentExt = globals.context.extension.id
8081
if (condition.extensionId !== currentExt) {
82+
logger.verbose(
83+
'notification id: (%s) did NOT pass extension id check, actual ext id: (%s), expected ext id: (%s)',
84+
id,
85+
currentExt,
86+
condition.extensionId
87+
)
8188
return false
8289
}
8390

8491
if (condition.ideVersion) {
8592
if (!isValidVersion(this.context.ideVersion, condition.ideVersion)) {
93+
logger.verbose(
94+
'notification id: (%s) did NOT pass IDE version check, actual version: (%s), expected version: (%s)',
95+
id,
96+
this.context.ideVersion,
97+
condition.ideVersion
98+
)
8699
return false
87100
}
88101
}
89102
if (condition.extensionVersion) {
90103
if (!isValidVersion(this.context.extensionVersion, condition.extensionVersion)) {
104+
logger.verbose(
105+
'notification id: (%s) did NOT pass extension version check, actual ext version: (%s), expected ext version: (%s)',
106+
id,
107+
this.context.extensionVersion,
108+
condition.extensionVersion
109+
)
91110
return false
92111
}
93112
}
94113

95114
if (condition.additionalCriteria) {
96115
for (const criteria of condition.additionalCriteria) {
97116
if (!this.evaluateRule(criteria)) {
117+
logger.verbose('notification id: (%s) did NOT pass criteria check: %O', id, criteria)
98118
return false
99119
}
120+
logger.debug('notification id: (%s) passed criteria check: %O', id, criteria)
100121
}
101122
}
102123

@@ -176,7 +197,7 @@ export async function getRuleContext(context: vscode.ExtensionContext, authState
176197
}
177198

178199
const { activeExtensions, ...loggableRuleContext } = ruleContext
179-
getLogger('notifications').debug('getRuleContext() determined rule context: %O', loggableRuleContext)
200+
logger.debug('getRuleContext() determined rule context: %O', loggableRuleContext)
180201

181202
return ruleContext
182203
}

0 commit comments

Comments
 (0)