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.



11
12
13
14
15
# File 'lib/datadog/appsec/scope.rb', line 11

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.



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

def processor_context
  @processor_context
end

#service_entry_spanObject (readonly)

Returns the value of attribute service_entry_span.



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

def service_entry_span
  @service_entry_span
end

#traceObject (readonly)

Returns the value of attribute trace.



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

def trace
  @trace
end

Class Method Details

.activate_scope(trace, service_entry_span, processor) ⇒ Object

Raises:



22
23
24
25
26
27
28
# File 'lib/datadog/appsec/scope.rb', line 22

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

  context = Datadog::AppSec::Processor::Context.new(processor)

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

.active_scopeObject



40
41
42
# File 'lib/datadog/appsec/scope.rb', line 40

def active_scope
  Thread.current[:datadog_appsec_active_scope]
end

.deactivate_scopeObject

Raises:



30
31
32
33
34
35
36
37
38
# File 'lib/datadog/appsec/scope.rb', line 30

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



17
18
19
# File 'lib/datadog/appsec/scope.rb', line 17

def finalize
  @processor_context.finalize
end