@@ -24,23 +24,31 @@ def generate_stack(action_params)
24
24
if Datadog . configuration . appsec . stack_trace . enabled
25
25
context = AppSec ::Context . active
26
26
# We use methods defined in Tracing::Metadata::Tagging,
27
- # which means we can work on both the trace and the service entry span
28
- service_entry_operation = context && ( context . trace || context . span )
27
+ # which means we can use both the trace and the service entry span
28
+ service_entry_operation = ( context . trace || context . span ) if context
29
29
30
30
unless service_entry_operation
31
31
Datadog . logger . debug { 'Cannot find trace or service entry span to add stack trace' }
32
32
return
33
33
end
34
34
35
+ # caller_locations without params always returns an array but steep still thinks it can be nil
36
+ # So we add || [] but it will never run the second part anyway (either this or steep:ignore)
35
37
stack_frames = caller_locations || [ ]
36
- # caller_locations without params always returns an array but rbs still thinks it can be nil
37
- stack_frames . reject! { |loc | loc . path && loc . path . include? ( 'lib/datadog' ) }
38
+ # Steep that path can still be nil and that include? is not a method of nil
39
+ # A way to fix this is to assign loc.path to a variable and use it instead, but it adds an operation
40
+ # Which is why we are ignoring this line
41
+ stack_frames . reject! do |loc |
42
+ loc . path &&
43
+ loc . path . include? ( 'lib/datadog' ) # steep:ignore NoMethod
44
+ end
38
45
39
46
collected_stack_frames = AppSec ::StackTrace ::Collection . new ( stack_frames )
40
47
41
48
# ASCII-8BIT is encoded as byte array and backend cannot decode it properly so we enforce UTF-8 on stack_id.
42
49
# We must copy it as it can be frozen.
43
- utf8_stack_id = action_params [ 'stack_id' ] && action_params [ 'stack_id' ] . encode ( 'UTF-8' )
50
+ utf8_stack_id = action_params [ 'stack_id' ] . encode ( 'UTF-8' ) if action_params [ 'stack_id' ]
51
+ # We should always have a stack_id, but we should still send the stack trace if not (visible with feature flags)
44
52
stack_trace = AppSec ::StackTrace ::Representation . new ( utf8_stack_id , collected_stack_frames )
45
53
46
54
# Add stack trace to trace or service entry span by modifying meta_struct['_dd.stack']
0 commit comments