diff --git a/src/SourcePlusPlus.ts b/src/SourcePlusPlus.ts index baefe38..876d532 100644 --- a/src/SourcePlusPlus.ts +++ b/src/SourcePlusPlus.ts @@ -158,10 +158,12 @@ namespace SourcePlusPlus { function registerRemotes(eventBus: EventBus) { eventBus.registerHandler("spp.probe.command.live-instrument-remote", {}, (err, message) => { + debugLog("Received probe-wide instrument command: " + JSON.stringify(message.body)); liveInstrumentRemote.handleInstrumentCommand( LiveInstrumentCommand.fromJson(message.body)); }); eventBus.registerHandler(`spp.probe.command.live-instrument-remote:${probeConfig.spp.probe_id}`, {}, (err, message) => { + debugLog("Received probe-specific instrument command: " + JSON.stringify(message.body)); liveInstrumentRemote.handleInstrumentCommand( LiveInstrumentCommand.fromJson(message.body)); }); diff --git a/src/control/ContextReceiver.ts b/src/control/ContextReceiver.ts index f365826..c27a417 100644 --- a/src/control/ContextReceiver.ts +++ b/src/control/ContextReceiver.ts @@ -1,4 +1,3 @@ -// import LiveInstrumentRemote from "./LiveInstrumentRemote"; import {LogData, LogDataBody, LogTags, TextLog, TraceContext} from "skywalking-backend-js/lib/proto/logging/Logging_pb"; import {KeyStringValuePair} from "skywalking-backend-js/lib/proto/common/Common_pb"; import {ContextManager} from "skywalking-backend-js"; @@ -8,6 +7,9 @@ import {LogReportServiceClient} from "skywalking-backend-js/lib/proto/logging/Lo import {Debugger} from "inspector"; import VariableUtil from "../util/VariableUtil"; import ProbeMemory from "../ProbeMemory"; +import SourcePlusPlus from "../SourcePlusPlus"; + +const debugLog = (...args: any[]) => SourcePlusPlus.debugLog(args); namespace ContextReceiver { let logReport; @@ -50,6 +52,7 @@ namespace ContextReceiver { export function applyBreakpoint(breakpointId: string, source: string | undefined, line: number, frames: Debugger.CallFrame[], variables) { + debugLog(`applyBreakpoint: ${breakpointId} ${source} ${line}`); let activeSpan = ContextManager.current.newLocalSpan(callFrameToString(frames[0])); activeSpan.start(); @@ -94,6 +97,7 @@ namespace ContextReceiver { } export function applyLog(liveLogId: string, logFormat: string, logArguments: any) { + debugLog(`applyLog: ${liveLogId} ${logFormat} ${logArguments}`); let logTags = new LogTags(); logTags.addData(new KeyStringValuePair().setKey('log_id').setValue(liveLogId)); logTags.addData(new KeyStringValuePair().setKey('level').setValue('Live')); diff --git a/src/control/LiveInstrumentRemote.ts b/src/control/LiveInstrumentRemote.ts index d73577f..777f1cd 100644 --- a/src/control/LiveInstrumentRemote.ts +++ b/src/control/LiveInstrumentRemote.ts @@ -9,6 +9,9 @@ import EventBus from "@vertx/eventbus-bridge-client.js"; import LiveInstrumentCommand from "../model/command/LiveInstrumentCommand"; import CommandType from "../model/command/CommandType"; import VariableUtil from "../util/VariableUtil"; +import SourcePlusPlus from "../SourcePlusPlus"; + +const debugLog = (...args: any[]) => SourcePlusPlus.debugLog(args); export interface VariableInfo { block: Runtime.PropertyDescriptor[] @@ -221,6 +224,7 @@ export default class LiveInstrumentRemote { } private async setBreakpoint(scriptId: string, line: number): Promise { + debugLog(`Setting breakpoint at ${scriptId}:${line}`); if (this.pendingBreakpoints.has(scriptId + ':' + line)) { return this.pendingBreakpoints.get(scriptId + ':' + line); } @@ -253,6 +257,7 @@ export default class LiveInstrumentRemote { } async addInstrument(instrument: LiveInstrument): Promise { + debugLog(`Adding instrument: ${instrument.id}`); if (this.instruments.get(instrument.id) || this.instrumentCache.get(instrument.id)) { return; // Instrument already exists or is in the cache } @@ -287,6 +292,7 @@ export default class LiveInstrumentRemote { } removeInstrument(instrumentId: string) { + debugLog("Removing instrument: " + instrumentId); let instrument = this.instruments.get(instrumentId); if (!instrument) { @@ -338,6 +344,7 @@ export default class LiveInstrumentRemote { } handleConditionalFailed(instrument: LiveInstrument, error: string) { + debugLog("Conditional failed for instrument: " + instrument.id + " - " + error); this.removeInstrument(instrument.id); this.eventBus.publish("spp.processor.status.live-instrument-removed", { occurredAt: Date.now(), @@ -349,6 +356,7 @@ export default class LiveInstrumentRemote { // TODO: Call this regularly to clean up old instruments // TODO: Ensure the cache doesn't get too large private cleanCache() { + debugLog("Cleaning cache"); let now = Date.now(); this.instrumentCache.forEach((value, key) => { if (now - value.timeCached > 1000 * 60 * 60) { diff --git a/src/util/SourceMapper.ts b/src/util/SourceMapper.ts index c9c508f..e1b00bc 100644 --- a/src/util/SourceMapper.ts +++ b/src/util/SourceMapper.ts @@ -3,6 +3,9 @@ import path from "path"; import * as fs from "fs"; import LiveSourceLocation from "../model/LiveSourceLocation"; import * as vlq from 'vlq'; +import SourcePlusPlus from "../SourcePlusPlus"; + +const debugLog = (...args: any[]) => SourcePlusPlus.debugLog(args); export default class SourceMapper { scriptLoaded: (sourceLocation: string, scriptId: string) => void; @@ -56,7 +59,11 @@ export default class SourceMapper { mapLocation(location: LiveSourceLocation): MappedLocation { let mappedFile: MappedFile = this.mapped.get(location.source); - if (!mappedFile) return undefined; + if (!mappedFile) { + debugLog("SourceMapper.mapLocation", "No mapped file found for", location.source); + return undefined; + } + debugLog("SourceMapper.mapLocation", "Mapped file found for", location.source); return { scriptId: mappedFile.scriptId, diff --git a/test/TestUtils.js b/test/TestUtils.js index a91c526..54631ea 100644 --- a/test/TestUtils.js +++ b/test/TestUtils.js @@ -17,7 +17,7 @@ class TestUtils { static async setupProbe() { this.timeout(15000); - await SourcePlusPlus.start().then(function () { + await SourcePlusPlus.start(null, true).then(function () { console.log("SourcePlusPlus started"); }).catch(function (err) { assert.fail(err);