Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate "Profiler disabled because there was a problem in setting up the libddprof dependency" #2068

Closed
ivoanjo opened this issue Jun 6, 2022 · 7 comments · Fixed by #2134
Assignees
Labels
profiling Involves Datadog profiling

Comments

@ivoanjo
Copy link
Member

ivoanjo commented Jun 6, 2022

This was reported by @rgrey in #2045 (comment) , and I've extracted it to a separate issue so it can be investigated separately.

The issue is that profiling does not work with the following error message:

WARN -- ddtrace: [ddtrace] Profiling was requested but is not supported, profiling disabled: Your ddtrace installation is missing support for the Continuous Profiler because there was a problem in setting up the libddprof dependency. For help solving this issue, please contact Datadog support at https://docs.datadoghq.com/help/.

I'll add the next steps for this investigation soon.

@ivoanjo
Copy link
Member Author

ivoanjo commented Jun 6, 2022

The issue seems to be triggered by the pkg-config invocation failing:

unless pkg_config('ddprof_ffi_with_rpath')
skip_building_extension!(Datadog::Profiling::NativeExtensionHelpers::Supported::FAILED_TO_CONFIGURE_LIBDDPROF)

But Ruby does not seem to log a lot of information when that happens.

I'm researching a way to properly expose the logs when this failure happens. Will update this ticket once I have more details.

ivoanjo added a commit that referenced this issue Jun 7, 2022
To avoid impacting customers, whenever we detect an issue which
would've led to the profiling native extension compilation to fail, we
instead skip the compilation.

This ensures that customers (especially those *not* using profiling)
don't get impacted at installation time.

Instead, at execution time, if they do try to enable profiling,
they'll get a message such as

```
WARN -- ddtrace: [ddtrace] Profiling was requested but is not supported,
profiling disabled: Your ddtrace installation is missing support for the
Continuous Profiler because there was a problem in setting up the
libddprof dependency. For help solving this issue, please contact
Datadog support at https://docs.datadoghq.com/help/.
```

But while investigating one such issue reported by a customer
(<#2068>), I found that
it's helpful to have a way to break during installation, because
that will make Ruby print extra debug information, including the
location of the `mkmf.log` log file which can be useful when
debugging issues.

Thus, I've added a new `DD_PROFILING_FAIL_INSTALL_IF_MISSING_EXTENSION`
environment variable that support can request customers set to `true`
to force a failure at installation time.

Here's how it looks when I simulate a broken `libddprof` setup by
renaming a file:

```
 # Installs successfully, but profiling will not work:

$ gem install pkg/ddtrace-1.1.0.gem
Building native extensions. This could take a while...
Successfully installed ddtrace-1.1.0
Parsing documentation for ddtrace-1.1.0
Done installing documentation for ddtrace after 3 seconds
1 gem installed

 # Force failure to show up at gem installation time:

$ DD_PROFILING_FAIL_INSTALL_IF_MISSING_EXTENSION=true gem install pkg/ddtrace-1.1.0.gem
Building native extensions. This could take a while...
ERROR:  Error installing pkg/ddtrace-1.1.0.gem:
  ERROR: Failed to build gem native extension.

    current directory: ~/.rvm/gems/ruby-2.7.6/gems/ddtrace-1.1.0/ext/ddtrace_profiling_native_extension
~/.rvm/rubies/ruby-2.7.6/bin/ruby -I ~/.rvm/rubies/ruby-2.7.6/lib/ruby/2.7.0 -r ./siteconf20220607-83731-8dqh3w.rb extconf.rb

+------------------------------------------------------------------------------+
| ** Preparing to build the ddtrace profiling native extension... **           |
|                                                                              |
| If you run into any failures during this step, you can set the               |
| `DD_PROFILING_NO_EXTENSION` environment variable to `true` e.g.              |
| `$ DD_PROFILING_NO_EXTENSION=true bundle install` to skip this step.         |
|                                                                              |
| If you disable this extension, the Datadog Continuous Profiler will          |
| not be available, but all other ddtrace features will work fine!             |
|                                                                              |
| If you needed to use this, please tell us why on                             |
| <https://github.com/DataDog/dd-trace-rb/issues/new> so we can fix it :)      |
|                                                                              |
| Thanks for using ddtrace! You rock!                                          |
+------------------------------------------------------------------------------+

+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| there was a problem in setting up the `libddprof` dependency.                |
|                                                                              |
| Failing installation immediately because the                                 |
| `DD_PROFILING_FAIL_INSTALL_IF_MISSING_EXTENSION` environment variable is set |
| to `true`.                                                                   |
| When contacting support, please include the <mkmf.log> file that is shown    |
| below.                                                                       |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
  --with-opt-dir
  --with-opt-include
  --without-opt-include=${opt-dir}/include
  --with-opt-lib
  --without-opt-lib=${opt-dir}/lib
  --with-make-prog
  --without-make-prog
  --srcdir=.
  --curdir
  --ruby=~/.rvm/rubies/ruby-2.7.6/bin/$(RUBY_BASE_NAME)
  --with-ddprof_ffi_with_rpath_x-config
  --without-ddprof_ffi_with_rpath_x-config
  --with-pkg-config
  --without-pkg-config

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  ~/.rvm/gems/ruby-2.7.6/extensions/x86_64-darwin-20/2.7.0/ddtrace-1.1.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in ~/.rvm/gems/ruby-2.7.6/gems/ddtrace-1.1.0 for inspection.
Results logged to ~/.rvm/gems/ruby-2.7.6/extensions/x86_64-darwin-20/2.7.0/ddtrace-1.1.0/gem_make.out
```

You'll notice that a bunch more useful information shows up, including the
path to `mkmf.log`, which can provide extra information.
ivoanjo added a commit that referenced this issue Jun 7, 2022
To avoid impacting customers, whenever we detect an issue which
would've led to the profiling native extension compilation to fail, we
instead skip the compilation.

This ensures that customers (especially those *not* using profiling)
don't get impacted at installation time.

Instead, at execution time, if they do try to enable profiling,
they'll get a message such as

```
WARN -- ddtrace: [ddtrace] Profiling was requested but is not supported,
profiling disabled: Your ddtrace installation is missing support for the
Continuous Profiler because there was a problem in setting up the
libddprof dependency. For help solving this issue, please contact
Datadog support at https://docs.datadoghq.com/help/.
```

But while investigating one such issue reported by a customer
(<#2068>), I found that
it's helpful to have a way to break during installation, because
that will make Ruby print extra debug information, including the
location of the `mkmf.log` log file which can be useful when
debugging issues.

Thus, I've added a new `DD_PROFILING_FAIL_INSTALL_IF_MISSING_EXTENSION`
environment variable that support can request customers set to `true`
to force a failure at installation time.

Here's how it looks when I simulate a broken `libddprof` setup by
renaming a file:

```
 # Installs successfully, but profiling will not work:

$ gem install pkg/ddtrace-1.1.0.gem
Building native extensions. This could take a while...
Successfully installed ddtrace-1.1.0
Parsing documentation for ddtrace-1.1.0
Done installing documentation for ddtrace after 3 seconds
1 gem installed

 # Force failure to show up at gem installation time:

$ DD_PROFILING_FAIL_INSTALL_IF_MISSING_EXTENSION=true gem install pkg/ddtrace-1.1.0.gem
Building native extensions. This could take a while...
ERROR:  Error installing pkg/ddtrace-1.1.0.gem:
  ERROR: Failed to build gem native extension.

    current directory: ~/.rvm/gems/ruby-2.7.6/gems/ddtrace-1.1.0/ext/ddtrace_profiling_native_extension
~/.rvm/rubies/ruby-2.7.6/bin/ruby -I ~/.rvm/rubies/ruby-2.7.6/lib/ruby/2.7.0 -r ./siteconf20220607-83731-8dqh3w.rb extconf.rb

+------------------------------------------------------------------------------+
| ** Preparing to build the ddtrace profiling native extension... **           |
|                                                                              |
| If you run into any failures during this step, you can set the               |
| `DD_PROFILING_NO_EXTENSION` environment variable to `true` e.g.              |
| `$ DD_PROFILING_NO_EXTENSION=true bundle install` to skip this step.         |
|                                                                              |
| If you disable this extension, the Datadog Continuous Profiler will          |
| not be available, but all other ddtrace features will work fine!             |
|                                                                              |
| If you needed to use this, please tell us why on                             |
| <https://github.com/DataDog/dd-trace-rb/issues/new> so we can fix it :)      |
|                                                                              |
| Thanks for using ddtrace! You rock!                                          |
+------------------------------------------------------------------------------+

+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| there was a problem in setting up the `libddprof` dependency.                |
|                                                                              |
| Failing installation immediately because the                                 |
| `DD_PROFILING_FAIL_INSTALL_IF_MISSING_EXTENSION` environment variable is set |
| to `true`.                                                                   |
| When contacting support, please include the <mkmf.log> file that is shown    |
| below.                                                                       |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
  --with-opt-dir
  --with-opt-include
  --without-opt-include=${opt-dir}/include
  --with-opt-lib
  --without-opt-lib=${opt-dir}/lib
  --with-make-prog
  --without-make-prog
  --srcdir=.
  --curdir
  --ruby=~/.rvm/rubies/ruby-2.7.6/bin/$(RUBY_BASE_NAME)
  --with-ddprof_ffi_with_rpath_x-config
  --without-ddprof_ffi_with_rpath_x-config
  --with-pkg-config
  --without-pkg-config

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  ~/.rvm/gems/ruby-2.7.6/extensions/x86_64-darwin-20/2.7.0/ddtrace-1.1.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in ~/.rvm/gems/ruby-2.7.6/gems/ddtrace-1.1.0 for inspection.
Results logged to ~/.rvm/gems/ruby-2.7.6/extensions/x86_64-darwin-20/2.7.0/ddtrace-1.1.0/gem_make.out
```

You'll notice that a bunch more useful information shows up, including the
path to `mkmf.log`, which can provide extra information.
ivoanjo added a commit that referenced this issue Jun 7, 2022
This will help us investigate #2068 .
@ivoanjo ivoanjo added the profiling Involves Datadog profiling label Jun 7, 2022
@ivoanjo
Copy link
Member Author

ivoanjo commented Jun 7, 2022

I've been looking into this issue, but discovered that there's a bug/limitation in rubygems where the log file we would need to debug this issue is overwritten because dd-trace-rb ships two native extensions that both need compiling.

@rgrey Would you be open to trying a development build of ddtrace that should be able to log more information about why the failure is happening? (If not, please do let me know, I can look into speeding up a release with this extended logging)

You can get it from https://s3.amazonaws.com/gems.datadoghq.com/prerelease-v2/gems/ddtrace-1.1.0.ivoanjo.improve.native.extension.debugging.232295.gem and here's how to install it:

$ DD_PROFILING_FAIL_INSTALL_IF_MISSING_EXTENSION=true gem install ddtrace-1.1.0.ivoanjo.improve.native.extension.debugging.232295.gem

I've added the DD_PROFILING_FAIL_INSTALL_IF_MISSING_EXTENSION environment variable in #2069 and it should make it so that the error you're seeing happen immediately at installation-time, and Ruby will give you the path to the mkmf.log file that gets generated with more details on why installation failed.

@rgrey
Copy link

rgrey commented Jun 9, 2022

LD_LIBRARY_PATH=.:/usr/local/lib "gcc -o conftest -I/usr/local/include/ruby-3.1.0/x86_64-linux -I/usr/local/include/ruby-3.1.0/ruby/backward -I/usr/local/include/ruby-3.1.0 -I.    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef  -fPIC conftest.c  -L. -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed     -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lruby  -lm  -lc"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

LD_LIBRARY_PATH=.:/usr/local/lib "gcc -I/usr/local/include/ruby-3.1.0/x86_64-linux -I/usr/local/include/ruby-3.1.0/ruby/backward -I/usr/local/include/ruby-3.1.0 -I.    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef  -fPIC  -std=gnu99 -Werror -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

LD_LIBRARY_PATH=.:/usr/local/lib "gcc -I/usr/local/include/ruby-3.1.0/x86_64-linux -I/usr/local/include/ruby-3.1.0/ruby/backward -I/usr/local/include/ruby-3.1.0 -I.    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef  -fPIC -std=gnu99  -Wno-unused-function -Werror -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

LD_LIBRARY_PATH=.:/usr/local/lib "gcc -I/usr/local/include/ruby-3.1.0/x86_64-linux -I/usr/local/include/ruby-3.1.0/ruby/backward -I/usr/local/include/ruby-3.1.0 -I.    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef  -fPIC -std=gnu99 -Wno-unused-function  -Wno-declaration-after-statement -Werror -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

LD_LIBRARY_PATH=.:/usr/local/lib "gcc -I/usr/local/include/ruby-3.1.0/x86_64-linux -I/usr/local/include/ruby-3.1.0/ruby/backward -I/usr/local/include/ruby-3.1.0 -I.    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef  -fPIC -std=gnu99 -Wno-unused-function -Wno-declaration-after-statement  -Werror-implicit-function-declaration -Werror -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

LD_LIBRARY_PATH=.:/usr/local/lib "gcc -I/usr/local/include/ruby-3.1.0/x86_64-linux -I/usr/local/include/ruby-3.1.0/ruby/backward -I/usr/local/include/ruby-3.1.0 -I.    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wundef  -fPIC -std=gnu99 -Wno-unused-function -Wno-declaration-after-statement -Werror-implicit-function-declaration  -fvisibility=hidden -Werror -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

 [ddtrace] PKG_CONFIG_PATH set to ':/usr/local/bundle/gems/libddprof-0.6.0.1.0-x86_64-linux/vendor/libddprof-0.6.0/x86_64-linux/libddprof-x86_64-unknown-linux-gnu/lib/pkgconfig'
package configuration for ddprof_ffi_with_rpath is not found
 [ddtrace] Failure cause: there was a problem in setting up the `libddprof` dependency. For help solving this issue, please contact Datadog support at <https://docs.datadoghq.com/help/>.
GET | 200 | 233 ms | envoy

@ivoanjo
Copy link
Member Author

ivoanjo commented Jun 10, 2022

Thanks for the log! Just to add some context, mkmf (that generates mkmf.log) is a tool that's part of the Ruby standard library and get gets called when compiling native extensions, like ddtrace requires.

When a Ruby native extension wants to compile and link to an external native library, mkmf invokes a tool called pkg-config to get the correct settings to do this. This is the step that is failing here -- package configuration for ddprof_ffi_with_rpath is not found is actually logged directly by Ruby's mkmf.

Could you share the results of running the following commands:

  • 1️⃣ pkg-config --version
  • 2️⃣ PKG_CONFIG_PATH=:/usr/local/bundle/gems/libddprof-0.6.0.1.0-x86_64-linux/vendor/libddprof-0.6.0/x86_64-linux/libddprof-x86_64-unknown-linux-gnu/lib/pkgconfig pkg-config --debug ddprof_ffi_with_rpath

I suspect these two final clues will allow me to get to the bottom of this issue and produce a fix for your situation. Thanks for the patience so far!

@rgrey
Copy link

rgrey commented Jun 10, 2022

$ pkg-config --version
bash: pkg-config: command not found

It appears to build fine if we install pkg-config 😁

@ivoanjo
Copy link
Member Author

ivoanjo commented Jun 10, 2022

Great! It's really surprising that the Ruby mkmf library doesn't have a better error message in this situation. I'll keep this issue open until I add a check on our code to provide a good error message for this situation.

Thanks a lot for the help debugging this! 🙇

ivoanjo added a commit that referenced this issue Jul 7, 2022
In #2068 a customer reported that they were not getting profiling
with the message:

> Profiling was requested but is not supported, profiling disabled:
> Your ddtrace installation is missing support for the Continuous
> Profiler because there was a problem in setting up the libddprof
> dependency.

After investigating this issue (and adding extra tools to debug it,
see #2069) it turns out that the customer was missing the `pkg-config`
tool.

This tool is currently invoked indirectly via Ruby's `mkmf` helper,
and is used to configure linking to libddprof/libdatadog.

I must admit I was surprised that there's not better error logging
in `mkmf` when the `pkg-config` tool is actually missing
(vs it being installed but returning an error when being called).

Thus, to hopefully avoid other customers running into this issue,
I've added a bit of code to detect it, and hopefully present a
better error message in that situation.

I've also learned that `pkg-config` is "old news" on some Linux
distributions, and instead they ship something called `pkgconf`
which is a reimplementation of `pkg-config`.

Beyond the RSpec tests, this can be triggered for testing by:

1. Changing the `pkg_config` call on extconf.rb

```diff
-unless pkg_config('ddprof_ffi_with_rpath')
+unless pkg_config('ddprof_ffi_with_rpath_broken')
```

which triggers the generic message (because pkg-config is
available but returns an error since the configuration file
is not found):

```
+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| there was a problem in setting up the `libddprof` dependency.                |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+
```

2. Crippling `pkg_config`:

```bash
$ docker-compose run --no-deps --rm tracer-2.1 /bin/bash
  # doing this inside docker is fine because it doesn't persist
$ rm /usr/bin/pkg-config
$ bundle exec rake clean compile
 # ...
+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| the `pkg-config` system tool is missing.                                     |
| This issue can usually be fixed by installing:                               |
| 1. the `pkg-config` package on Homebrew and Debian/Ubuntu-based Linux;       |
| 2. the `pkgconf` package on Arch and Alpine-based Linux;                     |
| 3. the `pkgconf-pkg-config` package on Fedora/Red Hat-based Linux.           |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+
```

Closes #2068
ivoanjo added a commit that referenced this issue Jul 7, 2022
In #2068 a customer reported that they were not getting profiling
with the message:

> Profiling was requested but is not supported, profiling disabled:
> Your ddtrace installation is missing support for the Continuous
> Profiler because there was a problem in setting up the libddprof
> dependency.

After investigating this issue (and adding extra tools to debug it,
see #2069) it turns out that the customer was missing the `pkg-config`
tool.

This tool is currently invoked indirectly via Ruby's `mkmf` helper,
and is used to configure linking to libddprof/libdatadog.

I must admit I was surprised that there's not better error logging
in `mkmf` when the `pkg-config` tool is actually missing
(vs it being installed but returning an error when being called).

Thus, to hopefully avoid other customers running into this issue,
I've added a bit of code to detect it, and hopefully present a
better error message in that situation.

I've also learned that `pkg-config` is "old news" on some Linux
distributions, and instead they ship something called `pkgconf`
which is a reimplementation of `pkg-config`.

Beyond the RSpec tests, this can be triggered for testing by:

1. Changing the `pkg_config` call on extconf.rb

```diff
-unless pkg_config('ddprof_ffi_with_rpath')
+unless pkg_config('ddprof_ffi_with_rpath_broken')
```

which triggers the generic message (because pkg-config is
available but returns an error since the configuration file
is not found):

```
+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| there was a problem in setting up the `libddprof` dependency.                |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+
```

2. Crippling `pkg_config`:

```bash
$ docker-compose run --no-deps --rm tracer-2.1 /bin/bash
  # doing this inside docker is fine because it doesn't persist
$ rm /usr/bin/pkg-config
$ bundle exec rake clean compile
 # ...
+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| the `pkg-config` system tool is missing.                                     |
| This issue can usually be fixed by installing:                               |
| 1. the `pkg-config` package on Homebrew and Debian/Ubuntu-based Linux;       |
| 2. the `pkgconf` package on Arch and Alpine-based Linux;                     |
| 3. the `pkgconf-pkg-config` package on Fedora/Red Hat-based Linux.           |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+
```

Closes #2068
ivoanjo added a commit that referenced this issue Jul 7, 2022
In #2068 a customer reported that they were not getting profiling
with the message:

> Profiling was requested but is not supported, profiling disabled:
> Your ddtrace installation is missing support for the Continuous
> Profiler because there was a problem in setting up the libddprof
> dependency.

After investigating this issue (and adding extra tools to debug it,
see #2069) it turns out that the customer was missing the `pkg-config`
tool.

This tool is currently invoked indirectly via Ruby's `mkmf` helper,
and is used to configure linking to libddprof/libdatadog.

I must admit I was surprised that there's not better error logging
in `mkmf` when the `pkg-config` tool is actually missing
(vs it being installed but returning an error when being called).

Thus, to hopefully avoid other customers running into this issue,
I've added a bit of code to detect it, and hopefully present a
better error message in that situation.

I've also learned that `pkg-config` is "old news" on some Linux
distributions, and instead they ship something called `pkgconf`
which is a reimplementation of `pkg-config`.

Beyond the RSpec tests, this can be triggered for testing by:

1. Changing the `pkg_config` call on extconf.rb

```diff
-unless pkg_config('ddprof_ffi_with_rpath')
+unless pkg_config('ddprof_ffi_with_rpath_broken')
```

which triggers the generic message (because pkg-config is
available but returns an error since the configuration file
is not found):

```
+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| there was a problem in setting up the `libddprof` dependency.                |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+
```

2. Crippling `pkg_config`:

```bash
$ docker-compose run --no-deps --rm tracer-2.1 /bin/bash
  # doing this inside docker is fine because it doesn't persist
$ rm /usr/bin/pkg-config
$ bundle exec rake clean compile
 # ...
+------------------------------------------------------------------------------+
| Could not compile the Datadog Continuous Profiler because                    |
| the `pkg-config` system tool is missing.                                     |
| This issue can usually be fixed by installing:                               |
| 1. the `pkg-config` package on Homebrew and Debian/Ubuntu-based Linux;       |
| 2. the `pkgconf` package on Arch and Alpine-based Linux;                     |
| 3. the `pkgconf-pkg-config` package on Fedora/Red Hat-based Linux.           |
|                                                                              |
| The Datadog Continuous Profiler will not be available,                       |
| but all other ddtrace features will work fine!                               |
|                                                                              |
| For help solving this issue, please contact Datadog support at               |
| <https://docs.datadoghq.com/help/>.                                          |
+------------------------------------------------------------------------------+
```

Closes #2068
@ivoanjo
Copy link
Member Author

ivoanjo commented Jul 11, 2022

👋 @rgrey the improved message has been released in v1.2.0.
No more users shall be confused by this issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants