Skip to content

Conversation

RubenCerna2079
Copy link
Contributor

@RubenCerna2079 RubenCerna2079 commented May 2, 2025

Why make this change?

This closes #2642

What is this change?

This PR enhances the OTEL instrumentation for the GraphQL APIs by adding custom traces and metrics.
Metrics can be filtered for status_code, api_type, endpoint and method.

How was this tested?

  • Local Testing
  • Integration Tests
  • Unit Tests

All of the tests were done locally to check if the log information that was provided was correct, for both scenarios in which the query gave the proper information or when an exception was raised.
Another thing that was tested is that when we open GraphQL it would send a few requests called Introspection Queries used to ensure that GraphQL is working properly. However, we do not want the user to see these requests as part of the total count as this is done automatically, which may confuse the users.

Sample Request(s)

image
image
image

Instructions on how to use DAB Workbench

  • Clone the following repo https://github.com/tommasodotNET/dab-workbench.git
  • Run your DAB version in CLI so the files from the out folder are created, and make sure to stop it before running the DAB Workbench since both cannot be running at the same time.
  • Find the path to the Microsoft.DataApiBuilder.exe, which should look something like <PATH_TO_REPO>\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.exe
  • Copy the path of the .exe file and paste it in the file /DABWorkbench.AppHost/Program.cs in the variable dabCLIPath which is found in line 3 as follows:
    var dabCLIPath = @"<PATH_TO_REPO>\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.exe";
  • Now you should be able to run DAB Workbench with your version of DAB.

@RubenCerna2079 RubenCerna2079 added this to the 1.5 milestone May 2, 2025
@RubenCerna2079 RubenCerna2079 self-assigned this May 2, 2025
@Copilot Copilot AI review requested due to automatic review settings May 2, 2025 16:59
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the OTEL instrumentation for GraphQL APIs by incorporating custom traces and metrics. Key changes include adding new telemetry using directives and namespaces, integrating activity tracking in query execution, and updating the BuildRequestStateMiddleware to support custom telemetry for GraphQL operations.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Service/Startup.cs Added telemetry using directive.
src/Service/Controllers/RestController.cs Updated telemetry namespace usage to align with telemetry enhancements.
src/Core/Telemetry/TelemetryTracesHelper.cs Updated namespace and provided clarified telemetry trace comments.
src/Core/Telemetry/TelemetryMetricsHelper.cs Updated namespace and removed unneeded using statements.
src/Core/Services/ExecutionHelper.cs Added telemetry activity tracking for both query and mutation execution.
src/Core/Services/BuildRequestStateMiddleware.cs Integrated telemetry, runtime config provider, and error tracking.

@RubenCerna2079
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079 RubenCerna2079 changed the title Jerry/otel ruben Enhance GraphQL OTEL instrumentation with custom metrics and traces May 2, 2025
@RubenCerna2079
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@sourabh1007
Copy link
Contributor

You should follow open telemetry semantic conventions for otel metrics and trace.
For HTTP related information, this should be the semantic convention: https://opentelemetry.io/docs/specs/semconv/http/http-spans/

There are few HTTP metrics already available, https://opentelemetry.io/docs/specs/semconv/http/http-metrics/.

Similar exercise, we did for Cosmos DB SDK. ref. https://opentelemetry.io/docs/specs/semconv/database/cosmosdb/. Right now, it is under preview.

@Aniruddh25 what do you think about it?

@RubenCerna2079
Copy link
Contributor Author

@sourabh1007 I will be addressing the semantic conventions for OTEL in a future PR.
Thank you for letting us know about this!

@RubenCerna2079
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079 RubenCerna2079 merged commit 7f8fa6b into main May 15, 2025
11 checks passed
@RubenCerna2079 RubenCerna2079 deleted the jerry/otel-ruben branch May 15, 2025 22:10
@github-project-automation github-project-automation bot moved this from Review In Progress to Done in Data API builder May 15, 2025
RubenCerna2079 added a commit that referenced this pull request May 16, 2025
…2673)

This closes #2642

This PR enhances the OTEL instrumentation for the GraphQL APIs by adding
custom traces and metrics.
Metrics can be filtered for `status_code`, `api_type`, `endpoint` and
`method`.

- [X] Local Testing
- [ ] Integration Tests
- [ ] Unit Tests

All of the tests were done locally to check if the log information that
was provided was correct, for both scenarios in which the query gave the
proper information or when an exception was raised.
Another thing that was tested is that when we open GraphQL it would send
a few requests called `Introspection Queries` used to ensure that
GraphQL is working properly. However, we do not want the user to see
these requests as part of the total count as this is done automatically,
which may confuse the users.

![image](https://github.com/user-attachments/assets/1f66da36-d537-47cc-95d6-fd19cf73242e)

![image](https://github.com/user-attachments/assets/91b3801f-b48e-4841-99a6-72de1b8b482a)

![image](https://github.com/user-attachments/assets/48a8ee9a-4d17-4b52-9f66-7e5c745aeef4)

- Clone the following repo
`https://github.com/tommasodotNET/dab-workbench.git`
- Run your DAB version in CLI so the files from the `out` folder are
created, and make sure to stop it before running the DAB Workbench since
both cannot be running at the same time.
- Find the path to the `Microsoft.DataApiBuilder.exe`, which should look
something like
`<PATH_TO_REPO>\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.exe`
- Copy the path of the `.exe` file and paste it in the file
`/DABWorkbench.AppHost/Program.cs` in the variable `dabCLIPath` which is
found in line 3 as follows:
`var dabCLIPath =
@"<PATH_TO_REPO>\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.exe";`
- Now you should be able to run DAB Workbench with your version of DAB.

---------

Co-authored-by: Tommaso Stocchi <[email protected]>
Co-authored-by: Jerry Nixon <[email protected]>
Co-authored-by: Ruben Cerna <[email protected]>
RubenCerna2079 added a commit that referenced this pull request May 29, 2025
…2673)

This closes #2642

This PR enhances the OTEL instrumentation for the GraphQL APIs by adding
custom traces and metrics.
Metrics can be filtered for `status_code`, `api_type`, `endpoint` and
`method`.

- [X] Local Testing
- [ ] Integration Tests
- [ ] Unit Tests

All of the tests were done locally to check if the log information that
was provided was correct, for both scenarios in which the query gave the
proper information or when an exception was raised.
Another thing that was tested is that when we open GraphQL it would send
a few requests called `Introspection Queries` used to ensure that
GraphQL is working properly. However, we do not want the user to see
these requests as part of the total count as this is done automatically,
which may confuse the users.

![image](https://github.com/user-attachments/assets/1f66da36-d537-47cc-95d6-fd19cf73242e)

![image](https://github.com/user-attachments/assets/91b3801f-b48e-4841-99a6-72de1b8b482a)

![image](https://github.com/user-attachments/assets/48a8ee9a-4d17-4b52-9f66-7e5c745aeef4)

- Clone the following repo
`https://github.com/tommasodotNET/dab-workbench.git`
- Run your DAB version in CLI so the files from the `out` folder are
created, and make sure to stop it before running the DAB Workbench since
both cannot be running at the same time.
- Find the path to the `Microsoft.DataApiBuilder.exe`, which should look
something like
`<PATH_TO_REPO>\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.exe`
- Copy the path of the `.exe` file and paste it in the file
`/DABWorkbench.AppHost/Program.cs` in the variable `dabCLIPath` which is
found in line 3 as follows:
`var dabCLIPath =
@"<PATH_TO_REPO>\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.exe";`
- Now you should be able to run DAB Workbench with your version of DAB.

---------

Co-authored-by: Tommaso Stocchi <[email protected]>
Co-authored-by: Jerry Nixon <[email protected]>
Co-authored-by: Ruben Cerna <[email protected]>
aaronburtle added a commit that referenced this pull request May 29, 2025
## Why make this change?

This change is made in order to add all of the commits for milestone 1.5
into its respective branch.

## What is this change?

This change cherry-picks all of the commits that were added after the
first release candidate.
Cherry-picked commits:
 - #2648 
#2657
#2617 
#2659 
#2655 
#2633 
#2667 
#2673 
#2650 
#2695 
#2702 
#2688

## How was this tested?

- [ ] Integration Tests
- [ ] Unit Tests

## Sample Request(s)

---------

Co-authored-by: Sezal Chug <[email protected]>
Co-authored-by: sezalchug <[email protected]>
Co-authored-by: Tommaso Stocchi <[email protected]>
Co-authored-by: Aaron Powell <[email protected]>
Co-authored-by: aaronburtle <[email protected]>
Co-authored-by: Aniruddh Munde <[email protected]>
Co-authored-by: Jerry Nixon <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Michael Staib <[email protected]>
Co-authored-by: souvikghosh04 <[email protected]>
Co-authored-by: Souvik Ghosh <[email protected]>
RubenCerna2079 added a commit that referenced this pull request May 29, 2025
…2673)

This closes #2642

This PR enhances the OTEL instrumentation for the GraphQL APIs by adding
custom traces and metrics.
Metrics can be filtered for `status_code`, `api_type`, `endpoint` and
`method`.

- [X] Local Testing
- [ ] Integration Tests
- [ ] Unit Tests

All of the tests were done locally to check if the log information that
was provided was correct, for both scenarios in which the query gave the
proper information or when an exception was raised.
Another thing that was tested is that when we open GraphQL it would send
a few requests called `Introspection Queries` used to ensure that
GraphQL is working properly. However, we do not want the user to see
these requests as part of the total count as this is done automatically,
which may confuse the users.

![image](https://github.com/user-attachments/assets/1f66da36-d537-47cc-95d6-fd19cf73242e)

![image](https://github.com/user-attachments/assets/91b3801f-b48e-4841-99a6-72de1b8b482a)

![image](https://github.com/user-attachments/assets/48a8ee9a-4d17-4b52-9f66-7e5c745aeef4)

- Clone the following repo
`https://github.com/tommasodotNET/dab-workbench.git`
- Run your DAB version in CLI so the files from the `out` folder are
created, and make sure to stop it before running the DAB Workbench since
both cannot be running at the same time.
- Find the path to the `Microsoft.DataApiBuilder.exe`, which should look
something like
`<PATH_TO_REPO>\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.exe`
- Copy the path of the `.exe` file and paste it in the file
`/DABWorkbench.AppHost/Program.cs` in the variable `dabCLIPath` which is
found in line 3 as follows:
`var dabCLIPath =
@"<PATH_TO_REPO>\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.exe";`
- Now you should be able to run DAB Workbench with your version of DAB.

---------

Co-authored-by: Tommaso Stocchi <[email protected]>
Co-authored-by: Jerry Nixon <[email protected]>
Co-authored-by: Ruben Cerna <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

OTEL Implementation for GraphQL

5 participants