Skip to content

Commit 7eb5a2e

Browse files
authored
feat: Add tracing hook. (#496)
Adds support for an OTEL tracing hook. Unlike other packages we will not be providing a build of this package. A customer wanting to use this package will need to build the SDK themselves in the correct configuration. This allows for the hook to use the version of OpenTelemetry that they are using with their application. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduces a new server-side OpenTelemetry integration (`libs/server-sdk-otel`) with a tracing hook, example app, build flags, CI workflow, and release config. > > - **Server OTEL Integration**: > - New package `libs/server-sdk-otel` implementing `TracingHook` with options (`TracingHookOptions`, builder), headers, implementation, unit tests, `CMakeLists.txt`, `CHANGELOG.md`, and `README.md`. > - Exposes target alias `launchdarkly::server_otel`. > - **Example**: > - Adds `examples/hello-cpp-server-otel` (CMake, README, main) demonstrating OTLP HTTP tracing and hook usage. > - **Build/Config**: > - Top-level: new options `LD_BUILD_OTEL_SUPPORT`, `LD_BUILD_OTEL_FETCH_DEPS`, `LD_OTEL_CPP_VERSION`; conditionally `add_subdirectory(libs/server-sdk-otel)` and example; docs updated in `README.md`. > - `libs/server-sdk-otel/CMakeLists.txt`: optional FetchContent of OpenTelemetry (when `LD_BUILD_OTEL_FETCH_DEPS=ON`), link to `opentelemetry-cpp::api`. > - `scripts/build.sh`: auto-enables OTEL flags for `launchdarkly-cpp-server-otel` and test targets. > - `cmake/json.cmake`: rename FetchContent target to `nlohmann_json`. > - **CI/Release**: > - New workflow `.github/workflows/server-otel.yml` (Ubuntu/macOS/Windows) building `launchdarkly-cpp-server-otel` with CURL dev libs. > - Composite action `.github/actions/ci`: adds `install_curl` input and broadens CURL install condition; passes `CMAKE_PREFIX_PATH`. > - `release-please` config/manifests updated to include `libs/server-sdk-otel` (initial version `0.1.0`). > - Manual docs workflow: adds `libs/server-sdk-otel` option. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0771956. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent c9a6b17 commit 7eb5a2e

File tree

23 files changed

+1706
-5
lines changed

23 files changed

+1706
-5
lines changed

.github/actions/ci/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ inputs:
3333
description: 'Whether to enable CURL networking (LD_CURL_NETWORKING=ON)'
3434
required: false
3535
default: 'false'
36+
install_curl:
37+
description: 'Whether to install CURL development libraries. Required for OpenTelemetry builds (server-sdk-otel), but does not enable CURL networking for the SDK itself.'
38+
required: false
39+
default: 'false'
3640

3741
runs:
3842
using: composite
@@ -49,7 +53,7 @@ runs:
4953
uses: ./.github/actions/install-openssl
5054
id: install-openssl
5155
- name: Install CURL
52-
if: inputs.use_curl == 'true'
56+
if: inputs.use_curl == 'true' || inputs.install_curl == 'true'
5357
uses: ./.github/actions/install-curl
5458
id: install-curl
5559
- name: Build Library

.github/workflows/manual-publish-doc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- libs/client-sdk
1111
- libs/server-sdk
1212
- libs/server-sdk-redis-source
13+
- libs/server-sdk-otel
1314
name: Publish Documentation
1415
jobs:
1516
build-publish:

.github/workflows/release-please.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
package-server-tag: ${{ steps.release.outputs['libs/server-sdk--tag_name'] }}
1515
package-server-redis-released: ${{ steps.release.outputs['libs/server-sdk-redis-source--release_created'] }}
1616
package-server-redis-tag: ${{ steps.release.outputs['libs/server-sdk-redis-source--tag_name'] }}
17+
package-server-otel-released: ${{ steps.release.outputs['libs/server-sdk-otel--release_created'] }}
18+
package-server-otel-tag: ${{ steps.release.outputs['libs/server-sdk-otel--tag_name'] }}
1719
steps:
1820
- uses: googleapis/release-please-action@v4
1921
id: release
@@ -142,3 +144,4 @@ jobs:
142144
upload-assets: true
143145
upload-tag-name: ${{ needs.release-please.outputs.package-server-redis-tag }}
144146
provenance-name: ${{ format('{0}-server-redis-multiple-provenance.intoto.jsonl', matrix.os) }}
147+

.github/workflows/server-otel.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: libs/server-sdk-otel
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths-ignore:
7+
- '**.md' # Do not need to run CI for markdown changes.
8+
pull_request:
9+
branches: [ "main", "feat/**" ]
10+
paths-ignore:
11+
- '**.md'
12+
schedule:
13+
# Run daily at midnight PST
14+
- cron: '0 8 * * *'
15+
16+
jobs:
17+
build-test-otel:
18+
runs-on: ubuntu-22.04
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: ./.github/actions/ci
22+
with:
23+
cmake_target: launchdarkly-cpp-server-otel
24+
install_curl: true
25+
# We don't produce release artifacts.
26+
simulate_release: false
27+
build-otel-mac:
28+
runs-on: macos-13
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: ./.github/actions/ci
32+
with:
33+
cmake_target: launchdarkly-cpp-server-otel
34+
platform_version: 12
35+
install_curl: true
36+
# We don't produce release artifacts.
37+
simulate_release: false
38+
build-test-otel-windows:
39+
runs-on: windows-2022
40+
steps:
41+
- uses: actions/checkout@v4
42+
- uses: ilammy/msvc-dev-cmd@v1
43+
- uses: ./.github/actions/ci
44+
env:
45+
BOOST_LIBRARY_DIR: 'C:\local\boost_1_87_0\lib64-msvc-14.3'
46+
BOOST_LIBRARYDIR: 'C:\local\boost_1_87_0\lib64-msvc-14.3'
47+
Boost_DIR: 'C:\local\boost_1_87_0\lib64-msvc-14.3\cmake\Boost-1.87.0'
48+
with:
49+
cmake_target: launchdarkly-cpp-server-otel
50+
platform_version: 2022
51+
toolset: msvc
52+
install_curl: true
53+
# We don't produce release artifacts.
54+
simulate_windows_release: false

.release-please-manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"libs/internal": "0.12.1",
66
"libs/server-sdk": "3.9.1",
77
"libs/server-sdk-redis-source": "2.2.0",
8+
"libs/server-sdk-otel": "0.0.0",
89
"libs/networking": "0.1.0"
910
}

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ option(LD_BUILD_EXAMPLES "Build hello-world examples." ON)
108108

109109
option(LD_BUILD_REDIS_SUPPORT "Build redis support." OFF)
110110

111+
option(LD_BUILD_OTEL_SUPPORT "Build OpenTelemetry integration." OFF)
112+
111113
option(LD_CURL_NETWORKING "Enable CURL-based networking for SSE client (alternative to Boost.Beast/Foxy)" OFF)
112114

113115
# If using 'make' as the build system, CMake causes the 'install' target to have a dependency on 'all', meaning
@@ -220,6 +222,11 @@ if (LD_BUILD_REDIS_SUPPORT)
220222
add_subdirectory(libs/server-sdk-redis-source)
221223
endif ()
222224

225+
if (LD_BUILD_OTEL_SUPPORT)
226+
message("LaunchDarkly: building OpenTelemetry integration")
227+
add_subdirectory(libs/server-sdk-otel)
228+
endif ()
229+
223230
# Built as static or shared depending on LD_BUILD_SHARED_LIBS variable.
224231
# This target "links" in common, internal, and sse as object libraries.
225232
add_subdirectory(libs/client-sdk)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ Various CMake options are available to customize the client/server SDK builds.
6666
| `LD_DYNAMIC_LINK_OPENSSL` | Whether OpenSSL is dynamically linked or not. | Off (static link) | N/A |
6767
| `LD_BUILD_REDIS_SUPPORT` | Whether the server-side Redis Source is built or not. | Off | N/A |
6868
| `LD_CURL_NETWORKING` | Enable CURL-based networking for all HTTP requests (SSE streams and event delivery). When OFF, Boost.Beast/Foxy is used instead. CURL must be available as a dependency when this option is ON. | Off | N/A |
69+
| `LD_BUILD_OTEL_SUPPORT` | Whether the server-side OpenTelemetry integration package is built or not. | Off | N/A |
70+
| `LD_BUILD_OTEL_FETCH_DEPS` | When building OpenTelemetry support, automatically fetch and configure OpenTelemetry dependencies via CMake FetchContent. This is useful for local development and CI. When OFF, you must provide OpenTelemetry yourself via `find_package`. | Off | `LD_BUILD_OTEL_SUPPORT` |
71+
| `LD_OTEL_CPP_VERSION` | Specifies the OpenTelemetry C++ SDK version (git tag or commit hash) to fetch when `LD_BUILD_OTEL_FETCH_DEPS` is enabled. Can be set to any valid git reference from the [opentelemetry-cpp repository](https://github.com/open-telemetry/opentelemetry-cpp). | `ea1f0d61ce5baa5584b097266bf133d1f31e3607` (v1.23.0) | `LD_BUILD_OTEL_FETCH_DEPS` |
6972

7073
> [!WARNING]
7174
> When building shared libraries C++ symbols are not exported, only the C API will be exported. This is because C++ does

cmake/json.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
99
cmake_policy(SET CMP0135 NEW)
1010
endif ()
1111

12-
FetchContent_Declare(json
12+
# Use the same FetchContent name as OpenTelemetry to avoid duplicate targets
13+
FetchContent_Declare(nlohmann_json
1314
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
1415
)
1516

16-
FetchContent_MakeAvailable(json)
17+
FetchContent_MakeAvailable(nlohmann_json)

examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ if (LD_BUILD_REDIS_SUPPORT)
88
add_subdirectory(hello-cpp-server-redis)
99
add_subdirectory(hello-c-server-redis)
1010
endif ()
11+
12+
if (LD_BUILD_OTEL_SUPPORT)
13+
add_subdirectory(hello-cpp-server-otel)
14+
endif ()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Required for Apple Silicon support.
2+
cmake_minimum_required(VERSION 3.19)
3+
4+
project(
5+
LaunchDarklyHelloCPPServerOTel
6+
VERSION 0.1
7+
DESCRIPTION "LaunchDarkly Hello CPP Server-side SDK with OpenTelemetry Integration"
8+
LANGUAGES CXX
9+
)
10+
11+
set(THREADS_PREFER_PTHREAD_FLAG ON)
12+
find_package(Threads REQUIRED)
13+
14+
add_executable(hello-cpp-server-otel main.cpp)
15+
16+
target_link_libraries(hello-cpp-server-otel
17+
PRIVATE
18+
launchdarkly::server
19+
launchdarkly::server_otel
20+
Threads::Threads
21+
opentelemetry_trace
22+
opentelemetry_exporter_otlp_http
23+
)

0 commit comments

Comments
 (0)