@absolutejs/beacon 0.6.45 → 0.6.46

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.
package/README.md CHANGED
@@ -186,7 +186,10 @@ beacon.captureMessage("checkout started", "info");
186
186
  exposes it; missing browser attribution is labeled explicitly. Layout
187
187
  Instability names shifted elements. Successful HTTP responses can be
188
188
  classified through the host-owned `instrument.classifyResponse` callback for
189
- GraphQL-style errors without Beacon retaining response bodies.
189
+ GraphQL-style errors. Selected HTTP 4xx/5xx responses can be promoted through
190
+ the opt-in `instrument.classifyErrorResponse` callback when application context
191
+ proves they are internal contract failures. Beacon never retains response
192
+ bodies.
190
193
  - **Lifecycle and platform gaps** — marked empty application roots, marked dirty
191
194
  forms abandoned during navigation, marked media errors/stalls, Web Storage and
192
195
  IndexedDB failures, discarded documents, bfcache rejection reasons, slow
@@ -216,6 +219,7 @@ close() => Promise<void> // remove listeners + final flush
216
219
  BEACON_SIGNAL.FETCH_FAILED
217
220
  BEACON_SIGNAL.SLOW_RESPONSE
218
221
  BEACON_SIGNAL.HTTP_5XX
222
+ BEACON_SIGNAL.HTTP_RESPONSE_FAILURE
219
223
  BEACON_TRACE_HEADER // "x-absolute-trace-id"
220
224
 
221
225
  // Global helpers (no-op until initBeacon): captureException, captureMessage,
package/dist/index.d.ts CHANGED
@@ -42,6 +42,7 @@ export declare const BEACON_SIGNAL: {
42
42
  readonly FORM_ABANDONMENT: "form_abandonment";
43
43
  readonly FOCUSED_CONTROL_OFFSCREEN: "focused_control_offscreen";
44
44
  readonly HTTP_5XX: "http_5xx";
45
+ readonly HTTP_RESPONSE_FAILURE: "http_response_failure";
45
46
  readonly INVISIBLE_TEXT: "invisible_text";
46
47
  readonly EMBEDDED_CONTENT_STALLED: "embedded_content_stalled";
47
48
  readonly LAYOUT_OVERFLOW: "layout_overflow";
@@ -155,6 +156,16 @@ export type BeaconTransport = (request: {
155
156
  /** True on unload-time flushes — prefer `navigator.sendBeacon`. */
156
157
  useBeacon: boolean;
157
158
  }) => void | Promise<void>;
159
+ export type BeaconResponseClassification = {
160
+ groupingKey: string;
161
+ level?: BeaconLevel;
162
+ message: string;
163
+ tags?: Record<string, string>;
164
+ };
165
+ export type BeaconResponseClassifier = (response: Response, request: {
166
+ method: string;
167
+ url: string;
168
+ }) => void | false | BeaconResponseClassification | Promise<void | false | BeaconResponseClassification>;
158
169
  export type BeaconInstrumentation = {
159
170
  /** `window.onerror` / `error` events. Default true. */
160
171
  globalErrors?: boolean;
@@ -184,18 +195,12 @@ export type BeaconInstrumentation = {
184
195
  /** Privacy-owned application classifier for successful HTTP responses that
185
196
  * encode a semantic failure (for example GraphQL errors in an HTTP 200).
186
197
  * Beacon never reads or stores the response body itself. */
187
- classifyResponse?: (response: Response, request: {
188
- method: string;
189
- url: string;
190
- }) => void | false | {
191
- groupingKey: string;
192
- message: string;
193
- tags?: Record<string, string>;
194
- } | Promise<void | false | {
195
- groupingKey: string;
196
- message: string;
197
- tags?: Record<string, string>;
198
- }>;
198
+ classifyResponse?: BeaconResponseClassifier;
199
+ /** Opt-in classifier for HTTP responses with status >= 400. Use this when
200
+ * application context can distinguish an internal contract failure carried
201
+ * as 4xx from an expected user/input rejection. Ordinary 4xx responses stay
202
+ * silent by default, and Beacon never reads or stores the body itself. */
203
+ classifyErrorResponse?: BeaconResponseClassifier;
199
204
  };
200
205
  export type BeaconResourceFailure = {
201
206
  crossOrigin: boolean;
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ var BEACON_SIGNAL = {
29
29
  FORM_ABANDONMENT: "form_abandonment",
30
30
  FOCUSED_CONTROL_OFFSCREEN: "focused_control_offscreen",
31
31
  HTTP_5XX: "http_5xx",
32
+ HTTP_RESPONSE_FAILURE: "http_response_failure",
32
33
  INVISIBLE_TEXT: "invisible_text",
33
34
  EMBEDDED_CONTENT_STALLED: "embedded_content_stalled",
34
35
  LAYOUT_OVERFLOW: "layout_overflow",
@@ -4039,22 +4040,26 @@ var createBeacon = (options) => {
4039
4040
  recordRequestForStorm = null;
4040
4041
  });
4041
4042
  }
4042
- const classifySemanticResponse = (response, request) => {
4043
- const classifier = instrument.classifyResponse;
4044
- if (classifier === undefined || !response.ok)
4043
+ const classifyInstrumentedResponse = (response, request) => {
4044
+ const errorResponse = response.status >= 400;
4045
+ const classifier = errorResponse ? instrument.classifyErrorResponse : response.ok ? instrument.classifyResponse : undefined;
4046
+ if (classifier === undefined)
4045
4047
  return;
4048
+ const traceId = responseTraceId(response.headers.get(BEACON_TRACE_HEADER));
4046
4049
  Promise.resolve(classifier(response.clone(), request)).then((result) => {
4047
4050
  if (result === undefined || result === false)
4048
4051
  return;
4049
- captureException(errorWithoutStack("SemanticResponseFailure", result.message), {
4052
+ captureException(errorWithoutStack(errorResponse ? "HttpResponseFailure" : "SemanticResponseFailure", result.message), {
4050
4053
  groupingKey: result.groupingKey,
4051
- level: "warning",
4054
+ level: result.level ?? "warning",
4052
4055
  tags: {
4053
4056
  endpoint: shortUrl(request.url),
4054
4057
  method: request.method.toUpperCase(),
4055
- signal: BEACON_SIGNAL.SEMANTIC_RESPONSE_FAILURE,
4058
+ signal: errorResponse ? BEACON_SIGNAL.HTTP_RESPONSE_FAILURE : BEACON_SIGNAL.SEMANTIC_RESPONSE_FAILURE,
4059
+ status: String(response.status),
4056
4060
  ...result.tags ?? {}
4057
- }
4061
+ },
4062
+ ...traceId === undefined ? {} : { traceId }
4058
4063
  });
4059
4064
  }).catch(() => {});
4060
4065
  };
@@ -4077,7 +4082,7 @@ var createBeacon = (options) => {
4077
4082
  type: "fetch"
4078
4083
  });
4079
4084
  reportResponseSignal(url, method, response.status, Date.now() - start, responseTraceId(response.headers.get(BEACON_TRACE_HEADER)));
4080
- classifySemanticResponse(response, { method, url });
4085
+ classifyInstrumentedResponse(response, { method, url });
4081
4086
  return response;
4082
4087
  } catch (error) {
4083
4088
  const resolved = toError(error);
@@ -4132,7 +4137,7 @@ var createBeacon = (options) => {
4132
4137
  });
4133
4138
  if (!failed) {
4134
4139
  reportResponseSignal(request.url, request.method, this.status, Date.now() - start, responseTraceId(this.getResponseHeader(BEACON_TRACE_HEADER)));
4135
- if (instrument.classifyResponse !== undefined && this.status >= 200 && this.status < 300 && (this.responseType === "" || this.responseType === "text")) {
4140
+ if ((instrument.classifyResponse !== undefined && this.status >= 200 && this.status < 300 || instrument.classifyErrorResponse !== undefined && this.status >= 400) && (this.responseType === "" || this.responseType === "text")) {
4136
4141
  const headers = new Headers;
4137
4142
  for (const line of this.getAllResponseHeaders().split(/\r?\n/u)) {
4138
4143
  const separator = line.indexOf(":");
@@ -4140,7 +4145,7 @@ var createBeacon = (options) => {
4140
4145
  continue;
4141
4146
  headers.append(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
4142
4147
  }
4143
- classifySemanticResponse(new Response(this.responseText, {
4148
+ classifyInstrumentedResponse(new Response(this.responseText, {
4144
4149
  headers,
4145
4150
  status: this.status,
4146
4151
  statusText: this.statusText
@@ -4295,5 +4300,5 @@ export {
4295
4300
  BEACON_ATTRIBUTE
4296
4301
  };
4297
4302
 
4298
- //# debugId=DEE1AFDA72425FCF64756E2164756E21
4303
+ //# debugId=F6CB1E584C36B1B164756E2164756E21
4299
4304
  //# sourceMappingURL=index.js.map