https://github.com/runsidekick/sidekick-client-node
Sidekick Node.js Client
https://github.com/runsidekick/sidekick-client-node
Last synced: about 1 month ago
JSON representation
Sidekick Node.js Client
- Host: GitHub
- URL: https://github.com/runsidekick/sidekick-client-node
- Owner: runsidekick
- License: mit
- Created: 2022-07-21T12:46:27.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-12-27T13:09:16.000Z (over 3 years ago)
- Last Synced: 2025-02-15T01:48:44.739Z (over 1 year ago)
- Language: JavaScript
- Size: 231 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Sidekick Node.js client
Node.js client for Sidekick. Send your Sidekick logs and traces to any target in seconds!
Explore the docs »
Sidekick Home
·
Report Bug & Request Feature
Table of Contents
## 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 snapshot 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
* [ws](https://github.com/websockets/ws)
* [axios](https://github.com/axios/axios)
### Prerequisites
Tested with node v16.14.2
* npm
```sh
npm install npm@latest -g
```
# Getting Started
## Installation
1. Install sidekick-client
```sh
$ npm i @runsidekick/sidekick-client
```
## Example usage
### Put tracepoint on a line
1. Import `SidekickApi`
```js
const { SidekickApi} = require('@runsidekick/sidekick-client')
```
2. Create an instance from Sidekick Api
```js
const apiClient = new SidekickApi({apiKey:, apiToken:});
```
3. Create a parameter that contains your file information to put tracepoint.
```js
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
}
```
4. Call `putTracepoint` function
```js
apiClient.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
1. Create a `config.json` according to your needs
```js
"SIDEKICK_TRACEPOINT_INDEX": "sidekick_tracepoint",
"SIDEKICK_LOGPOINT_INDEX": "sidekick_logpoint",
"SIDEKICK_EMAIL": "",
"SIDEKICK_PASSWORD": "",
```
2. Import `onTrigger` from `@runsidekick/sidekick-client`
```js
const { onTrigger } = require('@runsidekick/sidekick-client')
```
3. Create an `ingest` function that will send collected data to desired target:
```js
function ingestFunc (index) {
return async function (data) {
console.log(JSON.stringify({index,data}));
}
}
```
4. Initialize Sidekick client info with proper parameters.
```js
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):
```js
"sidekickHost": "ws://127.0.0.1",
"sidekickPort": "7777"
```
If have your user token you can use it instead of email & password (Optional):
```js
"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](https://twitter.com/boroskoyo)
Sidekick: [website](https://www.runsidekick.com)
## Special Thanks
Emin Bilgiç - [linkedin](https://www.linkedin.com/in/eminbilgic/)