Skip to content

Conversation

solnic
Copy link
Collaborator

@solnic solnic commented Jun 10, 2025

#skip-changelog

@solnic solnic force-pushed the traces-sampler-support branch from d01bcbd to c0489ff Compare June 10, 2025 13:44
@solnic solnic changed the title WIP Support for traces_sampler option Jun 11, 2025
@solnic solnic force-pushed the traces-sampler-support branch from c0489ff to bfd2cc9 Compare June 11, 2025 12:47
@solnic solnic marked this pull request as ready for review June 11, 2025 12:50
@solnic solnic requested a review from sl0thentr0py June 11, 2025 12:50
@solnic solnic marked this pull request as draft June 11, 2025 13:05
@solnic solnic force-pushed the traces-sampler-support branch from bfd2cc9 to 2ebef7d Compare June 11, 2025 13:10
@solnic solnic force-pushed the traces-sampler-support branch from 2ebef7d to 27bfc44 Compare June 11, 2025 13:13
@solnic solnic marked this pull request as ready for review June 11, 2025 13:16
@solnic solnic requested a review from whatyouhide June 11, 2025 13:21
@jwaldrip
Copy link

Are we close this time? Had everything working smoothly working in prod using the last branch, but lost it all with the revert. Hoping to see something completed this week if possible...

decision = if trace_sampled, do: :record_and_sample, else: :drop

{decision, [], tracestate}
if traces_sampler do
Copy link
Member

Choose a reason for hiding this comment

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

the traces_sampler has to be invoked only for root spans, see
https://github.com/getsentry/sentry-python/blob/c21525e4252805561d83cd2d726020dd41aa074d/sentry_sdk/opentelemetry/sampler.py#L246

so in this case I think the :inherit case shouldn't exist but only the :no_trace case below should invoke the traces_sampler

}

if attributes && map_size(attributes) > 0 do
Map.merge(sampling_context, attributes)
Copy link
Member

Choose a reason for hiding this comment

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

attributes is already part of transaction_context above, why this merge?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sl0thentr0py accidental left-over after a refactoring :)

result = call_traces_sampler(traces_sampler, sampling_context)
sample_rate = normalize_sampler_result(result)

cond do
Copy link
Member

Choose a reason for hiding this comment

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

could you just use make_sampling_decision after getting the rate here? wanna avoid duplication here especially

@solnic solnic force-pushed the traces-sampler-support branch from 06a3499 to 38df5df Compare June 17, 2025 07:20
@solnic solnic force-pushed the traces-sampler-support branch from 38df5df to 36a6b4d Compare June 17, 2025 07:41
@solnic solnic requested a review from sl0thentr0py June 17, 2025 07:41
@solnic solnic merged commit 499140c into span-processor-with-new-sampler Jun 17, 2025
8 checks passed
@solnic solnic deleted the traces-sampler-support branch June 17, 2025 07:49
@solnic
Copy link
Collaborator Author

solnic commented Jun 17, 2025

Are we close this time? Had everything working smoothly working in prod using the last branch, but lost it all with the revert. Hoping to see something completed this week if possible...

@jwaldrip yes it's happening this time 🎉 we just need to wrap up integration tests and merge the big #902 again to master and this time it'll include properly implemented sampler. Then we'll push a new release with OTel support in beta 😄

solnic added a commit that referenced this pull request Jun 17, 2025
* Revert "Revert "Add SpanProcessor for OpenTelemetry (#875)""

This reverts commit 2ced90e.

* Better span sampler (#903)

* Better span sampler

This updates OpenTelemetry.Sampler so that it uses
`traces_sample_rate` for sampling spans before they
get sent to the span processor.

This way we're not processing spans when they are
dropped during sampling, which was previously the
case as the Client was responsible for sampling
just before attemping to send a transaction.

* Enhance sampling logic to record discarded transactions

* Clarify trace-level sampling decision-making

Previously it incorrectly referred to "parent" where
in reality we're dealing with spans from the same
trace and respect sampling decisions that were
already made for a given trace.

This is not the same thing as parent/child spans
that we're handling in the SpanProcessor as this
type of relationship is established post-sampling.

* Remove unnecessary sleep calls in sampler tests

* Fix flaky test

* Clean up make_sampling_decision

* Simplify client reports for dropped transactions

* Update traces_sample_rate default value to be nil

* Account for `nil` sample_rate when sampling

* Use put_test_config

* Update traces_sample_rate spec to allow nil value

* Support for traces_sampler option (#910)

* Add support for `traces_sampler` config option

* Update docs

* Remove unnecessary attribute merging

* Call traces_sampler only for root spans

* Reuse sampling decision logic

* Add test for handling invalid traces_sampler return values

* Add tests for SamplingContext access functions

* Add basic integration tests for OpenTelemetry (#912)

* Update CHANGELOG
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.

3 participants