File tree Expand file tree Collapse file tree 7 files changed +84
-16
lines changed Expand file tree Collapse file tree 7 files changed +84
-16
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @hyperdx/node-opentelemetry ' : patch
3
+ ' @hyperdx/node-logger ' : patch
4
+ ---
5
+
6
+ feat: expose 'bufferSize', 'sendIntervalMs' and 'timeout' logger options
Original file line number Diff line number Diff line change @@ -51,6 +51,14 @@ const logger = winston.createLogger({
51
51
export default logger;
52
52
```
53
53
54
+ #### Options
55
+
56
+ - ** apiKey** - Required. Your HyperDX ingestion API key.
57
+ - ** service** - The name of the service.
58
+ - ** sendIntervalMs** - Time in milliseconds to wait between retry attempts. Default: ` 2000 ` (2 sec)
59
+ - ** bufferSize** - The maximum number of messages the logger will accumulate before sending them all as a bulk. Default: ` 100 ` .
60
+ - ** timeout** - The read/write/connection timeout in milliseconds. Default: ` 30000 ` .
61
+
54
62
### Pino Transport
55
63
56
64
Create a new HyperDX Pino Transport and append it to your list of transports. Example:
@@ -77,6 +85,14 @@ const logger = pino(
77
85
export default logger;
78
86
```
79
87
88
+ #### Options
89
+
90
+ - ** apiKey** - Required. Your HyperDX ingestion API key.
91
+ - ** service** - The name of the service.
92
+ - ** sendIntervalMs** - Time in milliseconds to wait between retry attempts. Default: ` 2000 ` (2 sec)
93
+ - ** bufferSize** - The maximum number of messages the logger will accumulate before sending them all as a bulk. Default: ` 100 ` .
94
+ - ** timeout** - The read/write/connection timeout in milliseconds. Default: ` 30000 ` .
95
+
80
96
### NestJS Custom Logger
81
97
82
98
(powered by [ nest-winston] ( https://www.npmjs.com/package/nest-winston?activeTab=readme ) )
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ class HyperdxLogger {
51
51
token,
52
52
host = 'in.hyperdx.io' ,
53
53
type = 'nodejs' ,
54
- sendIntervalMs = 10 * 1000 ,
54
+ sendIntervalMs = 2 * 1000 ,
55
55
bufferSize = 100 ,
56
56
numberOfRetries = 3 ,
57
57
supressErrors = false ,
@@ -150,6 +150,7 @@ class HyperdxLogger {
150
150
}
151
151
152
152
_timerSend ( ) {
153
+ this . _debug ( 'Timer fired. Trying to wake up and send messages...' ) ;
153
154
if ( this . messages . length > 0 ) {
154
155
this . _debug (
155
156
`Woke up and saw ${ this . messages . length } messages to send. Sending now...` ,
Original file line number Diff line number Diff line change @@ -60,6 +60,15 @@ export const parseWinstonLog = (log: {
60
60
61
61
const DEFAULT_TIMEOUT = 30000 ;
62
62
63
+ export type LoggerOptions = {
64
+ apiKey : string ;
65
+ baseUrl ?: string ;
66
+ bufferSize ?: number ;
67
+ sendIntervalMs ?: number ;
68
+ service ?: string ;
69
+ timeout ?: number ; // The read/write/connection timeout in milliseconds
70
+ } ;
71
+
63
72
export class Logger {
64
73
private readonly service : string ;
65
74
@@ -68,11 +77,17 @@ export class Logger {
68
77
constructor ( {
69
78
apiKey,
70
79
baseUrl,
80
+ bufferSize,
81
+ sendIntervalMs,
71
82
service,
83
+ timeout,
72
84
} : {
73
85
apiKey : string ;
74
86
baseUrl ?: string ;
87
+ bufferSize ?: number ;
88
+ sendIntervalMs ?: number ;
75
89
service ?: string ;
90
+ timeout ?: number ;
76
91
} ) {
77
92
if ( ! apiKey ) {
78
93
console . error ( `${ LOG_PREFIX } API key not found` ) ;
@@ -96,10 +111,12 @@ export class Logger {
96
111
97
112
this . client = apiKey
98
113
? createLogger ( {
114
+ bufferSize,
99
115
host,
100
116
port,
101
117
protocol,
102
- timeout : DEFAULT_TIMEOUT ,
118
+ sendIntervalMs,
119
+ timeout : timeout ?? DEFAULT_TIMEOUT ,
103
120
token : apiKey ,
104
121
} )
105
122
: null ;
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import build from 'pino-abstract-transport';
3
3
import hdx from './debug' ;
4
4
import { Logger , parsePinoLog } from './logger' ;
5
5
6
+ import type { LoggerOptions } from './logger' ;
7
+
6
8
// map pino level to text
7
9
const PINO_LEVELS = {
8
10
10 : 'trace' ,
@@ -13,11 +15,9 @@ const PINO_LEVELS = {
13
15
60 : 'fatal' ,
14
16
} ;
15
17
16
- export default ( opts : {
17
- apiKey : string ;
18
- baseUrl ?: string ;
19
- service ?: string ;
20
- } ) => {
18
+ export type HyperDXPinoOptions = LoggerOptions ;
19
+
20
+ export default ( opts : HyperDXPinoOptions ) => {
21
21
try {
22
22
hdx ( 'Initializing HyperDX pino transport...' ) ;
23
23
const logger = new Logger ( opts ) ;
Original file line number Diff line number Diff line change @@ -3,23 +3,34 @@ import Transport from 'winston-transport';
3
3
import hdx from './debug' ;
4
4
import { Logger , parseWinstonLog } from './logger' ;
5
5
6
+ import type { LoggerOptions } from './logger' ;
7
+
8
+ export type HyperDXWinstonOptions = LoggerOptions & {
9
+ maxLevel ?: string ;
10
+ } ;
11
+
6
12
export default class HyperDXWinston extends Transport {
7
13
private readonly logger : Logger ;
8
14
9
15
constructor ( {
10
16
apiKey,
11
17
baseUrl,
18
+ bufferSize,
12
19
maxLevel,
20
+ sendIntervalMs,
13
21
service,
14
- } : {
15
- apiKey : string ;
16
- baseUrl ?: string ;
17
- maxLevel ?: string ;
18
- service ?: string ;
19
- } ) {
22
+ timeout,
23
+ } : HyperDXWinstonOptions ) {
20
24
hdx ( 'Initializing HyperDX winston transport...' ) ;
21
25
super ( { level : maxLevel ?? 'info' } ) ;
22
- this . logger = new Logger ( { apiKey, baseUrl, service } ) ;
26
+ this . logger = new Logger ( {
27
+ apiKey,
28
+ baseUrl,
29
+ bufferSize,
30
+ sendIntervalMs,
31
+ service,
32
+ timeout,
33
+ } ) ;
23
34
hdx ( `HyperDX winston transport initialized!` ) ;
24
35
}
25
36
Original file line number Diff line number Diff line change @@ -10,20 +10,37 @@ const HYPERDX_API_KEY = (env.HYPERDX_API_KEY ??
10
10
11
11
const SERVICE_NAME = env . OTEL_SERVICE_NAME as string ;
12
12
13
- export const getWinsonTransport = ( maxLevel = 'info' ) => {
13
+ type WinstonTransportOptions = {
14
+ baseUrl ?: string ;
15
+ bufferSize ?: number ;
16
+ sendIntervalMs ?: number ;
17
+ timeout ?: number ; // The read/write/connection timeout in milliseconds
18
+ } ;
19
+
20
+ type PinotTransportOptions = WinstonTransportOptions ;
21
+
22
+ export const getWinsonTransport = (
23
+ maxLevel = 'info' ,
24
+ options : WinstonTransportOptions = { } ,
25
+ ) => {
14
26
hdx ( 'Initializing winston transport' ) ;
15
27
return new HyperDXWinston ( {
16
28
apiKey : HYPERDX_API_KEY ,
17
29
maxLevel,
18
30
service : SERVICE_NAME ,
31
+ ...options ,
19
32
} ) ;
20
33
} ;
21
34
22
- export const getPinoTransport = ( maxLevel = 'info' ) => ( {
35
+ export const getPinoTransport = (
36
+ maxLevel = 'info' ,
37
+ options : PinotTransportOptions = { } ,
38
+ ) => ( {
23
39
target : '@hyperdx/node-logger/build/src/pino' ,
24
40
options : {
25
41
apiKey : HYPERDX_API_KEY ,
26
42
service : SERVICE_NAME ,
43
+ ...options ,
27
44
} ,
28
45
level : maxLevel ,
29
46
} ) ;
You can’t perform that action at this time.
0 commit comments