Skip to content

Add ISpan.GetTransaction convenience method - #2014

Merged
mattjohnsonpint merged 5 commits into
mainfrom
get-transaction-from-span
Oct 26, 2022
Merged

Add ISpan.GetTransaction convenience method#2014
mattjohnsonpint merged 5 commits into
mainfrom
get-transaction-from-span

Conversation

@mattjohnsonpint

@mattjohnsonpint mattjohnsonpint commented Oct 26, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

2 participants