-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollbar.ts
57 lines (49 loc) · 1.44 KB
/
rollbar.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { BasePlugin } from '@opentelemetry/core';
import { getSpan, context, diag } from '@opentelemetry/api';
import * as Rollbar from 'rollbar';
import * as shimmer from 'shimmer';
import { VERSION } from './version';
export class RollbarPlugin extends BasePlugin<typeof Rollbar> {
static readonly COMPONENT = 'rollbar';
static readonly COMPONENT_SHORT = 'rollbar';
readonly supportedVersions = ['2.19.4', '2.19.4'];
constructor(readonly moduleName: string) {
super('rollbar', VERSION);
}
protected patch() {
if (this._moduleExports) {
diag.debug('patching rollbar');
shimmer.wrap(
this._moduleExports.prototype,
'error',
this._getErrorPatch.bind(this)
);
}
return this._moduleExports;
}
protected unpatch(): void {
if (this._moduleExports) {
shimmer.unwrap(this._moduleExports.prototype, 'error');
}
}
private _getErrorPatch(
original: (...args: Rollbar.LogArgument[]) => Rollbar.LogResult
) {
return function error(
this: any,
...args: Rollbar.LogArgument[]
): Rollbar.LogResult {
const span = getSpan(context.active());
const result = original.apply(this, args);
if (span) {
span.setAttributes({
'rollbar.has_error': true,
'rollbar.uuid': result.uuid,
error: true,
});
}
return result;
};
}
}
export const plugin = new RollbarPlugin(RollbarPlugin.COMPONENT);