Skip to content

Commit 1d5fd3d

Browse files
committed
Merge branch 'feat/graphqlClientIntegration' of https://github.com/Zen-cronic/sentry-javascript into feat/graphqlClientIntegration
2 parents 87031de + 81a7408 commit 1d5fd3d

File tree

13 files changed

+43
-650
lines changed

13 files changed

+43
-650
lines changed

dev-packages/browser-integration-tests/suites/integrations/graphqlClient/fetch/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const query = `query Test{
1313
}`;
1414
const queryPayload = JSON.stringify({ query });
1515

16-
sentryTest('should update spans for GraphQL Fetch requests', async ({ getLocalTestPath, page }) => {
17-
const url = await getLocalTestPath({ testDir: __dirname });
16+
sentryTest('should update spans for GraphQL Fetch requests', async ({ getLocalTestUrl, page }) => {
17+
const url = await getLocalTestUrl({ testDir: __dirname });
1818

1919
await page.route('**/foo', route => {
2020
return route.fulfill({
@@ -57,8 +57,8 @@ sentryTest('should update spans for GraphQL Fetch requests', async ({ getLocalTe
5757
});
5858
});
5959

60-
sentryTest('should update breadcrumbs for GraphQL Fetch requests', async ({ getLocalTestPath, page }) => {
61-
const url = await getLocalTestPath({ testDir: __dirname });
60+
sentryTest('should update breadcrumbs for GraphQL Fetch requests', async ({ getLocalTestUrl, page }) => {
61+
const url = await getLocalTestUrl({ testDir: __dirname });
6262

6363
await page.route('**/foo', route => {
6464
return route.fulfill({

dev-packages/browser-integration-tests/suites/integrations/graphqlClient/xhr/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const query = `query Test{
1313
}`;
1414
const queryPayload = JSON.stringify({ query });
1515

16-
sentryTest('should update spans for GraphQL XHR requests', async ({ getLocalTestPath, page }) => {
17-
const url = await getLocalTestPath({ testDir: __dirname });
16+
sentryTest('should update spans for GraphQL XHR requests', async ({ getLocalTestUrl, page }) => {
17+
const url = await getLocalTestUrl({ testDir: __dirname });
1818

1919
await page.route('**/foo', route => {
2020
return route.fulfill({
@@ -57,8 +57,8 @@ sentryTest('should update spans for GraphQL XHR requests', async ({ getLocalTest
5757
});
5858
});
5959

60-
sentryTest('should update breadcrumbs for GraphQL XHR requests', async ({ getLocalTestPath, page }) => {
61-
const url = await getLocalTestPath({ testDir: __dirname });
60+
sentryTest('should update breadcrumbs for GraphQL XHR requests', async ({ getLocalTestUrl, page }) => {
61+
const url = await getLocalTestUrl({ testDir: __dirname });
6262

6363
await page.route('**/foo', route => {
6464
return route.fulfill({

packages/browser/src/index.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ export {
1212
captureFeedback,
1313
} from '@sentry/core';
1414

15-
export {
16-
replayIntegration,
17-
getReplay,
18-
} from '@sentry-internal/replay';
15+
export { replayIntegration, getReplay } from '@sentry-internal/replay';
1916
export type {
2017
ReplayEventType,
2118
ReplayEventWithTime,
@@ -35,8 +32,6 @@ import { feedbackSyncIntegration } from './feedbackSync';
3532
export { feedbackAsyncIntegration, feedbackSyncIntegration, feedbackSyncIntegration as feedbackIntegration };
3633
export { getFeedback, sendFeedback } from '@sentry-internal/feedback';
3734

38-
export * from './metrics';
39-
4035
export { defaultRequestInstrumentationOptions, instrumentOutgoingRequests } from './tracing/request';
4136
export {
4237
browserTracingIntegration,
@@ -62,7 +57,7 @@ export {
6257
zodErrorsIntegration,
6358
thirdPartyErrorFilterIntegration,
6459
} from '@sentry/core';
65-
export type { Span } from '@sentry/types';
60+
export type { Span } from '@sentry/core';
6661
export { makeBrowserOfflineTransport } from './transports/offline';
6762
export { browserProfilingIntegration } from './profiling/integration';
6863
export { spotlightBrowserIntegration } from './integrations/spotlight';
@@ -73,4 +68,4 @@ export {
7368
} from './integrations/featureFlags';
7469
export { launchDarklyIntegration, buildLaunchDarklyFlagUsedHandler } from './integrations/featureFlags/launchdarkly';
7570
export { openFeatureIntegration, OpenFeatureIntegrationHook } from './integrations/featureFlags/openfeature';
76-
export { unleashIntegration } from './integrations/featureFlags/unleash';
71+
export { unleashIntegration } from './integrations/featureFlags/unleash';

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
292292
};
293293

294294
if (handlerData.error) {
295+
const data: FetchBreadcrumbData = handlerData.fetchData;
295296
const hint: FetchBreadcrumbHint = {
296297
data: handlerData.error,
297298
input: handlerData.args,
@@ -311,7 +312,11 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
311312
addBreadcrumb(breadcrumb, hint);
312313
} else {
313314
const response = handlerData.response as Response | undefined;
314-
315+
const data: FetchBreadcrumbData = {
316+
...handlerData.fetchData,
317+
status_code: response && response.status,
318+
};
319+
315320
breadcrumbData.request_body_size = handlerData.fetchData.request_body_size;
316321
breadcrumbData.response_body_size = handlerData.fetchData.response_body_size;
317322
breadcrumbData.status_code = response?.status;

packages/browser/src/integrations/graphqlClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
defineIntegration,
99
spanToJSON,
1010
} from '@sentry/core';
11-
import type { Client, IntegrationFn } from '@sentry/types';
12-
import { isString, stringMatchesSomePattern } from '@sentry/utils';
11+
import type { Client, IntegrationFn } from '@sentry/core';
12+
import { isString, stringMatchesSomePattern } from '@sentry/core';
1313

1414
interface GraphQLClientOptions {
1515
endpoints: Array<string | RegExp>;

packages/browser/src/tracing/request.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
addXhrInstrumentationHandler,
55
} from '@sentry-internal/browser-utils';
66
import type { Client, HandlerDataXhr, SentryWrappedXMLHttpRequest, Span } from '@sentry/core';
7-
import type { XhrHint } from '@sentry-internal/replay';
87
import {
98
SEMANTIC_ATTRIBUTE_SENTRY_OP,
109
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
@@ -13,6 +12,7 @@ import {
1312
addFetchInstrumentationHandler,
1413
browserPerformanceTimeOrigin,
1514
getActiveSpan,
15+
getClient,
1616
getLocationHref,
1717
getTraceData,
1818
hasTracingEnabled,
@@ -21,19 +21,10 @@ import {
2121
setHttpStatus,
2222
spanToJSON,
2323
startInactiveSpan,
24-
} from '@sentry/core';
25-
import type { Client, HandlerDataXhr, SentryWrappedXMLHttpRequest, Span } from '@sentry/types';
26-
import {
27-
BAGGAGE_HEADER_NAME,
28-
addFetchEndInstrumentationHandler,
29-
addFetchInstrumentationHandler,
30-
browserPerformanceTimeOrigin,
31-
dynamicSamplingContextToSentryBaggageHeader,
32-
generateSentryTraceHeader,
33-
parseUrl,
3424
stringMatchesSomePattern,
3525
} from '@sentry/core';
3626
import { WINDOW } from '../helpers';
27+
import { XhrHint } from '@sentry-internal/replay';
3728

3829
/** Options for Request Instrumentation */
3930
export interface RequestInstrumentationOptions {
@@ -415,6 +406,7 @@ export function xhrCallback(
415406
);
416407
}
417408

409+
const client = getClient();
418410
if (client) {
419411
client.emit('beforeOutgoingRequestSpan', span, handlerData as XhrHint);
420412
}

packages/browser/test/integrations/graphqlClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('GraphqlClient', () => {
7979
queryThree,
8080
{ operationName: 'OnTestItemAdded', operationType: 'subscription' },
8181
],
82-
// ['should handle query without name', queryFour, { operationName: undefined, operationType: 'query' }],
82+
// TODO: ['should handle query without name', queryFour, { operationName: undefined, operationType: 'query' }],
8383
])('%s', (_, input, output) => {
8484
expect(parseGraphQLQuery(input)).toEqual(output);
8585
});

packages/core/src/client.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,16 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
594594
*/
595595
public on(hook: 'startNavigationSpan', callback: (options: StartSpanOptions) => void): () => void;
596596

597-
/** @inheritdoc */
597+
/**
598+
* A hook for GraphQL client integration to enhance a span with request data.
599+
* @returns A function that, when executed, removes the registered callback.
600+
*/
598601
public on(hook: 'beforeOutgoingRequestSpan', callback: (span: Span, hint: XhrHint | FetchHint) => void): () => void;
599602

600-
/** @inheritdoc */
603+
/**
604+
* A hook for GraphQL client integration to enhance a breadcrumb with request data.
605+
* @returns A function that, when executed, removes the registered callback.
606+
*/
601607
public on(
602608
hook: 'beforeOutgoingRequestBreadcrumb',
603609
callback: (breadcrumb: Breadcrumb, hint: XhrHint | FetchHint) => void,
@@ -729,13 +735,19 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
729735
*/
730736
public emit(hook: 'startNavigationSpan', options: StartSpanOptions): void;
731737

732-
/** @inheritdoc */
738+
/**
739+
* Emit a hook event for GraphQL client integration to enhance a span with request data.
740+
*/
733741
public emit(hook: 'beforeOutgoingRequestSpan', span: Span, hint: XhrHint | FetchHint): void;
734742

735-
/** @inheritdoc */
743+
/**
744+
* Emit a hook event for GraphQL client integration to enhance a breadcrumb with request data.
745+
*/
736746
public emit(hook: 'beforeOutgoingRequestBreadcrumb', breadcrumb: Breadcrumb, hint: XhrHint | FetchHint): void;
737747

738-
/** @inheritdoc */
748+
/**
749+
* Emit a hook event for client flush
750+
*/
739751
public emit(hook: 'flush'): void;
740752

741753
/**

packages/core/src/fetch.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
import type { Client, HandlerDataFetch, Scope, Span, SpanOrigin } from '@sentry/types';
2-
import {
3-
BAGGAGE_HEADER_NAME,
4-
dynamicSamplingContextToSentryBaggageHeader,
5-
generateSentryTraceHeader,
6-
isInstanceOf,
7-
parseUrl,
8-
} from '@sentry/utils';
9-
import type { FetchHint } from './baseclient';
10-
import { getClient, getCurrentScope, getIsolationScope } from './currentScopes';
1+
import { FetchHint } from './client';
2+
import { getClient } from './currentScopes';
113
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes';
124
import { SPAN_STATUS_ERROR, setHttpStatus, startInactiveSpan } from './tracing';
135
import { SentryNonRecordingSpan } from './tracing/sentryNonRecordingSpan';
@@ -60,9 +52,6 @@ export function instrumentFetchRequest(
6052
return undefined;
6153
}
6254

63-
const scope = getCurrentScope();
64-
const client = getClient();
65-
6655
const { method, url } = handlerData.fetchData;
6756

6857
const fullUrl = getFullURL(url);
@@ -109,6 +98,7 @@ export function instrumentFetchRequest(
10998
}
11099
}
111100

101+
const client = getClient();
112102
if (client) {
113103
// There's no 'input' key in HandlerDataFetch
114104
const fetchHint = {

packages/core/test/utils-hoist/graphql.test.ts

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

0 commit comments

Comments
 (0)