Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ISpan.GetTransaction convenience method #2014

Merged
merged 5 commits into from Oct 26, 2022

Conversation

mattjohnsonpint
Copy link
Contributor

@mattjohnsonpint mattjohnsonpint commented Oct 26, 2022

This adds a convenience method for when you have an ISpan and need to get the ITransaction it belongs to.

For example:

void DoSomething(ISpan span)
{
    var transaction = span.GetTransaction();
}

This also works well anywhere we have a GetSpan method, such as IHub and SentrySdk

var hub = serviceProvider.GetRequiredService<IHub>();
var transaction = hub.GetSpan()?.GetTransaction();

or

var transaction = SentrySdk.GetSpan()?.GetTransaction();

Motivation

With custom measurements added in #2013, we have this:

transaction.SetMeasurement("some_time", 50, MeasurementUnit.Duration.Millisecond);

Since sometimes we only have a span, we need to do this:

span.GetTransaction().SetMeasurement("some_time", 50, MeasurementUnit.Duration.Millisecond);

The alternative would have been to attach SetMeasurement extension methods on ISpan as well, but that would imply that measurement data is set on individual spans - which it is not.

This seems cleaner and has other usages as well.

@mattjohnsonpint
Copy link
Contributor Author

Some minor formatting changes in the PR as well.

@mattjohnsonpint mattjohnsonpint enabled auto-merge (squash) October 26, 2022 22:39
@mattjohnsonpint mattjohnsonpint merged commit 8d4e116 into main Oct 26, 2022
@mattjohnsonpint mattjohnsonpint deleted the get-transaction-from-span branch October 26, 2022 23:37
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.

None yet

2 participants