Skip to content

Commit 90fb58d

Browse files
authored
Merge pull request #155 from digma-ai/feature/trace-support
Feature/trace support
2 parents 72010f2 + d9bd483 commit 90fb58d

27 files changed

+381
-115
lines changed

package.json

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"Continuous Delivery",
2525
"DevOps"
2626
],
27-
"badges": [
28-
{
27+
"badges": [{
2928
"url": "https://img.shields.io/github/stars/digma-ai/digma?style=social",
3029
"description": "Star Digma on Github",
3130
"href": "bit.ly/36LyUcr"
@@ -72,22 +71,18 @@
7271
"main": "./out/extension.js",
7372
"contributes": {
7473
"views": {
75-
"digma": [
76-
{
77-
"type": "webview",
78-
"id": "codeAnalytics",
79-
"name": "CodeAnalytics"
80-
}
81-
]
74+
"digma": [{
75+
"type": "webview",
76+
"id": "codeAnalytics",
77+
"name": "CodeAnalytics"
78+
}]
8279
},
8380
"viewsContainers": {
84-
"activitybar": [
85-
{
86-
"id": "digma",
87-
"title": "Digma",
88-
"icon": "icon.png"
89-
}
90-
]
81+
"activitybar": [{
82+
"id": "digma",
83+
"title": "Digma",
84+
"icon": "icon.png"
85+
}]
9186
},
9287
"configuration": {
9388
"properties": {
@@ -99,7 +94,8 @@
9994
"type": "string",
10095
"default": "https://localhost:5051"
10196
},
102-
"digma.environment": {
97+
98+
"digma.jaegerAddress": {
10399
"type": "string"
104100
},
105101
"digma.hideFramesOutsideWorkspace": {
@@ -166,4 +162,4 @@
166162
"node-sass": "^7.0.1",
167163
"typescript": "^4.4.4"
168164
}
169-
}
165+
}

src/decorators/hotspotMarkerDecorator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ export class HotspotMarkerDecorator implements vscode.Disposable
6262
const rangesByLevel: Dictionary<number, vscode.Range[]> = {};
6363
for(let methodInfo of docInfo.methods)
6464
{
65+
if (!methodInfo.nameRange)
66+
continue;
67+
6568
const score = docInfo.summaries.get(MethodCodeObjectSummary, methodInfo.symbol.id)?.score ?? 0;
6669
if(score < 70)
6770
continue;
6871

6972
const level = Math.floor((score/101)*this.LEVELS); // [0-100] => [0-9]
70-
const decorationType = this._decorationTypes[level];
73+
//const decorationType = this._decorationTypes[level];
7174
var s =new vscode.Position(methodInfo.nameRange!.end.line+1,
7275
0);
7376
var e = new vscode.Position(methodInfo.range.end.line,

src/extension.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { EditorHelper } from './services/EditorHelper';
1515
import { CodeInspector } from './services/codeInspector';
1616
import { VsCodeDebugInstrumentation } from './instrumentation/vscodeInstrumentation';
1717
import { GoLanguageExtractor } from './services/languages/go/languageExtractor';
18+
import { WorkspaceState } from './state';
1819

1920
export async function activate(context: vscode.ExtensionContext)
2021
{
@@ -26,26 +27,29 @@ export async function activate(context: vscode.ExtensionContext)
2627
const supportedSourceControls = [
2728
new Git()
2829
];
30+
31+
const workspaceState = new WorkspaceState(context.workspaceState);
2932
const sourceControl = new SourceControl(supportedSourceControls);
3033
const codeInspector = new CodeInspector();
3134
const symbolProvider = new SymbolProvider(supportedLanguages, codeInspector);
32-
const analyticsProvider = new AnalyticsProvider();
33-
const documentInfoProvider = new DocumentInfoProvider(analyticsProvider, symbolProvider);
35+
const analyticsProvider = new AnalyticsProvider(workspaceState);
36+
const documentInfoProvider = new DocumentInfoProvider(analyticsProvider, symbolProvider,workspaceState);
3437
const editorHelper = new EditorHelper(sourceControl, documentInfoProvider);
3538

36-
if(!Settings.environment.value){
39+
if(!workspaceState.environment){
3740
const firstEnv = (await analyticsProvider.getEnvironments()).firstOrDefault();
3841
if(firstEnv) {
39-
await Settings.environment.set(firstEnv);
42+
workspaceState.setEnvironment(firstEnv);
4043
}
4144
}
45+
4246
context.subscriptions.push(new AnaliticsCodeLens(documentInfoProvider));
4347
//context.subscriptions.push(new ContextView(analyticsProvider, context.extensionUri));
4448
context.subscriptions.push(new MethodCallErrorTooltip(documentInfoProvider, codeInspector));
4549
context.subscriptions.push(sourceControl);
4650
context.subscriptions.push(documentInfoProvider);
4751
context.subscriptions.push(new CodeAnalyticsView(analyticsProvider, documentInfoProvider,
48-
context.extensionUri, editorHelper));
52+
context.extensionUri, editorHelper,workspaceState));
4953
context.subscriptions.push(new ErrorsLineDecorator(documentInfoProvider));
5054
context.subscriptions.push(new HotspotMarkerDecorator(documentInfoProvider));
5155
context.subscriptions.push(new VsCodeDebugInstrumentation(analyticsProvider));

src/services/analyticsProvider.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { decimal, integer } from "vscode-languageclient";
99
import * as os from 'os';
1010
import { stringify } from "querystring";
1111
import { SpanInfo } from "../views/codeAnalytics/InsightListView/CommonInsightObjects";
12+
import { WorkspaceState } from "../state";
1213

1314

1415
export enum Impact
@@ -324,6 +325,9 @@ export interface CodeObjectErrorDetails extends CodeObjectErrorResponse{
324325

325326
export class AnalyticsProvider
326327
{
328+
public constructor(private state: WorkspaceState){
329+
330+
}
327331
public async getEnvironments() : Promise<string[]>
328332
{
329333
try
@@ -351,7 +355,7 @@ export class AnalyticsProvider
351355

352356
public async getCodeObjectsErrors(codeObjectIds: string []): Promise<CodeObjectErrorResponse[]>
353357
{
354-
let params : [string, any][] = [["environment",Settings.environment.value]];
358+
let params : [string, any][] = [["environment",this.state.environment]];
355359
codeObjectIds.forEach(o=> params.push(["codeObjectId",o]));
356360

357361
const response = await this.send<CodeObjectErrorResponse[]>(
@@ -421,7 +425,7 @@ export class AnalyticsProvider
421425
`/CodeAnalytics/insights`,
422426
undefined,
423427
{
424-
environment: Settings.environment.value
428+
environment: this.state.environment
425429
});
426430
return response;
427431
}
@@ -435,7 +439,7 @@ export class AnalyticsProvider
435439
undefined,
436440
{
437441
codeObjectIds: codeObjectIds,
438-
environment: Settings.environment.value
442+
environment: this.state.environment
439443
});
440444
return response;
441445
}
@@ -448,7 +452,7 @@ export class AnalyticsProvider
448452
'POST',
449453
`/CodeAnalytics/summary`,
450454
undefined,
451-
{codeObjectIds: symbolsIdentifiers, environment: Settings.environment.value});
455+
{codeObjectIds: symbolsIdentifiers, environment: this.state.environment});
452456

453457
return response;
454458
}
@@ -462,7 +466,7 @@ export class AnalyticsProvider
462466
{
463467
try
464468
{
465-
let params : [string, any][] = [["environment",Settings.environment.value]];
469+
let params : [string, any][] = [["environment",this.state.environment]];
466470

467471
if(sort){
468472
params.push(["sort",sort]);
@@ -494,7 +498,7 @@ export class AnalyticsProvider
494498
'POST',
495499
`/CodeAnalytics/errorFlow`,
496500
undefined,
497-
{id: errorFlowId, environment: Settings.environment.value});
501+
{id: errorFlowId, environment: this.state.environment});
498502

499503
return response;
500504
}

src/services/documentInfoProvider.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { EndpointInfo, SpanLocationInfo as SpanLocationInfo, SymbolInfo, CodeObj
99
import { InstrumentationInfo } from './EditorHelper';
1010
import { SymbolInformation } from 'vscode';
1111
import { Settings } from '../settings';
12+
import { WorkspaceState } from '../state';
1213

1314
export class DocumentInfoProvider implements vscode.Disposable
1415
{
@@ -17,27 +18,28 @@ export class DocumentInfoProvider implements vscode.Disposable
1718
private _timer;
1819

1920
private ensureDocDictionaryForEnv(){
20-
let envDictionary = this._documentsByEnv[Settings.environment.value];
21+
let envDictionary = this._documentsByEnv[this.workspaceState.environment];
2122
if (!envDictionary){
22-
this._documentsByEnv[Settings.environment.value]={};
23+
this._documentsByEnv[this.workspaceState.environment]={};
2324
}
2425
}
2526
get _documents(): Dictionary<string, DocumentInfoContainer> {
2627

2728
this.ensureDocDictionaryForEnv();
28-
return this._documentsByEnv[Settings.environment.value];
29+
return this._documentsByEnv[this.workspaceState.environment];
2930
}
3031

3132
set _documents(value: Dictionary<string, DocumentInfoContainer>){
3233
this.ensureDocDictionaryForEnv();
33-
this._documentsByEnv[Settings.environment.value]=value;
34+
this._documentsByEnv[this.workspaceState.environment]=value;
3435

3536
}
3637

3738

3839
constructor(
3940
public analyticsProvider: AnalyticsProvider,
40-
public symbolProvider: SymbolProvider)
41+
public symbolProvider: SymbolProvider,
42+
private workspaceState: WorkspaceState)
4143
{
4244
this._disposables.push(vscode.workspace.onDidCloseTextDocument((doc: vscode.TextDocument) => this.removeDocumentInfo(doc)));
4345

src/settings.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ export class SettingsKey<T>
3131
}
3232
}
3333

34+
3435
export class Settings
3536
{
3637
public static readonly url = new SettingsKey('url', '');
3738

3839
public static readonly enableCodeLens = new SettingsKey('enableCodeLens', true);
3940

40-
public static readonly environment = new SettingsKey('environment', '');
41+
// public static readonly environment = new SettingsKey('environment', '');
42+
43+
public static readonly jaegerAddress = new SettingsKey('jaegerAddress', '');
44+
4145

4246
public static readonly hideFramesOutsideWorkspace = new SettingsKey('hideFramesOutsideWorkspace', true);
4347

src/state.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as vscode from 'vscode';
2+
3+
export class WorkspaceState {
4+
5+
environmentKey:string = "environment";
6+
7+
public constructor(private state: vscode.Memento){
8+
9+
}
10+
11+
public get environment():string {
12+
const result:string|undefined = this.state.get(this.environmentKey);
13+
if (result != null){
14+
return result;
15+
}
16+
else{
17+
return "";
18+
}
19+
}
20+
21+
public async setEnvironment(environmet: string) {
22+
await this.state.update(this.environmentKey, environmet);
23+
}
24+
}

src/views-ui/codeAnalytics/contracts.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export namespace UiMessage
3333
export class OpenHistogramPanel {
3434
constructor(public span?: string, public instrumentationLibrary?:string){}
3535
}
36+
37+
export class OpenTracePanel {
38+
constructor(public traceIds?: string[], public traceLabels?:string[], public span?:string, public jaegerAddress?:string){}
39+
}
3640
export class OpenRawTrace {
3741
constructor(public content?: string) {}
3842
}
@@ -64,9 +68,8 @@ export namespace UiMessage
6468
constructor(public htmlContent?: string) {}
6569
}
6670

67-
export class HistogramPanel{
68-
constructor(public data?: decimal[]) {}
69-
71+
export class TracePanel {
72+
constructor(public url?: string) {}
7073
}
7174

7275
export class GlobalInsightsList {

src/views-ui/codeAnalytics/main.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ vscode-panel-view {
460460
.percentiles-grid {
461461
display: grid;
462462
justify-content: start;
463-
grid-template-columns: auto auto 1fr auto;
463+
grid-template-columns: auto auto auto 1fr;
464464
column-gap: 10px;
465465
row-gap: 5px;
466466
}

src/views-ui/codeAnalytics/main.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ window.addEventListener("load", () =>
2828
const overlay = $("#view-overlay");
2929
const tabsContainer = $("#view-tabs");
3030
const insightsTab = $("#view-insights");
31+
const tacePanel = $("#view-trace-panel");
32+
3133
const globalInsightsTab = $("#view-global-insights");
3234
const errorsTab = $("#view-errors");
3335

@@ -66,6 +68,8 @@ window.addEventListener("load", () =>
6668
}
6769
});
6870

71+
72+
6973
consume(UiMessage.Set.GlobalInsightsList, (event) => {
7074
if (event.htmlContent !== undefined) {
7175
globalInsightsTab.find("#insightList").html(event.htmlContent);
@@ -132,7 +136,35 @@ window.addEventListener("load", () =>
132136

133137
publish(new UiMessage.Notify.OpenHistogramPanel(spanName,spanInstrumentationLibrary));
134138
});
135-
139+
140+
$(document).on("click", ".trace-link", function () {
141+
const traceIds = $(this).data("trace-id").split(",");
142+
const traceLabels = $(this).data("trace-label")?.split(",");
143+
144+
const span = $(this).data("span-name");
145+
const jaeger = $(this).data("jaeger-address");
146+
147+
publish(new UiMessage.Notify.OpenTracePanel(traceIds,traceLabels,span, jaeger));
148+
});
149+
150+
consume(UiMessage.Set.TracePanel, (event) => {
151+
152+
153+
if (event.url !== undefined) {
154+
155+
fetch(event.url, { mode: 'cors'}).then(async response=>{
156+
switch (response.status) {
157+
// status "OK"
158+
case 200:
159+
tacePanel.find("#trace-jaeger-content").html(await response.text());
160+
// status "Not Found"
161+
case 404:
162+
throw response;
163+
}
164+
});
165+
166+
}
167+
});
136168

137169

138170
$(document).on("click", ".error_frames_btn", function () {

0 commit comments

Comments
 (0)