-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add tracing hook. #496
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ea9bae5
feat: Add tracing hook.
kinyoklion fe4310f
Merge branch 'main' into rlamb/tracing-hook
kinyoklion 540107b
Don't simulate release for otel package.
kinyoklion 891dcf8
Allow custom GIT_TAG for OpenTelemetry.
kinyoklion 52a49fc
Extend tests.
kinyoklion 57a75d8
Update example to use LD Observability by default.
kinyoklion 6aedc89
Trim readme.
kinyoklion b87de85
Remove outdated comment.
kinyoklion 2a7f7da
Add service name to otel example.
kinyoklion 5d4c1dd
Revert windows built script changes.
kinyoklion 0771956
Remove errant slash.
kinyoklion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: libs/server-sdk-otel | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| paths-ignore: | ||
| - '**.md' # Do not need to run CI for markdown changes. | ||
| pull_request: | ||
| branches: [ "main", "feat/**" ] | ||
| paths-ignore: | ||
| - '**.md' | ||
| schedule: | ||
| # Run daily at midnight PST | ||
| - cron: '0 8 * * *' | ||
|
|
||
| jobs: | ||
| build-test-otel: | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: ./.github/actions/ci | ||
| with: | ||
| cmake_target: launchdarkly-cpp-server-otel | ||
| install_curl: true | ||
| # We don't produce release artifacts. | ||
| simulate_release: false | ||
| build-otel-mac: | ||
| runs-on: macos-13 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: ./.github/actions/ci | ||
| with: | ||
| cmake_target: launchdarkly-cpp-server-otel | ||
| platform_version: 12 | ||
| install_curl: true | ||
| # We don't produce release artifacts. | ||
| simulate_release: false | ||
| build-test-otel-windows: | ||
| runs-on: windows-2022 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: ilammy/msvc-dev-cmd@v1 | ||
kinyoklion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - uses: ./.github/actions/ci | ||
| env: | ||
| BOOST_LIBRARY_DIR: 'C:\local\boost_1_87_0\lib64-msvc-14.3' | ||
| BOOST_LIBRARYDIR: 'C:\local\boost_1_87_0\lib64-msvc-14.3' | ||
| Boost_DIR: 'C:\local\boost_1_87_0\lib64-msvc-14.3\cmake\Boost-1.87.0' | ||
| with: | ||
| cmake_target: launchdarkly-cpp-server-otel | ||
| platform_version: 2022 | ||
| toolset: msvc | ||
| install_curl: true | ||
| # We don't produce release artifacts. | ||
| simulate_windows_release: false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Required for Apple Silicon support. | ||
| cmake_minimum_required(VERSION 3.19) | ||
|
|
||
| project( | ||
| LaunchDarklyHelloCPPServerOTel | ||
| VERSION 0.1 | ||
| DESCRIPTION "LaunchDarkly Hello CPP Server-side SDK with OpenTelemetry Integration" | ||
| LANGUAGES CXX | ||
| ) | ||
|
|
||
| set(THREADS_PREFER_PTHREAD_FLAG ON) | ||
| find_package(Threads REQUIRED) | ||
|
|
||
| add_executable(hello-cpp-server-otel main.cpp) | ||
|
|
||
| target_link_libraries(hello-cpp-server-otel | ||
| PRIVATE | ||
| launchdarkly::server | ||
| launchdarkly::server_otel | ||
| Threads::Threads | ||
| opentelemetry_trace | ||
| opentelemetry_exporter_otlp_http | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # LaunchDarkly C++ Server SDK - OpenTelemetry Integration Example | ||
|
|
||
| This example demonstrates how to integrate the LaunchDarkly C++ Server SDK with OpenTelemetry tracing to automatically enrich your distributed traces with feature flag evaluation data. | ||
|
|
||
| ## What This Example Shows | ||
|
|
||
| - Setting up OpenTelemetry with OTLP HTTP exporter | ||
| - Configuring the LaunchDarkly OpenTelemetry tracing hook | ||
| - Creating HTTP spans with Boost.Beast | ||
| - Automatic feature flag span events in traces | ||
| - Passing explicit parent span context to evaluations | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - C++17 or later | ||
| - CMake 3.19 or later | ||
| - Boost 1.81 or later | ||
| - LaunchDarkly SDK key | ||
|
|
||
| ## Building | ||
|
|
||
| From the repository root: | ||
|
|
||
| ```bash | ||
| mkdir build && cd build | ||
| cmake .. -DLD_BUILD_EXAMPLES=ON -DLD_BUILD_OTEL_SUPPORT=ON | ||
| cmake --build . --target hello-cpp-server-otel | ||
| ``` | ||
|
|
||
| ## Running | ||
|
|
||
| ### 1. Set Your LaunchDarkly SDK Key | ||
|
|
||
| Either edit `main.cpp` and set the `SDK_KEY` constant, or use an environment variable: | ||
|
|
||
| ```bash | ||
| export LD_SDK_KEY=your-sdk-key-here | ||
| ``` | ||
|
|
||
| ### 2. Create a Feature Flag | ||
|
|
||
| In your LaunchDarkly dashboard, create a boolean flag named `show-detailed-weather`. | ||
|
|
||
| ### 3. Run the Example | ||
|
|
||
| ```bash | ||
| ./build/examples/hello-cpp-server-otel/hello-cpp-server-otel | ||
| ``` | ||
|
|
||
| You should see: | ||
|
|
||
| ``` | ||
| *** SDK successfully initialized! | ||
|
|
||
| *** Weather server running on http://0.0.0.0:8080 | ||
| *** Try: curl http://localhost:8080/weather | ||
| *** OpenTelemetry tracing enabled, sending traces to LaunchDarkly | ||
| *** LaunchDarkly integration enabled with OpenTelemetry tracing hook | ||
| ``` | ||
|
|
||
| ### 4. Make Requests | ||
|
|
||
| ```bash | ||
| curl http://localhost:8080/weather | ||
| ``` | ||
|
|
||
| ### 5. View Traces in LaunchDarkly | ||
|
|
||
| Navigate to your LaunchDarkly project's Observability section to view traces. Each HTTP request will have: | ||
| 1. **Root Span**: "HTTP GET /weather" with HTTP attributes | ||
| 2. **Feature Flag Event**: Attached to the span with evaluation details: | ||
| - `feature_flag.key`: "show-detailed-weather" | ||
| - `feature_flag.provider.name`: "LaunchDarkly" | ||
| - `feature_flag.context.id`: "user:weather-api-user" | ||
| - `feature_flag.result.value`: The evaluated flag value | ||
|
|
||
|
|
||
| ### Custom OTLP Endpoint | ||
|
|
||
| To send traces to a different OpenTelemetry collector, set the `LD_OTEL_ENDPOINT` environment variable: | ||
|
|
||
| ```bash | ||
| export LD_OTEL_ENDPOINT=http://localhost:4318/v1/traces | ||
| ./build/examples/hello-cpp-server-otel/hello-cpp-server-otel | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We aren't doing a build, so strictly speaking we don't need these, but I wonder if we should just leave them for consistency.