Skip to content

Commit e85be49

Browse files
committed
feat: parse log severity number/array of object attributes + setup linting
1 parent 6472326 commit e85be49

26 files changed

+327
-107
lines changed

.changeset/mighty-humans-sparkle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hyperdx/node-opentelemetry': minor
3+
---
4+
5+
feat: use getSeverityNumber and parseLogAttributes for logger

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
"prepare": "husky install"
1919
},
2020
"lint-staged": {
21-
"**/*": "prettier --write --ignore-unknown"
21+
"**/*.{ts,tsx}": [
22+
"prettier --write --ignore-unknown",
23+
"eslint --fix"
24+
],
25+
"**/*.{json,yml}": [
26+
"prettier --write --ignore-unknown"
27+
]
2228
},
2329
"devDependencies": {
2430
"@changesets/cli": "^2.26.1",
@@ -29,13 +35,15 @@
2935
"@typescript-eslint/eslint-plugin": "^5.59.9",
3036
"@typescript-eslint/parser": "^5.59.9",
3137
"eslint": "^8.42.0",
32-
"eslint-config-prettier": "^8.8.0",
38+
"eslint-config-prettier": "^9.1.0",
3339
"eslint-plugin-jest": "^27.2.1",
40+
"eslint-plugin-prettier": "^5.2.1",
41+
"eslint-plugin-simple-import-sort": "^12.1.1",
3442
"husky": "^8.0.3",
3543
"jest": "^29.5.0",
3644
"lint-staged": "^13.2.2",
3745
"nx": "^15.9.2",
38-
"prettier": "^2.8.7",
46+
"prettier": "^3.3.3",
3947
"rimraf": "^5.0.1",
4048
"ts-jest": "^29.1.0",
4149
"ts-node": "^10.9.1",

packages/node-opentelemetry/.eslintrc.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
"sourceType": "module",
1111
"ecmaVersion": 2020
1212
},
13-
"plugins": ["@typescript-eslint", "jest"],
13+
"plugins": ["@typescript-eslint", "jest", "prettier", "simple-import-sort"],
1414
"extends": [
1515
"eslint:recommended",
1616
"plugin:@typescript-eslint/recommended",
1717
"plugin:jest/recommended",
18-
"prettier"
18+
"plugin:prettier/recommended"
1919
],
2020
"rules": {
21-
// The following rule is enabled only to supplement the inline suppression
22-
// examples, and because it is not a recommended rule, you should either
23-
// disable it, or understand what it enforces.
24-
// https://typescript-eslint.io/rules/explicit-function-return-type/
25-
"@typescript-eslint/explicit-function-return-type": "warn",
2621
"@typescript-eslint/ban-ts-comment": "warn",
27-
"@typescript-eslint/no-this-alias": "warn"
22+
"@typescript-eslint/explicit-function-return-type": "warn",
23+
"@typescript-eslint/no-this-alias": "warn",
24+
"prettier/prettier": "error",
25+
"simple-import-sort/exports": "error",
26+
"simple-import-sort/imports": "error"
2827
}
2928
}

packages/node-opentelemetry/__tests__/otel.test.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/node-opentelemetry/bin/opentelemetry-instrument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
import process from 'process';
43
import fs from 'fs';
4+
import process from 'process';
55
import { promisify } from 'util';
66

77
const realpath = promisify(fs.realpath);

packages/node-opentelemetry/examples/dummy.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,30 @@ app.get('/instruments', async (req, res) => {
292292
});
293293

294294
app.get('/logs', async (req, res) => {
295-
console.debug({
295+
const nestedObj = {
296296
headers: req.headers,
297297
method: req.method,
298298
url: req.url,
299-
query: req.query,
299+
nested: [
300+
{
301+
foo: 'bar',
302+
},
303+
],
304+
nested2: {
305+
nested3: {
306+
foo: 'bar',
307+
},
308+
},
309+
};
310+
console.error({
311+
message: 'Console 🍕',
312+
...nestedObj,
300313
});
301-
console.error('BANG !!!');
302-
console.log('Console 🍕');
303-
logger.info({
304-
message: 'Winston 🍕',
305-
headers: req.headers,
306-
method: req.method,
307-
url: req.url,
314+
logger.info('Winston 🍕', nestedObj);
315+
pinoLogger.info({
316+
message: 'Pino 🍕',
317+
...nestedObj,
308318
});
309-
pinoLogger.info('Pino 🍕');
310-
311319
bunyanLogger.info('Bunyan 🍕');
312320

313321
console.log(await sendGetRequest());

packages/node-opentelemetry/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const config: Config = {
99
moduleNameMapper: {
1010
'^(\\.{1,2}/.*)\\.(m)?js$': '$1',
1111
},
12+
modulePathIgnorePatterns: ['<rootDir>/build/'],
1213
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(m)?ts$',
1314
coverageDirectory: 'coverage',
1415
collectCoverageFrom: [

packages/node-opentelemetry/src/MutableAsyncLocalStorageContextManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { Context, ROOT_CONTEXT } from '@opentelemetry/api';
1818
import { AsyncLocalStorage } from 'async_hooks';
19+
1920
import { AbstractAsyncHooksContextManager } from './AbstractAsyncHooksContextManager';
2021

2122
type MutableContextStore = {

packages/node-opentelemetry/__tests__/logger.test.ts renamed to packages/node-opentelemetry/src/__tests__/logger.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import winston from 'winston';
22

3-
import { getWinstonTransport } from '../src/logger';
3+
import { getWinstonTransport } from '../logger';
44

55
const MAX_LEVEL = 'info';
66

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { init, initSDK, shutdown } from '../otel';
2+
3+
describe('otel', () => {
4+
it('can sucessively shutdown without initialization', () => {
5+
shutdown();
6+
shutdown();
7+
});
8+
9+
it('should be able to initialize the SDK with initSDK', async () => {
10+
initSDK({
11+
apiKey: 'blabla',
12+
advancedNetworkCapture: true,
13+
consoleCapture: true,
14+
});
15+
16+
await new Promise((resolve) => setTimeout(resolve, 1000));
17+
18+
shutdown();
19+
});
20+
21+
it('should be able to initialize the SDK with init', async () => {
22+
init({
23+
apiKey: 'blabla',
24+
});
25+
26+
await new Promise((resolve) => setTimeout(resolve, 1000));
27+
28+
shutdown();
29+
});
30+
});

0 commit comments

Comments
 (0)