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

Export SamplingPriority method on spanContext [SVLS-3934] #2291

Merged
merged 2 commits into from
Oct 30, 2023

Conversation

purple4reina
Copy link
Contributor

What does this PR do?

Exports the SamplingPriority method on the spanContext type.

Motivation

We on the serverless team are working to update the Lambda Extension from doing manual trace context extraction to instead deferring to dd-trace-go for all extraction. This will allow us to be able to support W3C trace context headers.

The problem is that we also need to have access to the sampling priority. We must add this value to the trace chunk before it's processed by the trace agent.

Currently, dd-trace-go offers no way for us to get access to the sampling priority.

Discussion

I am very much open to discussion for how best to get the sampling priority from the SpanContext. I have chosen to simply export the SamplingPriority method because it's the lightest touch creating a small diff. Furthermore, the exported method will not show up in godocs and therefore not be immediately visible to users. One would have to read the code and specifically cast the SpanContext to a new interface to get access to it.

Here's how I'm proposing to use the method:

func getSamplingPriority(sc ddtrace.SpanContext) (priority sampler.SamplingPriority) {
	priority = defaultPriority
	if pc, ok := sc.(interface{ SamplingPriority() (int, bool) }); ok && pc != nil {
		if p, ok := pc.SamplingPriority(); ok {
			priority = sampler.SamplingPriority(p)
		}
	}
	return
}

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@pr-commenter
Copy link

pr-commenter bot commented Oct 25, 2023

Benchmarks

Benchmark execution time: 2023-10-25 18:01:58

Comparing candidate commit cb0edc7 in PR branch rey.abolofia/sampling-priority with baseline commit a95d449 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 40 metrics, 1 unstable metrics.

Copy link
Contributor

@darccio darccio left a comment

Choose a reason for hiding this comment

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

I see no reason to not export this function. LGTM 👍

@darccio darccio merged commit 1e7a3e0 into main Oct 30, 2023
51 of 52 checks passed
@darccio darccio deleted the rey.abolofia/sampling-priority branch October 30, 2023 16:22
@darccio darccio restored the rey.abolofia/sampling-priority branch November 16, 2023 09:52
@darccio darccio deleted the rey.abolofia/sampling-priority branch November 16, 2023 09:54
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