@dash0/sdk-web 0.16.1 → 0.16.3

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,14 @@
1
- import { debug, observeResourcePerformance, perf, win, setTimeout, isSameOrigin, wrap, parseUrl } from "../../utils";
1
+ import {
2
+ debug,
3
+ observeResourcePerformance,
4
+ perf,
5
+ win,
6
+ setTimeout,
7
+ isSameOrigin,
8
+ wrap,
9
+ parseUrl,
10
+ clearTimeout,
11
+ } from "../../utils";
2
12
  import { isUrlIgnored, matchesAny } from "../../utils/ignore-rules";
3
13
  import {
4
14
  addAttribute,
@@ -156,6 +166,8 @@ function isGraphQLQuery(input: RequestInfo | URL, init?: RequestInit) {
156
166
 
157
167
  function tryCaptureHttpHeaders(headers: Headers, span: InProgressSpan, getAttributeKey: (headerKey: string) => string) {
158
168
  try {
169
+ if (!vars.headersToCapture.length) return;
170
+
159
171
  headers.forEach((value, key) => {
160
172
  if (vars.headersToCapture.some((rxp) => rxp.test(key))) {
161
173
  addAttribute(span.attributes, getAttributeKey(key), value);
@@ -194,7 +206,8 @@ function wrapResponse(
194
206
  let fallbackTs: number = perf.now();
195
207
  const body = originalResponse.body;
196
208
 
197
- if (!body) {
209
+ // For some reason browsers return a response body on responses that can't be constructed with one. In that case we can't wrap the body stream
210
+ if (!body || !responseCanHaveBody(originalResponse)) {
198
211
  onDone();
199
212
  return originalResponse;
200
213
  }
@@ -314,3 +327,8 @@ function addTraceContextHttpHeaders(
314
327
  }
315
328
  }
316
329
  }
330
+
331
+ function responseCanHaveBody(response: Response) {
332
+ const status = response.status;
333
+ return status >= 200 && status != 204 && status != 205 && status != 304;
334
+ }
@@ -12,7 +12,7 @@ export async function send(path: string, body: unknown): Promise<void> {
12
12
  let isCompressed = false;
13
13
 
14
14
  // Try to compress if supported
15
- if (typeof CompressionStream !== "undefined") {
15
+ if (typeof CompressionStream !== "undefined" && vars.enableTransportCompression) {
16
16
  requestBody = await compressWithGzip(jsonString);
17
17
  byteLength = requestBody.byteLength;
18
18
  isCompressed = true;
@@ -58,5 +58,6 @@ export type InitOptions = {
58
58
  | "headersToCapture"
59
59
  | "urlAttributeScrubber"
60
60
  | "pageViewInstrumentation"
61
+ | "enableTransportCompression"
61
62
  >
62
63
  >;
package/src/utils/wrap.ts CHANGED
@@ -26,6 +26,7 @@ export function wrap<ModuleType extends object, TargetNameType extends keyof Mod
26
26
 
27
27
  if (isAlreadyInstrumented(original)) {
28
28
  debug(`${String(target)} has already been instrumented, skipping`);
29
+ return;
29
30
  }
30
31
 
31
32
  markAsInstrumented(original);
package/src/vars.ts CHANGED
@@ -165,6 +165,12 @@ export type Vars = {
165
165
  urlAttributeScrubber: UrlAttributeScrubber;
166
166
 
167
167
  pageViewInstrumentation: PageViewInstrumentationSettings;
168
+
169
+ /**
170
+ * Enables telemetry transport compression using gzip.
171
+ * experimental - in rare cases causes Chrome to crash to use at your own risk.
172
+ */
173
+ enableTransportCompression: boolean;
168
174
  };
169
175
 
170
176
  export const vars: Vars = {
@@ -191,4 +197,5 @@ export const vars: Vars = {
191
197
  trackVirtualPageViews: true,
192
198
  includeParts: [],
193
199
  },
200
+ enableTransportCompression: false,
194
201
  };