Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit ab7ce30

Browse files
author
ranrib
committed
feat(index.js): first release
0 parents  commit ab7ce30

22 files changed

+11645
-0
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/node_modules/**
2+
examples/**

.eslintrc

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"extends": "airbnb",
3+
"env": {
4+
"node": true,
5+
"browser": false
6+
},
7+
"plugins": [
8+
"json"
9+
],
10+
"rules": {
11+
"indent": ["error", 4],
12+
"function-paren-newline": ["error", "consistent"],
13+
"require-jsdoc": ["error", {
14+
"require": {
15+
"FunctionDeclaration": true,
16+
"MethodDefinition": true,
17+
"ClassDeclaration": true,
18+
"ArrowFunctionExpression": false,
19+
"FunctionExpression": true
20+
}
21+
}],
22+
"operator-linebreak": ["error", "after"],
23+
"valid-jsdoc": ["error", {
24+
"requireReturn": false
25+
}],
26+
"comma-dangle": ["error", {
27+
"arrays": "always-multiline",
28+
"objects": "always-multiline",
29+
"imports": "never",
30+
"exports": "never",
31+
"functions": "never"
32+
}]
33+
}
34+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
node_modules/
3+
dist/

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
.idea/

.travis.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
language: node_js
2+
3+
branches:
4+
only:
5+
- master
6+
7+
install:
8+
- npm install
9+
- npm install -g serverless
10+
11+
node_js:
12+
- "8.10"
13+
- "10.15"
14+
15+
script:
16+
- npm run lint
17+
18+
19+
jobs:
20+
include:
21+
- stage: build-and-deploy
22+
node_js: "8.10"
23+
script:
24+
- npm run build && npm run semantic-release
25+
26+
stages:
27+
- Test
28+
# - name: build-and-deploy
29+
# if: branch = master AND type = push

CODE_OF_CONDUCT.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Epsagon
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Epsagon Instrumentation for Node.js
2+
[![Build Status](https://travis-ci.com/epsagon/epsagon-node-frameworks.svg?token=wsveVqcNtBtmq6jpZfSf&branch=master)](https://travis-ci.com/epsagon/epsagon-node-frameworks)
3+
[![npm version](https://badge.fury.io/js/epsagon-frameworks.svg)](https://badge.fury.io/js/epsagon-frameworks)
4+
[![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)
5+
6+
This package provides an instrumentation to Node.js code running on functions for collection of distributed tracing and performance monitoring.
7+
8+
## Installation
9+
10+
From your project directory:
11+
12+
```sh
13+
npm install --save epsagon
14+
```
15+
16+
## Getting started
17+
18+
Simply use the wrapper to send traces from your code:
19+
20+
```node
21+
const epsagon = require('epsagon');
22+
epsagon.init({
23+
token: 'my-secret-token',
24+
appName: 'my-app-name',
25+
metadataOnly: false, // Optional, send more trace data
26+
});
27+
28+
function handler(event, context, callback) {
29+
callback(null, 'It worked!')
30+
}
31+
32+
handler = epsagon.lambdaWrapper(handler)
33+
```
34+
35+
## Custom labels
36+
37+
You can add custom labels to your traces. Filters can later be used for filtering
38+
traces that contains specific labels:
39+
```node
40+
function handler(event, context, callback) {
41+
epsagon.label('myCustomLabel', 'labelValue');
42+
callback(null, 'It worked!')
43+
}
44+
```
45+
46+
## Custom errors
47+
48+
You can set a trace as an error (although handled correctly) by catching an error:
49+
```node
50+
function handler(event, context, callback) {
51+
try {
52+
// something bad happens
53+
} catch (err) {
54+
epsagon.setError(err);
55+
}
56+
57+
callback(null, 'It worked!')
58+
}
59+
```
60+
61+
Or manually specify Error object:
62+
```node
63+
function handler(event, context, callback) {
64+
epsagon.setError(Error('My custom error'));
65+
callback(null, 'It worked!')
66+
}
67+
```
68+
69+
## Express application
70+
71+
If you're running express.js application on any non Lambda environment, you can still use Epsagon!
72+
Note: Only Express 4 and above is supported
73+
You can accomplish that with the following example:
74+
75+
```node
76+
const express = require('express');
77+
const epsagon = require('epsagon');
78+
79+
epsagon.init({
80+
token: 'my-secret-token',
81+
appName: 'my-app-name',
82+
metadataOnly: false,
83+
});
84+
85+
const app = express()
86+
87+
app.get('/', (req, res) => res.send('Hello World!'))
88+
89+
app.listen(3000)
90+
```
91+
92+
## Hapi application
93+
94+
If you're running Hapi.js application on any non Lambda environment, you can still use Epsagon!
95+
Note: Only Hapi 17 and above is supported
96+
You can accomplish that with the following example:
97+
98+
```node
99+
const Hapi = require('hapi');
100+
const epsagon = require('epsagon');
101+
102+
epsagon.init({
103+
token: 'my-secret-token',
104+
appName: 'my-app-name',
105+
metadataOnly: false,
106+
});
107+
108+
const init = async () => {
109+
110+
const server = Hapi.server({
111+
port: 3000,
112+
host: 'localhost'
113+
});
114+
115+
server.route({
116+
method: 'GET',
117+
path:'/',
118+
handler: (request, h) => {
119+
return 'Hello World!';
120+
}
121+
});
122+
123+
await server.start();
124+
console.log('Server running on %ss', server.info.uri);
125+
};
126+
127+
init();
128+
```
129+
130+
131+
## Copyright
132+
133+
Provided under the MIT license. See LICENSE for details.
134+
135+
Copyright 2019, Epsagon

commitlint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {extends: ['@commitlint/config-angular']}

examples/.eslintrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"import/no-unresolved": 0
4+
}
5+
}

examples/express_example.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const express = require('express');
2+
const epsagon = require('epsagon-frameworks');
3+
4+
epsagon.init({
5+
token: 'my-secret-token',
6+
appName: 'my-app-name',
7+
metadataOnly: false,
8+
});
9+
10+
const app = express()
11+
12+
app.get('/', (req, res) => res.send('Hello World!'))
13+
14+
app.get('/label_example', (req, res) => {
15+
// Example label usage
16+
req.epsagon.label('myFirstLabel', 'customValue1');
17+
res.send('Hello World!'))
18+
}
19+
20+
app.listen(3000)

examples/hapi_example.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const Hapi = require('hapi');
2+
const epsagon = require('epsagon-frameworks');
3+
4+
epsagon.init({
5+
token: 'my-secret-token',
6+
appName: 'my-app-name',
7+
metadataOnly: false,
8+
});
9+
10+
const init = async () => {
11+
12+
const server = Hapi.server({
13+
port: 3000,
14+
host: 'localhost'
15+
});
16+
17+
server.route({
18+
method: 'GET',
19+
path:'/',
20+
handler: (request, h) => {
21+
return 'Hello World!';
22+
}
23+
});
24+
25+
server.route({
26+
method: 'GET',
27+
path:'/label_example',
28+
handler: (request, h) => {
29+
request.epsagon.label('myFirstLabel', 'customValue1');
30+
return 'Hello World!';
31+
}
32+
});
33+
34+
await server.start();
35+
console.log('Server running on %ss', server.info.uri);
36+
};
37+
38+
init();

0 commit comments

Comments
 (0)