Skip to content

Commit 0464f76

Browse files
alexr00Copilot
andauthored
Add insiders telemetry for API calls (#8692)
* Add insiders telemetry for API calls Co-authored-by: Copilot <copilot@github.com> * CCR feedback --------- Co-authored-by: Copilot <copilot@github.com>
1 parent 8883813 commit 0464f76

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/github/loggingOctokit.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,27 @@ export class RateLogger {
3232
private bulkhead: BulkheadPolicy = bulkhead(140);
3333
private static ID = 'RateLimit';
3434
private hasLoggedLowRateLimit: boolean = false;
35+
private readonly _isInsiders: boolean;
3536

36-
constructor(private readonly telemetry: ITelemetry, private readonly errorOnFlood: boolean) { }
37+
constructor(private readonly telemetry: ITelemetry, private readonly errorOnFlood: boolean) {
38+
this._isInsiders = vscode.env.appName.toLowerCase().includes('insider');
39+
}
40+
41+
private static sanitizeOperationName(info: string): string {
42+
// REST URLs like /repos/{owner}/{repo}/pulls get redacted because they look
43+
// like file paths. Convert slashes to dots to avoid redaction.
44+
return info.replace(/\/+/g, '.').replace(/^\.+|\.+$/g, '');
45+
}
3746

3847
public logAndLimit<T extends Promise<any>>(info: string | undefined, apiRequest: () => T): T | undefined {
48+
if (this._isInsiders && info) {
49+
/* __GDPR__
50+
"pr.apiCall" : {
51+
"operation" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
52+
}
53+
*/
54+
this.telemetry.sendTelemetryEvent('pr.apiCall', { operation: RateLogger.sanitizeOperationName(info) });
55+
}
3956
if (this.bulkhead.executionSlots === 0) {
4057
Logger.error('API call count has exceeded 140 concurrent calls.', RateLogger.ID);
4158
// We have hit more than 140 concurrent API requests.
@@ -126,7 +143,7 @@ export class LoggingApolloClient {
126143
}
127144

128145
mutate<T = any, TVariables = OperationVariables>(options: MutationOptions<T, TVariables>): Promise<FetchResult<T>> {
129-
const logInfo = options.context;
146+
const logInfo = String(options.context);
130147
const result = this._rateLogger.logAndLimit(logInfo, () => this._graphql.mutate(options));
131148
if (result === undefined) {
132149
throw new Error('API call count has exceeded a rate limit.');

0 commit comments

Comments
 (0)