Skip to content

Commit

Permalink
mitigate potential hook race condition and close open handles (#396)
Browse files Browse the repository at this point in the history
* chore: sync prettier config parser with npm script

* chore: redo package-lock.json

* chore: change codeowners to angels

* fix: mitigate potential race condition in unhandledrejection hook,

close open test connections,
test utils cleanup (typos and formatting)
  • Loading branch information
therightstuff authored Oct 2, 2022
1 parent 1f86185 commit 2703251
Show file tree
Hide file tree
Showing 33 changed files with 4,516 additions and 32,375 deletions.
11 changes: 7 additions & 4 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const targets = { node: 'current' };
const presets = ["@babel/preset-typescript", ['@babel/preset-env', { targets }]];
const presets = [
"@babel/preset-typescript",
[ "@babel/preset-env", { targets } ]
];

const plugins = [
["@babel/plugin-proposal-decorators", { "legacy": true }],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining',
[ "@babel/plugin-proposal-decorators", { "legacy": true } ],
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-optional-chaining",
];

module.exports = { presets, plugins };
11 changes: 6 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
username: lumigo
password: $DOCKERHUB_PASSWORD
environment:
- TZ: Asia/Jerusalem
- NODE_OPTIONS: --max_old_space_size=1500
- TZ: Asia/Jerusalem
- NODE_OPTIONS: --max_old_space_size=1500
resource_class: medium+
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: install-npm-wee
name: install npm dependencies
command: npm install
- run:
name: install-npm-inner
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
password: $DOCKERHUB_PASSWORD
resource_class: medium+
environment:
- TZ: Asia/Jerusalem
- TZ: Asia/Jerusalem
steps:
- run:
command: |
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
username: lumigo
password: $DOCKERHUB_PASSWORD
environment:
- TZ: Asia/Jerusalem
- TZ: Asia/Jerusalem
resource_class: medium+
steps:
- run:
Expand Down Expand Up @@ -197,6 +197,7 @@ jobs:
- run:
name: deploy to npm + lambda layer
command: ./scripts/bd_to_prod.sh

workflows:
test-deploy:
jobs:
Expand Down
16 changes: 11 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
module.exports = {
parser: 'babel-eslint',
extends: ['eslint:recommended', 'prettier'],
plugins: ['jest'],
parser: "@typescript-eslint/parser",
plugins: [
"@typescript-eslint",
"jest"
],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"prettier"
],
rules: {
camelcase: 'error',
camelcase: "error",
},
globals: {
process: true,
Expand All @@ -15,7 +21,7 @@ module.exports = {
Set: true,
},
env: {
'jest/globals': true,
"jest/globals": true,
node: true,
},
};
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @lumigo-io/wall-e
* @lumigo-io/angels
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"singleQuote": true,
"trailingComma": "es5",
"useTabs": false,
"parser": "babel",
"parser": "typescript",
"overrides": [
{
"files": "*.json",
"options": { "parser": "json", "printWidth": 200 }
"options": { "parser": "json" }
}
]
}
101 changes: 70 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
# lumigo-node :stars:

[![CircleCI](https://circleci.com/gh/lumigo-io/lumigo-node.svg?style=svg&circle-token=47f40cb5e95e8532e73f69754fac65830b5e86a1)](https://circleci.com/gh/lumigo-io/lumigo-node)
[![codecov](https://codecov.io/gh/lumigo-io/lumigo-node/branch/master/graph/badge.svg?token=mUkKlI8ifC)](https://codecov.io/gh/lumigo-io/lumigo-node)
[![npm version](https://badge.fury.io/js/%40lumigo%2Ftracer.svg)](https://badge.fury.io/js/%40lumigo%2Ftracer)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)


This is [`@lumigo/tracer`](https://), Lumigo's Node.js agent for distributed tracing and performance monitoring.

Supported NodeJS runtimes: 8.10, 10.x, 12.x, 14.x, 16.x


## Usage
## Usage

The `@lumigo/tracer` package allows you to pursue automated metric gathering through Lambda Layers, automated metric gathering and instrumentation through the Serverless framework, or manual metric creation and implementation.

### With Lambda Layers:
### With Lambda Layers

* When configuring your Lambda functions, include the appropriate Lambda Layer ARN [from these tables](https://github.com/lumigo-io/lumigo-node/blob/master/layers)

*Note* - Lambda Layers are an optional feature. If you decide to use this capability, the list of Lambda layers available is available [here.](https://github.com/lumigo-io/lumigo-node/blob/master/layers)

### With Serverless framework:
### With Serverless framework

* To configure the Serverless Framework to work with Lumigo, simply install our plugin: [**serverless-lumigo-plugin**](https://github.com/lumigo-io/serverless-lumigo-plugin/blob/master/README.md)

### Manually:
### Manually

To manually configure Lumigo in your Lambda functions:

* First, install the `@lumigo/tracer` package using your preferred package manager:

~~~bash
```bash
$ npm i @lumigo/tracer
# or
$ yarn add @lumigo/tracer
~~~
```

* Next, wrap your `handler` in Lumigo's `trace` function (note: replace `YOUR-TOKEN-HERE` with your Lumigo API token):

~~~js
```javascript
// javascript
const lumigo = require('@lumigo/tracer')({ token: 'YOUR-TOKEN-HERE' })

const myHandler = async (event, context, callback) => { ... }

exports.handler = lumigo.trace(myHandler)
~~~
```

~~~typescript
```typescript
// typescript
import lumigo from '@lumigo/tracer';

Expand All @@ -56,40 +56,47 @@ const tracer = lumigo({ token: 'YOUR-TOKEN-HERE' });
export const handler = tracer.trace(async (event, context) => {
...
});
~~~
```

#### Note

##### Note:
For Typescript users, you must add the following to your `tsconfig.json` file:
~~~json

```json
{
...,
"esModuleInterop": true,
"esModuleInterop": true,
}
~~~
[read more about it here](https://www.typescriptlang.org/tsconfig#esModuleInterop)
```

You can read more about it [here](https://www.typescriptlang.org/tsconfig#esModuleInterop)

* Your function is now fully instrumented

## Configuration

`@lumigo/tracer` offers several different configuration options. Pass these to the Lambda function as environment variables:

* `LUMIGO_DEBUG=TRUE` - Enables debug logging
* `LUMIGO_SECRET_MASKING_REGEX='["regex1", "regex2"]'` - Prevents Lumigo from sending keys that match the supplied regular expressions. All regular expressions are case-insensitive. By default, Lumigo applies the following regular expressions: `[".*pass.*", ".*key.*", ".*secret.*", ".*credential.*", ".*passphrase.*"]`.
* `LUMIGO_SECRET_MASKING_REGEX='["regex1", "regex2"]'` - Prevents Lumigo from sending keys that match the supplied regular expressions. All regular expressions are case-insensitive. By default, Lumigo applies the following regular expressions: `[".*pass.*", ".*key.*", ".*secret.*", ".*credential.*", ".*passphrase.*"]`.
* `LUMIGO_DOMAINS_SCRUBBER='[".*secret.*"]'` - Prevents Lumigo from collecting both request and response details from a list of domains. This accepts a comma-separated list of regular expressions that is JSON-formatted. By default, the tracer uses `["secretsmanager\..*\.amazonaws\.com", "ssm\..*\.amazonaws\.com", "kms\..*\.amazonaws\.com"]`. **Note** - These defaults are overridden when you define a different list of regular expressions.
* `LUMIGO_SWITCH_OFF=TRUE` - In the event a critical issue arises, this turns off all actions that Lumigo takes in response to your code. This happens without a deployment, and is picked up on the next function run once the environment variable is present.

### Step Functions

If your function is part of a set of step functions, you can add the flag `step_function: true` to the Lumigo tracer import. Alternatively, you can configure the step function using an environment variable `LUMIGO_STEP_FUNCTION=True`. When this is active, Lumigo tracks all states in the step function in a single transaction, easing debugging and observability.
```

```javascript
const lumigo = require('@lumigo/tracer')({ token: 'DEADBEEF', step_function: true })
```
Note: the tracer adds the key `"_lumigo"` to the return value of the function.

Note: the tracer adds the key `"_lumigo"` to the return value of the function.

If you override the `"Parameters"` configuration, add `"_lumigo.$": "$._lumigo"` to ensure this value is still present.

Below is an example configuration for a Lambda function that is part of a step function that has overridden its parameters:
```

```json
"States": {
"state1": {
"Type": "Task",
Expand All @@ -108,33 +115,65 @@ Below is an example configuration for a Lambda function that is part of a step f
```

## Logging Programmatic Errors
With the tracer configured, simply call `console.log("[LUMIGO_LOG] <YOUR_MESSAGE>");` to cerate custom errors that are visible throughout the platform. This can be used anywhere in your Lambda code, and is included with the `@lumigo/tracer` package.

With the tracer configured, simply call

```javascript
console.log("[LUMIGO_LOG] <YOUR_MESSAGE>");
```

to create custom errors that are visible throughout the platform. This can be used anywhere in your Lambda code, and is included with the `@lumigo/tracer` package.

## Adding Execution Tags

You can add execution tags to a function with dynamic values using the parameter `addExecutionTag`.

These tags will be searchable from within the Lumigo platform.

### Adding tags for Manual tracing

To add a tag to a manual trace statement:

* Add `const lumigo = require('@lumigo/tracer')({ token: 'YOUR-TOKEN-HERE' })` to your code.
* Add execution tags by using `lumigo.addExecutionTag('<key>', '<value>');`
* Add the following to your code:

```javascript
const lumigo = require('@lumigo/tracer')({ token: 'YOUR-TOKEN-HERE' })
```

* Add execution tags by using

```javascript
lumigo.addExecutionTag('<key>', '<value>');
```

### Adding tags for Auto tracing

To add a tag to an automatically-traced function:

* Add `const lumigo = require('@lumigo/tracer')` to the top of your handler's .js file
* Use `lumigo.addExecutionTag('<key>', '<value>');` anywhere in your lambda code.
* Add the following to the top of your handler's .js file:

```javascript
const lumigo = require('@lumigo/tracer')
```

* Use

```javascript
lumigo.addExecutionTag('<key>', '<value>');
```

anywhere in your lambda code.

### Execution Tag Limitations

### Execution Tag Limitations:
Execution tags are subject to the following limitations:

* The maximum number of tags is 50.
* The maximum number of tags is 50.
* Key length must be between 1 and 50.
* Value length must be between 1 and 70.

### Scrubbing Limitations:
### Scrubbing Limitations

Secrets scrubbing are subject to the following limitations:

* support only json data secrets scrubbing
* Only JSON data secrets scrubbing is supported
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"dependencies": {
"aws-sdk": "^2.501.0",
"axios": "^0.19.0",
"@lumigo/tracer": "file:../lumigo-node-d_exmaple.tgz"
"@lumigo/tracer": "file:../lumigo-node-d_example.tgz"
}
}
2 changes: 1 addition & 1 deletion example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ service: aws-nodejs # NOTE: update this with your service name

provider:
name: aws
runtime: nodejs10.x
runtime: nodejs16.x
env:
LUMIGO_DEBUG: TRUE

Expand Down
20 changes: 10 additions & 10 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module.exports = {
silent: true,
testEnvironment: 'node',
coverageDirectory: './coverage/',
testEnvironment: "node",
coverageDirectory: "./coverage/",
collectCoverage: true,
collectCoverageFrom: [
'**/src/**/**/**/**.js',
'**/src/**/**/**/**.ts',
'!./src/tools/xmlToJson.js',
'!./src/testdata/functions/**/**.js',
'!./d_example/**/**',
"**/src/**/**/**/**.js",
"**/src/**/**/**/**.ts",
"!./src/tools/xmlToJson.js",
"!./src/testdata/functions/**/**.js",
"!./d_example/**/**",
],
coverageThreshold: {
global: {
lines: 100,
},
},
setupFilesAfterEnv: ['./testUtils/jest.setup.js'],
roots: ['<rootDir>/src'],
modulePaths: ['<rootDir>/dist'],
setupFilesAfterEnv: [ "./testUtils/jest.setup.js" ],
roots: [ "<rootDir>/src" ],
modulePaths: [ "<rootDir>/dist" ],
};
Loading

0 comments on commit 2703251

Please sign in to comment.