際際滷

際際滷Share a Scribd company logo
What could go wrong
with a GraphQL query and
can OpenTelemetry help?
Sonja Chevre & Ahmet Soormally
What could go wrong  with a GraphQL query and can OpenTelemetry help? KubeCon Amsterdam 2023
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?
Lets 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
What could go wrong  with a GraphQL query and can OpenTelemetry help? KubeCon Amsterdam 2023
Resolver Errors
Errors
Upstream errors
1
2
What could go wrong  with a GraphQL query and can OpenTelemetry help? KubeCon Amsterdam 2023
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
What could go wrong  with a GraphQL query and can OpenTelemetry help? KubeCon Amsterdam 2023
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
What could go wrong  with a GraphQL query and can OpenTelemetry help? KubeCon Amsterdam 2023
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 (doesnt
match the semantic
conventions)
Field name (doesnt
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
What could go wrong  with a GraphQL query and can OpenTelemetry help? KubeCon Amsterdam 2023
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 (20)

GraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptxGraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptx
Soham Dasgupta
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 Boot
vipin 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 gRPC
Tim Burks
GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022
Soham 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 access
Connected Data World
GraphQL-ify your APIs
GraphQL-ify your APIsGraphQL-ify your APIs
GraphQL-ify your APIs
Soham Dasgupta
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
Roy Derks
React Flux to GraphQL
React Flux to GraphQLReact Flux to GraphQL
React Flux to GraphQL
Turadg Aleahmad
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIs
WSO2
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 Go
James Tan
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservices
Mohammed Shaban
Modern APIs with GraphQL
Modern APIs with GraphQLModern APIs with GraphQL
Modern APIs with GraphQL
Taikai
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at Stripe
Sashko 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 way
QAware GmbH
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
VMware Tanzu
Let's talk about GraphQL
Let's talk about GraphQLLet's talk about GraphQL
Let's talk about GraphQL
Commit Software Sh.p.k.
Scaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with DgraphScaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with Dgraph
Karthic Rao
GraphQL - Pikne API w Twojej Aplikacji - KrakowGraphAcademy
GraphQL - Pikne API w Twojej Aplikacji - KrakowGraphAcademyGraphQL - Pikne API w Twojej Aplikacji - KrakowGraphAcademy
GraphQL - Pikne API w Twojej Aplikacji - KrakowGraphAcademy
MarcinStachniuk
GraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptxGraphQL_devoxx_2023.pptx
GraphQL_devoxx_2023.pptx
Soham Dasgupta
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 Boot
vipin 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 gRPC
Tim Burks
GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022GraphQL-ify your API - JFall 2022
GraphQL-ify your API - JFall 2022
Soham 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 access
Connected Data World
GraphQL-ify your APIs
GraphQL-ify your APIsGraphQL-ify your APIs
GraphQL-ify your APIs
Soham Dasgupta
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
Roy Derks
React Flux to GraphQL
React Flux to GraphQLReact Flux to GraphQL
React Flux to GraphQL
Turadg Aleahmad
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIs
WSO2
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 Go
James Tan
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservices
Mohammed Shaban
Modern APIs with GraphQL
Modern APIs with GraphQLModern APIs with GraphQL
Modern APIs with GraphQL
Taikai
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at Stripe
Sashko 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 way
QAware GmbH
Scaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with DgraphScaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with Dgraph
Karthic Rao
GraphQL - Pikne API w Twojej Aplikacji - KrakowGraphAcademy
GraphQL - Pikne API w Twojej Aplikacji - KrakowGraphAcademyGraphQL - Pikne API w Twojej Aplikacji - KrakowGraphAcademy
GraphQL - Pikne API w Twojej Aplikacji - KrakowGraphAcademy
MarcinStachniuk

Recently uploaded (20)

Douwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-LatestDouwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-Latest
mubeen010khan
Carousel - Five Key FinTech Trends for 2025
Carousel - Five Key FinTech Trends for 2025Carousel - Five Key FinTech Trends for 2025
Carousel - Five Key FinTech Trends for 2025
Anadea
AI-Powered Chatbots for Employee Support
AI-Powered Chatbots for Employee SupportAI-Powered Chatbots for Employee Support
AI-Powered Chatbots for Employee Support
AutomationEdge Technologies
SE- Lecture 5 SE for easy understanding.ppt
SE- Lecture 5 SE for easy understanding.pptSE- Lecture 5 SE for easy understanding.ppt
SE- Lecture 5 SE for easy understanding.ppt
theworldimagine985
SketchUp Pro Crack [2025]-Free Download?
SketchUp Pro Crack [2025]-Free Download?SketchUp Pro Crack [2025]-Free Download?
SketchUp Pro Crack [2025]-Free Download?
kiran10101khan
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
Ava Isley
Data Storytelling for Portfolio Leaders - Webinar
Data Storytelling for Portfolio Leaders - WebinarData Storytelling for Portfolio Leaders - Webinar
Data Storytelling for Portfolio Leaders - Webinar
OnePlan Solutions
iTop VPN Latest Version 2025 Crack Free Download
iTop VPN Latest Version 2025 Crack Free DownloadiTop VPN Latest Version 2025 Crack Free Download
iTop VPN Latest Version 2025 Crack Free Download
lr74xqnvuf
Tenorshare 4uKey Crack Fre e Download
Tenorshare  4uKey  Crack  Fre e DownloadTenorshare  4uKey  Crack  Fre e Download
Tenorshare 4uKey Crack Fre e Download
oyv9tzurtx
EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]
bhagasufyan
Adobe InDesign Crack Full Version Free Download 2025
Adobe InDesign Crack  Full Version Free Download 2025Adobe InDesign Crack  Full Version Free Download 2025
Adobe InDesign Crack Full Version Free Download 2025
sannnasaba545
Code or No-Code Tests: Why Top Teams Choose Both
Code or No-Code Tests: Why Top Teams Choose BothCode or No-Code Tests: Why Top Teams Choose Both
Code or No-Code Tests: Why Top Teams Choose Both
Applitools
DevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdfDevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdf
Justin Reock
Wondershare Filmora 14.3.2 Crack + License Key Free Download
Wondershare Filmora 14.3.2 Crack + License Key Free DownloadWondershare Filmora 14.3.2 Crack + License Key Free Download
Wondershare Filmora 14.3.2 Crack + License Key Free Download
arshadkhokher01
AutoDesk Revit Crack | Revit Update 2025 free download
AutoDesk Revit Crack | Revit Update 2025 free downloadAutoDesk Revit Crack | Revit Update 2025 free download
AutoDesk Revit Crack | Revit Update 2025 free download
anamaslam971
Next-Gen Procurement: Leveraging AI for Smarter Sourcing & Cost Optimization
Next-Gen Procurement: Leveraging AI for Smarter Sourcing & Cost OptimizationNext-Gen Procurement: Leveraging AI for Smarter Sourcing & Cost Optimization
Next-Gen Procurement: Leveraging AI for Smarter Sourcing & Cost Optimization
asmith539880
Lecture-11-AutomatedTesting-software.pptx
Lecture-11-AutomatedTesting-software.pptxLecture-11-AutomatedTesting-software.pptx
Lecture-11-AutomatedTesting-software.pptx
ssuser39f59e
Minitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free DownloadMinitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free Download
v3r2eptd2q
20 Excel Shortcuts That Will Instantly Save You Hours.pdf
20 Excel Shortcuts That Will Instantly Save You Hours.pdf20 Excel Shortcuts That Will Instantly Save You Hours.pdf
20 Excel Shortcuts That Will Instantly Save You Hours.pdf
mohammadasim74
Build the future with Agentforce and Mulesoft
Build the future with Agentforce and  MulesoftBuild the future with Agentforce and  Mulesoft
Build the future with Agentforce and Mulesoft
GiulioPicchi
Douwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-LatestDouwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-Latest
mubeen010khan
Carousel - Five Key FinTech Trends for 2025
Carousel - Five Key FinTech Trends for 2025Carousel - Five Key FinTech Trends for 2025
Carousel - Five Key FinTech Trends for 2025
Anadea
SE- Lecture 5 SE for easy understanding.ppt
SE- Lecture 5 SE for easy understanding.pptSE- Lecture 5 SE for easy understanding.ppt
SE- Lecture 5 SE for easy understanding.ppt
theworldimagine985
SketchUp Pro Crack [2025]-Free Download?
SketchUp Pro Crack [2025]-Free Download?SketchUp Pro Crack [2025]-Free Download?
SketchUp Pro Crack [2025]-Free Download?
kiran10101khan
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
Ava Isley
Data Storytelling for Portfolio Leaders - Webinar
Data Storytelling for Portfolio Leaders - WebinarData Storytelling for Portfolio Leaders - Webinar
Data Storytelling for Portfolio Leaders - Webinar
OnePlan Solutions
iTop VPN Latest Version 2025 Crack Free Download
iTop VPN Latest Version 2025 Crack Free DownloadiTop VPN Latest Version 2025 Crack Free Download
iTop VPN Latest Version 2025 Crack Free Download
lr74xqnvuf
Tenorshare 4uKey Crack Fre e Download
Tenorshare  4uKey  Crack  Fre e DownloadTenorshare  4uKey  Crack  Fre e Download
Tenorshare 4uKey Crack Fre e Download
oyv9tzurtx
EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]EASEUS Partition Master Crack with License Code [Latest]
EASEUS Partition Master Crack with License Code [Latest]
bhagasufyan
Adobe InDesign Crack Full Version Free Download 2025
Adobe InDesign Crack  Full Version Free Download 2025Adobe InDesign Crack  Full Version Free Download 2025
Adobe InDesign Crack Full Version Free Download 2025
sannnasaba545
Code or No-Code Tests: Why Top Teams Choose Both
Code or No-Code Tests: Why Top Teams Choose BothCode or No-Code Tests: Why Top Teams Choose Both
Code or No-Code Tests: Why Top Teams Choose Both
Applitools
DevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdfDevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdf
Justin Reock
Wondershare Filmora 14.3.2 Crack + License Key Free Download
Wondershare Filmora 14.3.2 Crack + License Key Free DownloadWondershare Filmora 14.3.2 Crack + License Key Free Download
Wondershare Filmora 14.3.2 Crack + License Key Free Download
arshadkhokher01
AutoDesk Revit Crack | Revit Update 2025 free download
AutoDesk Revit Crack | Revit Update 2025 free downloadAutoDesk Revit Crack | Revit Update 2025 free download
AutoDesk Revit Crack | Revit Update 2025 free download
anamaslam971
Next-Gen Procurement: Leveraging AI for Smarter Sourcing & Cost Optimization
Next-Gen Procurement: Leveraging AI for Smarter Sourcing & Cost OptimizationNext-Gen Procurement: Leveraging AI for Smarter Sourcing & Cost Optimization
Next-Gen Procurement: Leveraging AI for Smarter Sourcing & Cost Optimization
asmith539880
Lecture-11-AutomatedTesting-software.pptx
Lecture-11-AutomatedTesting-software.pptxLecture-11-AutomatedTesting-software.pptx
Lecture-11-AutomatedTesting-software.pptx
ssuser39f59e
Minitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free DownloadMinitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free Download
v3r2eptd2q
20 Excel Shortcuts That Will Instantly Save You Hours.pdf
20 Excel Shortcuts That Will Instantly Save You Hours.pdf20 Excel Shortcuts That Will Instantly Save You Hours.pdf
20 Excel Shortcuts That Will Instantly Save You Hours.pdf
mohammadasim74
Build the future with Agentforce and Mulesoft
Build the future with Agentforce and  MulesoftBuild the future with Agentforce and  Mulesoft
Build the future with Agentforce and Mulesoft
GiulioPicchi

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
  • 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? Lets 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
  • 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
  • 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
  • 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 (doesnt match the semantic conventions) Field name (doesnt 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
  • 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