Skip to content

Commit

Permalink
feat: disable tracing through headers (#1189)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisnithin authored Sep 19, 2024
1 parent 180c714 commit c23fd77
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
8 changes: 6 additions & 2 deletions playground/src/components/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ export const Playground = (input: {
}, [schema, clientValidationEnabled]);

const [debouncedQuery] = useDebounce(query, 300);
const [debouncedHeaders] = useDebounce(headers, 300);

useEffect(() => {
const getPlan = async () => {
Expand All @@ -418,10 +419,13 @@ export const Playground = (input: {
return;
}

const existingHeaders = JSON.parse(debouncedHeaders || '{}');
delete existingHeaders['X-WG-TRACE'];
const requestHeaders: Record<string, string> = {
...JSON.parse(headers),
...existingHeaders,
'X-WG-Include-Query-Plan': 'true',
'X-WG-Skip-Loader': 'true',
'X-WG-DISABLE-TRACING': 'true',
};

validateHeaders(requestHeaders);
Expand All @@ -448,7 +452,7 @@ export const Playground = (input: {
};

getPlan();
}, [debouncedQuery, headers, url, schema]);
}, [debouncedQuery, debouncedHeaders, url, schema]);

return (
<TooltipProvider>
Expand Down
1 change: 1 addition & 0 deletions router/core/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ func NewRouter(opts ...Option) (*Router, error) {
"apollographql-client-version",
// Required for WunderGraph ART
"x-wg-trace",
"x-wg-disable-tracing",
"x-wg-token",
"x-wg-skip-loader",
"x-wg-include-query-plan",
Expand Down
2 changes: 1 addition & 1 deletion router/internal/graphiql/graphiql.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions router/pkg/config/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@
"Apollo-Graphql-Client-Name",
"Apollo-Graphql-Client-Version",
"x-wg-trace",
"x-wg-disable-tracing",
"x-wg-token",
"x-wg-include-query-plan",
"x-wg-skip-loader",
Expand Down
4 changes: 4 additions & 0 deletions router/pkg/trace/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func CommonRequestFilter(r *http.Request) bool {
if r.Method == "GET" && r.Header.Get("Upgrade") != "" {
return false
}
// Ignore if client disables tracing through header
if r.Header.Get("X-WG-DISABLE-TRACING") == "true" {
return false
}
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ const PlaygroundPage: NextPageWithLayout = () => {
]);

const [debouncedQuery] = useDebounce(query, 300);
const [debouncedHeaders] = useDebounce(headers, 300);

useEffect(() => {
const getPlan = async () => {
Expand All @@ -836,11 +837,14 @@ const PlaygroundPage: NextPageWithLayout = () => {
return;
}

const existingHeaders = JSON.parse(debouncedHeaders || "{}");
delete existingHeaders["X-WG-TRACE"];
const requestHeaders: Record<string, string> = {
...JSON.parse(headers),
...existingHeaders,
"X-WG-Token": graphContext.graphRequestToken,
"X-WG-Include-Query-Plan": "true",
"X-WG-Skip-Loader": "true",
"X-WG-DISABLE-TRACING": "true",
};

validateHeaders(requestHeaders);
Expand Down Expand Up @@ -879,9 +883,9 @@ const PlaygroundPage: NextPageWithLayout = () => {
getPlan();
}, [
debouncedQuery,
debouncedHeaders,
graphContext?.featureFlagsInLatestValidComposition,
graphContext?.graphRequestToken,
headers,
loadSchemaGraphId,
routingUrl,
schema,
Expand Down

0 comments on commit c23fd77

Please sign in to comment.