1
1
import { IInnerError } from '../../models/IInnerError' ;
2
- import { ILog } from '../../logging/ILog' ;
3
2
import { IEventPlugin } from '../IEventPlugin' ;
4
3
import { EventPluginContext } from '../EventPluginContext' ;
5
4
import { Utils } from '../../Utils' ;
@@ -18,27 +17,44 @@ export class DuplicateCheckerPlugin implements IEventPlugin {
18
17
this . _interval = interval ;
19
18
20
19
setInterval ( ( ) => {
21
- while ( this . _mergedEvents . length > 0 ) {
20
+ while ( this . _mergedEvents . length > 0 ) {
22
21
this . _mergedEvents . shift ( ) . resubmit ( ) ;
23
22
}
24
23
} , interval ) ;
25
24
}
26
25
27
26
public run ( context : EventPluginContext , next ?: ( ) => void ) : void {
28
- let hashCode = Utils . getHashCode ( JSON . stringify ( context . event . data [ '@error' ] , [ 'stack_trace' , 'inner' ] ) ) ;
29
- let count = context . event . count || 1 ;
27
+ function getHashCode ( error : IInnerError ) : number {
28
+ let hashCode = 0 ;
29
+
30
+ while ( error ) {
31
+ if ( error . stack_trace && error . stack_trace . length ) {
32
+ hashCode = ( hashCode * 397 ) ^ Utils . getHashCode ( JSON . stringify ( error . stack_trace ) ) ;
33
+ }
34
+ error = error . inner ;
35
+ }
36
+
37
+ return hashCode ;
38
+ }
39
+
40
+ let error = context . event . data [ '@error' ] ;
41
+ let hashCode = getHashCode ( error ) ;
42
+ if ( ! hashCode ) {
43
+ return ;
44
+ }
30
45
46
+ let count = context . event . count || 1 ;
31
47
let now = this . _getCurrentTime ( ) ;
32
48
33
49
let merged = this . _mergedEvents . filter ( s => s . hashCode === hashCode ) [ 0 ] ;
34
- if ( merged ) {
50
+ if ( merged ) {
35
51
merged . incrementCount ( count ) ;
36
52
merged . updateDate ( context . event . date ) ;
37
53
context . cancelled = true ;
38
54
return ;
39
55
}
40
56
41
- if ( this . _processedHashcodes . some ( h => h . hash === hashCode && h . timestamp >= ( now - this . _interval ) ) ) {
57
+ if ( this . _processedHashcodes . some ( h => h . hash === hashCode && h . timestamp >= ( now - this . _interval ) ) ) {
42
58
this . _mergedEvents . push ( new MergedEvent ( hashCode , context , count ) ) ;
43
59
context . cancelled = true ;
44
60
return ;
@@ -61,17 +77,17 @@ interface TimestampedHash {
61
77
}
62
78
63
79
class MergedEvent {
80
+ public hashCode : number ;
64
81
private _count : number ;
65
82
private _context : EventPluginContext ;
66
- public hashCode : number ;
67
83
68
- constructor ( hashCode : number , context : EventPluginContext , count : number ) {
84
+ constructor ( hashCode : number , context : EventPluginContext , count : number ) {
69
85
this . hashCode = hashCode ;
70
86
this . _context = context ;
71
87
this . _count = count ;
72
88
}
73
89
74
- public incrementCount ( count : number ) {
90
+ public incrementCount ( count : number ) {
75
91
this . _count += count ;
76
92
}
77
93
@@ -81,7 +97,7 @@ class MergedEvent {
81
97
}
82
98
83
99
public updateDate ( date ) {
84
- if ( date > this . _context . event . date ) {
100
+ if ( date > this . _context . event . date ) {
85
101
this . _context . event . date = date ;
86
102
}
87
103
}
0 commit comments