hook.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "opentelemetry/nostd/unique_ptr.h"
  5. #include "opentelemetry/version.h"
  6. #ifdef _WIN32
  7. /**
  8. * Cross-platform helper macro to declare the symbol used to load an OpenTelemetry implementation
  9. * as a plugin.
  10. *
  11. * Note: The symbols use weak linkage so as to support using an OpenTelemetry both as a regular
  12. * library and a dynamically loaded plugin. The weak linkage allows for multiple implementations to
  13. * be linked in without getting multiple definition errors.
  14. */
  15. # define OPENTELEMETRY_DEFINE_PLUGIN_HOOK(X) \
  16. extern "C" { \
  17. extern __declspec(dllexport) opentelemetry::plugin::OpenTelemetryHook const \
  18. OpenTelemetryMakeFactoryImpl; \
  19. \
  20. __declspec(selectany) opentelemetry::plugin::OpenTelemetryHook const \
  21. OpenTelemetryMakeFactoryImpl = X; \
  22. } // extern "C"
  23. #else
  24. # define OPENTELEMETRY_DEFINE_PLUGIN_HOOK(X) \
  25. extern "C" { \
  26. __attribute(( \
  27. weak)) extern opentelemetry::plugin::OpenTelemetryHook const OpenTelemetryMakeFactoryImpl; \
  28. \
  29. opentelemetry::plugin::OpenTelemetryHook const OpenTelemetryMakeFactoryImpl = X; \
  30. } // extern "C"
  31. #endif
  32. OPENTELEMETRY_BEGIN_NAMESPACE
  33. namespace plugin
  34. {
  35. struct LoaderInfo;
  36. class FactoryImpl;
  37. using OpenTelemetryHook =
  38. nostd::unique_ptr<Factory::FactoryImpl> (*)(const LoaderInfo &loader_info,
  39. nostd::unique_ptr<char[]> &error_message);
  40. } // namespace plugin
  41. OPENTELEMETRY_END_NAMESPACE