Skip to content

Commit 55bdaa4

Browse files
committed
sprintf_s -> snprintf on linux
1 parent 5c4d911 commit 55bdaa4

File tree

3 files changed

+75
-71
lines changed

3 files changed

+75
-71
lines changed

dll.md

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
1-
# OpenTelemetry as a single .dll
2-
3-
This branch builds a single `.dll`, combining both api + sdk parts, instead of being separate .dlls.
4-
5-
Why?
6-
- The `vcpkg` version of the package can build only static libraries, and in the future, if dynamic works it'll create .dll for each component: zlib, protobuf, etc.
7-
- The built-in `CMake` rules produce more than one .dll, and do not expose all of the `sdk` by default.
8-
9-
There are some critical issues with OpenTelemetry C++ in the original branch:
10-
- The static library version does not work across dlls using it - their own `singleton_test` fails.
11-
- The static library brings dozen of dependencies (zlib, protobuf, grpc, etc.)
12-
- This not only increases the distribution size (from 100mb to 2GB), it can also silently introduce `ODR` violations too.
13-
- Integration with MSVC's STL is needed, instead of relying the `nostd` custom implementation (using `abseil` internally).
14-
15-
Why not `CMake`:
16-
- It's not friendly, neither from the command-line, nor from the IDE.
17-
- It requires plenty of custom build steps, some from the `ci/` folder, others from `tools/`
18-
19-
```
20-
pwsh ci/setup_windows_ci_environment.ps1
21-
pwsh ci/do_ci.ps1 cmake.dll.test
22-
pwsh ci/do_ci.ps1 cmake.exporter.otprotocol.dll.test
23-
```
24-
25-
To tackle the above issues, this branch creates a dynamic `otel_sdk_r.dll` library, exposing only the OpenTelemetry C++ api:
26-
- All of the `api` classes are inline, and only few static function members need to be exported, in order to guarantee single stroage for their own static variables ("singletons")
27-
- Hence `OPENTELEMETRY_API_SINGLETON` would be `__declspec(dllimport)` when using the library.
28-
- For the `sdk` part (exporters, ext, etc.) the above is not used, but rather `OPENTELEMETRY_EXPORT` (also `dllimport`) for some classes.
29-
30-
## Build settings
31-
32-
- The `.bazelrc` file tries to import `../top.bazelrc`, where you can specify more settings (for example disk cache)
33-
- MSVC Toolset version `14.29.30133` is used (the last from the `v142` series in VS2019). This toolset is also available, as an additional install, in VS2022 too.
34-
- VS2019 was chosen due to: https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017#restrictions
35-
36-
## How to use
37-
38-
In order to use the library, the users only need to define OPENTELEMETRY_DLL to 1, and include `<opentelemetry/version.h>` as the first file:
39-
40-
```C++
41-
#define OPENTELEMETRY_DLL 1
42-
#include <opentelemetry/version.h>
43-
#include <opentelemetry/... some other header file>
44-
```
45-
46-
- Some MSVC warnings might have to be disabled too, like: 4505 4251 4275
47-
48-
## Some limitations
49-
50-
Some things are missing:
51-
- The `protobuf` level of accessing metrics/logs/trace APIs is missing.
52-
- Some useful plumbing with `grpc` is missing too.
53-
54-
## Building
55-
56-
This branch uses `bazel` to build, and relies on the `//:with_dll` bool flag to configure the build in `dll` mode:
57-
58-
```
59-
bazel test --//:with_dll=true ... -k
60-
```
61-
62-
This produces `otel_sdk_rd.dll` (in the default `fastbuild` configuration, `rd` stands for `release/debug` borrowed from `CMake`'s jargon).
63-
64-
## Packaging
65-
66-
A single `otel_sdk.zip` is produced, mimicking how `vcpkg` exports packages:
67-
- Single `include/` folder
68-
- Three `lib` folders: `lib/`, `debug/lib` and `reldeb/lib` (vcpkg only generates the first two)
69-
- Same for `bin`: `bin`, `debug/bin` and `reldeb/bin`
70-
- In addition Sentry's `sentrycli` was used to gather (from the .pdb files) all sources used to compile and bundle them in additional .zip files.
1+
# OpenTelemetry as a single .dll
2+
3+
This branch builds a single `.dll`, combining both api + sdk parts, instead of being separate .dlls.
4+
5+
Why?
6+
- The `vcpkg` version of the package can build only static libraries, and in the future, if dynamic works it'll create .dll for each component: zlib, protobuf, etc.
7+
- The built-in `CMake` rules produce more than one .dll, and do not expose all of the `sdk` by default.
8+
9+
There are some critical issues with OpenTelemetry C++ in the original branch:
10+
- The static library version does not work across dlls using it - their own `singleton_test` fails.
11+
- The static library brings dozen of dependencies (zlib, protobuf, grpc, etc.)
12+
- This not only increases the distribution size (from 100mb to 2GB), it can also silently introduce `ODR` violations too.
13+
- Integration with MSVC's STL is needed, instead of relying the `nostd` custom implementation (using `abseil` internally).
14+
15+
Why not `CMake`:
16+
- It's not friendly, neither from the command-line, nor from the IDE.
17+
- It requires plenty of custom build steps, some from the `ci/` folder, others from `tools/`
18+
19+
```
20+
pwsh ci/setup_windows_ci_environment.ps1
21+
pwsh ci/do_ci.ps1 cmake.dll.test
22+
pwsh ci/do_ci.ps1 cmake.exporter.otprotocol.dll.test
23+
```
24+
25+
To tackle the above issues, this branch creates a dynamic `otel_sdk_r.dll` library, exposing only the OpenTelemetry C++ api:
26+
- All of the `api` classes are inline, and only few static function members need to be exported, in order to guarantee single stroage for their own static variables ("singletons")
27+
- Hence `OPENTELEMETRY_API_SINGLETON` would be `__declspec(dllimport)` when using the library.
28+
- For the `sdk` part (exporters, ext, etc.) the above is not used, but rather `OPENTELEMETRY_EXPORT` (also `dllimport`) for some classes.
29+
30+
## Build settings
31+
32+
- The `.bazelrc` file tries to import `../top.bazelrc`, where you can specify more settings (for example disk cache)
33+
- MSVC Toolset version `14.29.30133` is used (the last from the `v142` series in VS2019). This toolset is also available, as an additional install, in VS2022 too.
34+
- VS2019 was chosen due to: https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017#restrictions
35+
36+
## How to use
37+
38+
In order to use the library, the users only need to define OPENTELEMETRY_DLL to 1, and include `<opentelemetry/version.h>` as the first file:
39+
40+
```C++
41+
#define OPENTELEMETRY_DLL 1
42+
#include <opentelemetry/version.h>
43+
#include <opentelemetry/... some other header file>
44+
```
45+
46+
- Some MSVC warnings might have to be disabled too, like: 4505 4251 4275
47+
48+
## Some limitations
49+
50+
Some things are missing:
51+
- The `protobuf` level of accessing metrics/logs/trace APIs is missing.
52+
- Some useful plumbing with `grpc` is missing too.
53+
54+
## Building
55+
56+
This branch uses `bazel` to build, and relies on the `//:with_dll` bool flag to configure the build in `dll` mode:
57+
58+
```
59+
bazel test --//:with_dll=true ... -k
60+
```
61+
62+
This produces `otel_sdk_rd.dll` (in the default `fastbuild` configuration, `rd` stands for `release/debug` borrowed from `CMake`'s jargon).
63+
64+
## Packaging
65+
66+
A single `otel_sdk.zip` is produced, mimicking how `vcpkg` exports packages:
67+
- Single `include/` folder
68+
- Three `lib` folders: `lib/`, `debug/lib` and `reldeb/lib` (vcpkg only generates the first two)
69+
- Same for `bin`: `bin`, `debug/bin` and `reldeb/bin`
70+
- In addition Sentry's `sentrycli` was used to gather (from the .pdb files) all sources used to compile and bundle them in additional .zip files.
-1 Bytes
Loading

exporters/otlp/src/otlp_grpc_forward_proxy.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ OtlpGrpcForwardProxy::Impl::Impl(const OtlpGrpcClientOptions& options)
145145
std::random_device rd;
146146
uint64_t p0 = (uint64_t(rd())<<32) | uint64_t(rd());
147147
uint64_t p1 = (uint64_t(rd())<<32) | uint64_t(rd());
148-
sprintf_s(buf, "%08.8lx%08.8lx", p0, p1);
148+
#if defined(_MSC_VER)
149+
sprintf_s(buf, "%8.8lx%8.8lx", p0, p1);
150+
#else
151+
snprintf(buf, sizeof(buf), "%8.8lx%8.8lx", p0, p1);
152+
#endif
149153
fw_proxy_id = buf;
150154
}
151155

0 commit comments

Comments
 (0)