Skip to content

Commit

Permalink
feat: initial commit for goodmetrics nodejs client
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce committed Sep 14, 2023
1 parent 28acd5f commit 92ac57d
Show file tree
Hide file tree
Showing 28 changed files with 9,226 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
generated
**/*.d.ts
60 changes: 60 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"root": true,
"env": {
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/recommended",
"plugin:prettier/recommended",
"plugin:node/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"rules": {
"semi": ["error", "always"],
"import/no-extraneous-dependencies": ["error", {}],
"node/no-unsupported-features/es-syntax": "off",
"node/no-missing-import": ["error", {
"tryExtensions": [".js", ".ts", ".json", ".node"]
}],
"prettier/prettier": "error",
"block-scoped-var": "error",
"eqeqeq": "error",
"no-var": "error",
"prefer-const": "error",
"eol-last": "error",
"prefer-arrow-callback": "error",
"no-trailing-spaces": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
"quotes": ["warn", "single", { "avoidEscape": true }],
"no-restricted-properties": [
"error",
{
"object": "describe",
"property": "only"
},
{
"object": "it",
"property": "only"
}
],
// async without await is often an error and in other uses it obfuscates
// the intent of the developer. Functions are async when they want to await.
"require-await": "error",
"import/no-duplicates": "error"
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
}
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Build Node.js Package

on:
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install and Build
if: ${{ steps.release.outputs.release_created }}
run: |
npm ci
npm run build
41 changes: 41 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: goodmetrics-nodejs
bump-minor-pre-major: true
prerelease: true
# The logic below handles the npm publication:
- uses: actions/checkout@v2
# these if statements ensure that a publication only occurs when
# a new release is created:
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v1
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}
- name: Install and Build
if: ${{ steps.release.outputs.release_created }}
run: |
npm ci
npm run build
- run: npm publish
name: Publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.js
!jest.config.js
*.d.ts
**/node_modules/**/*
.idea
dist/
.vscode/
.DS_Store
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"bracketSpacing": false,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "avoid"
}
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Goodmetrics Nodejs

example usage
```javascript
import {MetricsSetups} from './goodmetrics/metricsSetups';
import {Dimension} from './goodmetrics/_Metrics';
import {TimestampAt} from './goodmetrics/metricsFactory';

const delay = async (ms: number): Promise<void> => {
return await new Promise(resolve => {
setTimeout(() => {
resolve();
}, ms);
});
};

const main = async () => {
const metrics =
MetricsSetups.lightstepNativeOtlpButItSendsMetricsUponRecordingForLambda({
aggregationWidthMillis: 10 * 1000 * 1000,
lightstepAccessToken: '<your lightstep api key>',
prescientDimensions: new Map<string, Dimension>(),
});

await metrics.record('my_metric', TimestampAt.Start, async metrics => {
console.info('inside metrics block');
metrics.measure('runs', 1);
await delay(100);
metrics.dimension('result', 'success');
});
};

main().finally();
```
Loading

0 comments on commit 92ac57d

Please sign in to comment.