Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/SourcePlusPlus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down
6 changes: 5 additions & 1 deletion src/control/ContextReceiver.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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'));
Expand Down
8 changes: 8 additions & 0 deletions src/control/LiveInstrumentRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -221,6 +224,7 @@ export default class LiveInstrumentRemote {
}

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

async addInstrument(instrument: LiveInstrument): Promise<void> {
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
}
Expand Down Expand Up @@ -287,6 +292,7 @@ export default class LiveInstrumentRemote {
}

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

if (!instrument) {
Expand Down Expand Up @@ -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(),
Expand All @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion src/util/SourceMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/TestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down