Skip to content

Adds skipping non-matching URLs in OpenAITelemetryPlugin#1206

Merged
waldekmastykarz merged 1 commit intodotnet:mainfrom
waldekmastykarz:fix-openaiotel-response
May 22, 2025
Merged

Adds skipping non-matching URLs in OpenAITelemetryPlugin#1206
waldekmastykarz merged 1 commit intodotnet:mainfrom
waldekmastykarz:fix-openaiotel-response

Conversation

@waldekmastykarz
Copy link
Copy Markdown
Collaborator

  • Adds skipping non-matching URLs in OpenAITelemetryPlugin
  • Changes the order of checks in OpenAIMockResponsePlugin so that checking for matching URLs is done first, which makes more sense.

@waldekmastykarz waldekmastykarz requested a review from a team as a code owner May 22, 2025 08:27
@waldekmastykarz waldekmastykarz added the pr-bugfix Fixes a bug label May 22, 2025
@waldekmastykarz waldekmastykarz requested a review from Copilot May 22, 2025 08:27
Copy link
Copy Markdown
Contributor

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 refactors the URL matching logic to skip non-matching URLs in the telemetry and mock response plugins, and reorders the checks in the mock response plugin for improved logical consistency.

  • Prioritize URL matching before checking if a response is already set in OpenAIMockResponsePlugin.
  • Add URL matching logic to OpenAITelemetryPlugin for early bailout on non-matching requests.

Reviewed Changes

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

File Description
dev-proxy-plugins/Mocks/OpenAIMockResponsePlugin.cs Reorders the condition checks to perform URL matching before checking if the response has been set.
dev-proxy-plugins/Inspection/OpenAITelemetryPlugin.cs Introduces URL matching logic to skip processing when the request URL does not match.

Comment thread dev-proxy-plugins/Mocks/OpenAIMockResponsePlugin.cs
@waldekmastykarz waldekmastykarz force-pushed the fix-openaiotel-response branch from ba6e2e9 to 867122e Compare May 22, 2025 08:29
@waldekmastykarz waldekmastykarz requested a review from Copilot May 22, 2025 08:33
@waldekmastykarz waldekmastykarz enabled auto-merge (squash) May 22, 2025 08:34
Copy link
Copy Markdown
Contributor

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 ensures that both the telemetry and mock response plugins skip processing when a request’s URL doesn’t match the configured list, and it reorders checks in the mock plugin to first verify the URL before checking if a response is already set.

  • Added a URL-match guard in OpenAITelemetryPlugin to early-return on non-matching URLs.
  • Reordered the if conditions in OpenAIMockResponsePlugin so URL matching is checked before ResponseState.HasBeenSet.
  • Updated skipped log messages to reflect the new check order.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
dev-proxy-plugins/Mocks/OpenAIMockResponsePlugin.cs Swapped the order of URL-match and response-set checks; updated corresponding log messages.
dev-proxy-plugins/Inspection/OpenAITelemetryPlugin.cs Introduced an early-return guard for non-matching URLs in OnRequestAsync.
Comments suppressed due to low confidence (2)

dev-proxy-plugins/Inspection/OpenAITelemetryPlugin.cs:139

  • Consider adding unit tests that verify telemetry is correctly skipped when URLs do not match, and that it proceeds when they do.
if (UrlsToWatch is null || !e.HasRequestUrlMatch(UrlsToWatch))

dev-proxy-plugins/Mocks/OpenAIMockResponsePlugin.cs:38

  • Replacing the original e.ShouldExecute(UrlsToWatch) with e.HasRequestUrlMatch(...) may omit additional checks that ShouldExecute performed. Verify that no other execution conditions (e.g., HTTP method or headers) are lost, or consolidate into a single guard method.
!e.HasRequestUrlMatch(UrlsToWatch)

Comment thread dev-proxy-plugins/Mocks/OpenAIMockResponsePlugin.cs
Comment thread dev-proxy-plugins/Inspection/OpenAITelemetryPlugin.cs
Comment thread dev-proxy-plugins/Inspection/OpenAITelemetryPlugin.cs
@waldekmastykarz waldekmastykarz merged commit 4587a22 into dotnet:main May 22, 2025
4 checks passed
@waldekmastykarz waldekmastykarz deleted the fix-openaiotel-response branch May 22, 2025 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants