Skip to content

Commit 66075c7

Browse files
authored
add Token setting (#146)
fix insight infinit loading when go error from backend
1 parent 1f2ef51 commit 66075c7

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
"None",
119119
"Git"
120120
]
121+
},
122+
"digma.token": {
123+
"type": "string"
121124
}
122125
}
123126
}

src/services/analyticsProvider.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Dictionary, momentJsDateParser } from "./utils";
77
import moment = require("moment");
88
import { integer } from "vscode-languageclient";
99
import * as os from 'os';
10+
import { stringify } from "querystring";
1011

1112

1213
export enum Impact
@@ -473,22 +474,29 @@ export class AnalyticsProvider
473474
url += `${key}=${encodeURIComponent(queryParams[key])}&`;
474475
}
475476

477+
478+
const requestHeaders: any = {'Content-Type': 'application/json'};
479+
if(Settings.token.value !== undefined && Settings.token.value.trim() !== ""){
480+
requestHeaders['Authorization'] = `Token ${Settings.token.value}`;
481+
}
482+
483+
476484
let response = await fetch(
477485
url,
478486
{
479487
agent: agent,
480488
method: method,
481-
headers: {'Content-Type': 'application/json' },
489+
headers: requestHeaders,
482490
body: body ? JSON.stringify(body) : undefined,
483491
});
484492

485493
if(!response.ok)
486494
{
487495
const txt = await response.text();
488496
throw new HttpError(response.status, response.statusText, txt);
489-
}
497+
}
490498
return <TResponse>JSON.parse(await response.text(), momentJsDateParser);
491-
}
499+
}
492500
}
493501

494502
export class HttpError extends Error {

src/settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ export class Settings
4242
public static readonly hideFramesOutsideWorkspace = new SettingsKey('hideFramesOutsideWorkspace', true);
4343

4444
public static readonly sourceControl = new SettingsKey('sourceControl', SourceControlType.None);
45+
46+
public static readonly token = new SettingsKey('token', '');
47+
4548
}

src/views/codeAnalytics/insightsViewTab.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,26 @@ export class InsightsViewTab implements ICodeAnalyticsViewTab
5656
this.clearSpanLabel();
5757
let responseItems: any [] | undefined = undefined;
5858
let usageResults: UsageStatusResults;
59-
60-
const editor = vscode.window.activeTextEditor;
61-
if(!editor) {
62-
return;
63-
}
64-
const docInfo = await this._documentInfoProvider.getDocumentInfo(editor.document);
65-
if(!docInfo) {
66-
return;
67-
}
68-
if (!codeObject || !codeObject.id) {
69-
let html = await this._noCodeObjectsMessage.showCodeSelectionNotFoundMessage(docInfo);
70-
this.updateListView(html);
71-
this.updateSpanListView("");
72-
this._viewedCodeObjectId=undefined;
73-
return;
74-
}
75-
const methodInfo = docInfo.methods.single(x => x.id == codeObject.id);
76-
const codeObjectsIds = [methodInfo.idWithType]
77-
.concat(methodInfo.relatedCodeObjects.map(r => r.idWithType));
78-
try
79-
{
59+
try {
60+
const editor = vscode.window.activeTextEditor;
61+
if(!editor) {
62+
return;
63+
}
64+
const docInfo = await this._documentInfoProvider.getDocumentInfo(editor.document);
65+
if(!docInfo) {
66+
return;
67+
}
68+
if (!codeObject || !codeObject.id) {
69+
let html = await this._noCodeObjectsMessage.showCodeSelectionNotFoundMessage(docInfo);
70+
this.updateListView(html);
71+
this.updateSpanListView("");
72+
this._viewedCodeObjectId=undefined;
73+
return;
74+
}
75+
const methodInfo = docInfo.methods.single(x => x.id == codeObject.id);
76+
const codeObjectsIds = [methodInfo.idWithType]
77+
.concat(methodInfo.relatedCodeObjects.map(r => r.idWithType));
78+
8079
responseItems = await this._analyticsProvider.getInsights(codeObjectsIds);
8180
//temp ugly workaround
8281
var bottleneck = responseItems.find(x=>x.type ==='SlowestSpans');

0 commit comments

Comments
 (0)