Skip to content
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
2 changes: 1 addition & 1 deletion demo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/wundergraph/cosmo/composition-go v0.0.0-20240124120900-5effe48a4a1d
github.com/wundergraph/cosmo/router v0.0.0-20250119174948-4b991294658e
github.com/wundergraph/cosmo/router-tests v0.0.0-20241213115435-a249dba8c52a
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.141
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.145
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.23.1
Expand Down
4 changes: 2 additions & 2 deletions demo/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ github.com/wundergraph/cosmo/router v0.0.0-20250119174948-4b991294658e h1:ee4fu7
github.com/wundergraph/cosmo/router v0.0.0-20250119174948-4b991294658e/go.mod h1:ImqCvxvvNOy1UxbuTnFtin/CDBFHoFqrZly3rC2z+e0=
github.com/wundergraph/cosmo/router-tests v0.0.0-20241213115435-a249dba8c52a h1:GVLe85f5g+G0IOorDBBNTfm5Ua9DO0vuVY7ReSTOEbQ=
github.com/wundergraph/cosmo/router-tests v0.0.0-20241213115435-a249dba8c52a/go.mod h1:I+SFviFnd3BHlPmYn+ckmzQyDB9+/c8RZJo4t6VQAds=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.141 h1:lPwwEJRYYuJflv7fhgwaWKt6FKRdX5CJ1Yp6RWzzKDA=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.141/go.mod h1:B7eV0Qh8Lop9QzIOQcsvKp3S0ejfC6mgyWoJnI917yQ=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.145 h1:3JuBmRux6YB/UZgh6COvgLXzQhMIsdHV7A02NsYdAVE=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.145/go.mod h1:B7eV0Qh8Lop9QzIOQcsvKp3S0ejfC6mgyWoJnI917yQ=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
2 changes: 1 addition & 1 deletion router-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/twmb/franz-go/pkg/kadm v1.11.0
github.com/wundergraph/cosmo/demo v0.0.0-20250119174948-4b991294658e
github.com/wundergraph/cosmo/router v0.0.0-20250119174948-4b991294658e
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.144
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.145
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/sdk/metric v1.28.0
Expand Down
4 changes: 2 additions & 2 deletions router-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ github.com/vektah/gqlparser/v2 v2.5.21 h1:Zw1rG2dr1pRR4wqwbVq4d6+xk2f4ut/yo+hwr4
github.com/vektah/gqlparser/v2 v2.5.21/go.mod h1:xMl+ta8a5M1Yo1A1Iwt/k7gSpscwSnHZdw7tfhEGfTM=
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083 h1:8/D7f8gKxTBjW+SZK4mhxTTBVpxcqeBgWF1Rfmltbfk=
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083/go.mod h1:eOTL6acwctsN4F3b7YE+eE2t8zcJ/doLm9sZzsxxxrE=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.144 h1:dkCHwG7ku5RzOWHcaDDG6cj/RXMZW7Q1spVKlLElAp4=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.144/go.mod h1:B7eV0Qh8Lop9QzIOQcsvKp3S0ejfC6mgyWoJnI917yQ=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.145 h1:3JuBmRux6YB/UZgh6COvgLXzQhMIsdHV7A02NsYdAVE=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.145/go.mod h1:B7eV0Qh8Lop9QzIOQcsvKp3S0ejfC6mgyWoJnI917yQ=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
}
]
}
]
],
"normalizedQuery": "query Requires {products {__typename ... on Consultancy {lead {__typename id derivedMood} isLeadAvailable}}}"
Comment thread
df-wg marked this conversation as resolved.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
}
]
}
]
],
"normalizedQuery": "query Requires {products {__typename ... on Consultancy {lead {__typename id derivedMood} isLeadAvailable}}}"
},
"trace": {
"version": "1",
Expand Down Expand Up @@ -214,6 +215,36 @@
]
}
]
},
"request": {
"method": "POST",
"url": "/graphql",
"headers": {
"Accept-Encoding": [
"identity"
],
"Content-Length": [
"294"
],
"User-Agent": [
"Go-http-client/1.1"
],
"X-Wg-Include-Query-Plan": [
"true"
],
"X-Wg-Skip-Loader": [
"true"
],
"X-Wg-Trace": [
"true",
"enable_predictable_debug_timings"
]
},
"body": {
"query": "query Requires {\n\t\t\t\t\t products {\n\t\t\t\t\t\t__typename\n\t\t\t\t\t\t... on Consultancy {\n\t\t\t\t\t\t lead {\n\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\tderivedMood\n\t\t\t\t\t\t }\n\t\t\t\t\t\t isLeadAvailable\n\t\t\t\t\t\t}\n\t\t\t\t\t }\n\t\t\t\t\t}",
"operationName": "Requires",
"variables": {}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@
}
]
}
]
],
"normalizedQuery": "query Requires {products {__typename ... on Consultancy {lead {__typename id derivedMood} isLeadAvailable}}}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@
}
]
}
]
],
"normalizedQuery": "query Requires {products {__typename ... on Consultancy {lead {__typename id derivedMood} isLeadAvailable}}}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
}
]
}
]
],
"normalizedQuery": "query Requires {products {__typename ... on Consultancy {lead {__typename id derivedMood} isLeadAvailable}}}"
},
"trace": {
"version": "1",
Expand Down Expand Up @@ -214,6 +215,36 @@
]
}
]
},
"request": {
"method": "POST",
"url": "/graphql",
"headers": {
"Accept-Encoding": [
"identity"
],
"Content-Length": [
"294"
],
"User-Agent": [
"Go-http-client/1.1"
],
"X-Wg-Include-Query-Plan": [
"true"
],
"X-Wg-Skip-Loader": [
"true"
],
"X-Wg-Trace": [
"true",
"enable_predictable_debug_timings"
]
},
"body": {
"query": "query Requires {\n\t\t\t\t\t products {\n\t\t\t\t\t\t__typename\n\t\t\t\t\t\t... on Consultancy {\n\t\t\t\t\t\t lead {\n\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\tderivedMood\n\t\t\t\t\t\t }\n\t\t\t\t\t\t isLeadAvailable\n\t\t\t\t\t\t}\n\t\t\t\t\t }\n\t\t\t\t\t}",
"operationName": "Requires",
"variables": {}
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions router-tests/testdata/tracing.json
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,29 @@
}
}
]
},
"request": {
"method": "POST",
"url": "/graphql",
"headers": {
"Accept-Encoding": [
"identity"
],
"Content-Length": [
"596"
],
"User-Agent": [
"Go-http-client/1.1"
],
"X-Wg-Trace": [
"true",
"enable_predictable_debug_timings"
]
},
"body": {
"query": "{\n employees {\n id\n details {\n forename\n surname\n hasChildren\n }\n role {\n title\n departments\n }\n hobbies {\n ... on Exercise {\n category\n }\n ... on Flying {\n planeModels\n yearsOfExperience\n }\n ... on Gaming {\n name\n genres\n yearsOfExperience\n }\n ... on Programming {\n languages\n }\n ... on Travelling {\n countriesLived {\n\t\t language\n\t\t}\n }\n ... on Other {\n name\n }\n }\n }\n}",
"variables": {}
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion router/core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ type operationContext struct {
internalHash uint64
// remapVariables is a map of variables that have been remapped to the new names
remapVariables map[string]string
// Content is the content of the operation
// RawContent is the raw content of the operation
rawContent string
// Content is the normalized content of the operation
content string
variables *astjson.Value
files []httpclient.File
Expand Down
21 changes: 21 additions & 0 deletions router/core/graphql_prehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/ecdsa"
"encoding/json"
"fmt"
"net/http"
"strconv"
Expand Down Expand Up @@ -350,6 +351,20 @@ func (h *PreHandler) Handler(next http.Handler) http.Handler {

art.SetRequestTracingStats(r.Context(), traceOptions, traceTimings)

if traceOptions.Enable {
reqData := &resolve.RequestData{
Method: r.Method,
URL: r.URL.String(),
Headers: r.Header,
Body: resolve.BodyData{
Query: requestContext.operation.rawContent,
OperationName: requestContext.operation.name,
Variables: json.RawMessage(requestContext.operation.variables.String()),
},
}
r = r.WithContext(resolve.SetRequest(r.Context(), reqData))
Comment thread
df-wg marked this conversation as resolved.
}

ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)

// The request context needs to be updated with the latest request to ensure that the context is up to date
Expand Down Expand Up @@ -612,6 +627,7 @@ func (h *PreHandler) handleOperation(req *http.Request, variablesParser *astjson
requestContext.telemetry.addCommonAttribute(operationHashAttribute)
httpOperation.routerSpan.SetAttributes(operationHashAttribute)

requestContext.operation.rawContent = operationKit.parsedOperation.Request.Query
requestContext.operation.content = operationKit.parsedOperation.NormalizedRepresentation
requestContext.operation.variables, err = variablesParser.ParseBytes(operationKit.parsedOperation.Request.Variables)
if err != nil {
Expand Down Expand Up @@ -770,6 +786,11 @@ func (h *PreHandler) handleOperation(req *http.Request, variablesParser *astjson
if (h.queryPlansEnabled && requestContext.operation.executionOptions.IncludeQueryPlanInResponse) ||
h.alwaysIncludeQueryPlan {

switch p := requestContext.operation.preparedPlan.preparedPlan.(type) {
case *plan.SynchronousResponsePlan:
p.Response.Fetches.NormalizedQuery = operationKit.parsedOperation.NormalizedRepresentation
}

if h.queryPlansLoggingEnabled {
switch p := requestContext.operation.preparedPlan.preparedPlan.(type) {
case *plan.SynchronousResponsePlan:
Expand Down
2 changes: 1 addition & 1 deletion router/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/tidwall/gjson v1.18.0
github.com/tidwall/sjson v1.2.5
github.com/twmb/franz-go v1.16.1
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.144
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.145
// Do not upgrade, it renames attributes we rely on
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
go.opentelemetry.io/contrib/propagators/b3 v1.23.0
Expand Down
4 changes: 2 additions & 2 deletions router/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0
github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww=
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083 h1:8/D7f8gKxTBjW+SZK4mhxTTBVpxcqeBgWF1Rfmltbfk=
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083/go.mod h1:eOTL6acwctsN4F3b7YE+eE2t8zcJ/doLm9sZzsxxxrE=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.144 h1:dkCHwG7ku5RzOWHcaDDG6cj/RXMZW7Q1spVKlLElAp4=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.144/go.mod h1:B7eV0Qh8Lop9QzIOQcsvKp3S0ejfC6mgyWoJnI917yQ=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.145 h1:3JuBmRux6YB/UZgh6COvgLXzQhMIsdHV7A02NsYdAVE=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.145/go.mod h1:B7eV0Qh8Lop9QzIOQcsvKp3S0ejfC6mgyWoJnI917yQ=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24=
Expand Down