File tree Expand file tree Collapse file tree 4 files changed +85
-1
lines changed
instrumentation-exception/src/node/utils
node-opentelemetry/examples Expand file tree Collapse file tree 4 files changed +85
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @hyperdx/instrumentation-exception ' : patch
3+ ' @hyperdx/node-opentelemetry ' : patch
4+ ---
5+
6+ fix: console log uncaught exceptions
Original file line number Diff line number Diff line change 1+ import { consoleSandbox } from '@sentry/utils' ;
12import { diag } from '@opentelemetry/api' ;
23
34const DEFAULT_SHUTDOWN_TIMEOUT = 2000 ;
@@ -21,7 +22,10 @@ export async function logAndExitProcess(
2122 error : Error ,
2223 forceFlush : ( ) => Promise < void > ,
2324) : Promise < void > {
24- diag . error ( 'Exiting process due to fatal error' , error ) ;
25+ consoleSandbox ( ( ) => {
26+ // eslint-disable-next-line no-console
27+ console . error ( error ) ;
28+ } ) ;
2529
2630 try {
2731 await Promise . race ( [
Original file line number Diff line number Diff line change 1+ const express = require ( 'express' ) ;
2+ const HyperDX = require ( '../build/src' ) ;
3+
4+ HyperDX . init ( {
5+ apiKey : '' ,
6+ service : 'hard-crash' ,
7+ } ) ;
8+
9+ // Crash immediately
10+ har ( ) ;
11+
12+ // unhandledRejection
13+ // new Promise((resolve, reject) => {
14+ // reject(new Error('🦄🦄🦄🦄'));
15+ // });
16+
17+ const PORT = parseInt ( process . env . PORT || '7788' ) ;
18+ const app = express ( ) ;
19+
20+ app . get ( '/uncaught' , async ( req , res ) => {
21+ setTimeout ( ( ) => {
22+ throw new Error ( '💥💥💥💥' ) ;
23+ } , 2000 ) ;
24+ res . send ( 'Uncaught exception in 2 seconds' ) ;
25+ } ) ;
26+
27+ app . get ( '/crash' , ( req , res ) => {
28+ throw new Error ( '🧨🧨🧨🧨' ) ;
29+ } ) ;
30+
31+ app . get ( '/' , ( req , res ) => {
32+ res . send ( 'Hello World!' ) ;
33+ } ) ;
34+
35+ // HyperDX.setupExpressErrorHandler(app);
36+
37+ app . listen ( PORT , ( ) => {
38+ console . log ( `Listening for requests on http://localhost:${ PORT } ` ) ;
39+ } ) ;
Original file line number Diff line number Diff line change 1+ const express = require ( 'express' ) ;
2+ const Redis = require ( 'redis' ) ;
3+ const HyperDX = require ( '../build/src' ) ;
4+
5+ HyperDX . init ( {
6+ apiKey : '' ,
7+ service : 'dummy_redis4' ,
8+ } ) ;
9+
10+ const PORT = parseInt ( process . env . PORT || '7788' ) ;
11+ const app = express ( ) ;
12+
13+ app . use ( express . json ( ) ) ;
14+ app . get ( '/' , async ( req , res ) => {
15+ const client = await Redis . createClient ( {
16+ host : 'localhost' ,
17+ port : 6379 ,
18+ } ) . connect ( ) ;
19+ // await redis.commandsExecutor('set', 'foo', 'bar');
20+ await client . set ( 'foo1' , 'bar1' ) ;
21+ await client . get ( 'foo1' ) ;
22+ // await redis.sendCommand(['SET', 'foo1', 'bar1']);
23+ // await redis.sendCommand(['GET', 'foo1']);
24+ // const [setKeyReply, otherKeyValue] = await client
25+ // .multi()
26+ // .set('key', 'value')
27+ // .get('another-key')
28+ // .exec(); // ['OK', 'another-value']
29+ await client . disconnect ( ) ;
30+ res . send ( 'Hello World!!!' ) ;
31+ } ) ;
32+
33+ app . listen ( PORT , ( ) => {
34+ console . log ( `Listening for requests on http://localhost:${ PORT } ` ) ;
35+ } ) ;
You can’t perform that action at this time.
0 commit comments