Skip to content

Commit

Permalink
Added payload information for response messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner committed Dec 8, 2023
1 parent 72d23f5 commit 89de541
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 27 deletions.
24 changes: 12 additions & 12 deletions packages/vscode-messenger-devtools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/vscode-messenger-devtools/src/devtool-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function activate(context: vscode.ExtensionContext) {
listenToNotifications(compatibleExtensions());
});
console.debug('Messenger Devtools activated.');
return msg.diagnosticApi({ withParameterData: true });
return msg.diagnosticApi({ withParameterData: true, withResponseData: true});
}

export function deactivate(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ const columnDefs: ColDef[] = [
const rowType = params.data.type ?? 'unknown';
const error = params.data.error ? <span className='table-cell codicon codicon-stop' title={params.data.error}></span> : undefined;
return <div className={'rowType_' + rowType} style={{ display: 'flex', alignContent: 'space-between' }}><span style={{ flexGrow: 1 }}>{params.value}</span>{error}</div>;
}
},
tooltipField: 'payloadInfo'
},
{ field: 'sender', initialWidth: 180 },
{ field: 'receiver', initialWidth: 180 },
{
field: 'method', initialWidth: 135,
tooltipField: 'methodTooltip'
tooltipField: 'payloadInfo'
},
{
field: 'size', headerName: 'Size (Time)', initialWidth: 135,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ExtensionData {
}
export interface ExtendedMessengerEvent extends MessengerEvent {
timeAfterRequest?: number
methodTooltip?: string
payloadInfo?: string
}

const MESSENGER_EXTENSION_ID = 'TypeFox.vscode-messenger-devtools';
Expand Down Expand Up @@ -210,8 +210,8 @@ class DevtoolsComponent extends React.Component<Record<string, any>, DevtoolsCom
const extensionData = this.state.datasetSrc.get(dataEvent.extension)!;

const highlight: HighlightData[] = [];

if (dataEvent.event.type === 'response' && dataEvent.event.timestamp) {
const isResponse = dataEvent.event.type === 'response';
if (isResponse && dataEvent.event.timestamp) {
// Take max 200 entries to look-up
const request = extensionData.events.slice(0, 200).find(event => event.type === 'request' && event.id === dataEvent.event.id);
if (request && request.timestamp) {
Expand All @@ -220,12 +220,10 @@ class DevtoolsComponent extends React.Component<Record<string, any>, DevtoolsCom
}
}

if (dataEvent.event.type === 'notification' || dataEvent.event.type === 'request') {
if (dataEvent.event.parameter) {
dataEvent.event.methodTooltip = `Parameter (max 500 chars):\n ${JSON.stringify(dataEvent.event.parameter, undefined, ' ').substring(0, 499)}`;
} else {
dataEvent.event.methodTooltip = 'Parameters are empty or suppressed using diagnostic API options.';
}
if (dataEvent.event.parameter) {
dataEvent.event.payloadInfo = `${isResponse?'Response':'Parameter'} (max 500 chars):\n ${JSON.stringify(dataEvent.event.parameter, undefined, ' ').substring(0, 499)}`;
} else {
dataEvent.event.payloadInfo = 'Payload information is empty or suppressed using diagnostic API options.';
}

extensionData.events.unshift(dataEvent.event);
Expand Down
9 changes: 8 additions & 1 deletion packages/vscode-messenger/src/diagnostic-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export interface DiagnosticOptions {
* If `true` request/notification parameter will be added to the diagnostic MessengerEvent as payload.
* If you don't want to expose potential sensible Data to public API set it to false.
* Default is: `false`
*/
*/
withParameterData?: boolean

/**
* If `true` response value will be added to the diagnostic MessengerEvent as payload.
* If you don't want to expose potential sensible Data to public API set it to false.
* Default is: `false`
*/
withResponseData?: boolean
}
10 changes: 8 additions & 2 deletions packages/vscode-messenger/src/messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ export class Messenger implements MessengerAPI {
event.type = 'response';
event.id = msg.id;
event.size = JSON.stringify(msg.result)?.length ?? 0;
event.parameter = msg.result;
if (msg.error) {
event.error = msg.error?.message ? msg.error?.message : 'No error message provided';
if (msg.error.data) {
Expand All @@ -440,8 +441,13 @@ export class Messenger implements MessengerAPI {
event.error = `Unknown message to ${msg.receiver}`;
}
this.eventListeners.forEach((options, listener) => {
if (!options?.withParameterData) {
// Clear parameter if user don't want to expose potential sensible Data to public API
if(isResponseMessage(msg)) {
if(!options?.withResponseData) {
// Clear response value if user don't want to expose it
event.parameter = undefined;
}
} else if (!options?.withParameterData) {
// Clear parameter if user don't want to expose it
event.parameter = undefined;
}
listener(event);
Expand Down

0 comments on commit 89de541

Please sign in to comment.