@sentry/core 10.32.0-alpha.0 → 10.32.1

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.
Files changed (184) hide show
  1. package/build/cjs/attributes.js +74 -57
  2. package/build/cjs/attributes.js.map +1 -1
  3. package/build/cjs/client.js +6 -11
  4. package/build/cjs/client.js.map +1 -1
  5. package/build/cjs/envelope.js +7 -41
  6. package/build/cjs/envelope.js.map +1 -1
  7. package/build/cjs/index.js +0 -29
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/cjs/integrations/eventFilters.js +1 -1
  10. package/build/cjs/integrations/eventFilters.js.map +1 -1
  11. package/build/cjs/integrations/requestdata.js +6 -72
  12. package/build/cjs/integrations/requestdata.js.map +1 -1
  13. package/build/cjs/integrations/supabase.js.map +1 -1
  14. package/build/cjs/logs/internal.js +8 -54
  15. package/build/cjs/logs/internal.js.map +1 -1
  16. package/build/cjs/scope.js +12 -6
  17. package/build/cjs/scope.js.map +1 -1
  18. package/build/cjs/semanticAttributes.js +0 -36
  19. package/build/cjs/semanticAttributes.js.map +1 -1
  20. package/build/cjs/tracing/sentrySpan.js +0 -31
  21. package/build/cjs/tracing/sentrySpan.js.map +1 -1
  22. package/build/cjs/tracing/trace.js +0 -1
  23. package/build/cjs/tracing/trace.js.map +1 -1
  24. package/build/cjs/tracing/vercel-ai/index.js +9 -1
  25. package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
  26. package/build/cjs/utils/aggregate-errors.js +4 -4
  27. package/build/cjs/utils/aggregate-errors.js.map +1 -1
  28. package/build/cjs/utils/applyScopeDataToEvent.js +1 -4
  29. package/build/cjs/utils/applyScopeDataToEvent.js.map +1 -1
  30. package/build/cjs/utils/featureFlags.js +0 -1
  31. package/build/cjs/utils/featureFlags.js.map +1 -1
  32. package/build/cjs/utils/is.js +2 -0
  33. package/build/cjs/utils/is.js.map +1 -1
  34. package/build/cjs/utils/should-ignore-span.js +9 -31
  35. package/build/cjs/utils/should-ignore-span.js.map +1 -1
  36. package/build/cjs/utils/spanUtils.js +2 -101
  37. package/build/cjs/utils/spanUtils.js.map +1 -1
  38. package/build/cjs/utils/version.js +1 -1
  39. package/build/cjs/utils/version.js.map +1 -1
  40. package/build/esm/attributes.js +74 -58
  41. package/build/esm/attributes.js.map +1 -1
  42. package/build/esm/client.js +1 -6
  43. package/build/esm/client.js.map +1 -1
  44. package/build/esm/envelope.js +8 -41
  45. package/build/esm/envelope.js.map +1 -1
  46. package/build/esm/index.js +3 -9
  47. package/build/esm/index.js.map +1 -1
  48. package/build/esm/integrations/eventFilters.js +1 -1
  49. package/build/esm/integrations/eventFilters.js.map +1 -1
  50. package/build/esm/integrations/requestdata.js +6 -72
  51. package/build/esm/integrations/requestdata.js.map +1 -1
  52. package/build/esm/integrations/supabase.js.map +1 -1
  53. package/build/esm/logs/internal.js +9 -54
  54. package/build/esm/logs/internal.js.map +1 -1
  55. package/build/esm/package.json +1 -1
  56. package/build/esm/scope.js +12 -6
  57. package/build/esm/scope.js.map +1 -1
  58. package/build/esm/semanticAttributes.js +1 -26
  59. package/build/esm/semanticAttributes.js.map +1 -1
  60. package/build/esm/tracing/sentrySpan.js +1 -32
  61. package/build/esm/tracing/sentrySpan.js.map +1 -1
  62. package/build/esm/tracing/trace.js +0 -1
  63. package/build/esm/tracing/trace.js.map +1 -1
  64. package/build/esm/tracing/vercel-ai/index.js +10 -2
  65. package/build/esm/tracing/vercel-ai/index.js.map +1 -1
  66. package/build/esm/utils/aggregate-errors.js +4 -4
  67. package/build/esm/utils/aggregate-errors.js.map +1 -1
  68. package/build/esm/utils/applyScopeDataToEvent.js +1 -4
  69. package/build/esm/utils/applyScopeDataToEvent.js.map +1 -1
  70. package/build/esm/utils/featureFlags.js +0 -1
  71. package/build/esm/utils/featureFlags.js.map +1 -1
  72. package/build/esm/utils/is.js +2 -0
  73. package/build/esm/utils/is.js.map +1 -1
  74. package/build/esm/utils/should-ignore-span.js +9 -31
  75. package/build/esm/utils/should-ignore-span.js.map +1 -1
  76. package/build/esm/utils/spanUtils.js +3 -97
  77. package/build/esm/utils/spanUtils.js.map +1 -1
  78. package/build/esm/utils/version.js +1 -1
  79. package/build/esm/utils/version.js.map +1 -1
  80. package/build/types/attributes.d.ts +18 -5
  81. package/build/types/attributes.d.ts.map +1 -1
  82. package/build/types/client.d.ts +2 -40
  83. package/build/types/client.d.ts.map +1 -1
  84. package/build/types/envelope.d.ts +1 -6
  85. package/build/types/envelope.d.ts.map +1 -1
  86. package/build/types/index.d.ts +4 -10
  87. package/build/types/index.d.ts.map +1 -1
  88. package/build/types/integrations/requestdata.d.ts.map +1 -1
  89. package/build/types/integrations/supabase.d.ts.map +1 -1
  90. package/build/types/logs/internal.d.ts +1 -9
  91. package/build/types/logs/internal.d.ts.map +1 -1
  92. package/build/types/scope.d.ts +12 -6
  93. package/build/types/scope.d.ts.map +1 -1
  94. package/build/types/semanticAttributes.d.ts +0 -21
  95. package/build/types/semanticAttributes.d.ts.map +1 -1
  96. package/build/types/tracing/sentrySpan.d.ts +1 -10
  97. package/build/types/tracing/sentrySpan.d.ts.map +1 -1
  98. package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
  99. package/build/types/types-hoist/breadcrumb.d.ts.map +1 -1
  100. package/build/types/types-hoist/context.d.ts.map +1 -1
  101. package/build/types/types-hoist/envelope.d.ts +2 -22
  102. package/build/types/types-hoist/envelope.d.ts.map +1 -1
  103. package/build/types/types-hoist/error.d.ts.map +1 -1
  104. package/build/types/types-hoist/event.d.ts.map +1 -1
  105. package/build/types/types-hoist/instrument.d.ts.map +1 -1
  106. package/build/types/types-hoist/integration.d.ts.map +1 -1
  107. package/build/types/types-hoist/link.d.ts +2 -2
  108. package/build/types/types-hoist/link.d.ts.map +1 -1
  109. package/build/types/types-hoist/log.d.ts +2 -14
  110. package/build/types/types-hoist/log.d.ts.map +1 -1
  111. package/build/types/types-hoist/misc.d.ts.map +1 -1
  112. package/build/types/types-hoist/options.d.ts +2 -18
  113. package/build/types/types-hoist/options.d.ts.map +1 -1
  114. package/build/types/types-hoist/polymorphics.d.ts.map +1 -1
  115. package/build/types/types-hoist/samplingcontext.d.ts.map +1 -1
  116. package/build/types/types-hoist/span.d.ts +0 -27
  117. package/build/types/types-hoist/span.d.ts.map +1 -1
  118. package/build/types/types-hoist/stackframe.d.ts.map +1 -1
  119. package/build/types/types-hoist/user.d.ts.map +1 -1
  120. package/build/types/utils/applyScopeDataToEvent.d.ts +1 -1
  121. package/build/types/utils/applyScopeDataToEvent.d.ts.map +1 -1
  122. package/build/types/utils/featureFlags.d.ts.map +1 -1
  123. package/build/types/utils/is.d.ts +1 -1
  124. package/build/types/utils/is.d.ts.map +1 -1
  125. package/build/types/utils/should-ignore-span.d.ts +3 -3
  126. package/build/types/utils/should-ignore-span.d.ts.map +1 -1
  127. package/build/types/utils/spanUtils.d.ts +2 -26
  128. package/build/types/utils/spanUtils.d.ts.map +1 -1
  129. package/build/types-ts3.8/attributes.d.ts +18 -5
  130. package/build/types-ts3.8/client.d.ts +2 -40
  131. package/build/types-ts3.8/envelope.d.ts +1 -6
  132. package/build/types-ts3.8/index.d.ts +4 -10
  133. package/build/types-ts3.8/logs/internal.d.ts +1 -9
  134. package/build/types-ts3.8/scope.d.ts +12 -6
  135. package/build/types-ts3.8/semanticAttributes.d.ts +0 -21
  136. package/build/types-ts3.8/tracing/sentrySpan.d.ts +1 -10
  137. package/build/types-ts3.8/types-hoist/envelope.d.ts +2 -22
  138. package/build/types-ts3.8/types-hoist/link.d.ts +2 -2
  139. package/build/types-ts3.8/types-hoist/log.d.ts +2 -14
  140. package/build/types-ts3.8/types-hoist/options.d.ts +2 -18
  141. package/build/types-ts3.8/types-hoist/span.d.ts +0 -27
  142. package/build/types-ts3.8/utils/applyScopeDataToEvent.d.ts +1 -1
  143. package/build/types-ts3.8/utils/is.d.ts +1 -1
  144. package/build/types-ts3.8/utils/should-ignore-span.d.ts +3 -3
  145. package/build/types-ts3.8/utils/spanUtils.d.ts +2 -26
  146. package/package.json +1 -1
  147. package/build/cjs/integrations/serverSpanStreaming.js +0 -51
  148. package/build/cjs/integrations/serverSpanStreaming.js.map +0 -1
  149. package/build/cjs/spans/captureSpan.js +0 -107
  150. package/build/cjs/spans/captureSpan.js.map +0 -1
  151. package/build/cjs/spans/spanBuffer.js +0 -117
  152. package/build/cjs/spans/spanBuffer.js.map +0 -1
  153. package/build/cjs/spans/spanFirstUtils.js +0 -187
  154. package/build/cjs/spans/spanFirstUtils.js.map +0 -1
  155. package/build/cjs/utils/beforeSendSpan.js +0 -36
  156. package/build/cjs/utils/beforeSendSpan.js.map +0 -1
  157. package/build/esm/integrations/serverSpanStreaming.js +0 -49
  158. package/build/esm/integrations/serverSpanStreaming.js.map +0 -1
  159. package/build/esm/spans/captureSpan.js +0 -105
  160. package/build/esm/spans/captureSpan.js.map +0 -1
  161. package/build/esm/spans/spanBuffer.js +0 -115
  162. package/build/esm/spans/spanBuffer.js.map +0 -1
  163. package/build/esm/spans/spanFirstUtils.js +0 -183
  164. package/build/esm/spans/spanFirstUtils.js.map +0 -1
  165. package/build/esm/utils/beforeSendSpan.js +0 -33
  166. package/build/esm/utils/beforeSendSpan.js.map +0 -1
  167. package/build/types/integrations/serverSpanStreaming.d.ts +0 -8
  168. package/build/types/integrations/serverSpanStreaming.d.ts.map +0 -1
  169. package/build/types/spans/captureSpan.d.ts +0 -10
  170. package/build/types/spans/captureSpan.d.ts.map +0 -1
  171. package/build/types/spans/spanBuffer.d.ts +0 -31
  172. package/build/types/spans/spanBuffer.d.ts.map +0 -1
  173. package/build/types/spans/spanFirstUtils.d.ts +0 -20
  174. package/build/types/spans/spanFirstUtils.d.ts.map +0 -1
  175. package/build/types/types-hoist/attributes.d.ts +0 -19
  176. package/build/types/types-hoist/attributes.d.ts.map +0 -1
  177. package/build/types/utils/beforeSendSpan.d.ts +0 -22
  178. package/build/types/utils/beforeSendSpan.d.ts.map +0 -1
  179. package/build/types-ts3.8/integrations/serverSpanStreaming.d.ts +0 -8
  180. package/build/types-ts3.8/spans/captureSpan.d.ts +0 -10
  181. package/build/types-ts3.8/spans/spanBuffer.d.ts +0 -31
  182. package/build/types-ts3.8/spans/spanFirstUtils.d.ts +0 -20
  183. package/build/types-ts3.8/types-hoist/attributes.d.ts +0 -19
  184. package/build/types-ts3.8/utils/beforeSendSpan.d.ts +0 -22
@@ -1,8 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const debugBuild = require('./debug-build.js');
4
- const debugLogger = require('./utils/debug-logger.js');
5
-
6
3
  /**
7
4
  * Type-guard: The attribute object has the shape the official attribute object (value, type, unit).
8
5
  * https://develop.sentry.dev/sdk/telemetry/scopes/#setting-attributes
@@ -19,33 +16,88 @@ function isAttributeObject(maybeObj) {
19
16
  /**
20
17
  * Converts an attribute value to a typed attribute value.
21
18
  *
22
- * Does not allow mixed arrays. In case of a mixed array, the value is stringified and the type is 'string'.
23
- * All values besides the supported attribute types (see {@link AttributeTypeMap}) are stringified to a string attribute value.
19
+ * For now, we intentionally only support primitive values and attribute objects with primitive values.
20
+ * If @param useFallback is true, we stringify non-primitive values to a string attribute value. Otherwise
21
+ * we return `undefined` for unsupported values.
24
22
  *
25
23
  * @param value - The value of the passed attribute.
24
+ * @param useFallback - If true, unsupported values will be stringified to a string attribute value.
25
+ * Defaults to false. In this case, `undefined` is returned for unsupported values.
26
26
  * @returns The typed attribute.
27
27
  */
28
- function attributeValueToTypedAttributeValue(rawValue) {
28
+ function attributeValueToTypedAttributeValue(
29
+ rawValue,
30
+ useFallback,
31
+ ) {
29
32
  const { value, unit } = isAttributeObject(rawValue) ? rawValue : { value: rawValue, unit: undefined };
30
- return { ...getTypedAttributeValue(value), ...(unit && typeof unit === 'string' ? { unit } : {}) };
31
- }
33
+ const attributeValue = getTypedAttributeValue(value);
34
+ const checkedUnit = unit && typeof unit === 'string' ? { unit } : {};
35
+ if (attributeValue) {
36
+ return { ...attributeValue, ...checkedUnit };
37
+ }
32
38
 
33
- // Only allow string, boolean, or number types
34
- const getPrimitiveType
39
+ if (!useFallback) {
40
+ return;
41
+ }
35
42
 
36
- = item =>
37
- typeof item === 'string'
38
- ? 'string'
39
- : typeof item === 'boolean'
40
- ? 'boolean'
41
- : typeof item === 'number' && !Number.isNaN(item)
42
- ? Number.isInteger(item)
43
- ? 'integer'
44
- : 'double'
45
- : null;
43
+ // Fallback: stringify the value
44
+ // TODO(v11): be smarter here and use String constructor if stringify fails
45
+ // (this is a breaking change for already existing attribute values)
46
+ let stringValue = '';
47
+ try {
48
+ stringValue = JSON.stringify(value) ?? '';
49
+ } catch {
50
+ // Do nothing
51
+ }
52
+ return {
53
+ value: stringValue,
54
+ type: 'string',
55
+ ...checkedUnit,
56
+ };
57
+ }
46
58
 
59
+ /**
60
+ * Serializes raw attributes to typed attributes as expected in our envelopes.
61
+ *
62
+ * @param attributes The raw attributes to serialize.
63
+ * @param fallback If true, unsupported values will be stringified to a string attribute value.
64
+ * Defaults to false. In this case, `undefined` is returned for unsupported values.
65
+ *
66
+ * @returns The serialized attributes.
67
+ */
68
+ function serializeAttributes(attributes, fallback = false) {
69
+ const serializedAttributes = {};
70
+ for (const [key, value] of Object.entries(attributes)) {
71
+ const typedValue = attributeValueToTypedAttributeValue(value, fallback);
72
+ if (typedValue) {
73
+ serializedAttributes[key] = typedValue;
74
+ }
75
+ }
76
+ return serializedAttributes;
77
+ }
78
+
79
+ /**
80
+ * NOTE: We intentionally do not return anything for non-primitive values:
81
+ * - array support will come in the future but if we stringify arrays now,
82
+ * sending arrays (unstringified) later will be a subtle breaking change.
83
+ * - Objects are not supported yet and product support is still TBD.
84
+ * - We still keep the type signature for TypedAttributeValue wider to avoid a
85
+ * breaking change once we add support for non-primitive values.
86
+ * - Once we go back to supporting arrays and stringifying all other values,
87
+ * we already implemented the serialization logic here:
88
+ * https://github.com/getsentry/sentry-javascript/pull/18165
89
+ */
47
90
  function getTypedAttributeValue(value) {
48
- const primitiveType = getPrimitiveType(value);
91
+ const primitiveType =
92
+ typeof value === 'string'
93
+ ? 'string'
94
+ : typeof value === 'boolean'
95
+ ? 'boolean'
96
+ : typeof value === 'number' && !Number.isNaN(value)
97
+ ? Number.isInteger(value)
98
+ ? 'integer'
99
+ : 'double'
100
+ : null;
49
101
  if (primitiveType) {
50
102
  // @ts-expect-error - TS complains because {@link TypedAttributeValue} is strictly typed to
51
103
  // avoid setting the wrong `type` on the attribute value.
@@ -55,44 +107,9 @@ function getTypedAttributeValue(value) {
55
107
  // Therefore, we ignore it.
56
108
  return { value, type: primitiveType };
57
109
  }
58
-
59
- if (Array.isArray(value)) {
60
- const coherentArrayType = value.reduce((acc, item) => {
61
- if (!acc || getPrimitiveType(item) !== acc) {
62
- return null;
63
- }
64
- return acc;
65
- }, getPrimitiveType(value[0]));
66
-
67
- if (coherentArrayType) {
68
- return { value, type: `${coherentArrayType}[]` };
69
- }
70
- }
71
-
72
- // Fallback: stringify the passed value
73
- let fallbackValue = '';
74
- try {
75
- fallbackValue = JSON.stringify(value) ?? String(value);
76
- } catch {
77
- try {
78
- fallbackValue = String(value);
79
- } catch {
80
- debugBuild.DEBUG_BUILD && debugLogger.debug.warn('Failed to stringify attribute value', value);
81
- // ignore
82
- }
83
- }
84
-
85
- // This is quite a low-quality message but we cannot safely log the original `value`
86
- // here due to String() or JSON.stringify() potentially throwing.
87
- debugBuild.DEBUG_BUILD &&
88
- debugLogger.debug.log(`Stringified attribute value to ${fallbackValue} because it's not a supported attribute value type`);
89
-
90
- return {
91
- value: fallbackValue,
92
- type: 'string',
93
- };
94
110
  }
95
111
 
96
112
  exports.attributeValueToTypedAttributeValue = attributeValueToTypedAttributeValue;
97
113
  exports.isAttributeObject = isAttributeObject;
114
+ exports.serializeAttributes = serializeAttributes;
98
115
  //# sourceMappingURL=attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.js","sources":["../../src/attributes.ts"],"sourcesContent":["import { DEBUG_BUILD } from './debug-build';\nimport type { DurationUnit, FractionUnit, InformationUnit } from './types-hoist/measurement';\nimport { debug } from './utils/debug-logger';\n\nexport type RawAttributes<T> = T & ValidatedAttributes<T>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAttribute<T> = T extends { value: any } | { unit: any } ? AttributeObject : T;\n\nexport type TypedAttributes = Record<string, TypedAttributeValue>;\n\nexport type AttributeValueType = string | number | boolean | Array<string> | Array<number> | Array<boolean>;\n\ntype AttributeTypeMap = {\n string: string;\n integer: number;\n double: number;\n boolean: boolean;\n 'string[]': Array<string>;\n 'integer[]': Array<number>;\n 'double[]': Array<number>;\n 'boolean[]': Array<boolean>;\n};\n\n/* Generates a type from the AttributeTypeMap like:\n | { value: string; type: 'string' }\n | { value: number; type: 'integer' }\n | { value: number; type: 'double' }\n */\ntype AttributeUnion = {\n [K in keyof AttributeTypeMap]: {\n value: AttributeTypeMap[K];\n type: K;\n };\n}[keyof AttributeTypeMap];\n\nexport type TypedAttributeValue = AttributeUnion & { unit?: AttributeUnit };\n\nexport type AttributeObject = {\n value: unknown;\n unit?: AttributeUnit;\n};\n\n// Unfortunately, we loose type safety if we did something like Exclude<MeasurementUnit, string>\n// so therefore we unionize between the three supported unit categories.\nexport type AttributeUnit = DurationUnit | InformationUnit | FractionUnit;\n\n/* If an attribute has either a 'value' or 'unit' property, we use the ValidAttributeObject type. */\nexport type ValidatedAttributes<T> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof T]: T[K] extends { value: any } | { unit: any } ? AttributeObject : unknown;\n};\n\n/**\n * Type-guard: The attribute object has the shape the official attribute object (value, type, unit).\n * https://develop.sentry.dev/sdk/telemetry/scopes/#setting-attributes\n */\nexport function isAttributeObject(maybeObj: unknown): maybeObj is AttributeObject {\n return (\n typeof maybeObj === 'object' &&\n maybeObj != null &&\n !Array.isArray(maybeObj) &&\n Object.keys(maybeObj).includes('value')\n );\n}\n\n/**\n * Converts an attribute value to a typed attribute value.\n *\n * Does not allow mixed arrays. In case of a mixed array, the value is stringified and the type is 'string'.\n * All values besides the supported attribute types (see {@link AttributeTypeMap}) are stringified to a string attribute value.\n *\n * @param value - The value of the passed attribute.\n * @returns The typed attribute.\n */\nexport function attributeValueToTypedAttributeValue(rawValue: unknown): TypedAttributeValue {\n const { value, unit } = isAttributeObject(rawValue) ? rawValue : { value: rawValue, unit: undefined };\n return { ...getTypedAttributeValue(value), ...(unit && typeof unit === 'string' ? { unit } : {}) };\n}\n\n// Only allow string, boolean, or number types\nconst getPrimitiveType: (\n item: unknown,\n) => keyof Pick<AttributeTypeMap, 'string' | 'integer' | 'double' | 'boolean'> | null = item =>\n typeof item === 'string'\n ? 'string'\n : typeof item === 'boolean'\n ? 'boolean'\n : typeof item === 'number' && !Number.isNaN(item)\n ? Number.isInteger(item)\n ? 'integer'\n : 'double'\n : null;\n\nfunction getTypedAttributeValue(value: unknown): TypedAttributeValue {\n const primitiveType = getPrimitiveType(value);\n if (primitiveType) {\n // @ts-expect-error - TS complains because {@link TypedAttributeValue} is strictly typed to\n // avoid setting the wrong `type` on the attribute value.\n // In this case, getPrimitiveType already does the check but TS doesn't know that.\n // The \"clean\" alternative is to return an object per `typeof value` case\n // but that would require more bundle size\n // Therefore, we ignore it.\n return { value, type: primitiveType };\n }\n\n if (Array.isArray(value)) {\n const coherentArrayType = value.reduce((acc: 'string' | 'boolean' | 'integer' | 'double' | null, item) => {\n if (!acc || getPrimitiveType(item) !== acc) {\n return null;\n }\n return acc;\n }, getPrimitiveType(value[0]));\n\n if (coherentArrayType) {\n return { value, type: `${coherentArrayType}[]` };\n }\n }\n\n // Fallback: stringify the passed value\n let fallbackValue = '';\n try {\n fallbackValue = JSON.stringify(value) ?? String(value);\n } catch {\n try {\n fallbackValue = String(value);\n } catch {\n DEBUG_BUILD && debug.warn('Failed to stringify attribute value', value);\n // ignore\n }\n }\n\n // This is quite a low-quality message but we cannot safely log the original `value`\n // here due to String() or JSON.stringify() potentially throwing.\n DEBUG_BUILD &&\n debug.log(`Stringified attribute value to ${fallbackValue} because it's not a supported attribute value type`);\n\n return {\n value: fallbackValue,\n type: 'string',\n };\n}\n"],"names":["DEBUG_BUILD","debug"],"mappings":";;;;;AAoDA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,QAAQ,EAAwC;AAClF,EAAE;AACF,IAAI,OAAO,QAAA,KAAa,QAAA;AACxB,IAAI,QAAA,IAAY,IAAA;AAChB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAA;AAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO;AAC1C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,mCAAmC,CAAC,QAAQ,EAAgC;AAC5F,EAAE,MAAM,EAAE,KAAK,EAAE,MAAK,GAAI,iBAAiB,CAAC,QAAQ,CAAA,GAAI,QAAA,GAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAA,EAAW;AACvG,EAAE,OAAO,EAAE,GAAG,sBAAsB,CAAC,KAAK,CAAC,EAAE,IAAI,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,GAAW,EAAE,IAAA,KAAS,EAAE,CAAA,EAAG;AACpG;;AAEA;AACA,MAAM;;AAEN,GAAwF,IAAA;AACxF,EAAE,OAAO,SAAS;AAClB,MAAM;AACN,MAAM,OAAO,IAAA,KAAS;AACtB,QAAQ;AACR,QAAQ,OAAO,IAAA,KAAS,QAAA,IAAY,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI;AACtD,UAAU,MAAM,CAAC,SAAS,CAAC,IAAI;AAC/B,YAAY;AACZ,YAAY;AACZ,UAAU,IAAI;;AAEd,SAAS,sBAAsB,CAAC,KAAK,EAAgC;AACrE,EAAE,MAAM,aAAA,GAAgB,gBAAgB,CAAC,KAAK,CAAC;AAC/C,EAAE,IAAI,aAAa,EAAE;AACrB;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe;AACzC,EAAE;;AAEF,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AAC5B,IAAI,MAAM,iBAAA,GAAoB,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAsD,IAAI,KAAK;AAC9G,MAAM,IAAI,CAAC,GAAA,IAAO,gBAAgB,CAAC,IAAI,CAAA,KAAM,GAAG,EAAE;AAClD,QAAQ,OAAO,IAAI;AACnB,MAAM;AACN,MAAM,OAAO,GAAG;AAChB,IAAI,CAAC,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;;AAElC,IAAI,IAAI,iBAAiB,EAAE;AAC3B,MAAM,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAA,iBAAA,CAAA,EAAA,CAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA;AACA,EAAA,IAAA,aAAA,GAAA,EAAA;AACA,EAAA,IAAA;AACA,IAAA,aAAA,GAAA,IAAA,CAAA,SAAA,CAAA,KAAA,CAAA,IAAA,MAAA,CAAA,KAAA,CAAA;AACA,EAAA,CAAA,CAAA,MAAA;AACA,IAAA,IAAA;AACA,MAAA,aAAA,GAAA,MAAA,CAAA,KAAA,CAAA;AACA,IAAA,CAAA,CAAA,MAAA;AACA,MAAAA,sBAAA,IAAAC,iBAAA,CAAA,IAAA,CAAA,qCAAA,EAAA,KAAA,CAAA;AACA;AACA,IAAA;AACA,EAAA;;AAEA;AACA;AACA,EAAAD,sBAAA;AACA,IAAAC,iBAAA,CAAA,GAAA,CAAA,CAAA,+BAAA,EAAA,aAAA,CAAA,kDAAA,CAAA,CAAA;;AAEA,EAAA,OAAA;AACA,IAAA,KAAA,EAAA,aAAA;AACA,IAAA,IAAA,EAAA,QAAA;AACA,GAAA;AACA;;;;;"}
1
+ {"version":3,"file":"attributes.js","sources":["../../src/attributes.ts"],"sourcesContent":["import type { DurationUnit, FractionUnit, InformationUnit } from './types-hoist/measurement';\n\nexport type RawAttributes<T> = T & ValidatedAttributes<T>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAttribute<T> = T extends { value: any } | { unit: any } ? AttributeObject : T;\n\nexport type Attributes = Record<string, TypedAttributeValue>;\n\nexport type AttributeValueType = string | number | boolean | Array<string> | Array<number> | Array<boolean>;\n\ntype AttributeTypeMap = {\n string: string;\n integer: number;\n double: number;\n boolean: boolean;\n 'string[]': Array<string>;\n 'integer[]': Array<number>;\n 'double[]': Array<number>;\n 'boolean[]': Array<boolean>;\n};\n\n/* Generates a type from the AttributeTypeMap like:\n | { value: string; type: 'string' }\n | { value: number; type: 'integer' }\n | { value: number; type: 'double' }\n */\ntype AttributeUnion = {\n [K in keyof AttributeTypeMap]: {\n value: AttributeTypeMap[K];\n type: K;\n };\n}[keyof AttributeTypeMap];\n\nexport type TypedAttributeValue = AttributeUnion & { unit?: AttributeUnit };\n\nexport type AttributeObject = {\n value: unknown;\n unit?: AttributeUnit;\n};\n\n// Unfortunately, we loose type safety if we did something like Exclude<MeasurementUnit, string>\n// so therefore we unionize between the three supported unit categories.\ntype AttributeUnit = DurationUnit | InformationUnit | FractionUnit;\n\n/* If an attribute has either a 'value' or 'unit' property, we use the ValidAttributeObject type. */\nexport type ValidatedAttributes<T> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof T]: T[K] extends { value: any } | { unit: any } ? AttributeObject : unknown;\n};\n\n/**\n * Type-guard: The attribute object has the shape the official attribute object (value, type, unit).\n * https://develop.sentry.dev/sdk/telemetry/scopes/#setting-attributes\n */\nexport function isAttributeObject(maybeObj: unknown): maybeObj is AttributeObject {\n return (\n typeof maybeObj === 'object' &&\n maybeObj != null &&\n !Array.isArray(maybeObj) &&\n Object.keys(maybeObj).includes('value')\n );\n}\n\n/**\n * Converts an attribute value to a typed attribute value.\n *\n * For now, we intentionally only support primitive values and attribute objects with primitive values.\n * If @param useFallback is true, we stringify non-primitive values to a string attribute value. Otherwise\n * we return `undefined` for unsupported values.\n *\n * @param value - The value of the passed attribute.\n * @param useFallback - If true, unsupported values will be stringified to a string attribute value.\n * Defaults to false. In this case, `undefined` is returned for unsupported values.\n * @returns The typed attribute.\n */\nexport function attributeValueToTypedAttributeValue(\n rawValue: unknown,\n useFallback?: boolean,\n): TypedAttributeValue | void {\n const { value, unit } = isAttributeObject(rawValue) ? rawValue : { value: rawValue, unit: undefined };\n const attributeValue = getTypedAttributeValue(value);\n const checkedUnit = unit && typeof unit === 'string' ? { unit } : {};\n if (attributeValue) {\n return { ...attributeValue, ...checkedUnit };\n }\n\n if (!useFallback) {\n return;\n }\n\n // Fallback: stringify the value\n // TODO(v11): be smarter here and use String constructor if stringify fails\n // (this is a breaking change for already existing attribute values)\n let stringValue = '';\n try {\n stringValue = JSON.stringify(value) ?? '';\n } catch {\n // Do nothing\n }\n return {\n value: stringValue,\n type: 'string',\n ...checkedUnit,\n };\n}\n\n/**\n * Serializes raw attributes to typed attributes as expected in our envelopes.\n *\n * @param attributes The raw attributes to serialize.\n * @param fallback If true, unsupported values will be stringified to a string attribute value.\n * Defaults to false. In this case, `undefined` is returned for unsupported values.\n *\n * @returns The serialized attributes.\n */\nexport function serializeAttributes<T>(attributes: RawAttributes<T>, fallback: boolean = false): Attributes {\n const serializedAttributes: Attributes = {};\n for (const [key, value] of Object.entries(attributes)) {\n const typedValue = attributeValueToTypedAttributeValue(value, fallback);\n if (typedValue) {\n serializedAttributes[key] = typedValue;\n }\n }\n return serializedAttributes;\n}\n\n/**\n * NOTE: We intentionally do not return anything for non-primitive values:\n * - array support will come in the future but if we stringify arrays now,\n * sending arrays (unstringified) later will be a subtle breaking change.\n * - Objects are not supported yet and product support is still TBD.\n * - We still keep the type signature for TypedAttributeValue wider to avoid a\n * breaking change once we add support for non-primitive values.\n * - Once we go back to supporting arrays and stringifying all other values,\n * we already implemented the serialization logic here:\n * https://github.com/getsentry/sentry-javascript/pull/18165\n */\nfunction getTypedAttributeValue(value: unknown): TypedAttributeValue | void {\n const primitiveType =\n typeof value === 'string'\n ? 'string'\n : typeof value === 'boolean'\n ? 'boolean'\n : typeof value === 'number' && !Number.isNaN(value)\n ? Number.isInteger(value)\n ? 'integer'\n : 'double'\n : null;\n if (primitiveType) {\n // @ts-expect-error - TS complains because {@link TypedAttributeValue} is strictly typed to\n // avoid setting the wrong `type` on the attribute value.\n // In this case, getPrimitiveType already does the check but TS doesn't know that.\n // The \"clean\" alternative is to return an object per `typeof value` case\n // but that would require more bundle size\n // Therefore, we ignore it.\n return { value, type: primitiveType };\n }\n}\n"],"names":[],"mappings":";;AAkDA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,QAAQ,EAAwC;AAClF,EAAE;AACF,IAAI,OAAO,QAAA,KAAa,QAAA;AACxB,IAAI,QAAA,IAAY,IAAA;AAChB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAA;AAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO;AAC1C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,mCAAmC;AACnD,EAAE,QAAQ;AACV,EAAE,WAAW;AACb,EAA8B;AAC9B,EAAE,MAAM,EAAE,KAAK,EAAE,MAAK,GAAI,iBAAiB,CAAC,QAAQ,CAAA,GAAI,QAAA,GAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAA,EAAW;AACvG,EAAE,MAAM,cAAA,GAAiB,sBAAsB,CAAC,KAAK,CAAC;AACtD,EAAE,MAAM,WAAA,GAAc,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,GAAW,EAAE,IAAA,EAAK,GAAI,EAAE;AACtE,EAAE,IAAI,cAAc,EAAE;AACtB,IAAI,OAAO,EAAE,GAAG,cAAc,EAAE,GAAG,aAAa;AAChD,EAAE;;AAEF,EAAE,IAAI,CAAC,WAAW,EAAE;AACpB,IAAI;AACJ,EAAE;;AAEF;AACA;AACA;AACA,EAAE,IAAI,WAAA,GAAc,EAAE;AACtB,EAAE,IAAI;AACN,IAAI,WAAA,GAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAA,IAAK,EAAE;AAC7C,EAAE,EAAE,MAAM;AACV;AACA,EAAE;AACF,EAAE,OAAO;AACT,IAAI,KAAK,EAAE,WAAW;AACtB,IAAI,IAAI,EAAE,QAAQ;AAClB,IAAI,GAAG,WAAW;AAClB,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,mBAAmB,CAAI,UAAU,EAAoB,QAAQ,GAAY,KAAK,EAAc;AAC5G,EAAE,MAAM,oBAAoB,GAAe,EAAE;AAC7C,EAAE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAA,IAAK,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;AACzD,IAAI,MAAM,aAAa,mCAAmC,CAAC,KAAK,EAAE,QAAQ,CAAC;AAC3E,IAAI,IAAI,UAAU,EAAE;AACpB,MAAM,oBAAoB,CAAC,GAAG,CAAA,GAAI,UAAU;AAC5C,IAAI;AACJ,EAAE;AACF,EAAE,OAAO,oBAAoB;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,sBAAsB,CAAC,KAAK,EAAuC;AAC5E,EAAE,MAAM,aAAA;AACR,IAAI,OAAO,UAAU;AACrB,QAAQ;AACR,QAAQ,OAAO,KAAA,KAAU;AACzB,UAAU;AACV,UAAU,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK;AAC1D,YAAY,MAAM,CAAC,SAAS,CAAC,KAAK;AAClC,cAAc;AACd,cAAc;AACd,YAAY,IAAI;AAChB,EAAE,IAAI,aAAa,EAAE;AACrB;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe;AACzC,EAAE;AACF;;;;;;"}
@@ -11,7 +11,6 @@ const internal$1 = require('./metrics/internal.js');
11
11
  const session = require('./session.js');
12
12
  const dynamicSamplingContext = require('./tracing/dynamicSamplingContext.js');
13
13
  const base = require('./transports/base.js');
14
- const beforeSendSpan = require('./utils/beforeSendSpan.js');
15
14
  const clientreport = require('./utils/clientreport.js');
16
15
  const debugLogger = require('./utils/debug-logger.js');
17
16
  const dsn = require('./utils/dsn.js');
@@ -981,17 +980,13 @@ function _validateBeforeSendResult(
981
980
  /**
982
981
  * Process the matching `beforeSendXXX` callback.
983
982
  */
984
-
985
983
  function processBeforeSend(
986
984
  client,
987
985
  options,
988
986
  event,
989
987
  hint,
990
988
  ) {
991
- const { beforeSend, beforeSendTransaction, ignoreSpans } = options;
992
-
993
- const beforeSendSpan$1 = !beforeSendSpan.isV2BeforeSendSpanCallback(options.beforeSendSpan) && options.beforeSendSpan;
994
-
989
+ const { beforeSend, beforeSendTransaction, beforeSendSpan, ignoreSpans } = options;
995
990
  let processedEvent = event;
996
991
 
997
992
  if (isErrorEvent(processedEvent) && beforeSend) {
@@ -1000,7 +995,7 @@ function processBeforeSend(
1000
995
 
1001
996
  if (isTransactionEvent(processedEvent)) {
1002
997
  // Avoid processing if we don't have to
1003
- if (beforeSendSpan$1 || ignoreSpans) {
998
+ if (beforeSendSpan || ignoreSpans) {
1004
999
  // 1. Process root span
1005
1000
  const rootSpanJson = transactionEvent.convertTransactionEventToSpanJson(processedEvent);
1006
1001
 
@@ -1011,8 +1006,8 @@ function processBeforeSend(
1011
1006
  }
1012
1007
 
1013
1008
  // 1.2 If a `beforeSendSpan` callback is defined, process the root span
1014
- if (beforeSendSpan$1) {
1015
- const processedRootSpanJson = beforeSendSpan$1(rootSpanJson);
1009
+ if (beforeSendSpan) {
1010
+ const processedRootSpanJson = beforeSendSpan(rootSpanJson);
1016
1011
  if (!processedRootSpanJson) {
1017
1012
  spanUtils.showSpanDropWarning();
1018
1013
  } else {
@@ -1035,8 +1030,8 @@ function processBeforeSend(
1035
1030
  }
1036
1031
 
1037
1032
  // 2.b If a `beforeSendSpan` callback is defined, process the child span
1038
- if (beforeSendSpan$1) {
1039
- const processedSpan = beforeSendSpan$1(span);
1033
+ if (beforeSendSpan) {
1034
+ const processedSpan = beforeSendSpan(span);
1040
1035
  if (!processedSpan) {
1041
1036
  spanUtils.showSpanDropWarning();
1042
1037
  processedSpans.push(span);