Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2554 Enhance REST OTEL instrumentation with custom metrics and traces #2617

Open
wants to merge 36 commits into
base: main
Choose a base branch
from

Conversation

tommasodotNET
Copy link
Contributor

@tommasodotNET tommasodotNET commented Mar 14, 2025

Why make this change?

What is this change?

This PR enhances the OTEL instrumentation for the REST APIs by adding custom traces and metrics.

I have removed ASP NET Core standard instrumentation since it does not provide great value given the custom nature of the webservice. I have written two main Helper classes: TelemetryMetricsHelper and TelemetryTracesHelper to provide a single point of management for custom traces and metrics.

Metrics can be filtered for status_code, api_type, endpoint and method.

I have also fixed the loggings which are now sent to the configured OTEL endpoint.

Logs

image

Metrics

Screenshot 2025-03-14 190730

Traces

image (2)
image (3)
image (4)

How was this tested?

  • Integration Tests
  • Unit Tests

Sample Request(s)

To test everything locally I recommend using this repo that allows to run the local build of the dab cli and send metrics to the .NET Aspire OTEL endoint.

@JerryNixon
Copy link
Contributor

@Aniruddh25 is March realistic?

@tommasodotNET
Copy link
Contributor Author

/azp run

Copy link

Commenter does not have sufficient privileges for PR 2617 in repo Azure/data-api-builder

@sezal98
Copy link
Contributor

sezal98 commented Mar 27, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@sezal98
Copy link
Contributor

sezal98 commented Apr 1, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@Aniruddh25 Aniruddh25 requested a review from Copilot April 7, 2025 17:02
Copy link

@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.

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • src/Service/Azure.DataApiBuilder.Service.csproj: Language not supported
Comments suppressed due to low confidence (2)

src/Service/Telemetry/TelemetryTracesHelper.cs:94

  • The method name 'TrackRestControllerActivityFinishedWithWithException' contains a duplicate 'With'. Consider renaming it to 'TrackRestControllerActivityFinishedWithException' for clarity.
public static void TrackRestControllerActivityFinishedWithWithException(

src/Service/Controllers/RestController.cs:249

  • Manual disposal of 'queryActivity' is redundant since it is declared within a 'using' block, which will automatically dispose it. Removing the explicit call can prevent potential unexpected behavior from double disposal.
if (queryActivity is not null && queryActivity.IsAllDataRequested)
                    {
                        queryActivity.Dispose();
                    }

RubenCerna2079
RubenCerna2079 previously approved these changes Apr 7, 2025
Copy link
Contributor

@RubenCerna2079 RubenCerna2079 left a comment

Choose a reason for hiding this comment

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

LGTM! I just left one more comment. Thank you for working on this feature, it is really cool.

Aniruddh25
Aniruddh25 previously approved these changes Apr 7, 2025
Copy link
Contributor

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

LGTM, Thank you for adding this support!

@Aniruddh25
Copy link
Contributor

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Files not reviewed (1)

  • src/Service/Azure.DataApiBuilder.Service.csproj: Language not supported

Comments suppressed due to low confidence (2)
src/Service/Telemetry/TelemetryTracesHelper.cs:94

  • The method name 'TrackRestControllerActivityFinishedWithWithException' contains a duplicate 'With'. Consider renaming it to 'TrackRestControllerActivityFinishedWithException' for clarity.
public static void TrackRestControllerActivityFinishedWithWithException(

src/Service/Controllers/RestController.cs:249

  • Manual disposal of 'queryActivity' is redundant since it is declared within a 'using' block, which will automatically dispose it. Removing the explicit call can prevent potential unexpected behavior from double disposal.
if (queryActivity is not null && queryActivity.IsAllDataRequested)
                    {
                        queryActivity.Dispose();
                    }

@tommasodotNET Seems like queryActivity.Dispose() could be removed? Can it?

@tommasodotNET tommasodotNET dismissed stale reviews from Aniruddh25 and RubenCerna2079 via 30c61ca April 8, 2025 07:09
@tommasodotNET
Copy link
Contributor Author

Hey @Aniruddh25, I've addressed copilot review

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

});

})
//.WithLogging(logging =>
Copy link
Contributor

@Aniruddh25 Aniruddh25 Apr 12, 2025

Choose a reason for hiding this comment

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

if we dont need this to enable logging, please remove the commented out code from Startup.cs

@Aniruddh25
Copy link
Contributor

@tommasodotNET, waiting on all tests to pass..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🥕⭐ [Enhancement]: Custom DAB OTEL Traces & Counters
6 participants