![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@locker/instrumentation
Advanced tools
The instrumentation package provides interfaces to facilitate instrumenting Lightning Web Security code without having to bind the entire codebase to an external interface.
There are three instrumentation functions on the main interface, 1 for instrumenting errors, 1 for generic logging and 1 for metrics (activity).
Consumer of LWS needs to provide actual instrumentation service and the wrapper classes which implements the interfaces defined by this package. This package provides a mock implementation to be used when the consumer does not provide any instrumentation service.
// The `myInstrumentation` object is a wrapper for the actual instrumentation
// client which implements Locker instrumentation interface.
let { error, log, startActivity } = myInstrumentation;
let activity = startActivity('AwesomeActivity', data);
try {
foo();
error({ errorData });
log({ logData });
} catch (e) {
activity.error(e);
throw e;
} finally {
activity.stop();
}
import { LockerActivity, Instrumentation } from '@locker/instrumentation';
import { evaluateInSandbox } from '@locker/sandbox';
function makeLockerInstrumentation(myInstrumentationClient) {
const activityStartCallback = (activity, data) => {
// Call myInstrumentationService to start a performance activity metric.
};
const activityStopCallback = (activity, data) => {
// Call myInstrumentationService to stop a performance activity metric.
};
class MyInstrumentation extends Instrumentation {
startActivity(activityName, data) {
const activity = new LockerActivity(
activityName,
activityStartCallback,
activityStopCallback
);
activity.start(data);
return activity;
}
error(data) {
// Call myInstrumentationClient to log an error.
}
log(data) {
// Call myInstrumentationClient to make a regular log.
}
}
return new MyInstrumentation();
}
const myInstrumentation = makeLockerInstrumentation(myInstrumentationClient);
evaluateInSandbox(key, code, null, null, myInstrumentation);
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, LWS instrumentation interface will invoke the instrumentation client using specific information.
LWS instrumentation interface accepts telemetry data with simple JSON objects or native simple types (string, boolean, number). It is expected that the wrapper of the instrumentation client to dissect and re-format the data into the format that the instrumentation client accepts.
const { startActivity } = myInstrumentation;
// The instrumented activity is started for current `sandboxKey`.
const myActivity = startActivity(sandboxKey, 'fooActivity');
try {
foo();
} catch (e) {
// Stop the activity with error.
activity.error(e);
throw e;
} finally {
// Stop the activity after last instrumented call.
activity.stop();
}
const { log } = const { startActivity } = myInstrumentation;
const foo: Array = bar();
log(`bar method returned ${foo.length} results.`);
log({ sandboxKey, message: `bar method returned ${foo.length} results.` });
const { error } = new LockerInstrumentation(myService);
try {
foo();
} catch (e) {
error(`${e}`);
error({ sandboxKey, error: e });
throw e;
}
To plug in an external service in Lightning Web Security the following steps are required:
Instrumentation
from @locker/instrumentation
.import { DataType, DefaultInstrumentation, LockerActivity } from '@locker/instrumentation';
const activityStartCallback = (activity, data) => {
// Call external instrumentation service to start a performance activity metric.
};
const activityStopCallback = (activity, data) => {
// Call external instrumentation service to stop a performance activity metric.
};
class MyInstrumentation extends DefaultInstrumentation {
startActivity(activityName: string, data?: DataType) {
return new LockerActivity(activityName, startCallback, stopCallback);
}
error(data?: DataType) {
errorCallback(data);
}
log(data?: DataType) {
logCallback(data);
}
}
LockerActivity
will call startCallback
and stopCallback
respectively when
an activity is started or stopped.
evaluateInSandbox
or evaluateInCoreSandbox
and provide MyInstrumentation
as an argument.const instrumentation = new MyInstrumentation();
evaluateInSandbox(key, code, null, null, instrumentation);
FAQs
Lightning Web Security instrumentation utilities
The npm package @locker/instrumentation receives a total of 305 weekly downloads. As such, @locker/instrumentation popularity was classified as not popular.
We found that @locker/instrumentation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.