Skip to content

feat(spans): Add FlusherLogger to track top flush operations by bytes#108266

Merged
lvthanh03 merged 5 commits intomasterfrom
tony/buffer-logger-flusher
Feb 18, 2026
Merged

feat(spans): Add FlusherLogger to track top flush operations by bytes#108266
lvthanh03 merged 5 commits intomasterfrom
tony/buffer-logger-flusher

Conversation

@lvthanh03
Copy link
Copy Markdown
Member

@lvthanh03 lvthanh03 commented Feb 13, 2026

Adds FlusherLogger to track per-trace flush operations and log the top 50 traces by cumulative bytes flushed every 60 seconds.

@lvthanh03 lvthanh03 requested review from a team as code owners February 13, 2026 22:05
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 13, 2026
Copy link
Copy Markdown
Contributor

@fpacifici fpacifici left a comment

Choose a reason for hiding this comment

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

Why do you need to pipe back the logs to the main process ? Can't you just log from the flusher subprocess ? I would avoid adding that complexity unless absolutely necessary.

Copy link
Copy Markdown
Contributor

@fpacifici fpacifici left a comment

Choose a reason for hiding this comment

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

Please see the comment inline, specifically let's try to avoid the cross process communication for logging.

@evanh evanh requested a review from a team February 18, 2026 15:31
Copy link
Copy Markdown
Contributor

@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 1 potential issue.

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

@lvthanh03 lvthanh03 requested a review from fpacifici February 18, 2026 16:13
Copy link
Copy Markdown
Contributor

@fpacifici fpacifici left a comment

Choose a reason for hiding this comment

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

Please consider addressing the comments before merging.

Comment on lines +498 to +499
if logger_enabled:
ids_start = time.monotonic()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: You do not need the option to be enabled to collect the time, this is safe enough and avoiding the if block makes it more concise.

Copy link
Copy Markdown
Member Author

@lvthanh03 lvthanh03 Feb 18, 2026

Choose a reason for hiding this comment

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

removed the if block. I wasn't sure if we're OK with the extra work to collect the time even if we disable the option, but I guess it is negligible enough

Comment on lines +563 to +575
if logger_enabled and segment:
try:
project_id, trace_id, _ = parse_segment_key(segment_key)
project_and_trace = f"{project_id.decode('ascii')}:{trace_id.decode('ascii')}"
flusher_log_entries.append(
FlusherLogEntry(
project_and_trace,
len(segment),
sum(len(s) for s in segment),
)
)
except Exception:
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any reason not to put this inside the flusher logger?
AS this method is very long and complex, it is really important to try to keep outside everything not strictly needed to perform the business logic.
Please consider factoring this out.

Copy link
Copy Markdown
Member Author

@lvthanh03 lvthanh03 Feb 18, 2026

Choose a reason for hiding this comment

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

I put this here since parse_segment_key is also defined in this file.

Is it okay to move that function to a utils module of some sort so we can avoid the circular import (buffer -> buffer_logger -> buffer)?

Copy link
Copy Markdown
Contributor

@fpacifici fpacifici Feb 18, 2026

Choose a reason for hiding this comment

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

I would not call it util, but feel free to keep where it is and disregards this request


del payloads[key]
del cursors[key]
del sizes[key]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this change ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I realized since we are dropping the segment and deleting span payload, next scan position, so we could might as well delete the byte size total of that segment (sizes[key])

"""

def __init__(self) -> None:
self._data: dict[str, tuple[int, int, int]] = {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please define a type for this tuple[int, int, int], it is hard to tell what it represents.
Moreover the self._data name makes it even harder to tell what this dict represents. Give it a more specific name. like self._trace_latencies

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thanks, I made a NamedTuple for FlusherLogEntry but missed this one. I refactored buffer_logger._data and flusher_logger._data to both be NamedTuple for clarity.

@lvthanh03 lvthanh03 merged commit 0210c1a into master Feb 18, 2026
81 checks passed
@lvthanh03 lvthanh03 deleted the tony/buffer-logger-flusher branch February 18, 2026 21:58
JonasBa pushed a commit that referenced this pull request Feb 19, 2026
…#108266)

Adds `FlusherLogger` to track per-trace flush operations and log the top
50 traces by cumulative bytes flushed every 60 seconds.
mchen-sentry pushed a commit that referenced this pull request Feb 24, 2026
…#108266)

Adds `FlusherLogger` to track per-trace flush operations and log the top
50 traces by cumulative bytes flushed every 60 seconds.
@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

claude-code-assisted Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants