Skip to content

Commit 64f09d1

Browse files
committed
refactor(telemetry): simplify http request rollup
Drop the recorder interface, noop sentinels, and creation helper — construct HttpRequestsTelemetry unconditionally and let the noop reporter swallow .log() calls. Flatten route normalization rules, switch buckets to a nested map (no string key encoding), and stop pushing zero-duration samples when metadata is absent so p95 isn't skewed. Drop the LOCAL_SINK_SETTING backwards-compat alias.
1 parent 4828102 commit 64f09d1

7 files changed

Lines changed: 350 additions & 407 deletions

File tree

src/api/coderApi.ts

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ import {
2020
logRequest,
2121
logResponse,
2222
} from "../logging/httpLogger";
23-
import {
24-
HttpRequestsTelemetry,
25-
NOOP_HTTP_REQUESTS_TELEMETRY,
26-
type HttpRequestsTelemetryRecorder,
27-
} from "../logging/httpRequestsTelemetry";
23+
import { HttpRequestsTelemetry } from "../logging/httpRequestsTelemetry";
2824
import {
2925
HttpClientLogLevel,
3026
type RequestConfigWithMeta,
@@ -74,10 +70,6 @@ import type {
7470

7571
const coderSessionTokenHeader = "Coder-Session-Token";
7672

77-
const NOOP_DISPOSABLE: vscode.Disposable = {
78-
dispose: () => undefined,
79-
};
80-
8173
/**
8274
* Configuration settings that affect WebSocket connections.
8375
* Changes to these settings will trigger WebSocket reconnection.
@@ -109,7 +101,7 @@ export class CoderApi extends Api implements vscode.Disposable {
109101

110102
private constructor(
111103
private readonly output: Logger,
112-
private readonly httpRequestsTelemetry: HttpRequestsTelemetryRecorder,
104+
private readonly httpRequestsTelemetry: HttpRequestsTelemetry,
113105
) {
114106
super();
115107
this.configWatcher = this.watchConfigChanges();
@@ -126,7 +118,10 @@ export class CoderApi extends Api implements vscode.Disposable {
126118
output: Logger,
127119
telemetry: TelemetryReporter = NOOP_TELEMETRY_REPORTER,
128120
): CoderApi {
129-
const httpRequestsTelemetry = createHttpRequestsTelemetry(telemetry);
121+
const httpRequestsTelemetry = new HttpRequestsTelemetry(
122+
telemetry,
123+
readHttpRequestsTelemetryConfig(vscode.workspace.getConfiguration()),
124+
);
130125
const client = new CoderApi(output, httpRequestsTelemetry);
131126
client.setCredentials(baseUrl, token);
132127

@@ -217,10 +212,6 @@ export class CoderApi extends Api implements vscode.Disposable {
217212
}
218213

219214
private watchHttpRequestsConfigChanges(): vscode.Disposable {
220-
if (this.httpRequestsTelemetry === NOOP_HTTP_REQUESTS_TELEMETRY) {
221-
return NOOP_DISPOSABLE;
222-
}
223-
224215
return watchConfigurationChanges(
225216
[
226217
{
@@ -525,26 +516,10 @@ export class CoderApi extends Api implements vscode.Disposable {
525516
}
526517
}
527518

528-
/**
529-
* Set up logging and request interceptors for the CoderApi instance.
530-
*/
531-
function createHttpRequestsTelemetry(
532-
telemetry: TelemetryReporter,
533-
): HttpRequestsTelemetryRecorder {
534-
if (telemetry === NOOP_TELEMETRY_REPORTER) {
535-
return NOOP_HTTP_REQUESTS_TELEMETRY;
536-
}
537-
538-
return new HttpRequestsTelemetry(
539-
telemetry,
540-
readHttpRequestsTelemetryConfig(vscode.workspace.getConfiguration()),
541-
);
542-
}
543-
544519
function setupInterceptors(
545520
client: CoderApi,
546521
output: Logger,
547-
httpRequestsTelemetry: HttpRequestsTelemetryRecorder,
522+
httpRequestsTelemetry: HttpRequestsTelemetry,
548523
): void {
549524
addLoggingInterceptors(
550525
client.getAxiosInstance(),
@@ -601,7 +576,7 @@ function setupInterceptors(
601576
function addLoggingInterceptors(
602577
client: AxiosInstance,
603578
logger: Logger,
604-
httpRequestsTelemetry: HttpRequestsTelemetryRecorder,
579+
httpRequestsTelemetry: HttpRequestsTelemetry,
605580
) {
606581
client.interceptors.request.use(
607582
(config) => {

0 commit comments

Comments
 (0)