Class: Datadog::AppSec::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/appsec/scope.rb

Overview

Capture context essential to consistently call processor and report via traces

Defined Under Namespace

Classes: ActiveScopeError, InactiveScopeError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trace, service_entry_span, processor_context) ⇒ Scope

Returns a new instance of Scope.



9
10
11
12
13
# File 'lib/datadog/appsec/scope.rb', line 9

def initialize(trace, service_entry_span, processor_context)
  @trace = trace
  @service_entry_span = service_entry_span
  @processor_context = processor_context
end

Instance Attribute Details

#processor_contextObject (readonly)

Returns the value of attribute processor_context.



7
8
9
# File 'lib/datadog/appsec/scope.rb', line 7

def processor_context
  @processor_context
end

#service_entry_spanObject (readonly)

Returns the value of attribute service_entry_span.



7
8
9
# File 'lib/datadog/appsec/scope.rb', line 7

def service_entry_span
  @service_entry_span
end

#traceObject (readonly)

Returns the value of attribute trace.



7
8
9
# File 'lib/datadog/appsec/scope.rb', line 7

def trace
  @trace
end

Class Method Details

.activate_scope(trace, service_entry_span, processor) ⇒ Object

Raises:



20
21
22
23
24
25
# File 'lib/datadog/appsec/scope.rb', line 20

def activate_scope(trace, service_entry_span, processor)
  raise ActiveScopeError, 'another scope is active, nested scopes are not supported' if active_scope

  context = processor.new_context
  self.active_scope = new(trace, service_entry_span, context)
end

.active_scopeObject



37
38
39
# File 'lib/datadog/appsec/scope.rb', line 37

def active_scope
  Thread.current[:datadog_appsec_active_scope]
end

.deactivate_scopeObject

Raises:



27
28
29
30
31
32
33
34
35
# File 'lib/datadog/appsec/scope.rb', line 27

def deactivate_scope
  raise InactiveScopeError, 'no scope is active, nested scopes are not supported' unless active_scope

  scope = active_scope

  reset_active_scope

  scope.finalize
end

Instance Method Details

#finalizeObject



15
16
17
# File 'lib/datadog/appsec/scope.rb', line 15

def finalize
  @processor_context.finalize
end