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

Expose SpanFromContext #672

Merged
merged 2 commits into from Jul 27, 2023
Merged

Conversation

zhezhel
Copy link
Contributor

@zhezhel zhezhel commented Jul 24, 2023

I'm working on integration pgx with Sentry.

The new version of pgx provides an interface for tracing, which work in the way when you need to implement two different methods: TraceQueryStart & TraceQueryEnd.

To implement TraceQueryEnd, I need to get access to span in context and call Finish on it.

It would be great to provide a method to get span from context.
Current workaround:

func SpanFromContext(ctx interface{}) (*sentry.Span, bool) {
	values := reflect.ValueOf(ctx).Elem()

	for i := 0; i < values.NumField(); i++ {
		reflectValue := values.Field(i)
		reflectValue = reflect.NewAt(reflectValue.Type(), unsafe.Pointer(reflectValue.UnsafeAddr())).Elem()
		span, ok := reflectValue.Interface().(*sentry.Span)
		if !ok {
			continue
		}
		return span, true
	}
	return nil, false
}

@codecov
Copy link

codecov bot commented Jul 24, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (b551438) 80.56% compared to head (ba1e9b0) 80.56%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #672   +/-   ##
=======================================
  Coverage   80.56%   80.56%           
=======================================
  Files          44       44           
  Lines        4460     4460           
=======================================
  Hits         3593     3593           
  Misses        736      736           
  Partials      131      131           
Files Changed Coverage Δ
tracing.go 85.95% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@cleptric cleptric left a comment

Choose a reason for hiding this comment

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

Works for me, @tonyo ?

@cleptric cleptric requested a review from tonyo July 26, 2023 08:56
tracing.go Outdated Show resolved Hide resolved
@zhezhel zhezhel requested a review from tonyo July 26, 2023 15:08
Andrii Zhezhel and others added 2 commits July 26, 2023 17:50
Co-authored-by: Anton Ovchinnikov <anton@tonyo.info>
@zhezhel
Copy link
Contributor Author

zhezhel commented Jul 27, 2023

Hey @cleptric, @tonyo, do you have plans to merge this PR?

@tonyo
Copy link
Member

tonyo commented Jul 27, 2023

Yes, we do!

@tonyo tonyo merged commit dde4d36 into getsentry:master Jul 27, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants