Skip to content

Conversation

@EmrysMyrddin
Copy link
Collaborator

Description

This PR adds a default filter for HTTP spans to ignore prometheus metrics scraping requests.

Those request are not interesting to trace or monitor.

Details

The logic can look a bit complex for such a simple option. I have to set this default filter only if the configuration doesn't already contain a filter function for http spans. But TypeScript makes it difficult because it is not happy about accessing field or doing spreading on boolean (which would actually work but hey, that would be too easy it suppose).

Related to GW-482

@gemini-code-assist
Copy link

Summary of Changes

Hello @EmrysMyrddin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the OpenTelemetry plugin by implementing a default mechanism to prevent tracing of Prometheus metrics scraping requests. This change aims to streamline observability data by focusing on more relevant application traffic, thereby improving the signal-to-noise ratio in tracing logs. The implementation includes careful handling of existing configuration to ensure the default filter is only applied when no explicit HTTP span filtering is already in place.

Highlights

  • Default Prometheus Request Filtering: OpenTelemetry tracing now automatically ignores Prometheus metrics scraping requests by default, reducing irrelevant tracing data.
  • Configurable HTTP Span Filtering: A new default HTTP span filter has been introduced that specifically excludes requests ending with '/metrics'. This filter is applied only if no custom HTTP span filter is already configured.
  • Type Definition Refactoring: The OpenTelemetry plugin options have been refactored to extract complex tracing configuration into dedicated TracesConfig and SpansConfig types, improving code readability and maintainability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a default filter to exclude Prometheus scraping requests from OpenTelemetry tracing, which is a sensible default. The configuration types for traces have been nicely refactored for better readability and structure.

I've found a critical issue in the implementation logic for applying the default filter. The current code could lead to a runtime TypeError and also incorrectly overwrites existing user configurations for spans. I've provided a detailed comment with a suggested fix to address this.

Other than that, the changes look good and the new filter function is implemented correctly.

@EmrysMyrddin EmrysMyrddin force-pushed the feat/otel/filter-prom-requests branch from cf76cf9 to 438fd6e Compare October 31, 2025 13:26

export const defaultHttpFilter: SpansConfig['http'] = ({ request }) => {
// Ignore Prometheus requests
if (request.url.endsWith('/metrics')) {
Copy link
Member

@ardatan ardatan Oct 31, 2025

Choose a reason for hiding this comment

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

This assumes that prometheus metrics are always at /metrics. But it is configurable in Prometheus plugin, no?
Maybe we can have a shared flag to decide if the request is prom request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Humm difficult to do, because this will be executed before even the onRequest hook.

Or the prometheus plugin have to also implement instrument.request to mark the request (which is a possibility of course)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not very simple to do, because you end up again with plugin order issues ^^'
So it's more fragile in programmatic usage where we don't control the plugin order. And it also means that this little bit of code will not be inside the span.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've refactored, let me know what you think :-)

Copy link
Member

Choose a reason for hiding this comment

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

Looks better!

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 31, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-hive/gateway 2.1.14-alpha-92fb9e27adca3c259f49fa971532a994c6882f81 npm ↗︎ unpkg ↗︎
@graphql-hive/nestjs 2.0.19-alpha-92fb9e27adca3c259f49fa971532a994c6882f81 npm ↗︎ unpkg ↗︎
@graphql-hive/plugin-aws-sigv4 2.0.14-alpha-92fb9e27adca3c259f49fa971532a994c6882f81 npm ↗︎ unpkg ↗︎
@graphql-hive/plugin-deduplicate-request 2.0.6-alpha-92fb9e27adca3c259f49fa971532a994c6882f81 npm ↗︎ unpkg ↗︎
@graphql-hive/plugin-opentelemetry 1.1.0-alpha-92fb9e27adca3c259f49fa971532a994c6882f81 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-prometheus 2.1.0-alpha-92fb9e27adca3c259f49fa971532a994c6882f81 npm ↗︎ unpkg ↗︎
@graphql-hive/gateway-runtime 2.3.2-alpha-92fb9e27adca3c259f49fa971532a994c6882f81 npm ↗︎ unpkg ↗︎
@graphql-hive/gateway-testing 2.0.2-alpha-92fb9e27adca3c259f49fa971532a994c6882f81 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-http 1.0.10-alpha-92fb9e27adca3c259f49fa971532a994c6882f81 npm ↗︎ unpkg ↗︎

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 31, 2025

🚀 Snapshot Release (Binary for macOS-ARM64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 31, 2025

🚀 Snapshot Release (Binary for Linux-ARM64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 31, 2025

🚀 Snapshot Release (Binary for Linux-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 31, 2025

🚀 Snapshot Release (Binary for macOS-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 31, 2025

🚀 Snapshot Release (Binary for Windows-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 31, 2025

🚀 Snapshot Release (Bun Docker Image)

The latest changes of this PR are available as image on GitHub Container Registry (based on the declared changesets):

ghcr.io/graphql-hive/gateway:2.1.14-alpha-92fb9e27adca3c259f49fa971532a994c6882f81-bun

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 31, 2025

🚀 Snapshot Release (Node Docker Image)

The latest changes of this PR are available as image on GitHub Container Registry (based on the declared changesets):

ghcr.io/graphql-hive/gateway:2.1.14-alpha-92fb9e27adca3c259f49fa971532a994c6882f81

@EmrysMyrddin
Copy link
Collaborator Author

There is a security check fail because of a CVE in a deps of npm.
I haven't found an easy way to update it for now, I will see later to fix it on main.

@EmrysMyrddin EmrysMyrddin enabled auto-merge (squash) October 31, 2025 17:40
@EmrysMyrddin EmrysMyrddin disabled auto-merge October 31, 2025 17:41
@EmrysMyrddin EmrysMyrddin force-pushed the feat/otel/filter-prom-requests branch from ee0794b to c376a64 Compare November 3, 2025 14:42
@EmrysMyrddin EmrysMyrddin force-pushed the feat/otel/filter-prom-requests branch from c376a64 to 92fb9e2 Compare November 3, 2025 14:43
@ardatan ardatan merged commit a3f2811 into main Nov 5, 2025
66 checks passed
@ardatan ardatan deleted the feat/otel/filter-prom-requests branch November 5, 2025 14:10
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.

3 participants