Skip to content

Commit 8c04a9a

Browse files
authored
Merge pull request #241 from digma-ai/bug/navigating_to_code_does_not_reveal_insights
Bug/navigating to code does not reveal insights
2 parents 438023e + ee3f08e commit 8c04a9a

File tree

6 files changed

+109
-51
lines changed

6 files changed

+109
-51
lines changed

package.json

Lines changed: 24 additions & 23 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"
@@ -73,29 +72,23 @@
7372
"main": "./out/extension.js",
7473
"contributes": {
7574
"views": {
76-
"digma": [
77-
{
78-
"type": "webview",
79-
"id": "codeAnalytics",
80-
"name": "CodeAnalytics"
81-
}
82-
]
75+
"digma": [{
76+
"type": "webview",
77+
"id": "codeAnalytics",
78+
"name": "CodeAnalytics"
79+
}]
8380
},
8481
"viewsContainers": {
85-
"activitybar": [
86-
{
87-
"id": "digma",
88-
"title": "Digma",
89-
"icon": "icon.png"
90-
}
91-
]
82+
"activitybar": [{
83+
"id": "digma",
84+
"title": "Digma",
85+
"icon": "icon.png"
86+
}]
9287
},
93-
"commands": [
94-
{
95-
"command": "digma.changeSelectedEnvironment",
96-
"title": "Digma: Select deployment environment"
97-
}
98-
],
88+
"commands": [{
89+
"command": "digma.changeSelectedEnvironment",
90+
"title": "Digma: Select deployment environment"
91+
}],
9992
"configuration": {
10093
"properties": {
10194
"digma.enableCodeLens": {
@@ -140,6 +133,14 @@
140133
"digma.enableNotifications": {
141134
"type": "boolean",
142135
"default": false
136+
},
137+
138+
"digma.enableDebugOutput": {
139+
"type": "booean",
140+
"default": false,
141+
"description": "For troubleshooting only."
142+
143+
143144
}
144145
}
145146
}
@@ -196,4 +197,4 @@
196197
"publisherId": "caa21fe0-eb8b-43fd-9197-ae8fb8b1b5df",
197198
"isPreReleaseVersion": false
198199
}
199-
}
200+
}

src/analyticsCodeLens.ts

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
7676

7777
}
7878

79+
private async getRuntimeDataExistsLens(methodInfo: MethodInfo) :Promise<vscode.CodeLens>{
80+
return new vscode.CodeLens(methodInfo.range, {
81+
title: "Runtime data",
82+
tooltip: "Click to see this function's runtime data",
83+
command: CodelensProvider.clickCommand,
84+
arguments: [methodInfo, this._state.environment]
85+
86+
87+
});
88+
}
89+
7990

8091
private async getCodeLens(methodInfo: MethodInfo,
8192
codeObjectInfo:CodeObjectLocationInfo,
@@ -177,48 +188,50 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
177188
public async provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.CodeLens[]>
178189
{
179190
if (!Settings.enableCodeLens.value)
180-
return [];
191+
{return [];}
181192

182193
const documentInfo = await this._documentInfoProvider.getDocumentInfo(document);
183194
if(!documentInfo)
184-
return [];
195+
{return [];}
185196

186197
const codelens: vscode.CodeLens[] = [];
187198
for(let methodInfo of documentInfo.methods)
188199
{
200+
const methodCodeLens: vscode.CodeLens[] = [];
201+
189202
for (let alias of methodInfo.ids){
190-
const insights = documentInfo.insights.all.filter(x=>x.codeObjectId== alias)
191-
.filter(x=>x.scope=="Function");
203+
const insights = documentInfo.insights.all
204+
.filter(x=>x.codeObjectId == alias);
192205

193-
const thisEnvInsights = insights.filter(x=>x.environment==this._state.environment);
206+
const thisEnvInsights = insights
207+
.filter(x=>x.environment == this._state.environment);
194208

195-
const lenses = await this.getCodeLens(methodInfo,methodInfo,thisEnvInsights, documentInfo.usageData.getAll(),false);
209+
const lenses = await this.getCodeLens(methodInfo,methodInfo,
210+
thisEnvInsights.filter(x=>x.scope=="Function"),
211+
documentInfo.usageData.getAll(),false);
212+
196213
for (const lens of lenses){
197-
codelens.push(lens);
214+
methodCodeLens.push(lens);
198215
}
199216

200-
if (lenses.length===0 && thisEnvInsights.length>0){
201-
codelens.push(new vscode.CodeLens(methodInfo.range, {
202-
title: "Runtime data",
203-
tooltip: "Click to see this function's runtime data",
204-
command: CodelensProvider.clickCommand,
205-
arguments: [methodInfo, this._state.environment]
206-
}));
207-
208-
217+
if (methodCodeLens.length===0 && thisEnvInsights.length>0){
218+
methodCodeLens.push(await this.getRuntimeDataExistsLens(methodInfo));
209219
}
210220

211221
}
212222

213223
let spans = documentInfo.spans.filter(e => e.range.intersection(methodInfo.range) != undefined);
214-
let duplicates = spans.filter(x=>documentInfo.spans.any(span=>span!=x && span.name==x.name && span.range!=x.range));
224+
let duplicates = spans
225+
.filter(x=>documentInfo.spans
226+
.any(span=>span!=x && span.name==x.name && span.range!=x.range));
227+
215228
spans=spans.filter(span=>!duplicates.includes(span));
216229

217230
if(duplicates.length>0){
218231
const lenses = await this.getDuplicateSpanLens(methodInfo, duplicates);
219232

220233
for (const lens of lenses){
221-
codelens.push(lens);
234+
methodCodeLens.push(lens);
222235
}
223236

224237
}
@@ -227,8 +240,8 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
227240
spans,documentInfo.usageData.getAll(),documentInfo.insights.all.filter(x=>x.scope=="Span"));
228241

229242
for (const lens of lenses){
230-
codelens.push(lens);
231-
}
243+
methodCodeLens.push(lens);
244+
}
232245

233246
}
234247

@@ -240,11 +253,8 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
240253
uniqueEndpoints,documentInfo.usageData.getAll(),documentInfo.insights.all.filter(x=>x.scope=="EntrySpan"|| x.scope=="Span"),
241254
);
242255

243-
const uniqueLenses =[...new Map(lenses.map(item =>
244-
[item.command!.title, item])).values()];
245-
246-
for (const lens of uniqueLenses){
247-
codelens.push(lens);
256+
for (const lens of lenses){
257+
methodCodeLens.push(lens);
248258
}
249259

250260

@@ -263,10 +273,16 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
263273
const otherEnvLenses = await this.getCodeLens(methodInfo,methodInfo,otherEnvsInsights,
264274
documentInfo.usageData.getAll(),true);
265275
for (const lens of otherEnvLenses){
266-
codelens.push(lens);
276+
methodCodeLens.push(lens);
267277
}
268278

269279
}
280+
281+
const uniqueLenses =[...new Map(methodCodeLens.map(item =>
282+
[item.command!.title, item])).values()];
283+
284+
285+
codelens.push(...uniqueLenses);
270286

271287
}
272288

src/services/languages/modulePathToUriConverters.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as vscode from 'vscode';
2+
import { Settings } from '../../settings';
3+
import { Logger } from '../logger';
24

35
export interface ModulePathInfo {
46
modulePhysicalPath?: string;
@@ -34,13 +36,31 @@ export class PhysicalModulePathToUriConverter implements IModulePathToUriConvert
3436
const moduleRootFolder = modulePhysicalPath.split('/').firstOrDefault();
3537
const moduleWorkspace = vscode.workspace.workspaceFolders?.find(w => w.name === moduleRootFolder);
3638
if (moduleWorkspace) {
39+
if (Settings.enableDebugOutput){
40+
Logger.info(`Looking in workspace folder ${moduleWorkspace}`);
41+
}
3742
const workspaceUri = moduleWorkspace
3843
? vscode.Uri.joinPath(moduleWorkspace.uri, '..', modulePhysicalPath)
3944
: undefined;
4045
return workspaceUri;
4146
}
4247
else {
48+
if (Settings.enableDebugOutput){
49+
Logger.info(`Trying to find file ${modulePhysicalPath}`);
50+
}
51+
if (modulePhysicalPath.indexOf("site-packages")>0){
52+
return undefined;
53+
}
4354
const file = await (await vscode.workspace.findFiles(modulePhysicalPath)).firstOrDefault();
55+
if (Settings.enableDebugOutput){
56+
if (file){
57+
Logger.info(`Found file ${file}`);
58+
}
59+
else {
60+
Logger.info(`File not found`);
61+
62+
}
63+
}
4464
return file;
4565
}
4666
}

src/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export class Settings
3838

3939
public static readonly enableCodeLens = new SettingsKey('enableCodeLens', true);
4040

41+
public static readonly enableDebugOutput = new SettingsKey('enableDebugOutput', false);
42+
4143
// public static readonly environment = new SettingsKey('environment', '');
4244

4345
public static readonly jaegerAddress = new SettingsKey('jaegerAddress', '');

src/views/codeAnalytics/AdminInsights/noCodeObjectMessage.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { AnalyticsProvider } from "../../../services/analyticsProvider";
22
import { DocumentInfo } from "../../../services/documentInfoProvider";
3+
import { Logger } from "../../../services/logger";
4+
import { Settings } from "../../../settings";
35
import { WorkspaceState } from "../../../state";
46
import { WebViewUris } from "../../webViewUtils";
57
import { CodeObjectGroupEnvironments } from "../CodeObjectGroups/CodeObjectGroupEnvUsage";
@@ -20,7 +22,7 @@ export class NoCodeObjectMessage{
2022

2123
for(const method of docInfo.methods){
2224
const relatedInsights = docInfo.insights.all.filter(s =>
23-
method.id === s.codeObjectId ||
25+
method.ids.any(x=>x==s.codeObjectId) ||
2426
method.relatedCodeObjects.any(r => r.id === s.codeObjectId));
2527
if(relatedInsights.length !==0){
2628
links.push(/*html*/`<vscode-link class="codeobject-link" data-line="${method.range.start.line}">${method.displayName}</vscode-link>`);
@@ -38,6 +40,23 @@ export class NoCodeObjectMessage{
3840
${HtmlHelper.getInfoMessage("No data was received for any code object in this file.")}
3941
<div>Consider adding instrumentation or check your OTEL configuration</div>
4042
<div class="links-list">${links.join("")}</div>`;
43+
44+
if (Settings.enableDebugOutput){
45+
Logger.info("Was not able to link to existing data. ");
46+
for(const method of docInfo.methods){
47+
if (method.ids.length>0){
48+
Logger.info(`Method ids: ${method.ids.join(",")} `);
49+
}
50+
if (method.relatedCodeObjects.length>0){
51+
Logger.info(`Method relatedIds: ${method.relatedCodeObjects.join(",")} `);
52+
}
53+
}
54+
if (docInfo.insights.all.length>0){
55+
Logger.info(`Insights code objects ids: ${docInfo.insights.all.map(x=>x.codeObjectId).join(",")}`);
56+
}
57+
58+
}
59+
4160
}
4261
return html;
4362

src/views/codeAnalytics/overlayView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class OverlayView
103103
if(!editor || !e.line)
104104
return;
105105

106-
const range = new vscode.Range(new vscode.Position(e.line, 0), new vscode.Position(e.line, 0));
106+
const range = new vscode.Range(new vscode.Position(e.line+1, 0), new vscode.Position(e.line+1, 0));
107107
editor.selection = new vscode.Selection(range.start, range.end);
108108
editor.revealRange(range, vscode.TextEditorRevealType.InCenter);
109109
}

0 commit comments

Comments
 (0)