@runsidekick/sidekick-client
v0.0.8
Published
Sidekick Node.js Client
Downloads
9
Readme
About Sidekick
Sidekick is a production debugging and on-demand logging tool where you can debug your running applications while they keep on running. Sidekick provides the ability to add logs and put non-breaking breakpoints in your application code which captures the snapshot of the application state, the call stack, variables, etc.
Sidekick Actions:
- A tracepoint is basically a non-breaking remote breakpoint. In short, it takes a screenshot of the variables when the code hits that line.
- Logpoints open the way for dynamic logging to Sidekick users. Replacing traditional logging with dynamic logging has the potential to lower stage sizes, costs, and time for log searching while adding the ability to add new logpoints without editing the source code, redeploying or restarting the application
Client Features
- Sidekick Node Client opens up a new & headless way to use Sidekick. It allows you to both use custom ingest functions for the tracepoint/logpoint events and put/edit/delete your tracepoints/logpoints easily using code.
Built With
Prerequisites
Tested with node v16.14.2
- npm
npm install npm@latest -g
Getting Started
Installation
- Install sidekick-client
$ npm i @runsidekick/sidekick-client
Example usage
Put tracepoint on a line
Import
SidekickApi
const { SidekickApi} = require('@runsidekick/sidekick-client')
Create an instance from Sidekick Api
const apiClient = new SidekickApi({apiKey:<Your Api Key>, apiToken:<Your Account Token>});
Create a parameter that contains your file information to put tracepoint.
const params= { applicationFilters: [ { name: "Demo application", version: "v1.0", stage: "prod" } ], fileName: "gitlab.com/repos/...", lineNo: 23, expireSecs: -1, expireCount: -1, enableTracing: true, persist: true }
Call
putTracepoint
functionapiClient.putTracepoint(params);
Then your tracepoint will be added to line 23
in the given file. Also, you can use SidekickApi
for any other operations such as removing tracepoint or putting log point.
Use custom ingest function for the tracepoint/logpoint events
Create a
config.json
according to your needs"SIDEKICK_TRACEPOINT_INDEX": "sidekick_tracepoint", "SIDEKICK_LOGPOINT_INDEX": "sidekick_logpoint", "SIDEKICK_EMAIL": "<Email of your sidekick account>", "SIDEKICK_PASSWORD": "<Password of your sidekick account>",
Import
onTrigger
from@runsidekick/sidekick-client
const { onTrigger } = require('@runsidekick/sidekick-client')
Create an
ingest
function that will send collected data to desired target:function ingestFunc (index) { return async function (data) { console.log(JSON.stringify({index,data})); } }
Initialize Sidekick client info with proper parameters.
const clientInfo = { sidekickEmail : config['SIDEKICK_EMAIL'], sidekickPassword : config['SIDEKICK_PASSWORD'], tracepointFunction : ingestFunc(config['SIDEKICK_TRACEPOINT_INDEX']), logpointFunction : ingestFunc(config['SIDEKICK_LOGPOINT_INDEX']), errorSnapshotFunction : ingestFunc(config['SIDEKICK_ERRORSTACK_INDEX']) } onTrigger(clientInfo);
Then your tracepoint events will be logged. You can customize the ingest
function as you want.
If you have an on-premise setup add the fields below to client object (Optional):
"sidekickHost": "ws://127.0.0.1",
"sidekickPort": "7777"
If have your user token you can use it instead of email & password (Optional):
"sidekickToken": "<>"
Roadmap
- [x] Add websocket support
- [x] Custom ingest function
- [x] Add support for programattically putting logpoints & tracepoints using REST API
Contact
Barış Kaya - @boroskoyo
Sidekick: website
Special Thanks
Emin Bilgiç - linkedin