SlideShare a Scribd company logo
1 of 48
Download to read offline
What could go wrong
with a GraphQL query and
can OpenTelemetry help?
Sonja Chevre & Ahmet Soormally
How is GraphQL different from your typical REST API?
What does a query & schema look like?
What are the general use-cases for GraphQL?
GraphQL 101
DECLARATIVE QUERY LANGUAGE FOR THE INTERNET
What kinds of problems does GraphQL solve?
1
2
3
4
SELECT
authors.name,
posts.title
FROM
posts
LEFT JOIN authors
ON authors.id = posts.author_id
WHERE posts.status = ‘published’;
SQL
GET /posts?status=published
GET /authors/2
GET /authors/7
GET /authors/9
…
REST
query {
postsByStatus(status: "published") {
title
author {
name
}
}
}
GRAPHQL
GraphQL 101
SELECT
authors.name,
posts.title
FROM
posts
LEFT JOIN authors
ON authors.id = posts.author_id
WHERE posts.status = ‘published’;
SQL
GET /posts?status=published
GET /authors/2
GET /authors/7
GET /authors/9
REST
query {
postsByStatus(status: "published") {
title
author {
name
}
}
}
GRAPHQL
Overfetching
GRAPHQL 101
SELECT
authors.name,
posts.title
FROM
posts
LEFT JOIN authors
ON authors.id = posts.author_id
WHERE posts.status = ‘published’;
SQL
GET /posts?status=published
GET /authors/2
GET /authors/7
GET /authors/9
…
REST
query {
postsByStatus(status: "published") {
title
author {
name
}
}
}
}
GRAPHQL
Underfetching
GRAPHQL 101
type Query {
getPostsByStatus(status: String!): [Post]
}
type User {
id: ID!
name: String!
email: String!
posts: [Post]
comments: [Comment]
}
type Post {
title: String
content: String
status: String
author: User
comments: [Comment]
}
type Comment {
id: ID!
author: User
comment: String
}
Schema
query {
getPostsByStatus(status: "published") {
title
author {
name
}
}
}
Operation
{
“data”: [
{
“title”: “abc”,
“author”: {
“name”: “Ahmet”
}
},
{
“title”: “def”,
“author”: {
“name”: “Sonja”
}
},
]
}
Response
GraphQL 101
Kube travel - Server side
type Photo {
id: ID!
country: ID
src: String
title: String
}
type Country {
name: String
code: ID!
capital: String
currency: String
photos: [Photo]
weather: [Weather]
}
type Weather {
description: String
temperature: Int
}
type Query {
getCountries: [Country]
getCountry(code: ID!): Country
}
Countries service
GraphQL (SAAS)
Image service
REST (SAAS)
Weather service
REST
Node.js (express)
Kube travel app
React app
type Photo {
id: ID!
country: ID
src: String
title: String
}
type Country {
name: String
code: ID!
capital: String
currency: String
photos: [Photo]
weather: [Weather]
}
type Weather {
description: String
temperature: Int
}
type Query {
getCountries: [Country]
getCountry(code: ID!): Country
}
Countries service
GraphQL (SAAS)
Image service
REST (SAAS)
Weather service
REST
Node.js (express)
type Photo {
id: ID!
country: ID
src: String
title: String
}
type Country {
name: String
code: ID!
capital: String
currency: String
photos: [Photo]
weather: [Weather]
}
type Weather {
description: String
temperature: Int
}
type Query {
getCountries: [Country]
getCountry(code: ID!): Country
}
Countries service
GraphQL (SAAS)
Image service
REST (SAAS)
Kube travel API product
Weather service
REST
Weather app
Booking app
Gallery app
…
Node.js (express)
GraphQL
capable API
gateway
How do we monitor GraphQL in
production?
Let’s apply the RED method to GraphQL
Duration - distributions of the amount of time each request takes.
Errors - the number of failed requests per second.
Rate - the number of requests, per second, your services are serving.
R
E
D
Collector
Node.js (express)
Countries service
GraphQL (SAAS)
Image service
REST (SAAS)
Adding OpenTelemetry to Kube Travel
Weather service
REST
GraphQL capable
API gateway
Spans
Instrumentation libraries
available for GraphQL
Instrumenting GraphQL with
OpenTelemetry
GraphQL instrumentation
An end-to-end
distributed trace in
Jaeger
RED metrics from traces with Jaeger
Collector
Node.js (express)
Spans
Metrics
Traces
Span Metrics Connector creates two metrics based on spans:
Calls_total
Counts the total number of spans, including error spans. Call counts are
differentiated from errors via the status_code label. Errors are identified as
any time series with the label status_code = "STATUS_CODE_ERROR".
Latency
latency_count: The total number of data points across all buckets in the
histogram.
latency_sum: The sum of all data point values.
latency_bucket: A collection of n time series (where n is the number of
latency buckets) for each latency bucket identified by an le (less than or equal
to) label. The latency_bucket counter with lowest le and le >= span
latency will be incremented for each span.
Span
metrics
connector
Resolver Errors
Errors
Upstream errors
1
2
Something is going on…
25% error rate!
Causing GraphQL to return a
500 http status code
Weather service returning a
400 http status code
The GraphQL query that is
causing the error
Everything looks fine
All good!
GraphQL errors
The request returns HTTP
status code 200 even though
the response contains an error
Here is the error!
Adding GraphQL to error spans
Is there a semantic
convention we can use?
Report the error to
the active span
with manual
instrumentation
The error is now
recorded in the span
Including error details
Still no error
But we can use
Prometheus to report error
rates for GraphQL queries
How can we detect performance issues?
Is tracking the latency
for a the single graphql
endpoint good enough?
PERFORMANCE
How can we detect performance issues?
Is tracking the latency
for a the single graphql
endpoint good enough?
PERFORMANCE
Query depth
Query complexity
Cyclic queries
Performance issues
N+1
1
2
3
4
N+1 issue
PERFORMANCE
n
1
27 HTTP GET calls to the
weather service for this
GraphQL query!
Detecting N+1 queries
PERFORMANCE
On average, 1 GraphQL query
makes 24 outgoing requests
Cyclic queries
PERFORMANCE
Expensive Queries
PERFORMANCE
{
a {
b {
c
}
}
}
Depth 3
{
a b c {
d e {
f
}
}
}
Complexity 6
What information do we have on our spans?
Full query (doesn’t
match the semantic
conventions)
Field name (doesn’t
match the semantic
conventions either)
PERFORMANCE
OpenTelemetry collector
configuration to export
additional span metrics
Let try to group them by query
PERFORMANCE
Using operation type and name
but not available in our
instrumentation library
but not available in our
instrumentation library
Using operation type and name
query continents 300 ms
query continents 2400 ms
mutation updateCountry 500 ms
Adding a client identification
query continents mobile 600 ms
query continents react 3500 ms
query continents weather-app 550 ms
RED metrics approach of monitoring needs to be extended to report GraphQL specifics
(query type, operation name, query depth, query complexity)
GraphQL errors are missing from semantic conventions and from instrumentation
needed to detect for errors
and for error based sampling
What have we learnt?
Semantic conventions are not always respected by instrumentation libraries
4
3
2
OpenTelemetry is helpful for monitoring and troubleshooting GraphQL queries, BUT:
1
Thank you!
Come talk to us to continue the discussion
or reach out:
Sonja Chevre
@SonjaChevre
linkedin.com/in/sonjachevre
Ahmet Soormally
@SoormallyAhmet
linkedin.com/in/ahmet-soormally

More Related Content

Similar to What could go wrong with a GraphQL query and can OpenTelemetry help? KubeCon Amsterdam 2023

GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)Rob Crowley
 
GraphQL Introduction with Spring Boot
GraphQL Introduction with Spring BootGraphQL Introduction with Spring Boot
GraphQL Introduction with Spring Bootvipin kumar
 
Implementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCImplementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCTim Burks
 
GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022Soham Dasgupta
 
GraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database accessGraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database accessConnected Data World
 
Wrapping and securing REST APIs with GraphQL
Wrapping and securing REST APIs with GraphQLWrapping and securing REST APIs with GraphQL
Wrapping and securing REST APIs with GraphQLRoy Derks
 
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsWSO2
 
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Seven Peaks Speaks
 
GraphQL & DGraph with Go
GraphQL & DGraph with GoGraphQL & DGraph with Go
GraphQL & DGraph with GoJames Tan
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservicesMohammed Shaban
 
Modern APIs with GraphQL
Modern APIs with GraphQLModern APIs with GraphQL
Modern APIs with GraphQLTaikai
 
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at StripeSashko Stubailo
 
How to provide a GraphQL API - I want it that way
How to provide a GraphQL API - I want it that wayHow to provide a GraphQL API - I want it that way
How to provide a GraphQL API - I want it that wayQAware GmbH
 
Scaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with DgraphScaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with DgraphKarthic Rao
 
GraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademy
GraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademyGraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademy
GraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademyMarcinStachniuk
 

Similar to What could go wrong with a GraphQL query and can OpenTelemetry help? KubeCon Amsterdam 2023 (20)

GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
 
GraphQL Introduction with Spring Boot
GraphQL Introduction with Spring BootGraphQL Introduction with Spring Boot
GraphQL Introduction with Spring Boot
 
Implementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPCImplementing OpenAPI and GraphQL services with gRPC
Implementing OpenAPI and GraphQL services with gRPC
 
GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022
 
GraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database accessGraphQL and its schema as a universal layer for database access
GraphQL and its schema as a universal layer for database access
 
GraphQL-ify your APIs
GraphQL-ify your APIsGraphQL-ify your APIs
GraphQL-ify your APIs
 
Wrapping and securing REST APIs with GraphQL
Wrapping and securing REST APIs with GraphQLWrapping and securing REST APIs with GraphQL
Wrapping and securing REST APIs with GraphQL
 
React Flux to GraphQL
React Flux to GraphQLReact Flux to GraphQL
React Flux to GraphQL
 
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIs
 
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
 
GraphQL & DGraph with Go
GraphQL & DGraph with GoGraphQL & DGraph with Go
GraphQL & DGraph with Go
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservices
 
Modern APIs with GraphQL
Modern APIs with GraphQLModern APIs with GraphQL
Modern APIs with GraphQL
 
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at Stripe
 
How to provide a GraphQL API - I want it that way
How to provide a GraphQL API - I want it that wayHow to provide a GraphQL API - I want it that way
How to provide a GraphQL API - I want it that way
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Let's talk about GraphQL
Let's talk about GraphQLLet's talk about GraphQL
Let's talk about GraphQL
 
Scaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with DgraphScaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with Dgraph
 
GraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademy
GraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademyGraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademy
GraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademy
 
GraphQL & Ratpack
GraphQL & RatpackGraphQL & Ratpack
GraphQL & Ratpack
 

Recently uploaded

chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 

Recently uploaded (20)

chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 

What could go wrong with a GraphQL query and can OpenTelemetry help? KubeCon Amsterdam 2023

  • 1. What could go wrong with a GraphQL query and can OpenTelemetry help? Sonja Chevre & Ahmet Soormally
  • 2.
  • 3. How is GraphQL different from your typical REST API? What does a query & schema look like? What are the general use-cases for GraphQL? GraphQL 101 DECLARATIVE QUERY LANGUAGE FOR THE INTERNET What kinds of problems does GraphQL solve? 1 2 3 4
  • 4. SELECT authors.name, posts.title FROM posts LEFT JOIN authors ON authors.id = posts.author_id WHERE posts.status = ‘published’; SQL GET /posts?status=published GET /authors/2 GET /authors/7 GET /authors/9 … REST query { postsByStatus(status: "published") { title author { name } } } GRAPHQL GraphQL 101
  • 5. SELECT authors.name, posts.title FROM posts LEFT JOIN authors ON authors.id = posts.author_id WHERE posts.status = ‘published’; SQL GET /posts?status=published GET /authors/2 GET /authors/7 GET /authors/9 REST query { postsByStatus(status: "published") { title author { name } } } GRAPHQL Overfetching GRAPHQL 101
  • 6. SELECT authors.name, posts.title FROM posts LEFT JOIN authors ON authors.id = posts.author_id WHERE posts.status = ‘published’; SQL GET /posts?status=published GET /authors/2 GET /authors/7 GET /authors/9 … REST query { postsByStatus(status: "published") { title author { name } } } } GRAPHQL Underfetching GRAPHQL 101
  • 7. type Query { getPostsByStatus(status: String!): [Post] } type User { id: ID! name: String! email: String! posts: [Post] comments: [Comment] } type Post { title: String content: String status: String author: User comments: [Comment] } type Comment { id: ID! author: User comment: String } Schema query { getPostsByStatus(status: "published") { title author { name } } } Operation { “data”: [ { “title”: “abc”, “author”: { “name”: “Ahmet” } }, { “title”: “def”, “author”: { “name”: “Sonja” } }, ] } Response GraphQL 101
  • 8. Kube travel - Server side type Photo { id: ID! country: ID src: String title: String } type Country { name: String code: ID! capital: String currency: String photos: [Photo] weather: [Weather] } type Weather { description: String temperature: Int } type Query { getCountries: [Country] getCountry(code: ID!): Country } Countries service GraphQL (SAAS) Image service REST (SAAS) Weather service REST Node.js (express)
  • 9. Kube travel app React app type Photo { id: ID! country: ID src: String title: String } type Country { name: String code: ID! capital: String currency: String photos: [Photo] weather: [Weather] } type Weather { description: String temperature: Int } type Query { getCountries: [Country] getCountry(code: ID!): Country } Countries service GraphQL (SAAS) Image service REST (SAAS) Weather service REST Node.js (express)
  • 10. type Photo { id: ID! country: ID src: String title: String } type Country { name: String code: ID! capital: String currency: String photos: [Photo] weather: [Weather] } type Weather { description: String temperature: Int } type Query { getCountries: [Country] getCountry(code: ID!): Country } Countries service GraphQL (SAAS) Image service REST (SAAS) Kube travel API product Weather service REST Weather app Booking app Gallery app … Node.js (express) GraphQL capable API gateway
  • 11. How do we monitor GraphQL in production? Let’s apply the RED method to GraphQL Duration - distributions of the amount of time each request takes. Errors - the number of failed requests per second. Rate - the number of requests, per second, your services are serving. R E D
  • 12. Collector Node.js (express) Countries service GraphQL (SAAS) Image service REST (SAAS) Adding OpenTelemetry to Kube Travel Weather service REST GraphQL capable API gateway Spans
  • 13. Instrumentation libraries available for GraphQL Instrumenting GraphQL with OpenTelemetry
  • 16. RED metrics from traces with Jaeger Collector Node.js (express) Spans Metrics Traces Span Metrics Connector creates two metrics based on spans: Calls_total Counts the total number of spans, including error spans. Call counts are differentiated from errors via the status_code label. Errors are identified as any time series with the label status_code = "STATUS_CODE_ERROR". Latency latency_count: The total number of data points across all buckets in the histogram. latency_sum: The sum of all data point values. latency_bucket: A collection of n time series (where n is the number of latency buckets) for each latency bucket identified by an le (less than or equal to) label. The latency_bucket counter with lowest le and le >= span latency will be incremented for each span. Span metrics connector
  • 17.
  • 19.
  • 20. Something is going on… 25% error rate!
  • 21. Causing GraphQL to return a 500 http status code Weather service returning a 400 http status code
  • 22. The GraphQL query that is causing the error
  • 23.
  • 26. GraphQL errors The request returns HTTP status code 200 even though the response contains an error Here is the error!
  • 27. Adding GraphQL to error spans Is there a semantic convention we can use?
  • 28. Report the error to the active span with manual instrumentation
  • 29. The error is now recorded in the span Including error details
  • 30. Still no error But we can use Prometheus to report error rates for GraphQL queries
  • 31. How can we detect performance issues? Is tracking the latency for a the single graphql endpoint good enough? PERFORMANCE
  • 32.
  • 33. How can we detect performance issues? Is tracking the latency for a the single graphql endpoint good enough? PERFORMANCE
  • 34. Query depth Query complexity Cyclic queries Performance issues N+1 1 2 3 4
  • 36. 27 HTTP GET calls to the weather service for this GraphQL query!
  • 37. Detecting N+1 queries PERFORMANCE On average, 1 GraphQL query makes 24 outgoing requests
  • 39. Expensive Queries PERFORMANCE { a { b { c } } } Depth 3 { a b c { d e { f } } } Complexity 6
  • 40. What information do we have on our spans? Full query (doesn’t match the semantic conventions) Field name (doesn’t match the semantic conventions either) PERFORMANCE
  • 41. OpenTelemetry collector configuration to export additional span metrics
  • 42. Let try to group them by query PERFORMANCE
  • 43. Using operation type and name but not available in our instrumentation library but not available in our instrumentation library
  • 44. Using operation type and name query continents 300 ms query continents 2400 ms mutation updateCountry 500 ms
  • 45. Adding a client identification query continents mobile 600 ms query continents react 3500 ms query continents weather-app 550 ms
  • 46. RED metrics approach of monitoring needs to be extended to report GraphQL specifics (query type, operation name, query depth, query complexity) GraphQL errors are missing from semantic conventions and from instrumentation needed to detect for errors and for error based sampling What have we learnt? Semantic conventions are not always respected by instrumentation libraries 4 3 2 OpenTelemetry is helpful for monitoring and troubleshooting GraphQL queries, BUT: 1
  • 47.
  • 48. Thank you! Come talk to us to continue the discussion or reach out: Sonja Chevre @SonjaChevre linkedin.com/in/sonjachevre Ahmet Soormally @SoormallyAhmet linkedin.com/in/ahmet-soormally