Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: new config to enable stellate debug header and customFetch for l… #5683

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/dev-custom-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export default merge(base, devVm, {
gaId: 'UA-11686022-7', // dev-vm property
enableSentry: false,
sentryURI: 'https://[email protected]/1201287',
// apolloQueryFetchLogging: process.env.APOLLO_QUERY_FETCH_LOGGING || true,
// Testing values for stellate, uncomment and adjust as needed
// stellateGraphqlUri: process.env.STELLATE_GRAPHQL_URI || 'https://kiva.stellate.sh',
// stellateDebugHeaders: process.env.STELLATE_DEBUG_HEADERS || true,
// stellateGraphqlUri: process.env.STELLATE_GRAPHQL_URI || 'https://kiva-staging.stellate.sh',
// eslint-disable-next-line max-len
// stellateCachedOperations: process.env.STELLATE_CACHED_OPERATIONS || 'configSetting,experimentIds,experimentSetting',
auth0: {
Expand Down
2 changes: 2 additions & 0 deletions config/dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const app = {
defaultIndex: `${env}_fundraising_popularity`,
},
apolloBatching,
apolloQueryFetchLogging: process.env.APOLLO_QUERY_FETCH_LOGGING || false,
apolloNetworkErrorRetryActive,
apolloNetworkErrorRetryAttempts,
auth0: {
Expand Down Expand Up @@ -87,6 +88,7 @@ export const app = {
sentryURI: process.env.SENTRY_URI || 'https://[email protected]/1201287',
sentryTraceSampleRate: process.env.SENTRY_TRACE_RATE || 0.25,
snowplowUri: process.env.SNOWPLOW_URI || 'events.fivetran.com/snowplow/v5qt54ocr2nm',
stellateDebugHeaders: process.env.STELLATE_DEBUG_HEADERS || false,
stellateGraphqlUri: process.env.STELLATE_GRAPHQL_URI || null,
stellateCachedOperations: process.env.STELLATE_CACHED_OPERATIONS || '',
transport: 'https',
Expand Down
5 changes: 5 additions & 0 deletions src/api/HttpLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default ({
uri = '',
fetch,
apolloBatching,
stellateDebugHeaders,
stellateGraphqlUri,
stellateCachedOperations,
}) => {
Expand All @@ -26,6 +27,10 @@ export default ({
// Create a new options object for stellate
const stellateOptions = {
...options,
headers: stellateDebugHeaders ? {
...options?.headers,
'gcdn-debug': 1,
} : {},
uri: stellateGraphqlUri ?? uri,
};

Expand Down
1 change: 1 addition & 0 deletions src/api/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function createApolloClient({
uri,
fetch,
apolloBatching: appConfig?.apolloBatching ?? true,
stellateDebugHeaders: appConfig?.stellateDebugHeaders,
stellateGraphqlUri: appConfig?.stellateGraphqlUri,
stellateCachedOperations: appConfig?.stellateCachedOperations,
}),
Expand Down
15 changes: 14 additions & 1 deletion src/server-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ import fetch from 'make-fetch-happen';

const isDev = process.env.NODE_ENV !== 'production';

// custom fetch wrapper to log fetch requests
const customFetch = async (uri, options) => {
const response = await fetch(uri, options);
// Log the outgoing options
logFormatter(`Fetch Options: ${uri}, Options: ${JSON.stringify(options)}`);

// Log the full response
// eslint-disable-next-line max-len
logFormatter(`Server fetch: ${uri}, Status: ${response.status}, Headers: ${JSON.stringify(response.headers.raw())}`);

return response;
};

function fillTemplate(template, data) {
let html = template;
Object.keys(data).forEach(key => {
Expand Down Expand Up @@ -167,7 +180,7 @@ export default async context => {
device,
kvAuth0,
locale,
fetch,
fetch: config?.apolloQueryFetchLogging ? customFetch : fetch,
url,
isServer: true,
});
Expand Down
Loading