Preconfigured Contrast agent core services and models
npm install @contrast/core@contrast/coreDiscovers Contrast configuration data (yaml, env vars, etc) and preconfigures a common set of APIs to be used for agent and tooling development.
The module exports a factory function.
``typescript
const core = require('@contrast/core')();
`$3
- Logging
`typescript`
core.logger.info('...');
See more about the @contrast/logger service here.
- Monkey-patching
`typescript`
core.patcher.patch(res, 'end', {
name: 'http.ServerResponse.end',
patchType: 'http-things',
pre(data) {
// ...
}
});
See more about the @contrast/patcher service here.
- Code rewriting
`typescript`
core.rewriter.addTransforms({
CallExpression(path, state) {
// ...
};
});
core.rewriter.rewrite('function() { ...');
See more about the @contrast/rewriter service here.
- Dependency hooks
`typescript`
core.depHooks.resolve({ name: 'http' }, http => {
// implemention details
});
See more about the @contrast/dep-hooks service here.
- Models and factories
The construction of model data _can_ rely on configuration and therefore can be stateful. So, we provide the models and their factories as services that can be used by consumers as if static.
`typescript`
// stackframe filtration is configurable, thus stateful
const snap = core.models.StacktraceFactory.createSnapshot();
const frames = snap();
See more about the @contrast/models service here.
- Report messages
`typescript`
// configuration will tell which reporters become active
core.reporters.install();
core.messages.emit('ProtectInputTracingEvent', { ... });
See more about the @contrast/reporter service here.
- Other stuff
There are some utility-type functions that rely on configuration state.
`typescript`
// This uses core.config.stack_trace_filters (new to v5)
core.isAgentPath('/foo');
- @contrast/agentify`: Integrate core services and instrumentation into an application. See more here.