summaryrefslogtreecommitdiffstats
path: root/contrib/libs/opentelemetry-cpp/api/include/opentelemetry/plugin/hook.h
blob: 0d2a8538355c2607fa3ef49040ce97fed505909d (plain) (blame)
1
2
3
4
5
6
7
8
9
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/plugin/factory.h"
#include "opentelemetry/version.h"

#ifdef _WIN32

/**
 * Cross-platform helper macro to declare the symbol used to load an OpenTelemetry implementation
 * as a plugin.
 *
 * Note: The symbols use weak linkage so as to support using an OpenTelemetry both as a regular
 * library and a dynamically loaded plugin. The weak linkage allows for multiple implementations to
 * be linked in without getting multiple definition errors.
 */
#  define OPENTELEMETRY_DEFINE_PLUGIN_HOOK(X)                                   \
    extern "C" {                                                                \
    extern __declspec(dllexport) opentelemetry::plugin::OpenTelemetryHook const \
        OpenTelemetryMakeFactoryImpl;                                           \
                                                                                \
    __declspec(selectany) opentelemetry::plugin::OpenTelemetryHook const        \
        OpenTelemetryMakeFactoryImpl = X;                                       \
    }  // extern "C"

#else

#  define OPENTELEMETRY_DEFINE_PLUGIN_HOOK(X)                                                      \
    extern "C" {                                                                                   \
    __attribute((                                                                                  \
        weak)) extern opentelemetry::plugin::OpenTelemetryHook const OpenTelemetryMakeFactoryImpl; \
                                                                                                   \
    opentelemetry::plugin::OpenTelemetryHook const OpenTelemetryMakeFactoryImpl = X;               \
    }  // extern "C"

#endif

// Always print a warning

#if defined(__clang__) || defined(__GNUC__)
#  pragma GCC warning "opentelemetry/plugin/ is deprecated, and will be removed. Do not use."
#elif defined(_MSC_VER)
#  pragma message( \
      "[WARNING]: opentelemetry/plugin/ is deprecated, and will be removed. Do not use.")
#endif

// And fail in deprecated-free builds

#ifdef OPENTELEMETRY_NO_DEPRECATED_CODE
#  error "header <opentelemetry/plugin/> is deprecated."
#endif

OPENTELEMETRY_BEGIN_NAMESPACE
namespace plugin
{

struct LoaderInfo;

using OpenTelemetryHook =
    nostd::unique_ptr<Factory::FactoryImpl> (*)(const LoaderInfo &loader_info,
                                                nostd::unique_ptr<char[]> &error_message);
}  // namespace plugin
OPENTELEMETRY_END_NAMESPACE