-
Notifications
You must be signed in to change notification settings - Fork 438
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
Build OpenTelemetry C++ SDK and exporter into DLL #1932
Conversation
Thanks @ThomsonTan . Just to be clear, is this going to resolve the #1105 ? @meastp, @owent - It would be really helpful whenever you have time to review this. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1932 +/- ##
==========================================
+ Coverage 87.12% 87.13% +0.01%
==========================================
Files 165 166 +1
Lines 4596 4597 +1
==========================================
+ Hits 4004 4005 +1
Misses 592 592
|
Yes, it should resolve the issues in #1105. I still need some minor change on this draft, but feel free to take a look as the major change has been verified. I plan to add some document on exporting C++ inline member function to DLL.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In:
class OPENTELEMETRY_API TracerProviderFactory
It feels strange to see "API" in the name, for a class from the SDK.
IMPORT / EXPORT is orthogonal to api/sdk/etc
Rename to OPENTELEMETRY_EXPORT
, which will apply to any api / sdk / exporter classes ?
I actually named the macro as like |
Don't have strong opinion on naming, but OPENTELEMETRY_EXTERN or OPENTELEMETRY_WIN_EXTERN can be considered too, if we want to avoid API and EXPORT keywords :) |
Looked at some Chromium code,
Looked some Chromium code and pattern, seems naming it as *_EXPORT makes sense as suggested by @marcalff. See https://chromium.googlesource.com/chromium/src.git/+/master/base/base_export.h |
@latlib I'm on leave, so haven't looked at the changes in detail, but this is fantastic. Great work @ThomsonTan! :) When I did my "fork" I had problems with some of the examples/tests. I copied the shared dlls manually, which made it a bit cumbersome, but I think cmake has some function to fix this. Again, this makes me very happy - thanks! well done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(struggling with github UI, restart review to remove requested changes flag)
Agreed, with single DLL for opentelemetry-cpp, there may be further requests for single shared/static library for other platforms too :). As of now, building OpenTelemetry C++ as shared target(s) for Windows user is something missing, and this looks to be a promising first step towards it. Also building multiple DDL targets ( specifically for API ) would require us to either move away from header-only API support, or create source-api from header during build - and this needs to be discussed further. |
As @marc is not able to remove the flag.
Have removed the flag, hope it works. |
@owent could you please help review this PR when you have time? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is buried in comments, so repeating here to avoid missing it.
Please consider this suggestion:
The choice between import and export is driven by which file is compiled, not by the user code.
In CMakeList.txt:
if(DEFINED OPENTELEMETRY_BUILD_DLL)
if(NOT MSVC)
message(WARNING "Build DLL is supposed to work with MSVC!")
endif()
if(WITH_STL)
message(
WARNING "Build DLL with C++ STL could cause binary incompatibility!")
endif()
add_definitions(-DOPENTELEMETRY_BUILD_DLL) // <-------------------------
endif()
In macro.h:
#if defined(_MSC_VER) && defined(OPENTELEMETRY_BUILD_DLL)
#ifdef OPENTELEMETRY_BUILD_EXPORT_DLL // <-------------------------------------
# define OPENTELEMETRY_EXPORT __declspec(dllexport)
#else
# define OPENTELEMETRY_EXPORT __declspec(dllimport)
#endif
#else
//
// build OpenTelemetry as static library or not on Windows.
//
# define OPENTELEMETRY_EXPORT
#endif
And then, when compiling every file that is part of the DLL:
File sdk/src/trace/CMakeLists.txt
add_definitions(-DOPENTELEMETRY_BUILD_EXPORT_DLL) // <------------------------------
This totally avoids user to add OPENTELEMETRY_BUILD_IMPORT_DLL
.
Currently there are 3 macros, The suggestion seems about merging the CMake and one of the C++ macro definition which indeed can eliminate one def. So the point is that My concern is that this extra implicit assumption makes the intention less clear to the user. For example, ask the user to define C++ macro
|
exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, is it better to export all classes and functions when building a dll?
@owent what does it mean for exporting all classes? Even the classes internal to API/SDK/Exporters? If so, this could make the output DLL very fragile as any change on the internal classes could break the binary to be loaded to the app which linked to the older DLL, even there is not API change in this repo. |
Thanks for your explanation.I have another question, we install all headers when we run cmake --install now.In my understanding, is it better to select a subset of headers to install(all exported classes and their dependencies). Maybe we can also improve it in another PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Filed #1980 to track this. |
Fixes #1105
Changes
Please provide a brief description of the changes here.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes