Top Level Namespace

Defined Under Namespace

Modules: DDTrace, Datadog Classes: DatadogAutoInstrumentRailtie

Constant Summary collapse

EXTENSION_NAME =

Tag the native extension library with the Ruby version and Ruby platform. This makes it easier for development (avoids “oops I forgot to rebuild when I switched my Ruby”) and ensures that the wrong library is never loaded. When requiring, we need to use the exact same string, including the version and the platform.

"datadog_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}".freeze
SKIPPED_REASON_FILE =
"#{__dir__}/skipped_reason.txt".freeze

Instance Method Summary collapse

Methods included from Datadog::OpenTracer::GlobalTracer

#global_tracer=

Instance Method Details

#add_compiler_flag(flag) ⇒ Object

mkmf on modern Rubies actually has an append_cflags that does something similar (see github.com/ruby/ruby/pull/5760), but as usual we need a bit more boilerplate to deal with legacy Rubies



17
18
19
20
21
22
23
# File 'ext/datadog_profiling_loader/extconf.rb', line 17

def add_compiler_flag(flag)
  if try_cflags(flag)
    $CFLAGS << ' ' << flag
  else
    $stderr.puts("WARNING: '#{flag}' not accepted by compiler, skipping it")
  end
end

#skip_building_extension!(reason) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'ext/datadog_profiling_native_extension/extconf.rb', line 10

def skip_building_extension!(reason)
  fail_install_if_missing_extension =
    Datadog::Profiling::NativeExtensionHelpers.fail_install_if_missing_extension?

  $stderr.puts(
    Datadog::Profiling::NativeExtensionHelpers::Supported.failure_banner_for(
      **reason,
      fail_install: fail_install_if_missing_extension,
    )
  )

  File.write(
    SKIPPED_REASON_FILE,
    Datadog::Profiling::NativeExtensionHelpers::Supported.render_skipped_reason_file(**reason),
  )

  if fail_install_if_missing_extension
    require 'mkmf'
    Logging.message(
      '[ddtrace] Failure cause: ' \
      "#{Datadog::Profiling::NativeExtensionHelpers::Supported.render_skipped_reason_file(**reason)}\n"
    )
  else
    File.write('Makefile', 'all install clean: # dummy makefile that does nothing')
  end

  exit
end