Skip to content

Commit a05cc02

Browse files
authored
increase debug logging (#7)
* increase debug logging * increase debug logging * increase debug logging * increase debug logging * increase debug logging * decrease debug logging * debug logging * refactor: debug logging
1 parent 22af95f commit a05cc02

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

src/SourcePlusPlus.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,12 @@ namespace SourcePlusPlus {
158158

159159
function registerRemotes(eventBus: EventBus) {
160160
eventBus.registerHandler("spp.probe.command.live-instrument-remote", {}, (err, message) => {
161+
debugLog("Received probe-wide instrument command: " + JSON.stringify(message.body));
161162
liveInstrumentRemote.handleInstrumentCommand(
162163
LiveInstrumentCommand.fromJson(message.body));
163164
});
164165
eventBus.registerHandler(`spp.probe.command.live-instrument-remote:${probeConfig.spp.probe_id}`, {}, (err, message) => {
166+
debugLog("Received probe-specific instrument command: " + JSON.stringify(message.body));
165167
liveInstrumentRemote.handleInstrumentCommand(
166168
LiveInstrumentCommand.fromJson(message.body));
167169
});

src/control/ContextReceiver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// import LiveInstrumentRemote from "./LiveInstrumentRemote";
21
import {LogData, LogDataBody, LogTags, TextLog, TraceContext} from "skywalking-backend-js/lib/proto/logging/Logging_pb";
32
import {KeyStringValuePair} from "skywalking-backend-js/lib/proto/common/Common_pb";
43
import {ContextManager} from "skywalking-backend-js";
@@ -8,6 +7,9 @@ import {LogReportServiceClient} from "skywalking-backend-js/lib/proto/logging/Lo
87
import {Debugger} from "inspector";
98
import VariableUtil from "../util/VariableUtil";
109
import ProbeMemory from "../ProbeMemory";
10+
import SourcePlusPlus from "../SourcePlusPlus";
11+
12+
const debugLog = (...args: any[]) => SourcePlusPlus.debugLog(args);
1113

1214
namespace ContextReceiver {
1315
let logReport;
@@ -50,6 +52,7 @@ namespace ContextReceiver {
5052

5153
export function applyBreakpoint(breakpointId: string, source: string | undefined, line: number,
5254
frames: Debugger.CallFrame[], variables) {
55+
debugLog(`applyBreakpoint: ${breakpointId} ${source} ${line}`);
5356
let activeSpan = ContextManager.current.newLocalSpan(callFrameToString(frames[0]));
5457

5558
activeSpan.start();
@@ -94,6 +97,7 @@ namespace ContextReceiver {
9497
}
9598

9699
export function applyLog(liveLogId: string, logFormat: string, logArguments: any) {
100+
debugLog(`applyLog: ${liveLogId} ${logFormat} ${logArguments}`);
97101
let logTags = new LogTags();
98102
logTags.addData(new KeyStringValuePair().setKey('log_id').setValue(liveLogId));
99103
logTags.addData(new KeyStringValuePair().setKey('level').setValue('Live'));

src/control/LiveInstrumentRemote.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import EventBus from "@vertx/eventbus-bridge-client.js";
99
import LiveInstrumentCommand from "../model/command/LiveInstrumentCommand";
1010
import CommandType from "../model/command/CommandType";
1111
import VariableUtil from "../util/VariableUtil";
12+
import SourcePlusPlus from "../SourcePlusPlus";
13+
14+
const debugLog = (...args: any[]) => SourcePlusPlus.debugLog(args);
1215

1316
export interface VariableInfo {
1417
block: Runtime.PropertyDescriptor[]
@@ -221,6 +224,7 @@ export default class LiveInstrumentRemote {
221224
}
222225

223226
private async setBreakpoint(scriptId: string, line: number): Promise<string> {
227+
debugLog(`Setting breakpoint at ${scriptId}:${line}`);
224228
if (this.pendingBreakpoints.has(scriptId + ':' + line)) {
225229
return this.pendingBreakpoints.get(scriptId + ':' + line);
226230
}
@@ -253,6 +257,7 @@ export default class LiveInstrumentRemote {
253257
}
254258

255259
async addInstrument(instrument: LiveInstrument): Promise<void> {
260+
debugLog(`Adding instrument: ${instrument.id}`);
256261
if (this.instruments.get(instrument.id) || this.instrumentCache.get(instrument.id)) {
257262
return; // Instrument already exists or is in the cache
258263
}
@@ -287,6 +292,7 @@ export default class LiveInstrumentRemote {
287292
}
288293

289294
removeInstrument(instrumentId: string) {
295+
debugLog("Removing instrument: " + instrumentId);
290296
let instrument = this.instruments.get(instrumentId);
291297

292298
if (!instrument) {
@@ -338,6 +344,7 @@ export default class LiveInstrumentRemote {
338344
}
339345

340346
handleConditionalFailed(instrument: LiveInstrument, error: string) {
347+
debugLog("Conditional failed for instrument: " + instrument.id + " - " + error);
341348
this.removeInstrument(instrument.id);
342349
this.eventBus.publish("spp.processor.status.live-instrument-removed", {
343350
occurredAt: Date.now(),
@@ -349,6 +356,7 @@ export default class LiveInstrumentRemote {
349356
// TODO: Call this regularly to clean up old instruments
350357
// TODO: Ensure the cache doesn't get too large
351358
private cleanCache() {
359+
debugLog("Cleaning cache");
352360
let now = Date.now();
353361
this.instrumentCache.forEach((value, key) => {
354362
if (now - value.timeCached > 1000 * 60 * 60) {

src/util/SourceMapper.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import path from "path";
33
import * as fs from "fs";
44
import LiveSourceLocation from "../model/LiveSourceLocation";
55
import * as vlq from 'vlq';
6+
import SourcePlusPlus from "../SourcePlusPlus";
7+
8+
const debugLog = (...args: any[]) => SourcePlusPlus.debugLog(args);
69

710
export default class SourceMapper {
811
scriptLoaded: (sourceLocation: string, scriptId: string) => void;
@@ -56,7 +59,11 @@ export default class SourceMapper {
5659
mapLocation(location: LiveSourceLocation): MappedLocation {
5760
let mappedFile: MappedFile = this.mapped.get(location.source);
5861

59-
if (!mappedFile) return undefined;
62+
if (!mappedFile) {
63+
debugLog("SourceMapper.mapLocation", "No mapped file found for", location.source);
64+
return undefined;
65+
}
66+
debugLog("SourceMapper.mapLocation", "Mapped file found for", location.source);
6067

6168
return {
6269
scriptId: mappedFile.scriptId,

test/TestUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TestUtils {
1717
static async setupProbe() {
1818
this.timeout(15000);
1919

20-
await SourcePlusPlus.start().then(function () {
20+
await SourcePlusPlus.start(null, true).then(function () {
2121
console.log("SourcePlusPlus started");
2222
}).catch(function (err) {
2323
assert.fail(err);

0 commit comments

Comments
 (0)