Skip to content

Commit

Permalink
chore: add 'prettier' + 'simple-import-sort' linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
wrn14897 committed Jul 21, 2024
1 parent 6472326 commit 5b16643
Show file tree
Hide file tree
Showing 24 changed files with 178 additions and 102 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-humans-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/node-opentelemetry': minor
---

feat: use getSeverityNumber and parseLogAttributes for logger
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
"prepare": "husky install"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
"**/*.{ts,tsx}": [
"prettier --write --ignore-unknown",
"eslint --fix"
],
"**/*.{json,yml}": [
"prettier --write --ignore-unknown"
]
},
"devDependencies": {
"@changesets/cli": "^2.26.1",
Expand All @@ -29,13 +35,15 @@
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"husky": "^8.0.3",
"jest": "^29.5.0",
"lint-staged": "^13.2.2",
"nx": "^15.9.2",
"prettier": "^2.8.7",
"prettier": "^3.3.3",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
Expand Down
15 changes: 7 additions & 8 deletions packages/node-opentelemetry/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
"sourceType": "module",
"ecmaVersion": 2020
},
"plugins": ["@typescript-eslint", "jest"],
"plugins": ["@typescript-eslint", "jest", "prettier", "simple-import-sort"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"prettier"
"plugin:prettier/recommended"
],
"rules": {
// The following rule is enabled only to supplement the inline suppression
// examples, and because it is not a recommended rule, you should either
// disable it, or understand what it enforces.
// https://typescript-eslint.io/rules/explicit-function-return-type/
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-this-alias": "warn"
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/no-this-alias": "warn",
"prettier/prettier": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error"
}
}
15 changes: 0 additions & 15 deletions packages/node-opentelemetry/__tests__/otel.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import process from 'process';
import fs from 'fs';
import process from 'process';
import { promisify } from 'util';

const realpath = promisify(fs.realpath);
Expand Down
30 changes: 19 additions & 11 deletions packages/node-opentelemetry/examples/dummy.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,30 @@ app.get('/instruments', async (req, res) => {
});

app.get('/logs', async (req, res) => {
console.debug({
const nestedObj = {
headers: req.headers,
method: req.method,
url: req.url,
query: req.query,
nested: [
{
foo: 'bar',
},
],
nested2: {
nested3: {
foo: 'bar',
},
},
};
console.error({
message: 'Console 🍕',
...nestedObj,
});
console.error('BANG !!!');
console.log('Console 🍕');
logger.info({
message: 'Winston 🍕',
headers: req.headers,
method: req.method,
url: req.url,
logger.info('Winston 🍕', nestedObj);
pinoLogger.info({
message: 'Pino 🍕',
...nestedObj,
});
pinoLogger.info('Pino 🍕');

bunyanLogger.info('Bunyan 🍕');

console.log(await sendGetRequest());
Expand Down
1 change: 1 addition & 0 deletions packages/node-opentelemetry/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const config: Config = {
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.(m)?js$': '$1',
},
modulePathIgnorePatterns: ['<rootDir>/build/'],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(m)?ts$',
coverageDirectory: 'coverage',
collectCoverageFrom: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { Context, ROOT_CONTEXT } from '@opentelemetry/api';
import { AsyncLocalStorage } from 'async_hooks';

import { AbstractAsyncHooksContextManager } from './AbstractAsyncHooksContextManager';

type MutableContextStore = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import winston from 'winston';

import { getWinstonTransport } from '../src/logger';
import { getWinstonTransport } from '../logger';

const MAX_LEVEL = 'info';

Expand Down
30 changes: 30 additions & 0 deletions packages/node-opentelemetry/src/__tests__/otel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { init, initSDK, shutdown } from '../otel';

describe('otel', () => {
it('can sucessively shutdown without initialization', () => {
shutdown();
shutdown();
});

it('should be able to initialize the SDK with initSDK', async () => {
initSDK({
apiKey: 'blabla',
advancedNetworkCapture: true,
consoleCapture: true,
});

await new Promise((resolve) => setTimeout(resolve, 1000));

shutdown();
});

it('should be able to initialize the SDK with init', async () => {
init({
apiKey: 'blabla',
});

await new Promise((resolve) => setTimeout(resolve, 1000));

shutdown();
});
});
2 changes: 1 addition & 1 deletion packages/node-opentelemetry/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getEnv, getEnvWithoutDefaults } from '@opentelemetry/core';
import { defaultServiceName } from '@opentelemetry/resources';
import { getEnvWithoutDefaults, getEnv } from '@opentelemetry/core';

import { stringToBoolean } from './utils';

Expand Down
4 changes: 2 additions & 2 deletions packages/node-opentelemetry/src/gcp.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { context, SpanKind, trace } from '@opentelemetry/api';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { SpanKind, context, trace } from '@opentelemetry/api';

import { SDKConfig, initSDK } from './otel';
import { name as PKG_NAME, version as PKG_VERSION } from '../package.json';
import { initSDK, SDKConfig } from './otel';

export const registerGCPCloudFunctionEventHandler = (
handler: (event: any) => Promise<void>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PassThrough, Readable } from 'stream';

import { _parseConsoleArgs } from '../src/instrumentations/console';
import { _parseConsoleArgs } from '../console';
import {
getShouldRecordBody,
interceptReadableStream,
splitCommaSeparatedStrings,
} from '../src/instrumentations/http';
} from '../http';

describe('instrumentations', () => {
describe('console', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/node-opentelemetry/src/instrumentations/console.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import isObject from 'lodash.isobject';
import isPlainObject from 'lodash.isplainobject';
import opentelemetry, { Attributes } from '@opentelemetry/api';
import {
InstrumentationBase,
InstrumentationConfig,
InstrumentationNodeModuleDefinition,
} from '@opentelemetry/instrumentation';
import isObject from 'lodash.isobject';
import isPlainObject from 'lodash.isplainobject';

import { MutableAsyncLocalStorageContextManager } from '../MutableAsyncLocalStorageContextManager';
import { Logger, LoggerOptions } from '../otel-logger';
import { parseWinstonLog } from '../otel-logger/winston';
import { MutableAsyncLocalStorageContextManager } from '../MutableAsyncLocalStorageContextManager';

const PACKAGE_NAME = '@hyperdx/instrumentation-console';
const PACKAGE_VERSION = '0.1.0';
Expand Down
7 changes: 3 additions & 4 deletions packages/node-opentelemetry/src/instrumentations/http.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { diag, Span } from '@opentelemetry/api';
import { headerCapture } from '@opentelemetry/instrumentation-http';
import * as http from 'http';
import zlib from 'zlib';
import { PassThrough, Readable } from 'stream';

import { Span, diag } from '@opentelemetry/api';
import { headerCapture } from '@opentelemetry/instrumentation-http';
import zlib from 'zlib';

const SENSITIVE_DATA_SUBSTITUTE = '[Filtered]';
// https://github.com/getsentry/sentry-python/blob/1.18.0/sentry_sdk/scrubber.py#L17
Expand Down
5 changes: 2 additions & 3 deletions packages/node-opentelemetry/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import {
DEFAULT_HDX_NODE_BETA_MODE,
DEFAULT_SERVICE_NAME,
} from './constants';
import * as HyperDXPino from './otel-logger/pino';
import HyperDXWinston from './otel-logger/winston';

import type { HyperDXPinoOptions } from './otel-logger/pino';
import * as HyperDXPino from './otel-logger/pino';
import type { HyperDXWinstonOptions } from './otel-logger/winston';
import HyperDXWinston from './otel-logger/winston';

type WinstonTransportOptions = Omit<
HyperDXWinstonOptions,
Expand Down
16 changes: 8 additions & 8 deletions packages/node-opentelemetry/src/otel-logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { Attributes, diag } from '@opentelemetry/api';
import { getEnvWithoutDefaults } from '@opentelemetry/core';
import {
BatchLogRecordProcessor,
LoggerProvider,
NoopLogRecordProcessor,
} from '@opentelemetry/sdk-logs';
import { Logger as OtelLogger, logs } from '@opentelemetry/api-logs';
import { getEnvWithoutDefaults } from '@opentelemetry/core';
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
import {
Resource,
detectResourcesSync,
envDetectorSync,
hostDetectorSync,
osDetectorSync,
processDetector,
Resource,
} from '@opentelemetry/resources';
import {
BatchLogRecordProcessor,
LoggerProvider,
NoopLogRecordProcessor,
} from '@opentelemetry/sdk-logs';
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';

import { version as PKG_VERSION } from '../../package.json';
import {
DEFAULT_EXPORTER_BATCH_SIZE,
DEFAULT_EXPORTER_TIMEOUT_MS,
Expand All @@ -25,7 +26,6 @@ import {
DEFAULT_SEND_INTERVAL_MS,
DEFAULT_SERVICE_NAME,
} from '../constants';
import { version as PKG_VERSION } from '../../package.json';

const LOG_PREFIX = `⚠️ [LOGGER]`;

Expand Down
7 changes: 3 additions & 4 deletions packages/node-opentelemetry/src/otel-logger/pino.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import build from 'pino-abstract-transport';
import isString from 'lodash.isstring';
import {
Attributes,
context,
diag,
isSpanContextValid,
trace,
} from '@opentelemetry/api';
import isString from 'lodash.isstring';
import build from 'pino-abstract-transport';

import { Logger } from './';
import { jsonToString } from '../utils';

import type { LoggerOptions } from './';
import { Logger } from './';

export type PinoLogLine = {
level: number;
Expand Down
7 changes: 3 additions & 4 deletions packages/node-opentelemetry/src/otel-logger/winston.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Transport from 'winston-transport';
import { Attributes, diag } from '@opentelemetry/api';
import isPlainObject from 'lodash.isplainobject';
import isString from 'lodash.isstring';
import { Attributes, diag } from '@opentelemetry/api';
import Transport from 'winston-transport';

import { Logger } from './';
import { jsonToString } from '../utils';

import type { LoggerOptions } from './';
import { Logger } from './';

export const parseWinstonLog = (
log: {
Expand Down
Loading

0 comments on commit 5b16643

Please sign in to comment.