@sentry/browser 5.28.0 → 5.30.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,4 +1,4 @@
1
- /*! @sentry/browser 5.28.0 (705af78) | https://github.com/getsentry/sentry-javascript */
1
+ /*! @sentry/browser 5.30.0 (6de2dd4) | https://github.com/getsentry/sentry-javascript */
2
2
  var Sentry = (function (exports) {
3
3
  /** Console logging verbosity for the SDK. */
4
4
  var LogLevel;
@@ -117,6 +117,14 @@ var Sentry = (function (exports) {
117
117
  Status.fromHttpCode = fromHttpCode;
118
118
  })(exports.Status || (exports.Status = {}));
119
119
 
120
+ var TransactionSamplingMethod;
121
+ (function (TransactionSamplingMethod) {
122
+ TransactionSamplingMethod["Explicit"] = "explicitly_set";
123
+ TransactionSamplingMethod["Sampler"] = "client_sampler";
124
+ TransactionSamplingMethod["Rate"] = "client_rate";
125
+ TransactionSamplingMethod["Inheritance"] = "inheritance";
126
+ })(TransactionSamplingMethod || (TransactionSamplingMethod = {}));
127
+
120
128
  /* eslint-disable @typescript-eslint/no-explicit-any */
121
129
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
122
130
  /**
@@ -179,7 +187,7 @@ var Sentry = (function (exports) {
179
187
  return Object.prototype.toString.call(wat) === '[object String]';
180
188
  }
181
189
  /**
182
- * Checks whether given value's is a primitive (undefined, null, number, boolean, string)
190
+ * Checks whether given value's is a primitive (undefined, null, number, boolean, string, bigint, symbol)
183
191
  * {@link isPrimitive}.
184
192
  *
185
193
  * @param wat A value to be checked.
@@ -533,7 +541,7 @@ var Sentry = (function (exports) {
533
541
  * Truncates given string to the maximum characters count
534
542
  *
535
543
  * @param str An object that contains serializable values
536
- * @param max Maximum number of characters in truncated string
544
+ * @param max Maximum number of characters in truncated string (0 = unlimited)
537
545
  * @returns string Encoded
538
546
  */
539
547
  function truncate(str, max = 0) {
@@ -589,15 +597,16 @@ var Sentry = (function (exports) {
589
597
  *
590
598
  * @param source An object that contains a method to be wrapped.
591
599
  * @param name A name of method to be wrapped.
592
- * @param replacement A function that should be used to wrap a given method.
600
+ * @param replacementFactory A function that should be used to wrap a given method, returning the wrapped method which
601
+ * will be substituted in for `source[name]`.
593
602
  * @returns void
594
603
  */
595
- function fill(source, name, replacement) {
604
+ function fill(source, name, replacementFactory) {
596
605
  if (!(name in source)) {
597
606
  return;
598
607
  }
599
608
  const original = source[name];
600
- const wrapped = replacement(original);
609
+ const wrapped = replacementFactory(original);
601
610
  // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work
602
611
  // otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
603
612
  if (typeof wrapped === 'function') {
@@ -629,10 +638,10 @@ var Sentry = (function (exports) {
629
638
  .join('&');
630
639
  }
631
640
  /**
632
- * Transforms any object into an object literal with all it's attributes
641
+ * Transforms any object into an object literal with all its attributes
633
642
  * attached to it.
634
643
  *
635
- * @param value Initial source that we have to transform in order to be usable by the serializer
644
+ * @param value Initial source that we have to transform in order for it to be usable by the serializer
636
645
  */
637
646
  function getWalkSource(value) {
638
647
  if (isError(value)) {
@@ -703,7 +712,15 @@ var Sentry = (function (exports) {
703
712
  }
704
713
  return serialized;
705
714
  }
706
- /** Transforms any input value into a string form, either primitive value or a type of the input */
715
+ /**
716
+ * Transform any non-primitive, BigInt, or Symbol-type value into a string. Acts as a no-op on strings, numbers,
717
+ * booleans, null, and undefined.
718
+ *
719
+ * @param value The value to stringify
720
+ * @returns For non-primitive, BigInt, and Symbol-type values, a string denoting the value's type, type and value, or
721
+ * type and `description` property, respectively. For non-BigInt, non-Symbol primitives, returns the original value,
722
+ * unchanged.
723
+ */
707
724
  function serializeValue(value) {
708
725
  const type = Object.prototype.toString.call(value);
709
726
  // Node.js REPL notation
@@ -757,6 +774,13 @@ var Sentry = (function (exports) {
757
774
  if (typeof value === 'function') {
758
775
  return `[Function: ${getFunctionName(value)}]`;
759
776
  }
777
+ // symbols and bigints are considered primitives by TS, but aren't natively JSON-serilaizable
778
+ if (typeof value === 'symbol') {
779
+ return `[${String(value)}]`;
780
+ }
781
+ if (typeof value === 'bigint') {
782
+ return `[BigInt: ${String(value)}]`;
783
+ }
760
784
  return value;
761
785
  }
762
786
  /**
@@ -3131,8 +3155,11 @@ var Sentry = (function (exports) {
3131
3155
  }
3132
3156
  /**
3133
3157
  * Set key:value that will be sent as tags data with the event.
3158
+ *
3159
+ * Can also be used to unset a tag, by passing `undefined`.
3160
+ *
3134
3161
  * @param key String key of tag
3135
- * @param value String value of tag
3162
+ * @param value Value of tag
3136
3163
  */
3137
3164
  function setTag(key, value) {
3138
3165
  callOnHub('setTag', key, value);
@@ -3431,7 +3458,7 @@ var Sentry = (function (exports) {
3431
3458
  captureMessage(message, level, hint, scope) {
3432
3459
  let eventId = hint && hint.event_id;
3433
3460
  const promisedEvent = isPrimitive(message)
3434
- ? this._getBackend().eventFromMessage(`${message}`, level, hint)
3461
+ ? this._getBackend().eventFromMessage(String(message), level, hint)
3435
3462
  : this._getBackend().eventFromException(message, hint);
3436
3463
  this._process(promisedEvent
3437
3464
  .then(event => this._captureEvent(event, hint, scope))
@@ -3738,7 +3765,7 @@ var Sentry = (function (exports) {
3738
3765
  // 0.0 === 0% events are sent
3739
3766
  // Sampling for transaction happens somewhere else
3740
3767
  if (!isTransaction && typeof sampleRate === 'number' && Math.random() > sampleRate) {
3741
- return SyncPromise.reject(new SentryError('This event has been sampled, will not send event.'));
3768
+ return SyncPromise.reject(new SentryError(`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`));
3742
3769
  }
3743
3770
  return this._prepareEvent(event, scope, hint)
3744
3771
  .then(prepared => {
@@ -3878,6 +3905,31 @@ var Sentry = (function (exports) {
3878
3905
  }
3879
3906
  }
3880
3907
 
3908
+ /*! *****************************************************************************
3909
+ Copyright (c) Microsoft Corporation. All rights reserved.
3910
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
3911
+ this file except in compliance with the License. You may obtain a copy of the
3912
+ License at http://www.apache.org/licenses/LICENSE-2.0
3913
+
3914
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
3915
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
3916
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
3917
+ MERCHANTABLITY OR NON-INFRINGEMENT.
3918
+
3919
+ See the Apache Version 2.0 License for specific language governing permissions
3920
+ and limitations under the License.
3921
+ ***************************************************************************** */
3922
+
3923
+ function __rest(s, e) {
3924
+ var t = {};
3925
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3926
+ t[p] = s[p];
3927
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3928
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
3929
+ t[p[i]] = s[p[i]];
3930
+ return t;
3931
+ }
3932
+
3881
3933
  /** Creates a SentryRequest from an event. */
3882
3934
  function sessionToSentryRequest(session, api) {
3883
3935
  const envelopeHeaders = JSON.stringify({
@@ -3894,6 +3946,9 @@ var Sentry = (function (exports) {
3894
3946
  }
3895
3947
  /** Creates a SentryRequest from an event. */
3896
3948
  function eventToSentryRequest(event, api) {
3949
+ // since JS has no Object.prototype.pop()
3950
+ const _a = event.tags || {}, { __sentry_samplingMethod: samplingMethod, __sentry_sampleRate: sampleRate } = _a, otherTags = __rest(_a, ["__sentry_samplingMethod", "__sentry_sampleRate"]);
3951
+ event.tags = otherTags;
3897
3952
  const useEnvelope = event.type === 'transaction';
3898
3953
  const req = {
3899
3954
  body: JSON.stringify(event),
@@ -3912,6 +3967,9 @@ var Sentry = (function (exports) {
3912
3967
  });
3913
3968
  const itemHeaders = JSON.stringify({
3914
3969
  type: event.type,
3970
+ // TODO: Right now, sampleRate may or may not be defined (it won't be in the cases of inheritance and
3971
+ // explicitly-set sampling decisions). Are we good with that?
3972
+ sample_rates: [{ id: samplingMethod, rate: sampleRate }],
3915
3973
  });
3916
3974
  // The trailing newline is optional. We intentionally don't send it to avoid
3917
3975
  // sending unnecessary bytes.
@@ -4590,7 +4648,7 @@ var Sentry = (function (exports) {
4590
4648
  */
4591
4649
  const limited = this._handleRateLimit(headers);
4592
4650
  if (limited)
4593
- logger.warn(`Too many requests, backing off till: ${this._disabledUntil(requestType)}`);
4651
+ logger.warn(`Too many requests, backing off until: ${this._disabledUntil(requestType)}`);
4594
4652
  if (status === exports.Status.Success) {
4595
4653
  resolve({ status });
4596
4654
  return;
@@ -4617,6 +4675,16 @@ var Sentry = (function (exports) {
4617
4675
  const rlHeader = headers['x-sentry-rate-limits'];
4618
4676
  const raHeader = headers['retry-after'];
4619
4677
  if (rlHeader) {
4678
+ // rate limit headers are of the form
4679
+ // <header>,<header>,..
4680
+ // where each <header> is of the form
4681
+ // <retry_after>: <categories>: <scope>: <reason_code>
4682
+ // where
4683
+ // <retry_after> is a delay in ms
4684
+ // <categories> is the event type(s) (error, transaction, etc) being rate limited and is of the form
4685
+ // <category>;<category>;...
4686
+ // <scope> is what's being limited (org, project, or key) - ignored by SDK
4687
+ // <reason_code> is an arbitrary string like "org_quota" - ignored by SDK
4620
4688
  for (const limit of rlHeader.trim().split(',')) {
4621
4689
  const parameters = limit.split(':', 2);
4622
4690
  const headerDelay = parseInt(parameters[0], 10);
@@ -4686,7 +4754,13 @@ var Sentry = (function (exports) {
4686
4754
  'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
4687
4755
  'retry-after': response.headers.get('Retry-After'),
4688
4756
  };
4689
- this._handleResponse({ requestType: sentryRequest.type, response, headers, resolve, reject });
4757
+ this._handleResponse({
4758
+ requestType: sentryRequest.type,
4759
+ response,
4760
+ headers,
4761
+ resolve,
4762
+ reject,
4763
+ });
4690
4764
  })
4691
4765
  .catch(reject);
4692
4766
  }));
@@ -5039,7 +5113,7 @@ var Sentry = (function (exports) {
5039
5113
  }
5040
5114
  const client = currentHub.getClient();
5041
5115
  const event = isPrimitive(error)
5042
- ? this._eventFromIncompleteRejection(error)
5116
+ ? this._eventFromRejectionWithPrimitive(error)
5043
5117
  : eventFromUnknownInput(error, undefined, {
5044
5118
  attachStacktrace: client && client.getOptions().attachStacktrace,
5045
5119
  rejection: true,
@@ -5087,16 +5161,19 @@ var Sentry = (function (exports) {
5087
5161
  return this._enhanceEventWithInitialFrame(event, url, line, column);
5088
5162
  }
5089
5163
  /**
5090
- * This function creates an Event from an TraceKitStackTrace that has part of it missing.
5164
+ * Create an event from a promise rejection where the `reason` is a primitive.
5165
+ *
5166
+ * @param reason: The `reason` property of the promise rejection
5167
+ * @returns An Event object with an appropriate `exception` value
5091
5168
  */
5092
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5093
- _eventFromIncompleteRejection(error) {
5169
+ _eventFromRejectionWithPrimitive(reason) {
5094
5170
  return {
5095
5171
  exception: {
5096
5172
  values: [
5097
5173
  {
5098
5174
  type: 'UnhandledRejection',
5099
- value: `Non-Error promise rejection captured with value: ${error}`,
5175
+ // String() is needed because the Primitive type includes symbols (which can't be automatically stringified)
5176
+ value: `Non-Error promise rejection captured with value: ${String(reason)}`,
5100
5177
  },
5101
5178
  ],
5102
5179
  },
@@ -5686,7 +5763,7 @@ var Sentry = (function (exports) {
5686
5763
  });
5687
5764
 
5688
5765
  const SDK_NAME = 'sentry.javascript.browser';
5689
- const SDK_VERSION = '5.28.0';
5766
+ const SDK_VERSION = '5.30.0';
5690
5767
 
5691
5768
  /**
5692
5769
  * The Sentry Browser SDK Client.