Skip to content

Commit

Permalink
fix(core): Apply breadcrumb log level function in packages where `add…
Browse files Browse the repository at this point in the history
…Breadcrumb` is called

Signed-off-by: Kaung Zin Hein <kaungzinhein113@gmail.com>
  • Loading branch information
Zen-cronic committed Sep 18, 2024
1 parent 80efec1 commit 3100ead
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 7 deletions.
8 changes: 7 additions & 1 deletion packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
addHistoryInstrumentationHandler,
addXhrInstrumentationHandler,
} from '@sentry-internal/browser-utils';
import { addBreadcrumb, defineIntegration, getClient } from '@sentry/core';
import { addBreadcrumb, defineIntegration, getBreadcrumbLogLevel, getClient } from '@sentry/core';
import type {
Breadcrumb,
Client,
Expand Down Expand Up @@ -247,11 +247,14 @@ function _getXhrBreadcrumbHandler(client: Client): (handlerData: HandlerDataXhr)
endTimestamp,
};

const level = getBreadcrumbLogLevel(status_code);

addBreadcrumb(
{
category: 'xhr',
data,
type: 'http',
level,
},
hint,
);
Expand Down Expand Up @@ -309,11 +312,14 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
startTimestamp,
endTimestamp,
};
const level = getBreadcrumbLogLevel(data.status_code);

addBreadcrumb(
{
category: 'fetch',
data,
type: 'http',
level,
},
hint,
);
Expand Down
12 changes: 11 additions & 1 deletion packages/cloudflare/src/integrations/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { addBreadcrumb, defineIntegration, getClient, instrumentFetchRequest, isSentryRequestUrl } from '@sentry/core';
import {
addBreadcrumb,
defineIntegration,
getBreadcrumbLogLevel,
getClient,
instrumentFetchRequest,
isSentryRequestUrl,
} from '@sentry/core';
import type {
Client,
FetchBreadcrumbData,
Expand Down Expand Up @@ -144,11 +151,14 @@ function createBreadcrumb(handlerData: HandlerDataFetch): void {
startTimestamp,
endTimestamp,
};
const level = getBreadcrumbLogLevel(data.status_code);

addBreadcrumb(
{
category: 'fetch',
data,
type: 'http',
level,
},
hint,
);
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export { parseSampleRate } from './utils/parseSampleRate';
export { applySdkMetadata } from './utils/sdkMetadata';
export { getTraceData } from './utils/traceData';
export { getTraceMetaTags } from './utils/meta';
export { getBreadcrumbLogLevel } from './utils/breadcrumbsUtils';
export { DEFAULT_ENVIRONMENT } from './constants';
export { addBreadcrumb } from './breadcrumbs';
export { functionToStringIntegration } from './integrations/functiontostring';
Expand Down
5 changes: 4 additions & 1 deletion packages/deno/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addBreadcrumb, defineIntegration, getClient } from '@sentry/core';
import { addBreadcrumb, defineIntegration, getBreadcrumbLogLevel, getClient } from '@sentry/core';
import type {
Client,
Event as SentryEvent,
Expand Down Expand Up @@ -178,11 +178,14 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
startTimestamp,
endTimestamp,
};
const level = getBreadcrumbLogLevel(data.status_code);

addBreadcrumb(
{
category: 'fetch',
data,
type: 'http',
level,
},
hint,
);
Expand Down
7 changes: 6 additions & 1 deletion packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
import {
addBreadcrumb,
defineIntegration,
getBreadcrumbLogLevel,
getCapturedScopesOnSpan,
getCurrentScope,
getIsolationScope,
Expand Down Expand Up @@ -229,14 +230,18 @@ function _addRequestBreadcrumb(
}

const data = getBreadcrumbData(request);
const statusCode = response.statusCode;
const level = getBreadcrumbLogLevel(statusCode);

addBreadcrumb(
{
category: 'http',
data: {
status_code: response.statusCode,
status_code: statusCode,
...data,
},
type: 'http',
level,
},
{
event: 'response',
Expand Down
12 changes: 10 additions & 2 deletions packages/node/src/integrations/node-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { UndiciRequest, UndiciResponse } from '@opentelemetry/instrumentation-undici';
import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, addBreadcrumb, defineIntegration } from '@sentry/core';
import {
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
addBreadcrumb,
defineIntegration,
getBreadcrumbLogLevel,
} from '@sentry/core';
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
import type { IntegrationFn, SanitizedRequestData } from '@sentry/types';
import { getSanitizedUrlString, parseUrl } from '@sentry/utils';
Expand Down Expand Up @@ -56,15 +61,18 @@ export const nativeNodeFetchIntegration = defineIntegration(_nativeNodeFetchInte
/** Add a breadcrumb for outgoing requests. */
function addRequestBreadcrumb(request: UndiciRequest, response: UndiciResponse): void {
const data = getBreadcrumbData(request);
const statusCode = response.statusCode;
const level = getBreadcrumbLogLevel(statusCode);

addBreadcrumb(
{
category: 'http',
data: {
status_code: response.statusCode,
status_code: statusCode,
...data,
},
type: 'http',
level,
},
{
event: 'response',
Expand Down
12 changes: 11 additions & 1 deletion packages/vercel-edge/src/integrations/wintercg-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { addBreadcrumb, defineIntegration, getClient, instrumentFetchRequest, isSentryRequestUrl } from '@sentry/core';
import {
addBreadcrumb,
defineIntegration,
getBreadcrumbLogLevel,
getClient,
instrumentFetchRequest,
isSentryRequestUrl,
} from '@sentry/core';
import type {
Client,
FetchBreadcrumbData,
Expand Down Expand Up @@ -150,11 +157,14 @@ function createBreadcrumb(handlerData: HandlerDataFetch): void {
startTimestamp,
endTimestamp,
};
const level = getBreadcrumbLogLevel(data.status_code);

addBreadcrumb(
{
category: 'fetch',
data,
type: 'http',
level,
},
hint,
);
Expand Down

0 comments on commit 3100ead

Please sign in to comment.