New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@locker/instrumentation

Package Overview
Dependencies
Maintainers
7
Versions
214
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@locker/instrumentation

Locker Next Instrumentation Utilities

  • 0.14.2
  • npm
  • Socket score

Version published
Weekly downloads
305
decreased by-13.11%
Maintainers
7
Weekly downloads
 
Created
Source

Locker vNext instrumentation package

The instrumentation package provides utility functions, also known as beacons, to facilitate instrumenting Locker vNext code without having to bind the entire codebase to an external interface.

There are 3 beacons provided, 1 for instrumenting errors, 1 for generic logging and 1 for metrics (activity).

Usage

import { LockerInstrumentation } from '@locker/instrumentation';

const { activityBeacon, errorBeacon, logBeacon } = new LockerInstrumentation();

The beacons can now be used to instrument code in Locker.

Beacons interface

Due to possible restrictions on the instrumentation service, the high volume of method calls and privacy considerations in sandboxed code, Locker cannot instrument serialized method parameters or method return values. As a consequence, the beacons will invoke the instrumentation client using specific information.

activityBeacon
const { activityBeacon } = new LockerInstrumentation(myService);
// instrumented activity is started for current sandboxKey
const myActivity = activityBeacon(sandboxKey, 'fooActivity');
myActivity.start();
// or use chaining
// const myActivity = activityBeacon(sandboxKey, 'fooActivity').start();

foo();
// we stop the activity after last instrumeted call
myActivity.stop();
logBeacon
const { logBeacon } = new LockerInstrumentation(myService);
const foo: Array = bar();
logBeacon(sandboxKey, `bar method returned ${foo.length} results.`);
errorBeacon
const { errorBeacon } = new LockerInstrumentation(myService);

try {
    foo();
} catch (e) {
    errorBeacon(sandboxKey, e);
    throw e;
}

Plugging in an external instrumentation service

To plug in an external service in Locker vNext the following steps are required:

  1. Extend the class LockerInstrumentation.
class MyInstrumentation extends LockerInstrumentation {
    activityBeacon(sandboxKey, nameOrDescription) {
        return new Activity(sandboxKey, nameOrDescription, startCallback, stopCallback);
    }
    errorBeacon(sandboxKey, e) {
        errorCallback(sandboxKey, e.message, e.type, e.stack);
    }
    logBeacon(sandboxKey, message) {
        logCallback(sandboxKey, message);
    }
}
  1. Invoke evaluateInSandbox or evaluateInCoreSandbox and provide MyInstrumentation as an argument
const instrumentation = new MyInstrumentation();
evaluateInSandbox(key, code, null, null, instrumentation);

FAQs

Package last updated on 23 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc