Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add logging on all RESTful and WebSocket requests in VS Code#580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
EhabY merged 9 commits intocoder:mainfromEhabY:add-logging-on-all-requests
Sep 17, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,9 @@
### Added

- Add support for CLI global flag configurations through the `coder.globalFlags` setting.
- Add logging for all REST traffic. Verbosity is configurable via `coder.httpClientLogLevel` (`none`, `basic`, `headers`, `body`).
- Add lifecycle logs for WebSocket creation, errors, and closures.
- Include UUIDs in REST and WebSocket logs to correlate events and measure duration.

## [1.10.1](https://github.com/coder/vscode-coder/releases/tag/v1.10.1) 2025-08-13

Expand Down
17 changes: 17 additions & 0 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -126,6 +126,23 @@
"items": {
"type": "string"
}
},
"coder.httpClientLogLevel": {
"markdownDescription": "Controls the verbosity of HTTP client logging. This affects what details are logged for each HTTP request and response.",
"type": "string",
"enum": [
"none",
"basic",
"headers",
"body"
],
"markdownEnumDescriptions": [
"Disables all HTTP client logging",
"Logs the request method, URL, length, and the response status code",
"Logs everything from *basic* plus sanitized request and response headers",
"Logs everything from *headers* plus request and response bodies (may include sensitive data)"
],
"default": "basic"
}
}
},
Expand Down
53 changes: 33 additions & 20 deletionssrc/agentMetadataHelper.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
import { Api } from "coder/site/src/api/api";
import { WorkspaceAgent } from "coder/site/src/api/typesGenerated";
import { EventSource } from "eventsource";
import * as vscode from "vscode";
import { createStreamingFetchAdapter } from "./api";
import {
AgentMetadataEvent,
AgentMetadataEventSchemaArray,
errToStr,
} from "./api-helper";
} from "./api/api-helper";
import { CoderApi } from "./api/coderApi";

export type AgentMetadataWatcher = {
onChange: vscode.EventEmitter<null>["event"];
Expand All@@ -17,47 +15,62 @@ export type AgentMetadataWatcher = {
};

/**
* Opensan SSE connection to watch metadata for a given workspace agent.
* Opensa websocket connection to watch metadata for a given workspace agent.
* Emits onChange when metadata updates or an error occurs.
*/
export function createAgentMetadataWatcher(
agentId: WorkspaceAgent["id"],
restClient: Api,
client: CoderApi,
): AgentMetadataWatcher {
// TODO: Is there a better way to grab the url and token?
const url = restClient.getAxiosInstance().defaults.baseURL;
const metadataUrl = new URL(
`${url}/api/v2/workspaceagents/${agentId}/watch-metadata`,
);
const eventSource = new EventSource(metadataUrl.toString(), {
fetch: createStreamingFetchAdapter(restClient.getAxiosInstance()),
});
const socket = client.watchAgentMetadata(agentId);

let disposed = false;
const onChange = new vscode.EventEmitter<null>();
const watcher: AgentMetadataWatcher = {
onChange: onChange.event,
dispose: () => {
if (!disposed) {
eventSource.close();
socket.close();
disposed = true;
}
},
};

eventSource.addEventListener("data", (event) => {
const handleError = (error: unknown) => {
watcher.error = error;
onChange.fire(null);
};

socket.addEventListener("message", (event) => {
try {
const dataEvent = JSON.parse(event.data);
const metadata = AgentMetadataEventSchemaArray.parse(dataEvent);
if (event.parseError) {
handleError(event.parseError);
return;
}

const metadata = AgentMetadataEventSchemaArray.parse(
event.parsedMessage.data,
);

// Overwrite metadata if it changed.
if (JSON.stringify(watcher.metadata) !== JSON.stringify(metadata)) {
watcher.metadata = metadata;
onChange.fire(null);
}
} catch (error) {
watcher.error = error;
onChange.fire(null);
handleError(error);
}
});

socket.addEventListener("error", handleError);

socket.addEventListener("close", (event) => {
if (event.code !== 1000) {
handleError(
new Error(
`WebSocket closed unexpectedly: ${event.code} ${event.reason}`,
),
);
}
});

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp