Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Add support for log plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
morellic committed Apr 3, 2018
1 parent 2bfcb76 commit 7f19c5f
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 635 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -63,6 +63,7 @@ Check out the [configuration part](https://thundra.readme.io/docs/configuration-
| disableThundra | bool | false |
| disableTrace | bool | false |
| disableMetric | bool | false |
| plugins | array | [ ] |


## Async Monitoring with Zero Overhead
Expand All @@ -72,6 +73,13 @@ Instead, you can [setup async monitoring](https://docs.thundra.io/docs/how-to-se

Check out our async monitoring example at our [example projects](https://github.com/thundra-io/thundra-examples-lambda-nodejs) for a quick start.


## Log support
You can monitor your logs using Thundra and enjoy the three pillars of observability in one place!

Check out our [log module](https://github.com/thundra-io/thundra-lambda-agent-nodejs-log/tree/initial-log-module).


## How to build
[Webpack](https://webpack.js.org/) is used as a module bundler.

Expand Down
2 changes: 1 addition & 1 deletion config.json
Expand Up @@ -2,5 +2,5 @@
"testMatch": ["<rootDir>/test/*.js", "<rootDir>/test/plugins/*.js"],
"transform": {".*": "<rootDir>/node_modules/babel-jest"},
"moduleFileExtensions": ["js"],
"collectCoverageFrom": ["src/*.js"]
"collectCoverageFrom": ["src/*.js", "src/plugins/*.js", "index.js"]
}
32 changes: 23 additions & 9 deletions index.js
Expand Up @@ -2,32 +2,45 @@ import ThundraWrapper from "./src/thundra-wrapper";
import Trace from "./src/plugins/trace";
import Metric from "./src/plugins/metric";

const shouldEnablePlugin = (disableByEnv, disableByParameter) => {
const shouldDisable = (disableByEnv, disableByParameter) => {
if (disableByEnv === "true")
return false;
else if (disableByEnv === "false")
return true;
else if (disableByEnv === "false")
return false;
else
return !disableByParameter;
return disableByParameter;
};

module.exports = (config) => {
let apiKey, disableTrace, disableMetric, disableThundra;
let apiKey, disableTrace, disableMetric, disableThundra, plugins = [];
if (config) {
apiKey = config.apiKey;
disableTrace = config.disableTrace ? config.disableTrace : false;
disableMetric = config.disableMetric ? config.disableMetric : false;
disableThundra = config.disableThundra ? config.disableThundra : false;
plugins = config.plugins && Array.isArray(config.plugins) ? config.plugins : plugins;
}

apiKey = process.env.thundra_apiKey ? process.env.thundra_apiKey : apiKey;

if (process.env.thundra_disable === "true" || disableThundra || !apiKey)
if (!apiKey || shouldDisable(process.env.thundra_disable, disableThundra))
return originalFunc => originalFunc;

let plugins = [];
plugins = shouldEnablePlugin(process.env.thundra_trace_disable, disableTrace) ? [...plugins, Trace()] : plugins;
plugins = shouldEnablePlugin(process.env.thundra_metric_disable, disableMetric) ? [...plugins, Metric()] : plugins;
plugins = shouldDisable(process.env.thundra_trace_disable, disableTrace) ? plugins : [...plugins, Trace()];
plugins = shouldDisable(process.env.thundra_metric_disable, disableMetric) ? plugins : [...plugins, Metric()];

const pluginContext = {
applicationId: process.env.AWS_LAMBDA_LOG_STREAM_NAME.split("]").pop(),
applicationProfile: process.env.thundra_applicationProfile ? process.env.thundra_applicationProfile : "default",
applicationRegion: process.env.AWS_REGION,
applicationVersion: process.env.AWS_LAMBDA_FUNCTION_VERSION,
requestCount: 0,
apiKey: apiKey
};

plugins.forEach(plugin => {
plugin.setPluginContext(pluginContext);
});

return originalFunc => {
return (originalEvent, originalContext, originalCallback) => {
Expand All @@ -39,6 +52,7 @@ module.exports = (config) => {
originalCallback,
originalFunc,
plugins,
pluginContext,
apiKey
);
return thundraWrapper.invoke();
Expand Down

0 comments on commit 7f19c5f

Please sign in to comment.