Skip to content

Reduce locking in the implementation of Layer::on_close#173

Merged
djc merged 1 commit intotokio-rs:v0.1.xfrom
mzabaluev:minimize-locking-on-close
Oct 14, 2024
Merged

Reduce locking in the implementation of Layer::on_close#173
djc merged 1 commit intotokio-rs:v0.1.xfrom
mzabaluev:minimize-locking-on-close

Conversation

@mzabaluev
Copy link
Copy Markdown
Contributor

In the implementation of the on_close method, only hold the lock on span's extension to retrieve the extension data, but release it before processing and exporting.

Motivation

To achieve optimal performance, span locks should be held for as little time as possible.
It's especially troublesome to hold the lock while arbitrary code in the generic OpenTelemetry span and exporter is called to export the span.

Solution

Reduce the locked code section to what's needed to remove the data of interest from the extension map.

Only hold the lock on span's extension to retrieve
the extension data, but release it before processing and exporting.
Copy link
Copy Markdown
Collaborator

@djc djc left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@djc djc merged commit 515fe00 into tokio-rs:v0.1.x Oct 14, 2024
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.

2 participants