Skip to content

Commit 2535c70

Browse files
authored
[API/SDK] Provider cleanup (#2664)
1 parent 4f37503 commit 2535c70

38 files changed

+806
-228
lines changed

CHANGELOG.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,60 @@ Increment the:
2121
* [CI] Upgrade to clang-format 18
2222
[#2684](https://github.com/open-telemetry/opentelemetry-cpp/pull/2684)
2323

24+
* [API/SDK] Provider cleanup
25+
[#2664](https://github.com/open-telemetry/opentelemetry-cpp/pull/2664)
26+
27+
Important changes:
28+
29+
* [API/SDK] Provider cleanup
30+
[#2664](https://github.com/open-telemetry/opentelemetry-cpp/pull/2664)
31+
* Before this fix:
32+
* The API class `opentelemetry::trace::Tracer` exposed methods such
33+
as `ForceFlush()`, `ForceFlushWithMicroseconds()`, `Close()`
34+
and `CloseWithMicroseconds()`.
35+
* These methods are meant to be used when configuring the SDK,
36+
and should not be part of the API. Exposing them was an oversight.
37+
* Two of these methods are virtual, and therefore part of the ABI.
38+
* After this fix:
39+
* In `OPENTELEMETRY_ABI_VERSION_NO 1`, nothing is changed,
40+
because removing this code would break the ABI.
41+
* In `OPENTELEMETRY_ABI_VERSION_NO 2`, these methods are moved
42+
from the API to the SDK. This is a breaking change for ABI version 2,
43+
which is still experimental.
44+
* In all cases, instrumenting an application should not
45+
invoke flush or close on a tracer, do not use these methods.
46+
47+
Breaking changes:
48+
49+
* [API/SDK] Provider cleanup
50+
[#2664](https://github.com/open-telemetry/opentelemetry-cpp/pull/2664)
51+
* Before this fix:
52+
* SDK factory methods such as:
53+
* opentelemetry::sdk::trace::TracerProviderFactory::Create()
54+
* opentelemetry::sdk::metrics::MeterProviderFactory::Create()
55+
* opentelemetry::sdk::logs::LoggerProviderFactory::Create()
56+
* opentelemetry::sdk::logs::EventLoggerProviderFactory::Create()
57+
returned an API object (opentelemetry::trace::TracerProvider)
58+
to the caller.
59+
* After this fix, these methods return an SDK level object
60+
(opentelemetry::sdk::trace::TracerProvider) to the caller.
61+
* Returning an SDK object is necessary for the application to
62+
cleanup and invoke SDK level methods, such as ForceFlush(),
63+
on a provider.
64+
* The application code that configures the SDK, by calling
65+
the various provider factories, may need adjustment.
66+
* All the examples have been updated, and in particular no
67+
longer perform static_cast do convert an API object to an SDK object.
68+
Please refer to examples for guidance on how to adjust.
69+
* If adjusting application code is impractical,
70+
an alternate and temporary solution is to build with option
71+
WITH_DEPRECATED_SDK_FACTORY=ON in CMake.
72+
* Option WITH_DEPRECATED_SDK_FACTORY=ON will allow to build code
73+
without application changes, posponing changes for later.
74+
* WITH_DEPRECATED_SDK_FACTORY=ON is temporary, only to provide
75+
an easier migration path. Expect this flag to be removed,
76+
as early as by the next release.
77+
2478
Notes on experimental features:
2579

2680
* [#2372](https://github.com/open-telemetry/opentelemetry-cpp/issues/2372)

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ message(STATUS "OPENTELEMETRY_VERSION=${OPENTELEMETRY_VERSION}")
154154

155155
option(WITH_NO_DEPRECATED_CODE "Do not include deprecated code" OFF)
156156

157+
# This option is temporary, and will be removed. Set
158+
# WITH_DEPRECATED_SDK_FACTORY=OFF to migrate to the new SDK code.
159+
option(WITH_DEPRECATED_SDK_FACTORY "Use deprecated SDK provider factory" ON)
160+
161+
if(WITH_DEPRECATED_SDK_FACTORY)
162+
message(WARNING "WITH_DEPRECATED_SDK_FACTORY=ON is temporary and deprecated")
163+
endif()
164+
157165
set(WITH_STL
158166
"OFF"
159167
CACHE STRING "Which version of the Standard Library for C++ to use")

DEPRECATED.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,85 @@ No date set yet for the Jaeger Propagator.
8888

8989
## [opentelemetry-cpp SDK]
9090

91-
N/A
91+
### SDK ProviderFactory cleanup
92+
93+
#### Announcement (SDK ProviderFactory cleanup)
94+
95+
* Version: 1.15.0
96+
* Date: 2024-06-03
97+
* PR: [API/SDK] Provider cleanup
98+
[#2664](https://github.com/open-telemetry/opentelemetry-cpp/pull/2664)
99+
100+
This PR introduces changes to SDK ProviderFactory methods.
101+
102+
#### Motivation (SDK ProviderFactory cleanup)
103+
104+
SDK Factory methods for signal providers, such as:
105+
106+
* opentelemetry::sdk::trace::TracerProviderFactory
107+
* opentelemetry::sdk::metrics::MeterProviderFactory
108+
* opentelemetry::sdk::logs::LoggerProviderFactory
109+
* opentelemetry::sdk::logs::EventLoggerProviderFactory
110+
111+
currently returns a unique pointer on a API class.
112+
113+
This is incorrect, the proper return type should be
114+
a unique pointer on a SDK class instead.
115+
116+
#### Scope (SDK ProviderFactory cleanup)
117+
118+
All the current Create methods in:
119+
120+
* class opentelemetry::sdk::trace::TracerProviderFactory
121+
* class opentelemetry::sdk::metrics::MeterProviderFactory
122+
* class opentelemetry::sdk::logs::LoggerProviderFactory
123+
* class opentelemetry::sdk::logs::EventLoggerProviderFactory
124+
125+
are marked as deprecated, as they return an API object.
126+
127+
Instead, another set of Create methods is provided,
128+
with a different return type, an SDK object.
129+
130+
Both sets can not be exposed at the same time,
131+
as this would cause build breaks,
132+
so a compilation flag is defined to select which methods to use.
133+
134+
When OPENTELEMETRY_DEPRECATED_SDK_FACTORY is defined,
135+
the old, deprecated, methods are available.
136+
137+
When OPENTELEMETRY_DEPRECATED_SDK_FACTORY is not defined,
138+
the new methods are available.
139+
140+
The scope of this deprecation and removal,
141+
is to remove the flag OPENTELEMETRY_DEPRECATED_SDK_FACTORY itself,
142+
which implies that only the new set of Create() methods,
143+
returning an SDK object, are supported.
144+
145+
#### Mitigation (SDK ProviderFactory cleanup)
146+
147+
Build without defining flag OPENTELEMETRY_DEPRECATED_SDK_FACTORY.
148+
149+
Existing code, such as:
150+
151+
```cpp
152+
std::shared_ptr<opentelemetry::trace::TracerProvider> tracer_provider;
153+
tracer_provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(...);
154+
```
155+
156+
should be adjusted to:
157+
158+
```cpp
159+
std::shared_ptr<opentelemetry::sdk::trace::TracerProvider> tracer_provider;
160+
tracer_provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(...);
161+
```
162+
163+
#### Planned removal (SDK ProviderFactory cleanup)
164+
165+
Flag OPENTELEMETRY_DEPRECATED_SDK_FACTORY is introduced in release 1.16.0,
166+
to provide a migration path.
167+
168+
This flag is meant to be temporary, and short lived.
169+
Expect removal by release 1.17.0
92170

93171
## [opentelemetry-cpp Exporter]
94172

api/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ if(WITH_NO_DEPRECATED_CODE)
3535
INTERFACE OPENTELEMETRY_NO_DEPRECATED_CODE)
3636
endif()
3737

38+
if(WITH_DEPRECATED_SDK_FACTORY)
39+
target_compile_definitions(opentelemetry_api
40+
INTERFACE OPENTELEMETRY_DEPRECATED_SDK_FACTORY)
41+
endif()
42+
3843
if(WITH_ABSEIL)
3944
target_compile_definitions(opentelemetry_api INTERFACE HAVE_ABSEIL)
4045
target_link_libraries(

api/include/opentelemetry/plugin/tracer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class Tracer final : public trace::Tracer, public std::enable_shared_from_this<T
104104
return nostd::shared_ptr<trace::Span>{new (std::nothrow) Span{this->shared_from_this(), span}};
105105
}
106106

107+
#if OPENTELEMETRY_ABI_VERSION_NO == 1
108+
107109
void ForceFlushWithMicroseconds(uint64_t timeout) noexcept override
108110
{
109111
tracer_handle_->tracer().ForceFlushWithMicroseconds(timeout);
@@ -114,6 +116,8 @@ class Tracer final : public trace::Tracer, public std::enable_shared_from_this<T
114116
tracer_handle_->tracer().CloseWithMicroseconds(timeout);
115117
}
116118

119+
#endif /* OPENTELEMETRY_ABI_VERSION_NO */
120+
117121
private:
118122
// Note: The order is important here.
119123
//

api/include/opentelemetry/trace/noop.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ class OPENTELEMETRY_EXPORT NoopTracer final : public Tracer,
102102
return noop_span;
103103
}
104104

105+
#if OPENTELEMETRY_ABI_VERSION_NO == 1
106+
105107
void ForceFlushWithMicroseconds(uint64_t /*timeout*/) noexcept override {}
106108

107109
void CloseWithMicroseconds(uint64_t /*timeout*/) noexcept override {}
110+
111+
#endif /* OPENTELEMETRY_ABI_VERSION_NO */
108112
};
109113

110114
/**

api/include/opentelemetry/trace/tracer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ class Tracer
163163
}
164164
}
165165

166+
#if OPENTELEMETRY_ABI_VERSION_NO == 1
167+
168+
/*
169+
* The following is removed from the API in ABI version 2.
170+
* It belongs to the SDK.
171+
*/
172+
166173
/**
167174
* Force any buffered spans to flush.
168175
* @param timeout to complete the flush
@@ -188,6 +195,8 @@ class Tracer
188195
}
189196

190197
virtual void CloseWithMicroseconds(uint64_t timeout) noexcept = 0;
198+
199+
#endif /* OPENTELEMETRY_ABI_VERSION_NO */
191200
};
192201
} // namespace trace
193202
OPENTELEMETRY_END_NAMESPACE

api/test/singleton/singleton_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,13 @@ class MyTracer : public trace::Tracer
250250
return result;
251251
}
252252

253+
#if OPENTELEMETRY_ABI_VERSION_NO == 1
254+
253255
void ForceFlushWithMicroseconds(uint64_t /* timeout */) noexcept override {}
254256

255257
void CloseWithMicroseconds(uint64_t /* timeout */) noexcept override {}
258+
259+
#endif /* OPENTELEMETRY_ABI_VERSION_NO */
256260
};
257261

258262
class MyTracerProvider : public trace::TracerProvider

ci/do_ci.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ switch ($action) {
133133
cmake $SRC_DIR `
134134
-DOTELCPP_MAINTAINER_MODE=ON `
135135
-DWITH_NO_DEPRECATED_CODE=ON `
136+
-DWITH_DEPRECATED_SDK_FACTORY=OFF `
136137
-DVCPKG_TARGET_TRIPLET=x64-windows `
137138
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
138139
$exit = $LASTEXITCODE
@@ -157,6 +158,7 @@ switch ($action) {
157158
-DCMAKE_CXX_STANDARD=20 `
158159
-DOTELCPP_MAINTAINER_MODE=ON `
159160
-DWITH_NO_DEPRECATED_CODE=ON `
161+
-DWITH_DEPRECATED_SDK_FACTORY=OFF `
160162
-DVCPKG_TARGET_TRIPLET=x64-windows `
161163
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
162164
$exit = $LASTEXITCODE

ci/do_ci.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then
130130
-DWITH_ASYNC_EXPORT_PREVIEW=OFF \
131131
-DOTELCPP_MAINTAINER_MODE=ON \
132132
-DWITH_NO_DEPRECATED_CODE=ON \
133+
-DWITH_DEPRECATED_SDK_FACTORY=OFF \
133134
-DWITH_OTLP_HTTP_COMPRESSION=ON \
134135
${IWYU} \
135136
"${SRC_DIR}"
@@ -152,6 +153,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
152153
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
153154
-DOTELCPP_MAINTAINER_MODE=ON \
154155
-DWITH_NO_DEPRECATED_CODE=ON \
156+
-DWITH_DEPRECATED_SDK_FACTORY=OFF \
155157
-DWITH_OTLP_HTTP_COMPRESSION=ON \
156158
${IWYU} \
157159
"${SRC_DIR}"
@@ -175,6 +177,7 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then
175177
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
176178
-DOTELCPP_MAINTAINER_MODE=ON \
177179
-DWITH_NO_DEPRECATED_CODE=ON \
180+
-DWITH_DEPRECATED_SDK_FACTORY=OFF \
178181
-DWITH_OTLP_HTTP_COMPRESSION=ON \
179182
"${SRC_DIR}"
180183
make -k -j $(nproc)
@@ -196,6 +199,7 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then
196199
-DWITH_ASYNC_EXPORT_PREVIEW=OFF \
197200
-DOTELCPP_MAINTAINER_MODE=ON \
198201
-DWITH_NO_DEPRECATED_CODE=ON \
202+
-DWITH_DEPRECATED_SDK_FACTORY=OFF \
199203
-DWITH_ABI_VERSION_1=OFF \
200204
-DWITH_ABI_VERSION_2=ON \
201205
-DWITH_OTLP_HTTP_COMPRESSION=ON \

0 commit comments

Comments
 (0)