@opentelemetry/plugin-react-load 0.31.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"BaseOpenTelemetryComponent.d.ts","sourceRoot":"","sources":["../../src/BaseOpenTelemetryComponent.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAI1C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAa/B;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,KAAK,CAAC,SAAS;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAgB;IAC1C,UAAU,SAAkB;IAC5B,OAAO,CAAC,cAAc,CAAqC;IAC3D,OAAO,CAAC,MAAM,CAAC,OAAO,CAAa;IACnC,OAAO,CAAC,MAAM,CAAC,OAAO,CAA4B;IAElD;;OAEG;gBACS,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;IAMhC;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAOtD;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI;IAK9C;;;;;;OAMG;IACH,OAAO,CAAC,qBAAqB;IAgB7B;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAMnB;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;IA2B3B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAQtB;;;QAGI;IACJ,OAAO,CAAC,cAAc;IActB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,YAAY;IA4BpB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IA0B/B;;OAEG;IACH,OAAO,CAAC,cAAc;IAoBtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAoBzB;;OAEG;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uBAAuB;IA0B/B;;OAEG;IACH,OAAO,CAAC,cAAc;IAoBtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAoBzB;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAiCnC;;OAEG;IACH,OAAO,CAAC,6BAA6B;IA0BrC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IA4BhC;;OAEG;IACH,OAAO,CAAC,0BAA0B;IA4BlC;;OAEG;IACI,KAAK,IAAI,IAAI;IA8GpB;;OAEG;IACI,OAAO,IAAI,IAAI;CAqBvB"}
@@ -13,59 +13,46 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- var __extends = (this && this.__extends) || (function () {
17
- var extendStatics = function (d, b) {
18
- extendStatics = Object.setPrototypeOf ||
19
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
20
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
21
- return extendStatics(d, b);
22
- };
23
- return function (d, b) {
24
- if (typeof b !== "function" && b !== null)
25
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
26
- extendStatics(d, b);
27
- function __() { this.constructor = d; }
28
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29
- };
30
- })();
31
16
  import * as api from '@opentelemetry/api';
32
- import { isWrapped } from '@opentelemetry/core';
17
+ import { isWrapped } from '@opentelemetry/instrumentation';
33
18
  import * as shimmer from 'shimmer';
34
19
  import { AttributeNames } from './enums/AttributeNames';
35
20
  import * as React from 'react';
21
+ /** @knipignore */
36
22
  import { PACKAGE_VERSION } from './version';
37
23
  /**
38
24
  * This class is the base component for a React component with lifecycle instrumentation
39
25
  */
40
- var BaseOpenTelemetryComponent = /** @class */ (function (_super) {
41
- __extends(BaseOpenTelemetryComponent, _super);
26
+ class BaseOpenTelemetryComponent extends React.Component {
27
+ component = 'react-load';
28
+ moduleName = this.component;
29
+ _parentSpanMap;
30
+ static _tracer;
31
+ static _logger = api.diag;
42
32
  /**
43
33
  * @param props Props of the React component
44
34
  */
45
- function BaseOpenTelemetryComponent(props) {
46
- var _this = _super.call(this, props) || this;
47
- _this.component = 'react-load';
48
- _this.moduleName = _this.component;
49
- _this._parentSpanMap = new WeakMap();
50
- _this.patch();
51
- return _this;
35
+ constructor(props) {
36
+ super(props);
37
+ this._parentSpanMap = new WeakMap();
38
+ this.patch();
52
39
  }
53
40
  /**
54
41
  * Sets the tracer for all components being instrumented
55
42
  * @param name Name of tracer
56
43
  * @param version Version of tracer, this is optional. When not provided it will use the latest.
57
44
  */
58
- BaseOpenTelemetryComponent.setTracer = function (name, version) {
45
+ static setTracer(name, version) {
59
46
  BaseOpenTelemetryComponent._tracer = api.trace.getTracer(name, version ? version : PACKAGE_VERSION);
60
- };
47
+ }
61
48
  /**
62
49
  * Sets the logger for all components being instrumented
63
50
  * @param logger
64
51
  */
65
- BaseOpenTelemetryComponent.setLogger = function (logger) {
52
+ static setLogger(logger) {
66
53
  api.diag.setLogger(logger);
67
54
  BaseOpenTelemetryComponent._logger = logger;
68
- };
55
+ }
69
56
  /**
70
57
  * Creates a new span as a child of the current parent span.
71
58
  * If parent span is undefined, just the child is created.
@@ -73,23 +60,23 @@ var BaseOpenTelemetryComponent = /** @class */ (function (_super) {
73
60
  * @param name Name of span
74
61
  * @param parentSpan parent span
75
62
  */
76
- BaseOpenTelemetryComponent.prototype._createSpanWithParent = function (react, name, parentSpan) {
63
+ _createSpanWithParent(react, name, parentSpan) {
77
64
  return BaseOpenTelemetryComponent._tracer.startSpan(name, {
78
65
  attributes: this._getAttributes(react),
79
66
  }, parentSpan
80
67
  ? api.trace.setSpan(api.context.active(), parentSpan)
81
68
  : undefined);
82
- };
69
+ }
83
70
  /**
84
71
  * Creates a new span
85
72
  * @param react React component currently being instrumented
86
73
  * @param name Name of span
87
74
  */
88
- BaseOpenTelemetryComponent.prototype._createSpan = function (react, name) {
75
+ _createSpan(react, name) {
89
76
  return BaseOpenTelemetryComponent._tracer.startSpan(name, {
90
77
  attributes: this._getAttributes(react),
91
78
  });
92
- };
79
+ }
93
80
  /**
94
81
  * Provides instrumentation for a function
95
82
  * @param react React component currently instrumenting.
@@ -97,11 +84,11 @@ var BaseOpenTelemetryComponent = /** @class */ (function (_super) {
97
84
  * @param original Original function currently being wrapped.
98
85
  * @parentName Name to set parent span to on error.
99
86
  */
100
- BaseOpenTelemetryComponent.prototype._instrumentFunction = function (react, spanName, parent, original) {
101
- var span = this._createSpanWithParent(react, spanName, parent);
102
- var wasError = false;
87
+ _instrumentFunction(react, spanName, parent, original) {
88
+ const span = this._createSpanWithParent(react, spanName, parent);
89
+ let wasError = false;
103
90
  try {
104
- return api.context.with(api.trace.setSpan(api.context.active(), span), function () {
91
+ return api.context.with(api.trace.setSpan(api.context.active(), span), () => {
105
92
  return original();
106
93
  });
107
94
  }
@@ -116,155 +103,124 @@ var BaseOpenTelemetryComponent = /** @class */ (function (_super) {
116
103
  this._endParentSpan(react);
117
104
  }
118
105
  }
119
- };
106
+ }
120
107
  /**
121
108
  * Ends the current parent span.
122
109
  * @param react React component parent span belongs to.
123
110
  */
124
- BaseOpenTelemetryComponent.prototype._endParentSpan = function (react) {
125
- var parentSpan = this._parentSpanMap.get(react);
111
+ _endParentSpan(react) {
112
+ const parentSpan = this._parentSpanMap.get(react);
126
113
  if (parentSpan) {
127
114
  parentSpan.end();
128
115
  this._parentSpanMap.delete(react);
129
116
  }
130
- };
117
+ }
131
118
  /**
132
119
  * Returns attributes object for spans
133
120
  * @param react React component currently being instrumented
134
121
  **/
135
- BaseOpenTelemetryComponent.prototype._getAttributes = function (react) {
136
- var _a;
137
- var state;
122
+ _getAttributes(react) {
123
+ let state;
138
124
  try {
139
125
  state = JSON.stringify(react.state);
140
126
  }
141
- catch (_b) {
127
+ catch {
142
128
  state = '{"message": "state could not be turned into string"}';
143
129
  }
144
- return _a = {},
145
- _a[AttributeNames.LOCATION_URL] = window.location.href,
146
- _a[AttributeNames.REACT_NAME] = react.constructor.name,
147
- _a[AttributeNames.REACT_STATE] = state,
148
- _a;
149
- };
130
+ return {
131
+ [AttributeNames.LOCATION_URL]: window.location.href,
132
+ [AttributeNames.REACT_NAME]: react.constructor.name,
133
+ [AttributeNames.REACT_STATE]: state,
134
+ };
135
+ }
150
136
  /**
151
137
  * This function returns a parent span. If the parent doesn't
152
138
  * exist, the function creates one
153
139
  * @param react React component parent span belongs to.
154
140
  */
155
- BaseOpenTelemetryComponent.prototype._getParentSpan = function (react, parentName) {
156
- var parentSpan = this._parentSpanMap.get(react);
141
+ _getParentSpan(react, parentName) {
142
+ const parentSpan = this._parentSpanMap.get(react);
157
143
  if (!parentSpan) {
158
- var span = this._createSpan(react, parentName);
144
+ const span = this._createSpan(react, parentName);
159
145
  this._parentSpanMap.set(react, span);
160
146
  }
161
147
  return this._parentSpanMap.get(react);
162
- };
148
+ }
163
149
  /**
164
150
  * Patches the render lifecycle method
165
151
  */
166
- BaseOpenTelemetryComponent.prototype._patchRender = function () {
167
- var _this = this;
168
- return function (original) {
169
- var plugin = _this;
170
- return function patchRender() {
171
- var _this = this;
172
- var args = [];
173
- for (var _i = 0; _i < arguments.length; _i++) {
174
- args[_i] = arguments[_i];
175
- }
152
+ _patchRender() {
153
+ return (original) => {
154
+ const plugin = this;
155
+ return function patchRender(...args) {
176
156
  // Render is the first method in the mounting flow, if a parent span wasn't created already then we're in the mounting flow
177
- var parentSpan;
157
+ let parentSpan;
178
158
  if (!plugin._parentSpanMap.get(this)) {
179
159
  parentSpan = plugin._getParentSpan(this, AttributeNames.MOUNTING_SPAN);
180
160
  }
181
161
  else {
182
162
  parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
183
163
  }
184
- return plugin._instrumentFunction(this, 'render', parentSpan, function () {
185
- return original.apply(_this, args);
164
+ return plugin._instrumentFunction(this, 'render', parentSpan, () => {
165
+ return original.apply(this, args);
186
166
  });
187
167
  };
188
168
  };
189
- };
169
+ }
190
170
  /**
191
171
  * Patches the componentDidMount lifecycle method
192
172
  */
193
- BaseOpenTelemetryComponent.prototype._patchComponentDidMount = function () {
194
- var _this = this;
195
- return function (original) {
196
- var plugin = _this;
197
- return function patchComponentDidMount() {
198
- var _this = this;
199
- var args = [];
200
- for (var _i = 0; _i < arguments.length; _i++) {
201
- args[_i] = arguments[_i];
202
- }
203
- var parentSpan = plugin._getParentSpan(this, AttributeNames.MOUNTING_SPAN);
204
- var apply = plugin._instrumentFunction(this, 'componentDidMount', parentSpan, function () {
205
- return original.apply(_this, args);
173
+ _patchComponentDidMount() {
174
+ return (original) => {
175
+ const plugin = this;
176
+ return function patchComponentDidMount(...args) {
177
+ const parentSpan = plugin._getParentSpan(this, AttributeNames.MOUNTING_SPAN);
178
+ const apply = plugin._instrumentFunction(this, 'componentDidMount', parentSpan, () => {
179
+ return original.apply(this, args);
206
180
  });
207
181
  plugin._endParentSpan(this);
208
182
  return apply;
209
183
  };
210
184
  };
211
- };
185
+ }
212
186
  /**
213
187
  * Patches the setState function
214
188
  */
215
- BaseOpenTelemetryComponent.prototype._patchSetState = function () {
216
- var _this = this;
217
- return function (original) {
218
- var plugin = _this;
219
- return function patchSetState() {
220
- var _this = this;
221
- var args = [];
222
- for (var _i = 0; _i < arguments.length; _i++) {
223
- args[_i] = arguments[_i];
224
- }
225
- var parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
226
- return plugin._instrumentFunction(this, 'setState()', parentSpan, function () {
227
- return original.apply(_this, args);
189
+ _patchSetState() {
190
+ return (original) => {
191
+ const plugin = this;
192
+ return function patchSetState(...args) {
193
+ const parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
194
+ return plugin._instrumentFunction(this, 'setState()', parentSpan, () => {
195
+ return original.apply(this, args);
228
196
  });
229
197
  };
230
198
  };
231
- };
199
+ }
232
200
  /**
233
201
  * Patches the forceUpdate function
234
202
  */
235
- BaseOpenTelemetryComponent.prototype._patchForceUpdate = function () {
236
- var _this = this;
237
- return function (original) {
238
- var plugin = _this;
239
- return function patchForceUpdate() {
240
- var _this = this;
241
- var args = [];
242
- for (var _i = 0; _i < arguments.length; _i++) {
243
- args[_i] = arguments[_i];
244
- }
245
- var parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
246
- return plugin._instrumentFunction(this, 'forceUpdate()', parentSpan, function () {
247
- return original.apply(_this, args);
203
+ _patchForceUpdate() {
204
+ return (original) => {
205
+ const plugin = this;
206
+ return function patchForceUpdate(...args) {
207
+ const parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
208
+ return plugin._instrumentFunction(this, 'forceUpdate()', parentSpan, () => {
209
+ return original.apply(this, args);
248
210
  });
249
211
  };
250
212
  };
251
- };
213
+ }
252
214
  /**
253
215
  * Patches the shouldComponentUpdate lifecycle method
254
216
  */
255
- BaseOpenTelemetryComponent.prototype._patchShouldComponentUpdate = function () {
256
- var _this = this;
257
- return function (original) {
258
- var plugin = _this;
259
- return function patchShouldComponentUpdate() {
260
- var _this = this;
261
- var args = [];
262
- for (var _i = 0; _i < arguments.length; _i++) {
263
- args[_i] = arguments[_i];
264
- }
265
- var parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
266
- var apply = plugin._instrumentFunction(this, 'shouldComponentUpdate', parentSpan, function () {
267
- return original.apply(_this, args);
217
+ _patchShouldComponentUpdate() {
218
+ return (original) => {
219
+ const plugin = this;
220
+ return function patchShouldComponentUpdate(...args) {
221
+ const parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
222
+ const apply = plugin._instrumentFunction(this, 'shouldComponentUpdate', parentSpan, () => {
223
+ return original.apply(this, args);
268
224
  });
269
225
  // if shouldComponentUpdate returns false, the component does not get
270
226
  // updated and no other lifecycle methods get called
@@ -274,75 +230,57 @@ var BaseOpenTelemetryComponent = /** @class */ (function (_super) {
274
230
  return apply;
275
231
  };
276
232
  };
277
- };
233
+ }
278
234
  /**
279
235
  * Patches the shouldComponentUpdate lifecycle method
280
236
  */
281
- BaseOpenTelemetryComponent.prototype._patchGetSnapshotBeforeUpdate = function () {
282
- var _this = this;
283
- return function (original) {
284
- var plugin = _this;
285
- return function patchGetSnapshotBeforeUpdate() {
286
- var _this = this;
287
- var args = [];
288
- for (var _i = 0; _i < arguments.length; _i++) {
289
- args[_i] = arguments[_i];
290
- }
291
- var parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
292
- return plugin._instrumentFunction(this, 'getSnapshotBeforeUpdate', parentSpan, function () {
293
- return original.apply(_this, args);
237
+ _patchGetSnapshotBeforeUpdate() {
238
+ return (original) => {
239
+ const plugin = this;
240
+ return function patchGetSnapshotBeforeUpdate(...args) {
241
+ const parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
242
+ return plugin._instrumentFunction(this, 'getSnapshotBeforeUpdate', parentSpan, () => {
243
+ return original.apply(this, args);
294
244
  });
295
245
  };
296
246
  };
297
- };
247
+ }
298
248
  /**
299
249
  * Patches the componentDidUpdate lifecycle method
300
250
  */
301
- BaseOpenTelemetryComponent.prototype._patchComponentDidUpdate = function () {
302
- var _this = this;
303
- return function (original) {
304
- var plugin = _this;
305
- return function patchComponentDidUpdate() {
306
- var _this = this;
307
- var args = [];
308
- for (var _i = 0; _i < arguments.length; _i++) {
309
- args[_i] = arguments[_i];
310
- }
311
- var parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
312
- var apply = plugin._instrumentFunction(this, 'componentDidUpdate', parentSpan, function () {
313
- return original.apply(_this, args);
251
+ _patchComponentDidUpdate() {
252
+ return (original) => {
253
+ const plugin = this;
254
+ return function patchComponentDidUpdate(...args) {
255
+ const parentSpan = plugin._getParentSpan(this, AttributeNames.UPDATING_SPAN);
256
+ const apply = plugin._instrumentFunction(this, 'componentDidUpdate', parentSpan, () => {
257
+ return original.apply(this, args);
314
258
  });
315
259
  plugin._endParentSpan(this);
316
260
  return apply;
317
261
  };
318
262
  };
319
- };
263
+ }
320
264
  /**
321
265
  * Patches the componentWillUnmount lifecycle method
322
266
  */
323
- BaseOpenTelemetryComponent.prototype._patchComponentWillUnmount = function () {
324
- var _this = this;
325
- return function (original) {
326
- var plugin = _this;
327
- return function patchComponentWillUnmount() {
328
- var _this = this;
329
- var args = [];
330
- for (var _i = 0; _i < arguments.length; _i++) {
331
- args[_i] = arguments[_i];
332
- }
333
- var parentSpan = plugin._getParentSpan(this, AttributeNames.UNMOUNTING_SPAN);
334
- var apply = plugin._instrumentFunction(this, 'componentWillUnmount', parentSpan, function () {
335
- return original.apply(_this, args);
267
+ _patchComponentWillUnmount() {
268
+ return (original) => {
269
+ const plugin = this;
270
+ return function patchComponentWillUnmount(...args) {
271
+ const parentSpan = plugin._getParentSpan(this, AttributeNames.UNMOUNTING_SPAN);
272
+ const apply = plugin._instrumentFunction(this, 'componentWillUnmount', parentSpan, () => {
273
+ return original.apply(this, args);
336
274
  });
337
275
  plugin._endParentSpan(this);
338
276
  return apply;
339
277
  };
340
278
  };
341
- };
279
+ }
342
280
  /**
343
281
  * patch function which wraps all the lifecycle methods
344
282
  */
345
- BaseOpenTelemetryComponent.prototype.patch = function () {
283
+ patch() {
346
284
  BaseOpenTelemetryComponent._logger.debug('applying patch to', this.moduleName, PACKAGE_VERSION);
347
285
  if (isWrapped(this.render)) {
348
286
  shimmer.unwrap(this, 'render');
@@ -378,32 +316,32 @@ var BaseOpenTelemetryComponent = /** @class */ (function (_super) {
378
316
  }
379
317
  // Lifecycle methods must exist when patching, even if not defined in component
380
318
  if (!this.render) {
381
- this.render = function () {
319
+ this.render = () => {
382
320
  return null;
383
321
  };
384
322
  }
385
323
  if (!this.componentDidMount) {
386
- this.componentDidMount = function () {
324
+ this.componentDidMount = () => {
387
325
  return;
388
326
  };
389
327
  }
390
328
  if (!this.shouldComponentUpdate) {
391
- this.shouldComponentUpdate = function () {
329
+ this.shouldComponentUpdate = () => {
392
330
  return true;
393
331
  };
394
332
  }
395
333
  if (!this.getSnapshotBeforeUpdate) {
396
- this.getSnapshotBeforeUpdate = function () {
334
+ this.getSnapshotBeforeUpdate = () => {
397
335
  return null;
398
336
  };
399
337
  }
400
338
  if (!this.componentDidUpdate) {
401
- this.componentDidUpdate = function () {
339
+ this.componentDidUpdate = () => {
402
340
  return;
403
341
  };
404
342
  }
405
343
  if (!this.componentWillUnmount) {
406
- this.componentWillUnmount = function () {
344
+ this.componentWillUnmount = () => {
407
345
  return;
408
346
  };
409
347
  }
@@ -415,11 +353,11 @@ var BaseOpenTelemetryComponent = /** @class */ (function (_super) {
415
353
  shimmer.wrap(this, 'getSnapshotBeforeUpdate', this._patchGetSnapshotBeforeUpdate());
416
354
  shimmer.wrap(this, 'componentDidUpdate', this._patchComponentDidUpdate());
417
355
  shimmer.wrap(this, 'componentWillUnmount', this._patchComponentWillUnmount());
418
- };
356
+ }
419
357
  /**
420
358
  * unpatch function to unwrap all the lifecycle methods
421
359
  */
422
- BaseOpenTelemetryComponent.prototype.unpatch = function () {
360
+ unpatch() {
423
361
  BaseOpenTelemetryComponent._logger.debug('removing patch from', this.moduleName, PACKAGE_VERSION);
424
362
  shimmer.unwrap(this, 'render');
425
363
  shimmer.unwrap(this, 'componentDidMount');
@@ -430,9 +368,7 @@ var BaseOpenTelemetryComponent = /** @class */ (function (_super) {
430
368
  shimmer.unwrap(this, 'componentDidUpdate');
431
369
  shimmer.unwrap(this, 'componentWillUnmount');
432
370
  this._parentSpanMap = new WeakMap();
433
- };
434
- BaseOpenTelemetryComponent._logger = api.diag;
435
- return BaseOpenTelemetryComponent;
436
- }(React.Component));
371
+ }
372
+ }
437
373
  export { BaseOpenTelemetryComponent };
438
374
  //# sourceMappingURL=BaseOpenTelemetryComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseOpenTelemetryComponent.js","sourceRoot":"","sources":["../../src/BaseOpenTelemetryComponent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB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I,EAAE,oBAAoB,EAAE,IAAI,CAAC,wBAAwB,EAAE,CAAC,CAAC;QAC1E,OAAO,CAAC,IAAI,CACV,IAAI,EACJ,sBAAsB,EACtB,IAAI,CAAC,0BAA0B,EAAE,CAClC,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,4CAAO,GAAd;QACE,0BAA0B,CAAC,OAAO,CAAC,KAAK,CACtC,qBAAqB,EACrB,IAAI,CAAC,UAAU,EACf,eAAe,CAChB,CAAC;QAEF,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAE/B,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;QAE1C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACjC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACpC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;QAC9C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;QAE3C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;QAE7C,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAA6B,CAAC;IACjE,CAAC;IAjgBc,kCAAO,GAAmB,GAAG,CAAC,IAAI,CAAC;IAkgBpD,iCAAC;CAAA,AAvgBD,CAAgD,KAAK,CAAC,SAAS,GAugB9D;SAvgBY,0BAA0B","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport { isWrapped } from '@opentelemetry/core';\nimport * as shimmer from 'shimmer';\nimport { AttributeNames } from './enums/AttributeNames';\nimport * as React from 'react';\nimport { PACKAGE_VERSION } from './version';\nimport {\n RenderFunction,\n ComponentDidMountFunction,\n ComponentDidUpdateFunction,\n ShouldComponentUpdateFunction,\n SetStateFunction,\n ForceUpdateFunction,\n GetSnapshotBeforeUpdateFunction,\n ComponentWillUnmountFunction,\n} from './internal-types';\n\n/**\n * This class is the base component for a React component with lifecycle instrumentation\n */\nexport class BaseOpenTelemetryComponent extends React.Component {\n readonly component: string = 'react-load';\n moduleName = this.component;\n private _parentSpanMap: WeakMap<React.Component, api.Span>;\n private static _tracer: api.Tracer;\n private static _logger: api.DiagLogger = api.diag;\n\n /**\n * @param props Props of the React component\n */\n constructor(props: Readonly<any>) {\n super(props);\n this._parentSpanMap = new WeakMap<React.Component, api.Span>();\n this.patch();\n }\n\n /**\n * Sets the tracer for all components being instrumented\n * @param name Name of tracer\n * @param version Version of tracer, this is optional. When not provided it will use the latest.\n */\n static setTracer(name: string, version?: string): void {\n BaseOpenTelemetryComponent._tracer = api.trace.getTracer(\n name,\n version ? version : PACKAGE_VERSION\n );\n }\n\n /**\n * Sets the logger for all components being instrumented\n * @param logger\n */\n static setLogger(logger: api.DiagLogger): void {\n api.diag.setLogger(logger);\n BaseOpenTelemetryComponent._logger = logger;\n }\n\n /**\n * Creates a new span as a child of the current parent span.\n * If parent span is undefined, just the child is created.\n * @param react React component currently being instrumented\n * @param name Name of span\n * @param parentSpan parent span\n */\n private _createSpanWithParent(\n react: React.Component,\n name: string,\n parentSpan: api.Span\n ): api.Span {\n return BaseOpenTelemetryComponent._tracer.startSpan(\n name,\n {\n attributes: this._getAttributes(react),\n },\n parentSpan\n ? api.trace.setSpan(api.context.active(), parentSpan)\n : undefined\n );\n }\n\n /**\n * Creates a new span\n * @param react React component currently being instrumented\n * @param name Name of span\n */\n private _createSpan(react: React.Component, name: string): api.Span {\n return BaseOpenTelemetryComponent._tracer.startSpan(name, {\n attributes: this._getAttributes(react),\n });\n }\n\n /**\n * Provides instrumentation for a function\n * @param react React component currently instrumenting.\n * @param spanName Name to set the span of the instrumented function to.\n * @param original Original function currently being wrapped.\n * @parentName Name to set parent span to on error.\n */\n private _instrumentFunction(\n react: React.Component,\n spanName: string,\n parent: api.Span,\n original: any\n ) {\n const span = this._createSpanWithParent(react, spanName, parent);\n let wasError = false;\n try {\n return api.context.with(\n api.trace.setSpan(api.context.active(), span),\n () => {\n return original();\n }\n );\n } catch (err: any) {\n span.setAttribute(AttributeNames.REACT_ERROR, err.stack);\n wasError = true;\n throw err;\n } finally {\n span.end();\n if (wasError) {\n this._endParentSpan(react);\n }\n }\n }\n\n /**\n * Ends the current parent span.\n * @param react React component parent span belongs to.\n */\n private _endParentSpan(react: React.Component) {\n const parentSpan = this._parentSpanMap.get(react);\n if (parentSpan) {\n parentSpan.end();\n this._parentSpanMap.delete(react);\n }\n }\n\n /**\n * Returns attributes object for spans\n * @param react React component currently being instrumented\n **/\n private _getAttributes(react: React.Component) {\n let state: string;\n try {\n state = JSON.stringify(react.state);\n } catch {\n state = '{\"message\": \"state could not be turned into string\"}';\n }\n return {\n [AttributeNames.LOCATION_URL]: window.location.href,\n [AttributeNames.REACT_NAME]: react.constructor.name,\n [AttributeNames.REACT_STATE]: state,\n };\n }\n\n /**\n * This function returns a parent span. If the parent doesn't\n * exist, the function creates one\n * @param react React component parent span belongs to.\n */\n private _getParentSpan(react: React.Component, parentName: string): api.Span {\n const parentSpan: api.Span | undefined = this._parentSpanMap.get(react);\n if (!parentSpan) {\n const span = this._createSpan(react, parentName);\n this._parentSpanMap.set(react, span);\n }\n return this._parentSpanMap.get(react)!;\n }\n\n /**\n * Patches the render lifecycle method\n */\n private _patchRender() {\n return (original: RenderFunction): RenderFunction => {\n const plugin = this;\n return function patchRender(\n this: React.Component,\n ...args\n ): React.ReactNode {\n // Render is the first method in the mounting flow, if a parent span wasn't created already then we're in the mounting flow\n let parentSpan: api.Span;\n if (!plugin._parentSpanMap.get(this)) {\n parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.MOUNTING_SPAN\n );\n } else {\n parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n }\n\n return plugin._instrumentFunction(this, 'render', parentSpan, () => {\n return original!.apply(this, args);\n });\n };\n };\n }\n\n /**\n * Patches the componentDidMount lifecycle method\n */\n private _patchComponentDidMount() {\n return (original: ComponentDidMountFunction): ComponentDidMountFunction => {\n const plugin = this;\n\n return function patchComponentDidMount(\n this: React.Component,\n ...args\n ): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.MOUNTING_SPAN\n );\n const apply = plugin._instrumentFunction(\n this,\n 'componentDidMount',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n plugin._endParentSpan(this);\n return apply;\n };\n };\n }\n\n /**\n * Patches the setState function\n */\n private _patchSetState() {\n return (original: SetStateFunction): SetStateFunction => {\n const plugin = this;\n return function patchSetState(this: React.Component, ...args): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n return plugin._instrumentFunction(\n this,\n 'setState()',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n };\n };\n }\n\n /**\n * Patches the forceUpdate function\n */\n private _patchForceUpdate() {\n return (original: ForceUpdateFunction): ForceUpdateFunction => {\n const plugin = this;\n return function patchForceUpdate(this: React.Component, ...args): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n return plugin._instrumentFunction(\n this,\n 'forceUpdate()',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n };\n };\n }\n\n /**\n * Patches the shouldComponentUpdate lifecycle method\n */\n private _patchShouldComponentUpdate() {\n return (\n original: ShouldComponentUpdateFunction\n ): ShouldComponentUpdateFunction => {\n const plugin = this;\n\n return function patchShouldComponentUpdate(\n this: React.Component,\n ...args\n ): boolean {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n const apply = plugin._instrumentFunction(\n this,\n 'shouldComponentUpdate',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n // if shouldComponentUpdate returns false, the component does not get\n // updated and no other lifecycle methods get called\n if (!apply) {\n plugin._endParentSpan(this);\n }\n\n return apply;\n };\n };\n }\n\n /**\n * Patches the shouldComponentUpdate lifecycle method\n */\n private _patchGetSnapshotBeforeUpdate() {\n return (\n original: GetSnapshotBeforeUpdateFunction\n ): GetSnapshotBeforeUpdateFunction => {\n const plugin = this;\n\n return function patchGetSnapshotBeforeUpdate(\n this: React.Component,\n ...args\n ): any {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n return plugin._instrumentFunction(\n this,\n 'getSnapshotBeforeUpdate',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n };\n };\n }\n\n /**\n * Patches the componentDidUpdate lifecycle method\n */\n private _patchComponentDidUpdate() {\n return (\n original: ComponentDidUpdateFunction\n ): ComponentDidUpdateFunction => {\n const plugin = this;\n\n return function patchComponentDidUpdate(\n this: React.Component,\n ...args\n ): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n const apply = plugin._instrumentFunction(\n this,\n 'componentDidUpdate',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n plugin._endParentSpan(this);\n return apply;\n };\n };\n }\n\n /**\n * Patches the componentWillUnmount lifecycle method\n */\n private _patchComponentWillUnmount() {\n return (\n original: ComponentWillUnmountFunction\n ): ComponentWillUnmountFunction => {\n const plugin = this;\n\n return function patchComponentWillUnmount(\n this: React.Component,\n ...args\n ): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UNMOUNTING_SPAN\n );\n const apply = plugin._instrumentFunction(\n this,\n 'componentWillUnmount',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n plugin._endParentSpan(this);\n return apply;\n };\n };\n }\n\n /**\n * patch function which wraps all the lifecycle methods\n */\n public patch(): void {\n BaseOpenTelemetryComponent._logger.debug(\n 'applying patch to',\n this.moduleName,\n PACKAGE_VERSION\n );\n\n if (isWrapped(this.render)) {\n shimmer.unwrap(this, 'render');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method render'\n );\n }\n if (isWrapped(this.componentDidMount)) {\n shimmer.unwrap(this, 'componentDidMount');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method componentDidMount'\n );\n }\n if (isWrapped(this.shouldComponentUpdate)) {\n shimmer.unwrap(this, 'shouldComponentUpdate');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method shouldComponentUpdate'\n );\n }\n if (isWrapped(this.getSnapshotBeforeUpdate)) {\n shimmer.unwrap(this, 'getSnapshotBeforeUpdate');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method getSnapshotBeforeUpdate'\n );\n }\n if (isWrapped(this.setState)) {\n shimmer.unwrap(this, 'setState');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method setState'\n );\n }\n if (isWrapped(this.forceUpdate)) {\n shimmer.unwrap(this, 'forceUpdate');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method forceUpdate'\n );\n }\n if (isWrapped(this.componentDidUpdate)) {\n shimmer.unwrap(this, 'componentDidUpdate');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method componentDidUpdate'\n );\n }\n if (isWrapped(this.componentWillUnmount)) {\n shimmer.unwrap(this, 'componentWillUnmount');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method componentWillUnmount'\n );\n }\n\n // Lifecycle methods must exist when patching, even if not defined in component\n if (!this.render) {\n this.render = () => {\n return null;\n };\n }\n if (!this.componentDidMount) {\n this.componentDidMount = () => {\n return;\n };\n }\n if (!this.shouldComponentUpdate) {\n this.shouldComponentUpdate = () => {\n return true;\n };\n }\n if (!this.getSnapshotBeforeUpdate) {\n this.getSnapshotBeforeUpdate = () => {\n return null;\n };\n }\n if (!this.componentDidUpdate) {\n this.componentDidUpdate = () => {\n return;\n };\n }\n if (!this.componentWillUnmount) {\n this.componentWillUnmount = () => {\n return;\n };\n }\n\n shimmer.wrap(this, 'render', this._patchRender());\n shimmer.wrap(this, 'componentDidMount', this._patchComponentDidMount());\n shimmer.wrap(this, 'setState', this._patchSetState());\n shimmer.wrap(this, 'forceUpdate', this._patchForceUpdate());\n shimmer.wrap(\n this,\n 'shouldComponentUpdate',\n this._patchShouldComponentUpdate()\n );\n shimmer.wrap(\n this,\n 'getSnapshotBeforeUpdate',\n this._patchGetSnapshotBeforeUpdate()\n );\n shimmer.wrap(this, 'componentDidUpdate', this._patchComponentDidUpdate());\n shimmer.wrap(\n this,\n 'componentWillUnmount',\n this._patchComponentWillUnmount()\n );\n }\n\n /**\n * unpatch function to unwrap all the lifecycle methods\n */\n public unpatch(): void {\n BaseOpenTelemetryComponent._logger.debug(\n 'removing patch from',\n this.moduleName,\n PACKAGE_VERSION\n );\n\n shimmer.unwrap(this, 'render');\n\n shimmer.unwrap(this, 'componentDidMount');\n\n shimmer.unwrap(this, 'setState');\n shimmer.unwrap(this, 'forceUpdate');\n shimmer.unwrap(this, 'shouldComponentUpdate');\n shimmer.unwrap(this, 'getSnapshotBeforeUpdate');\n shimmer.unwrap(this, 'componentDidUpdate');\n\n shimmer.unwrap(this, 'componentWillUnmount');\n\n this._parentSpanMap = new WeakMap<React.Component, api.Span>();\n }\n}\n"]}
1
+ {"version":3,"file":"BaseOpenTelemetryComponent.js","sourceRoot":"","sources":["../../src/BaseOpenTelemetryComponent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,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IAAI,EAAE,mBAAmB,CAAC,CAAC;QAE1C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACjC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACpC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;QAC9C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;QAE3C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;QAE7C,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAA6B,CAAC;IACjE,CAAC;;SAtgBU,0BAA0B","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport { isWrapped } from '@opentelemetry/instrumentation';\nimport * as shimmer from 'shimmer';\nimport { AttributeNames } from './enums/AttributeNames';\nimport * as React from 'react';\n/** @knipignore */\nimport { PACKAGE_VERSION } from './version';\nimport {\n RenderFunction,\n ComponentDidMountFunction,\n ComponentDidUpdateFunction,\n ShouldComponentUpdateFunction,\n SetStateFunction,\n ForceUpdateFunction,\n GetSnapshotBeforeUpdateFunction,\n ComponentWillUnmountFunction,\n} from './internal-types';\n\n/**\n * This class is the base component for a React component with lifecycle instrumentation\n */\nexport class BaseOpenTelemetryComponent extends React.Component {\n readonly component: string = 'react-load';\n moduleName = this.component;\n private _parentSpanMap: WeakMap<React.Component, api.Span>;\n private static _tracer: api.Tracer;\n private static _logger: api.DiagLogger = api.diag;\n\n /**\n * @param props Props of the React component\n */\n constructor(props: Readonly<any>) {\n super(props);\n this._parentSpanMap = new WeakMap<React.Component, api.Span>();\n this.patch();\n }\n\n /**\n * Sets the tracer for all components being instrumented\n * @param name Name of tracer\n * @param version Version of tracer, this is optional. When not provided it will use the latest.\n */\n static setTracer(name: string, version?: string): void {\n BaseOpenTelemetryComponent._tracer = api.trace.getTracer(\n name,\n version ? version : PACKAGE_VERSION\n );\n }\n\n /**\n * Sets the logger for all components being instrumented\n * @param logger\n */\n static setLogger(logger: api.DiagLogger): void {\n api.diag.setLogger(logger);\n BaseOpenTelemetryComponent._logger = logger;\n }\n\n /**\n * Creates a new span as a child of the current parent span.\n * If parent span is undefined, just the child is created.\n * @param react React component currently being instrumented\n * @param name Name of span\n * @param parentSpan parent span\n */\n private _createSpanWithParent(\n react: React.Component,\n name: string,\n parentSpan: api.Span\n ): api.Span {\n return BaseOpenTelemetryComponent._tracer.startSpan(\n name,\n {\n attributes: this._getAttributes(react),\n },\n parentSpan\n ? api.trace.setSpan(api.context.active(), parentSpan)\n : undefined\n );\n }\n\n /**\n * Creates a new span\n * @param react React component currently being instrumented\n * @param name Name of span\n */\n private _createSpan(react: React.Component, name: string): api.Span {\n return BaseOpenTelemetryComponent._tracer.startSpan(name, {\n attributes: this._getAttributes(react),\n });\n }\n\n /**\n * Provides instrumentation for a function\n * @param react React component currently instrumenting.\n * @param spanName Name to set the span of the instrumented function to.\n * @param original Original function currently being wrapped.\n * @parentName Name to set parent span to on error.\n */\n private _instrumentFunction(\n react: React.Component,\n spanName: string,\n parent: api.Span,\n original: any\n ) {\n const span = this._createSpanWithParent(react, spanName, parent);\n let wasError = false;\n try {\n return api.context.with(\n api.trace.setSpan(api.context.active(), span),\n () => {\n return original();\n }\n );\n } catch (err: any) {\n span.setAttribute(AttributeNames.REACT_ERROR, err.stack);\n wasError = true;\n throw err;\n } finally {\n span.end();\n if (wasError) {\n this._endParentSpan(react);\n }\n }\n }\n\n /**\n * Ends the current parent span.\n * @param react React component parent span belongs to.\n */\n private _endParentSpan(react: React.Component) {\n const parentSpan = this._parentSpanMap.get(react);\n if (parentSpan) {\n parentSpan.end();\n this._parentSpanMap.delete(react);\n }\n }\n\n /**\n * Returns attributes object for spans\n * @param react React component currently being instrumented\n **/\n private _getAttributes(react: React.Component) {\n let state: string;\n try {\n state = JSON.stringify(react.state);\n } catch {\n state = '{\"message\": \"state could not be turned into string\"}';\n }\n return {\n [AttributeNames.LOCATION_URL]: window.location.href,\n [AttributeNames.REACT_NAME]: react.constructor.name,\n [AttributeNames.REACT_STATE]: state,\n };\n }\n\n /**\n * This function returns a parent span. If the parent doesn't\n * exist, the function creates one\n * @param react React component parent span belongs to.\n */\n private _getParentSpan(react: React.Component, parentName: string): api.Span {\n const parentSpan: api.Span | undefined = this._parentSpanMap.get(react);\n if (!parentSpan) {\n const span = this._createSpan(react, parentName);\n this._parentSpanMap.set(react, span);\n }\n return this._parentSpanMap.get(react)!;\n }\n\n /**\n * Patches the render lifecycle method\n */\n private _patchRender() {\n return (original: RenderFunction): RenderFunction => {\n const plugin = this;\n return function patchRender(\n this: React.Component,\n ...args\n ): React.ReactNode {\n // Render is the first method in the mounting flow, if a parent span wasn't created already then we're in the mounting flow\n let parentSpan: api.Span;\n if (!plugin._parentSpanMap.get(this)) {\n parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.MOUNTING_SPAN\n );\n } else {\n parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n }\n\n return plugin._instrumentFunction(this, 'render', parentSpan, () => {\n return original!.apply(this, args);\n });\n };\n };\n }\n\n /**\n * Patches the componentDidMount lifecycle method\n */\n private _patchComponentDidMount() {\n return (original: ComponentDidMountFunction): ComponentDidMountFunction => {\n const plugin = this;\n\n return function patchComponentDidMount(\n this: React.Component,\n ...args\n ): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.MOUNTING_SPAN\n );\n const apply = plugin._instrumentFunction(\n this,\n 'componentDidMount',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n plugin._endParentSpan(this);\n return apply;\n };\n };\n }\n\n /**\n * Patches the setState function\n */\n private _patchSetState() {\n return (original: SetStateFunction): SetStateFunction => {\n const plugin = this;\n return function patchSetState(this: React.Component, ...args): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n return plugin._instrumentFunction(\n this,\n 'setState()',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n };\n };\n }\n\n /**\n * Patches the forceUpdate function\n */\n private _patchForceUpdate() {\n return (original: ForceUpdateFunction): ForceUpdateFunction => {\n const plugin = this;\n return function patchForceUpdate(this: React.Component, ...args): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n return plugin._instrumentFunction(\n this,\n 'forceUpdate()',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n };\n };\n }\n\n /**\n * Patches the shouldComponentUpdate lifecycle method\n */\n private _patchShouldComponentUpdate() {\n return (\n original: ShouldComponentUpdateFunction\n ): ShouldComponentUpdateFunction => {\n const plugin = this;\n\n return function patchShouldComponentUpdate(\n this: React.Component,\n ...args\n ): boolean {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n const apply = plugin._instrumentFunction(\n this,\n 'shouldComponentUpdate',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n // if shouldComponentUpdate returns false, the component does not get\n // updated and no other lifecycle methods get called\n if (!apply) {\n plugin._endParentSpan(this);\n }\n\n return apply;\n };\n };\n }\n\n /**\n * Patches the shouldComponentUpdate lifecycle method\n */\n private _patchGetSnapshotBeforeUpdate() {\n return (\n original: GetSnapshotBeforeUpdateFunction\n ): GetSnapshotBeforeUpdateFunction => {\n const plugin = this;\n\n return function patchGetSnapshotBeforeUpdate(\n this: React.Component,\n ...args\n ): any {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n return plugin._instrumentFunction(\n this,\n 'getSnapshotBeforeUpdate',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n };\n };\n }\n\n /**\n * Patches the componentDidUpdate lifecycle method\n */\n private _patchComponentDidUpdate() {\n return (\n original: ComponentDidUpdateFunction\n ): ComponentDidUpdateFunction => {\n const plugin = this;\n\n return function patchComponentDidUpdate(\n this: React.Component,\n ...args\n ): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UPDATING_SPAN\n );\n const apply = plugin._instrumentFunction(\n this,\n 'componentDidUpdate',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n plugin._endParentSpan(this);\n return apply;\n };\n };\n }\n\n /**\n * Patches the componentWillUnmount lifecycle method\n */\n private _patchComponentWillUnmount() {\n return (\n original: ComponentWillUnmountFunction\n ): ComponentWillUnmountFunction => {\n const plugin = this;\n\n return function patchComponentWillUnmount(\n this: React.Component,\n ...args\n ): void {\n const parentSpan = plugin._getParentSpan(\n this,\n AttributeNames.UNMOUNTING_SPAN\n );\n const apply = plugin._instrumentFunction(\n this,\n 'componentWillUnmount',\n parentSpan,\n () => {\n return original!.apply(this, args);\n }\n );\n plugin._endParentSpan(this);\n return apply;\n };\n };\n }\n\n /**\n * patch function which wraps all the lifecycle methods\n */\n public patch(): void {\n BaseOpenTelemetryComponent._logger.debug(\n 'applying patch to',\n this.moduleName,\n PACKAGE_VERSION\n );\n\n if (isWrapped(this.render)) {\n shimmer.unwrap(this, 'render');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method render'\n );\n }\n if (isWrapped(this.componentDidMount)) {\n shimmer.unwrap(this, 'componentDidMount');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method componentDidMount'\n );\n }\n if (isWrapped(this.shouldComponentUpdate)) {\n shimmer.unwrap(this, 'shouldComponentUpdate');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method shouldComponentUpdate'\n );\n }\n if (isWrapped(this.getSnapshotBeforeUpdate)) {\n shimmer.unwrap(this, 'getSnapshotBeforeUpdate');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method getSnapshotBeforeUpdate'\n );\n }\n if (isWrapped(this.setState)) {\n shimmer.unwrap(this, 'setState');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method setState'\n );\n }\n if (isWrapped(this.forceUpdate)) {\n shimmer.unwrap(this, 'forceUpdate');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method forceUpdate'\n );\n }\n if (isWrapped(this.componentDidUpdate)) {\n shimmer.unwrap(this, 'componentDidUpdate');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method componentDidUpdate'\n );\n }\n if (isWrapped(this.componentWillUnmount)) {\n shimmer.unwrap(this, 'componentWillUnmount');\n BaseOpenTelemetryComponent._logger.warn(\n 'removing previous patch from method componentWillUnmount'\n );\n }\n\n // Lifecycle methods must exist when patching, even if not defined in component\n if (!this.render) {\n this.render = () => {\n return null;\n };\n }\n if (!this.componentDidMount) {\n this.componentDidMount = () => {\n return;\n };\n }\n if (!this.shouldComponentUpdate) {\n this.shouldComponentUpdate = () => {\n return true;\n };\n }\n if (!this.getSnapshotBeforeUpdate) {\n this.getSnapshotBeforeUpdate = () => {\n return null;\n };\n }\n if (!this.componentDidUpdate) {\n this.componentDidUpdate = () => {\n return;\n };\n }\n if (!this.componentWillUnmount) {\n this.componentWillUnmount = () => {\n return;\n };\n }\n\n shimmer.wrap(this, 'render', this._patchRender());\n shimmer.wrap(this, 'componentDidMount', this._patchComponentDidMount());\n shimmer.wrap(this, 'setState', this._patchSetState());\n shimmer.wrap(this, 'forceUpdate', this._patchForceUpdate());\n shimmer.wrap(\n this,\n 'shouldComponentUpdate',\n this._patchShouldComponentUpdate()\n );\n shimmer.wrap(\n this,\n 'getSnapshotBeforeUpdate',\n this._patchGetSnapshotBeforeUpdate()\n );\n shimmer.wrap(this, 'componentDidUpdate', this._patchComponentDidUpdate());\n shimmer.wrap(\n this,\n 'componentWillUnmount',\n this._patchComponentWillUnmount()\n );\n }\n\n /**\n * unpatch function to unwrap all the lifecycle methods\n */\n public unpatch(): void {\n BaseOpenTelemetryComponent._logger.debug(\n 'removing patch from',\n this.moduleName,\n PACKAGE_VERSION\n );\n\n shimmer.unwrap(this, 'render');\n\n shimmer.unwrap(this, 'componentDidMount');\n\n shimmer.unwrap(this, 'setState');\n shimmer.unwrap(this, 'forceUpdate');\n shimmer.unwrap(this, 'shouldComponentUpdate');\n shimmer.unwrap(this, 'getSnapshotBeforeUpdate');\n shimmer.unwrap(this, 'componentDidUpdate');\n\n shimmer.unwrap(this, 'componentWillUnmount');\n\n this._parentSpanMap = new WeakMap<React.Component, api.Span>();\n }\n}\n"]}