Module: Contrast::AgentLib::Init

Extended by:
FFI::Library
Included in:
Interface, Test
Defined in:
lib/contrast/agent_lib/api/init.rb

Overview

This module is defined in Rust as external, we used it here. Initializes the AgentLib. Here will be all methods from the C bindings agent_init mod.

Instance Method Summary collapse

Instance Method Details

#dl__init_with_options(enable_logging, log_dir, log_level) ⇒ Boolean

Initialize AgentLib with options. If init returns 0 = successful setup with options if init returns 1 = unsuccessful setup with options

Parameters:

  • enable_logging (Boolean)

    flag to enable or disable logging.

  • log_dir (String)

    path to existing log directory.

  • log_level (String)

    OFF, ERROR, WARN, INFO, DEBUG or TRACE.

Returns:

  • (Boolean)

    true if initialized false if not.



64
65
66
67
68
# File 'lib/contrast/agent_lib/api/init.rb', line 64

def dl__init_with_options enable_logging, log_dir, log_level
  # This is useful for scope sensitive string pointers, if function ends and
  # you need them to be picked up after the C function.
  init_with_options(enable_logging, log_dir, log_level).zero?
end

#initInteger

Init

0 => OK, -1 => Err The attach function could be called also like this: attach_function :ruby_name, :c_name, [ :params ], :returns, { :options => values } an that way we define a ruby_name for the C method, but we alias to make a documentation for the method.

Also we extend the FFI::Library inside this module so we could also redefine the attach_function to our taste, not worry about it leaking outside of this module.

Parameters:

  • Name (Symbol)

    of required function.

  • An (Array)

    array of argument types.

Returns:

  • (Integer)

    Return type of the function.



31
# File 'lib/contrast/agent_lib/api/init.rb', line 31

attach_function :init, [], :int

#init_with_optionsInteger

Initialize agent lib without any optional settings. To set optional settings consider using ‘init_with_options` instead If you want to enable logging, it must be set using environment variables `CONTRAST_AGENTLIB_LOG_LEVEL` - set to log level. Must of one of ERROR, WARN, INFO, DEBUG or TRACE `CONTRAST_AGENTLIB_LOG_DIR` - must point to an accessible directory where logs will be written.

The name of the log file

is auto-generated and cannot be set. The format is ‘libcontrast_<date>_<process_id>.log’

If these environment variables are not present during ‘init`, agent-lib will be initialized with logging disabled and you will not be able to re-enable it using `change_log_settings`

Parameters:

  • Name (Symbol)

    of required function.

  • An (Array)

    array of argument types.

Returns:

  • (Integer)

    Return type of the function.



45
# File 'lib/contrast/agent_lib/api/init.rb', line 45

attach_function :init_with_options, %i[bool string string], :int