@sentry/node 9.0.1 → 9.1.1-alpha.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.
Files changed (49) hide show
  1. package/build/cjs/index.js +22 -22
  2. package/build/cjs/integrations/anr/index.js +1 -1
  3. package/build/cjs/integrations/local-variables/local-variables-async.js +1 -1
  4. package/build/cjs/integrations/node-fetch/SentryNodeFetchInstrumentation.js +272 -0
  5. package/build/cjs/integrations/node-fetch/SentryNodeFetchInstrumentation.js.map +1 -0
  6. package/build/cjs/integrations/node-fetch/index.js +85 -0
  7. package/build/cjs/integrations/node-fetch/index.js.map +1 -0
  8. package/build/cjs/nodeVersion.js +2 -0
  9. package/build/cjs/nodeVersion.js.map +1 -1
  10. package/build/cjs/sdk/index.js +6 -6
  11. package/build/cjs/sdk/index.js.map +1 -1
  12. package/build/cjs/utils/baggage.js +36 -0
  13. package/build/cjs/utils/baggage.js.map +1 -0
  14. package/build/esm/index.js +1 -1
  15. package/build/esm/integrations/anr/index.js +1 -1
  16. package/build/esm/integrations/anr/worker-script.js +2 -2
  17. package/build/esm/integrations/local-variables/local-variables-async.js +1 -1
  18. package/build/esm/integrations/local-variables/worker-script.js +2 -2
  19. package/build/esm/integrations/node-fetch/SentryNodeFetchInstrumentation.js +270 -0
  20. package/build/esm/integrations/node-fetch/SentryNodeFetchInstrumentation.js.map +1 -0
  21. package/build/esm/integrations/node-fetch/index.js +83 -0
  22. package/build/esm/integrations/node-fetch/index.js.map +1 -0
  23. package/build/esm/nodeVersion.js +2 -1
  24. package/build/esm/nodeVersion.js.map +1 -1
  25. package/build/esm/package.json +1 -1
  26. package/build/esm/sdk/index.js +1 -1
  27. package/build/esm/utils/baggage.js +34 -0
  28. package/build/esm/utils/baggage.js.map +1 -0
  29. package/build/types/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts +51 -0
  30. package/build/types/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts.map +1 -0
  31. package/build/{types-ts3.8/integrations/node-fetch.d.ts → types/integrations/node-fetch/index.d.ts} +23 -15
  32. package/build/types/integrations/node-fetch/index.d.ts.map +1 -0
  33. package/build/types/integrations/node-fetch/types.d.ts +32 -0
  34. package/build/types/integrations/node-fetch/types.d.ts.map +1 -0
  35. package/build/types/nodeVersion.d.ts +1 -0
  36. package/build/types/nodeVersion.d.ts.map +1 -1
  37. package/build/types/utils/baggage.d.ts +6 -0
  38. package/build/types/utils/baggage.d.ts.map +1 -0
  39. package/build/types-ts3.8/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts +51 -0
  40. package/build/{types/integrations/node-fetch.d.ts → types-ts3.8/integrations/node-fetch/index.d.ts} +23 -15
  41. package/build/types-ts3.8/integrations/node-fetch/types.d.ts +31 -0
  42. package/build/types-ts3.8/nodeVersion.d.ts +1 -0
  43. package/build/types-ts3.8/utils/baggage.d.ts +6 -0
  44. package/package.json +4 -4
  45. package/build/cjs/integrations/node-fetch.js +0 -132
  46. package/build/cjs/integrations/node-fetch.js.map +0 -1
  47. package/build/esm/integrations/node-fetch.js +0 -130
  48. package/build/esm/integrations/node-fetch.js.map +0 -1
  49. package/build/types/integrations/node-fetch.d.ts.map +0 -1
@@ -1,130 +0,0 @@
1
- import { registerInstrumentations } from '@opentelemetry/instrumentation';
2
- import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';
3
- import { defineIntegration, LRUMap, hasSpansEnabled, getClient, getTraceData, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getBreadcrumbLogLevelFromHttpStatusCode, addBreadcrumb, parseUrl, getSanitizedUrlString } from '@sentry/core';
4
- import { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';
5
-
6
- const _nativeNodeFetchIntegration = ((options = {}) => {
7
- const _breadcrumbs = typeof options.breadcrumbs === 'undefined' ? true : options.breadcrumbs;
8
- const _ignoreOutgoingRequests = options.ignoreOutgoingRequests;
9
-
10
- return {
11
- name: 'NodeFetch',
12
- setupOnce() {
13
- const propagationDecisionMap = new LRUMap(100);
14
-
15
- const instrumentation = new UndiciInstrumentation({
16
- requireParentforSpans: false,
17
- ignoreRequestHook: request => {
18
- const url = getAbsoluteUrl(request.origin, request.path);
19
- const shouldIgnore = _ignoreOutgoingRequests && url && _ignoreOutgoingRequests(url);
20
-
21
- if (shouldIgnore) {
22
- return true;
23
- }
24
-
25
- // If span recording is disabled, we still want to propagate traces
26
- // So we do that manually here, matching what the instrumentation does otherwise
27
- if (!hasSpansEnabled()) {
28
- const tracePropagationTargets = getClient()?.getOptions().tracePropagationTargets;
29
- const addedHeaders = shouldPropagateTraceForUrl(url, tracePropagationTargets, propagationDecisionMap)
30
- ? getTraceData()
31
- : {};
32
-
33
- const requestHeaders = request.headers;
34
- if (Array.isArray(requestHeaders)) {
35
- Object.entries(addedHeaders).forEach(headers => requestHeaders.push(...headers));
36
- } else {
37
- request.headers += Object.entries(addedHeaders)
38
- .map(([k, v]) => `${k}: ${v}\r\n`)
39
- .join('');
40
- }
41
-
42
- // Prevent starting a span for this request
43
- return true;
44
- }
45
-
46
- return false;
47
- },
48
- startSpanHook: () => {
49
- return {
50
- [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.node_fetch',
51
- };
52
- },
53
- responseHook: (_, { request, response }) => {
54
- if (_breadcrumbs) {
55
- addRequestBreadcrumb(request, response);
56
- }
57
- },
58
- });
59
-
60
- registerInstrumentations({ instrumentations: [instrumentation] });
61
- },
62
- };
63
- }) ;
64
-
65
- const nativeNodeFetchIntegration = defineIntegration(_nativeNodeFetchIntegration);
66
-
67
- /** Add a breadcrumb for outgoing requests. */
68
- function addRequestBreadcrumb(request, response) {
69
- const data = getBreadcrumbData(request);
70
- const statusCode = response.statusCode;
71
- const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);
72
-
73
- addBreadcrumb(
74
- {
75
- category: 'http',
76
- data: {
77
- status_code: statusCode,
78
- ...data,
79
- },
80
- type: 'http',
81
- level,
82
- },
83
- {
84
- event: 'response',
85
- request,
86
- response,
87
- },
88
- );
89
- }
90
-
91
- function getBreadcrumbData(request) {
92
- try {
93
- const url = new URL(request.path, request.origin);
94
- const parsedUrl = parseUrl(url.toString());
95
-
96
- const data = {
97
- url: getSanitizedUrlString(parsedUrl),
98
- 'http.method': request.method || 'GET',
99
- };
100
-
101
- if (parsedUrl.search) {
102
- data['http.query'] = parsedUrl.search;
103
- }
104
- if (parsedUrl.hash) {
105
- data['http.fragment'] = parsedUrl.hash;
106
- }
107
-
108
- return data;
109
- } catch {
110
- return {};
111
- }
112
- }
113
-
114
- // Matching the behavior of the base instrumentation
115
- function getAbsoluteUrl(origin, path = '/') {
116
- const url = `${origin}`;
117
-
118
- if (url.endsWith('/') && path.startsWith('/')) {
119
- return `${url}${path.slice(1)}`;
120
- }
121
-
122
- if (!url.endsWith('/') && !path.startsWith('/')) {
123
- return `${url}/${path.slice(1)}`;
124
- }
125
-
126
- return `${url}${path}`;
127
- }
128
-
129
- export { nativeNodeFetchIntegration };
130
- //# sourceMappingURL=node-fetch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-fetch.js","sources":["../../../src/integrations/node-fetch.ts"],"sourcesContent":["import { registerInstrumentations } from '@opentelemetry/instrumentation';\nimport type { UndiciRequest, UndiciResponse } from '@opentelemetry/instrumentation-undici';\nimport { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';\nimport type { IntegrationFn, SanitizedRequestData } from '@sentry/core';\nimport {\n LRUMap,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n addBreadcrumb,\n defineIntegration,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n getSanitizedUrlString,\n getTraceData,\n hasSpansEnabled,\n parseUrl,\n} from '@sentry/core';\nimport { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';\n\ninterface NodeFetchOptions {\n /**\n * Whether breadcrumbs should be recorded for requests.\n * Defaults to true\n */\n breadcrumbs?: boolean;\n\n /**\n * Do not capture spans or breadcrumbs for outgoing fetch requests to URLs where the given callback returns `true`.\n * This controls both span & breadcrumb creation - spans will be non recording if tracing is disabled.\n */\n ignoreOutgoingRequests?: (url: string) => boolean;\n}\n\nconst _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => {\n const _breadcrumbs = typeof options.breadcrumbs === 'undefined' ? true : options.breadcrumbs;\n const _ignoreOutgoingRequests = options.ignoreOutgoingRequests;\n\n return {\n name: 'NodeFetch',\n setupOnce() {\n const propagationDecisionMap = new LRUMap<string, boolean>(100);\n\n const instrumentation = new UndiciInstrumentation({\n requireParentforSpans: false,\n ignoreRequestHook: request => {\n const url = getAbsoluteUrl(request.origin, request.path);\n const shouldIgnore = _ignoreOutgoingRequests && url && _ignoreOutgoingRequests(url);\n\n if (shouldIgnore) {\n return true;\n }\n\n // If span recording is disabled, we still want to propagate traces\n // So we do that manually here, matching what the instrumentation does otherwise\n if (!hasSpansEnabled()) {\n const tracePropagationTargets = getClient()?.getOptions().tracePropagationTargets;\n const addedHeaders = shouldPropagateTraceForUrl(url, tracePropagationTargets, propagationDecisionMap)\n ? getTraceData()\n : {};\n\n const requestHeaders = request.headers;\n if (Array.isArray(requestHeaders)) {\n Object.entries(addedHeaders).forEach(headers => requestHeaders.push(...headers));\n } else {\n request.headers += Object.entries(addedHeaders)\n .map(([k, v]) => `${k}: ${v}\\r\\n`)\n .join('');\n }\n\n // Prevent starting a span for this request\n return true;\n }\n\n return false;\n },\n startSpanHook: () => {\n return {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.node_fetch',\n };\n },\n responseHook: (_, { request, response }) => {\n if (_breadcrumbs) {\n addRequestBreadcrumb(request, response);\n }\n },\n });\n\n registerInstrumentations({ instrumentations: [instrumentation] });\n },\n };\n}) satisfies IntegrationFn;\n\nexport const nativeNodeFetchIntegration = defineIntegration(_nativeNodeFetchIntegration);\n\n/** Add a breadcrumb for outgoing requests. */\nfunction addRequestBreadcrumb(request: UndiciRequest, response: UndiciResponse): void {\n const data = getBreadcrumbData(request);\n const statusCode = response.statusCode;\n const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);\n\n addBreadcrumb(\n {\n category: 'http',\n data: {\n status_code: statusCode,\n ...data,\n },\n type: 'http',\n level,\n },\n {\n event: 'response',\n request,\n response,\n },\n );\n}\n\nfunction getBreadcrumbData(request: UndiciRequest): Partial<SanitizedRequestData> {\n try {\n const url = new URL(request.path, request.origin);\n const parsedUrl = parseUrl(url.toString());\n\n const data: Partial<SanitizedRequestData> = {\n url: getSanitizedUrlString(parsedUrl),\n 'http.method': request.method || 'GET',\n };\n\n if (parsedUrl.search) {\n data['http.query'] = parsedUrl.search;\n }\n if (parsedUrl.hash) {\n data['http.fragment'] = parsedUrl.hash;\n }\n\n return data;\n } catch {\n return {};\n }\n}\n\n// Matching the behavior of the base instrumentation\nfunction getAbsoluteUrl(origin: string, path: string = '/'): string {\n const url = `${origin}`;\n\n if (url.endsWith('/') && path.startsWith('/')) {\n return `${url}${path.slice(1)}`;\n }\n\n if (!url.endsWith('/') && !path.startsWith('/')) {\n return `${url}/${path.slice(1)}`;\n }\n\n return `${url}${path}`;\n}\n"],"names":[],"mappings":";;;;;AAgCA,MAAM,2BAAA,IAA+B,CAAC,OAAO,GAAqB,EAAE,KAAK;AACzE,EAAE,MAAM,YAAA,GAAe,OAAO,OAAO,CAAC,WAAA,KAAgB,WAAA,GAAc,IAAA,GAAO,OAAO,CAAC,WAAW;AAC9F,EAAE,MAAM,uBAAA,GAA0B,OAAO,CAAC,sBAAsB;;AAEhE,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,WAAW;AACrB,IAAI,SAAS,GAAG;AAChB,MAAM,MAAM,sBAAuB,GAAE,IAAI,MAAM,CAAkB,GAAG,CAAC;;AAErE,MAAM,MAAM,eAAA,GAAkB,IAAI,qBAAqB,CAAC;AACxD,QAAQ,qBAAqB,EAAE,KAAK;AACpC,QAAQ,iBAAiB,EAAE,OAAA,IAAW;AACtC,UAAU,MAAM,GAAA,GA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