Skip to content

feat: add support for client reports#1192

Merged
giortzisg merged 39 commits intomasterfrom
feat/client-reports
Mar 4, 2026
Merged

feat: add support for client reports#1192
giortzisg merged 39 commits intomasterfrom
feat/client-reports

Conversation

@giortzisg
Copy link
Contributor

Description

add support for client reports.

Issues

Changelog Entry Instructions

To add a custom changelog entry, uncomment the section above. Supports:

  • Single entry: just write text
  • Multiple entries: use bullet points
  • Nested bullets: indent 4+ spaces

For more details: custom changelog entries

Reminders

@giortzisg giortzisg self-assigned this Feb 10, 2026
@linear
Copy link

linear bot commented Feb 10, 2026

GO-94 Add client reports

@github-actions
Copy link

github-actions bot commented Feb 10, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • Add support for client reports by giortzisg in #1192
  • Add the option to set attributes on the scope by giortzisg in #1208

Internal Changes 🔧

  • (deps) Bump github.com/gofiber/fiber/v2 from 2.52.11 to 2.52.12 in /fiber by dependabot in #1209

🤖 This preview updates automatically when you update the PR.

@giortzisg giortzisg marked this pull request as ready for review February 12, 2026 12:45
@giortzisg giortzisg marked this pull request as draft February 24, 2026 13:55
@giortzisg giortzisg marked this pull request as ready for review February 25, 2026 12:30
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable autofix in the Cursor dashboard.

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

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

just some notes for understanding, lgtm otherwise

limits := ratelimit.FromResponse(response)

// Drain body up to a limit and close it, allowing the transport to reuse TCP connections.
_, _ = io.CopyN(io.Discard, response.Body, MaxDrainResponseBytes)
Copy link
Member

Choose a reason for hiding this comment

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

what is this lol

 is the drain in @internal/util/util.go shady
  ⎿  Read internal/util/util.go (120 lines)

⏺ Not shady — it's a standard Go pattern. Here's why it exists:

  The problem: Go's http.Client reuses TCP connections (called "keep-alive") for performance. But it can only reuse a connection if the previous response body was fully read and closed. If you just close without reading, Go
   throws away the connection and opens a new one for the next request — slower.

  What the code does:

  _, _ = io.CopyN(io.Discard, response.Body, MaxDrainResponseBytes)  // read up to 16KB, throw it away
  response.Body.Close()                                                // then close

  It reads up to 16KB of leftover response data into the void, then closes the body. This lets Go recycle the TCP connection.

  The 16KB cap (16 << 10) is a safety net — if the server sends back a huge response (e.g. an HTML error page), it won't waste time/memory reading all of it. It just gives up connection reuse for that one response.

  The _, _ = part intentionally discards both the byte count and any error. That's fine here because:
  - The data itself is unwanted (already logged what was needed in HandleHTTPResponse)
  - If the drain fails, the worst outcome is a non-reused connection — not a correctness issue

  This is a well-known Go idiom. You'll see it in the Go standard library docs and most HTTP client code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first part is that for go to reuse the tcp connection we need to empty and close the io connection, so we just throw all remaining bytes.
The second part with MaxDrainResponseBytes already existed in the SDK as a pattern and I am not really convinced about it's use(since we don't really expect relay to return a malicious response), but it's what the llm suggests, just a safety limit for draining that many response bytes.

}

if !options.DisableClientReports {
a := report.NewAggregator()
Copy link
Member

Choose a reason for hiding this comment

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

i understand that aggregator has the same functions as both recorder and provider, but then why make those interfaces in the first place? this is very confusing for a non-go person

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's mostly separation of concerns and not exposing the take reports functionality to a layer that doesn't need it.

@giortzisg giortzisg merged commit d875511 into master Mar 4, 2026
18 checks passed
@giortzisg giortzisg deleted the feat/client-reports branch March 4, 2026 11:56
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.

Add client reports

2 participants