1414import sentry_sdk
1515from sentry_sdk .consts import SPANDATA
1616from sentry_sdk .tracing import DEFAULT_SPAN_ORIGIN
17+ from sentry_sdk .tracing_utils import create_sampling_context
1718from sentry_sdk .utils import get_current_thread_meta
1819from sentry_sdk .profiler .continuous_profiler import (
1920 try_autostart_continuous_profiler ,
@@ -66,7 +67,7 @@ def on_start(self, span, parent_context=None):
6667 return
6768
6869 self ._add_root_span (span , get_current_span (parent_context ))
69- self ._start_profile (span )
70+ self ._start_profile (span , parent_context )
7071
7172 def on_end (self , span ):
7273 # type: (ReadableSpan) -> None
@@ -105,8 +106,8 @@ def _add_root_span(self, span, parent_span):
105106 # root span points to itself
106107 set_sentry_meta (span , "root_span" , span )
107108
108- def _start_profile (self , span ):
109- # type: (Span) -> None
109+ def _start_profile (self , span , parent_context ):
110+ # type: (Span, Optional[Context] ) -> None
110111 try_autostart_continuous_profiler ()
111112 profiler_id = get_profiler_id ()
112113 thread_id , thread_name = get_current_thread_meta ()
@@ -126,8 +127,10 @@ def _start_profile(self, span):
126127 # unix timestamp that is on span.start_time
127128 # setting it to 0 means the profiler will internally measure time on start
128129 profile = Profile (sampled , 0 )
129- # TODO-neel-potel sampling context??
130- profile ._set_initial_sampling_decision (sampling_context = {})
130+ sampling_context = create_sampling_context (
131+ span .name , span .attributes , parent_context , span .context .trace_id
132+ )
133+ profile ._set_initial_sampling_decision (sampling_context )
131134 profile .__enter__ ()
132135 set_sentry_meta (span , "profile" , profile )
133136
0 commit comments