Skip to content

Commit 6b517ff

Browse files
JLargent42Jacob Largent
andauthored
fix(appcomposer): reduce logger messages #4343
Problem: - During development, App Composer used several unnecessary logger calls. Solution: - Remove unnecessary logger calls and combine other logger calls into a single message. Co-authored-by: Jacob Largent <[email protected]>
1 parent 5eaa4f6 commit 6b517ff

File tree

2 files changed

+14
-39
lines changed

2 files changed

+14
-39
lines changed

src/applicationcomposer/messageHandlers/generateResourceHandler.ts

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
MessageType,
1313
} from '../types'
1414
import { ChatSession } from '../../codewhispererChat/clients/chat/v0/chat'
15-
import { AuthUtil, getChatAuthState } from '../../codewhisperer/util/authUtil'
15+
import { AuthUtil } from '../../codewhisperer/util/authUtil'
1616
import globals from '../../shared/extensionGlobals'
1717
import { getLogger } from '../../shared/logger/logger'
1818

@@ -80,8 +80,7 @@ async function generateResource(prompt: string) {
8080
// TODO-STARLING - Revisit to see if timeout still needed prior to launch
8181
const data = await timeout(chatSession.chat(request), TIMEOUT)
8282
const initialResponseTime = globals.clock.Date.now() - startTime
83-
getLogger().debug(`CW Chat initial response time: ${initialResponseTime} ms`)
84-
getLogger().debug(`CW Chat initial response: ${JSON.stringify(data, undefined, 2)}`)
83+
getLogger().debug(`CW Chat initial response: ${JSON.stringify(data, undefined, 2)}, ${initialResponseTime} ms`)
8584
if (data['$metadata']) {
8685
metadata = data['$metadata']
8786
}
@@ -133,21 +132,17 @@ async function generateResource(prompt: string) {
133132

134133
const elapsedTime = globals.clock.Date.now() - startTime
135134

136-
// TODO-STARLING: Reduce/remove below
137-
getLogger().debug(`===== CW Chat prompt start ====`)
138-
getLogger().debug(prompt)
139-
getLogger().debug(`===== CW Chat prompt end ======`)
140-
getLogger().debug(`===== CW Chat metadata start ======`)
141-
getLogger().debug(`CW Chat conversationId = ${conversationId}`)
142-
getLogger().debug(`CW Chat metadata = \n${JSON.stringify(metadata, undefined, 2)}`)
143-
getLogger().debug(`CW Chat supplementaryWebLinks = \n${JSON.stringify(supplementaryWebLinks, undefined, 2)}`)
144-
getLogger().debug(`CW Chat references = \n${JSON.stringify(references, undefined, 2)}`)
145-
getLogger().debug(`===== CW Chat metadata end ======`)
146-
getLogger().debug(`===== CW Chat raw response start ======`)
147-
getLogger().debug(`${response}`)
148-
getLogger().debug(`===== CW Chat raw response end ======`)
149-
getLogger().debug(`CW Chat initial response time = ${initialResponseTime} ms`)
150-
getLogger().debug(`CW Chat elapsed time = ${elapsedTime} ms`)
135+
getLogger().debug(
136+
`CW Chat Debug message:
137+
prompt = "${prompt}",
138+
conversationId = ${conversationId},
139+
metadata = \n${JSON.stringify(metadata, undefined, 2)},
140+
supplementaryWebLinks = \n${JSON.stringify(supplementaryWebLinks, undefined, 2)},
141+
references = \n${JSON.stringify(references, undefined, 2)},
142+
response = "${response}",
143+
initialResponse = ${initialResponseTime} ms,
144+
elapsed time = ${elapsedTime} ms`
145+
)
151146

152147
return {
153148
chatResponse: response,
@@ -161,7 +156,6 @@ async function generateResource(prompt: string) {
161156
}
162157
} catch (error: any) {
163158
getLogger().debug(`CW Chat error: ${error.name} - ${error.message}`)
164-
await debugConnection()
165159
if (error.$metadata) {
166160
const { requestId, cfId, extendedRequestId } = error.$metadata
167161
getLogger().debug(JSON.stringify({ requestId, cfId, extendedRequestId }, undefined, 2))
@@ -179,20 +173,3 @@ function timeout<T>(promise: Promise<T>, ms: number, timeoutError = new Error('P
179173
})
180174
return Promise.race<T>([promise, _timeout])
181175
}
182-
183-
// TODO-STARLING
184-
// Temporary function to assist with debug as Starling is coded
185-
// This will likely be removed prior to launch
186-
async function debugConnection() {
187-
const isConnected = AuthUtil.instance.isConnected()
188-
const isValid = AuthUtil.instance.isConnectionValid()
189-
const isExpired = AuthUtil.instance.isConnectionExpired()
190-
const authState = await getChatAuthState(AuthUtil.instance)
191-
const isConnectedToCodeWhisperer =
192-
authState.codewhispererChat === 'connected' || authState.codewhispererChat === 'expired'
193-
194-
getLogger().debug(`DEBUG: debugConnection - isConnected = ${isConnected}`)
195-
getLogger().debug(`DEBUG: debugConnection - isValid = ${isValid}`)
196-
getLogger().debug(`DEBUG: debugConnection - isExpired = ${isExpired}`)
197-
getLogger().debug(`DEBUG: debugConnection - isConnectedToCodeWhisperer = ${isConnectedToCodeWhisperer}`)
198-
}

src/applicationcomposer/webviewManager.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ export class ApplicationComposerManager {
110110
'There was an error rendering Application Composer, check logs for details.'
111111
)
112112
)
113-
114-
this.logger.debug(`${this.name}: Unable to setup webview panel.`)
115-
this.logger.error(`${this.name}: unexpected exception: %s`, err)
113+
this.logger.error(`${this.name}: Unable to show App Composer webview: ${err}`)
116114
}
117115

118116
protected handleNewVisualization(key: string, visualization: ApplicationComposer): void {

0 commit comments

Comments
 (0)