Skip to content

Commit e5e33ee

Browse files
author
Luca Forstner
committed
Clean up
1 parent bfa9caf commit e5e33ee

File tree

13 files changed

+75
-77
lines changed

13 files changed

+75
-77
lines changed

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
addHistoryInstrumentationHandler,
55
addXhrInstrumentationHandler,
66
} from '@sentry-internal/browser-utils';
7-
import { addBreadcrumb, defineIntegration, getBreadcrumbLogLevel, getClient } from '@sentry/core';
7+
import { addBreadcrumb, defineIntegration, getClient } from '@sentry/core';
88
import type {
99
Breadcrumb,
1010
Client,
@@ -23,6 +23,7 @@ import type {
2323
import {
2424
addConsoleInstrumentationHandler,
2525
addFetchInstrumentationHandler,
26+
getBreadcrumbLogLevelFromHttpStatusCode,
2627
getComponentName,
2728
getEventDescription,
2829
htmlTreeAsString,
@@ -247,14 +248,14 @@ function _getXhrBreadcrumbHandler(client: Client): (handlerData: HandlerDataXhr)
247248
endTimestamp,
248249
};
249250

250-
const level = getBreadcrumbLogLevel(status_code);
251+
const level = getBreadcrumbLogLevelFromHttpStatusCode(status_code);
251252

252253
addBreadcrumb(
253254
{
254255
category: 'xhr',
255256
data,
256257
type: 'http',
257-
...level,
258+
level,
258259
},
259260
hint,
260261
);
@@ -312,14 +313,14 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
312313
startTimestamp,
313314
endTimestamp,
314315
};
315-
const level = getBreadcrumbLogLevel(data.status_code);
316+
const level = getBreadcrumbLogLevelFromHttpStatusCode(data.status_code);
316317

317318
addBreadcrumb(
318319
{
319320
category: 'fetch',
320321
data,
321322
type: 'http',
322-
...level,
323+
level,
323324
},
324325
hint,
325326
);

packages/cloudflare/src/integrations/fetch.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
addBreadcrumb,
3-
defineIntegration,
4-
getBreadcrumbLogLevel,
5-
getClient,
6-
instrumentFetchRequest,
7-
isSentryRequestUrl,
8-
} from '@sentry/core';
1+
import { addBreadcrumb, defineIntegration, getClient, instrumentFetchRequest, isSentryRequestUrl } from '@sentry/core';
92
import type {
103
Client,
114
FetchBreadcrumbData,
@@ -14,7 +7,12 @@ import type {
147
IntegrationFn,
158
Span,
169
} from '@sentry/types';
17-
import { LRUMap, addFetchInstrumentationHandler, stringMatchesSomePattern } from '@sentry/utils';
10+
import {
11+
LRUMap,
12+
addFetchInstrumentationHandler,
13+
getBreadcrumbLogLevelFromHttpStatusCode,
14+
stringMatchesSomePattern,
15+
} from '@sentry/utils';
1816

1917
const INTEGRATION_NAME = 'Fetch';
2018

@@ -151,14 +149,14 @@ function createBreadcrumb(handlerData: HandlerDataFetch): void {
151149
startTimestamp,
152150
endTimestamp,
153151
};
154-
const level = getBreadcrumbLogLevel(data.status_code);
152+
const level = getBreadcrumbLogLevelFromHttpStatusCode(data.status_code);
155153

156154
addBreadcrumb(
157155
{
158156
category: 'fetch',
159157
data,
160158
type: 'http',
161-
...level,
159+
level,
162160
},
163161
hint,
164162
);

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export { parseSampleRate } from './utils/parseSampleRate';
8484
export { applySdkMetadata } from './utils/sdkMetadata';
8585
export { getTraceData } from './utils/traceData';
8686
export { getTraceMetaTags } from './utils/meta';
87-
export { getBreadcrumbLogLevel } from './utils/breadcrumbsUtils';
8887
export { DEFAULT_ENVIRONMENT } from './constants';
8988
export { addBreadcrumb } from './breadcrumbs';
9089
export { functionToStringIntegration } from './integrations/functiontostring';

packages/core/src/utils/breadcrumbsUtils.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/core/test/lib/utils/breadcrumbsUtils.test.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/deno/src/integrations/breadcrumbs.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addBreadcrumb, defineIntegration, getBreadcrumbLogLevel, getClient } from '@sentry/core';
1+
import { addBreadcrumb, defineIntegration, getClient } from '@sentry/core';
22
import type {
33
Client,
44
Event as SentryEvent,
@@ -11,6 +11,7 @@ import type {
1111
import {
1212
addConsoleInstrumentationHandler,
1313
addFetchInstrumentationHandler,
14+
getBreadcrumbLogLevelFromHttpStatusCode,
1415
getEventDescription,
1516
safeJoin,
1617
severityLevelFromString,
@@ -178,14 +179,14 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
178179
startTimestamp,
179180
endTimestamp,
180181
};
181-
const level = getBreadcrumbLogLevel(data.status_code);
182+
const level = getBreadcrumbLogLevelFromHttpStatusCode(data.status_code);
182183

183184
addBreadcrumb(
184185
{
185186
category: 'fetch',
186187
data,
187188
type: 'http',
188-
...level,
189+
level,
189190
},
190191
hint,
191192
);

packages/node/src/integrations/http.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
66
import {
77
addBreadcrumb,
88
defineIntegration,
9-
getBreadcrumbLogLevel,
109
getCapturedScopesOnSpan,
1110
getCurrentScope,
1211
getIsolationScope,
@@ -15,7 +14,12 @@ import {
1514
import { getClient } from '@sentry/opentelemetry';
1615
import type { IntegrationFn, SanitizedRequestData } from '@sentry/types';
1716

18-
import { getSanitizedUrlString, parseUrl, stripUrlQueryAndFragment } from '@sentry/utils';
17+
import {
18+
getBreadcrumbLogLevelFromHttpStatusCode,
19+
getSanitizedUrlString,
20+
parseUrl,
21+
stripUrlQueryAndFragment,
22+
} from '@sentry/utils';
1923
import type { NodeClient } from '../sdk/client';
2024
import { setIsolationScope } from '../sdk/scope';
2125
import type { HTTPModuleRequestIncomingMessage } from '../transports/http-module';
@@ -231,7 +235,7 @@ function _addRequestBreadcrumb(
231235

232236
const data = getBreadcrumbData(request);
233237
const statusCode = response.statusCode;
234-
const level = getBreadcrumbLogLevel(statusCode);
238+
const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);
235239

236240
addBreadcrumb(
237241
{
@@ -241,7 +245,7 @@ function _addRequestBreadcrumb(
241245
...data,
242246
},
243247
type: 'http',
244-
...level,
248+
level,
245249
},
246250
{
247251
event: 'response',

packages/node/src/integrations/node-fetch.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import type { UndiciRequest, UndiciResponse } from '@opentelemetry/instrumentation-undici';
22
import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';
3-
import {
4-
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
5-
addBreadcrumb,
6-
defineIntegration,
7-
getBreadcrumbLogLevel,
8-
} from '@sentry/core';
3+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, addBreadcrumb, defineIntegration } from '@sentry/core';
94
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
105
import type { IntegrationFn, SanitizedRequestData } from '@sentry/types';
11-
import { getSanitizedUrlString, parseUrl } from '@sentry/utils';
6+
import { getBreadcrumbLogLevelFromHttpStatusCode, getSanitizedUrlString, parseUrl } from '@sentry/utils';
127

138
interface NodeFetchOptions {
149
/**
@@ -62,7 +57,7 @@ export const nativeNodeFetchIntegration = defineIntegration(_nativeNodeFetchInte
6257
function addRequestBreadcrumb(request: UndiciRequest, response: UndiciResponse): void {
6358
const data = getBreadcrumbData(request);
6459
const statusCode = response.statusCode;
65-
const level = getBreadcrumbLogLevel(statusCode);
60+
const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);
6661

6762
addBreadcrumb(
6863
{
@@ -72,7 +67,7 @@ function addRequestBreadcrumb(request: UndiciRequest, response: UndiciResponse):
7267
...data,
7368
},
7469
type: 'http',
75-
...level,
70+
level,
7671
},
7772
{
7873
event: 'response',

packages/types/src/scope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export interface Scope {
189189
clear(): this;
190190

191191
/**
192-
* Sets the breadcrumb in the scope
192+
* Adds a breadcrumb to the scope
193193
* @param breadcrumb Breadcrumb
194194
* @param maxBreadcrumbs number of max breadcrumbs to merged into event.
195195
*/
@@ -201,7 +201,7 @@ export interface Scope {
201201
getLastBreadcrumb(): Breadcrumb | undefined;
202202

203203
/**
204-
* Clears all currently set Breadcrumbs.
204+
* Clears all breadcrumbs from the scope.
205205
*/
206206
clearBreadcrumbs(): this;
207207

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { SeverityLevel } from '@sentry/types';
2+
3+
/**
4+
* Determine a breadcrumb's log level (only `warning` or `error`) based on an HTTP status code.
5+
*/
6+
export function getBreadcrumbLogLevelFromHttpStatusCode(statusCode: number | undefined): SeverityLevel | undefined {
7+
// NOTE: undefined defaults to 'info' in Sentry
8+
if (statusCode === undefined) {
9+
return undefined;
10+
} else if (statusCode >= 400 && statusCode < 500) {
11+
return 'warning';
12+
} else if (statusCode >= 500) {
13+
return 'error';
14+
} else {
15+
return undefined;
16+
}
17+
}

0 commit comments

Comments
 (0)