@dash0/sdk-web
Version:
Dash0's Web SDK to collect telemetry from end-users' web browsers
23 lines (22 loc) • 953 B
JavaScript
import { debug } from "./debug";
const INSTRUMENTED_BY_DASH0_SYMBOL = Symbol.for("INSTRUMENTED_BY_DASH0");
function isAlreadyInstrumented(objOrFunction) {
// @ts-expect-error -- typescript does not know about this hidden marker and we're not going to tell it 🤫
return objOrFunction[INSTRUMENTED_BY_DASH0_SYMBOL] === true;
}
function markAsInstrumented(objOrFunction) {
// @ts-expect-error -- typescript does not know about this hidden marker and we're not going to tell it 🤫
objOrFunction[INSTRUMENTED_BY_DASH0_SYMBOL] = true;
}
export function wrap(module, target, wrapper) {
const original = module[target];
if (!original) {
debug(`${String(target)} is not defined, unable to instrument`);
return;
}
if (isAlreadyInstrumented(original)) {
debug(`${String(target)} has already been instrumented, skipping`);
}
markAsInstrumented(original);
module[target] = wrapper(original);
}