Skip to content

Commit

Permalink
Update readme of context propagation example with testing instructions,
Browse files Browse the repository at this point in the history
fixes #24
  • Loading branch information
duncanpo committed Aug 28, 2024
1 parent d01f306 commit 0f18ae6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
12 changes: 9 additions & 3 deletions examples/context_propagation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ option(USE_BATCH_FOR_MCC "Running on GitHub Actions workflows requires calling m
# C++ target
set(CONTEXTPROP_EXAMPLE_CPP_TARGET contextprop_example_client)
add_executable(${CONTEXTPROP_EXAMPLE_CPP_TARGET} cpp/client.cc)
add_dependencies(${CONTEXTPROP_EXAMPLE_CPP_TARGET} ${OTEL_CPP_PROJECT_NAME})
if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
add_dependencies(${CONTEXTPROP_EXAMPLE_CPP_TARGET} ${OTEL_CPP_PROJECT_NAME})
endif()

target_include_directories(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE ${OTEL_CPP_PREFIX}/include)
target_link_libraries(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE ${OPENTELEMETRY_PROXY_LINK_LIBRARIES})
Expand All @@ -13,8 +15,12 @@ if(UNIX AND NOT APPLE AND NOT CYGWIN)
elseif(APPLE)
set_target_properties(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PROPERTIES BUILD_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBMEXCLASS_PROXY_INSTALLED_DIR}")
endif()
# use the same C++ standard as OpenTelemetry-cpp
target_compile_features(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE cxx_std_${OTEL_CPP_CXX_STANDARD})
# use the same C++ standard as OpenTelemetry-cpp if known, otherwise just use the default C++14
if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
target_compile_features(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE cxx_std_${OTEL_CPP_CXX_STANDARD})
else()
target_compile_features(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE cxx_std_14)
endif()

# MATLAB target
find_package(Matlab REQUIRED COMPONENTS MCC_COMPILER MAIN_PROGRAM)
Expand Down
40 changes: 33 additions & 7 deletions examples/context_propagation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,38 @@ In this example, a C++ client calls a MATLAB function hosted on MATLAB Productio
cmake --build build --config Release
```
The built examples can be found in build/examples/context_propagation and subdirectories.
2. [Create](https://www.mathworks.com/help/mps/server/creating-a-server.html) and [start](https://www.mathworks.com/help/mps/qs/starting-and-stopping.html) a MATLAB Production Server instance.
3. [Deploy](https://www.mathworks.com/help/mps/qs/share-a-ctf-archive-on-the-server-instance.html) archive to server instance by copying to the auto_deploy directory.
4. If using a MATLAB release before R2023b, [copy](https://www.mathworks.com/help/mps/server/use-web-handler-for-custom-routes-and-custom-payloads.html) matlab/routes.json to the config directory of the server instance.
6. Start an instance of [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector).
7. Start the C++ client.
## Testing the Example
1. Start an instance of [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector).
2. Test the generated .ctf archive using the [testing interface](https://www.mathworks.com/help/compiler_sdk/mps_dev_test/test-web-request-handler.html) in the Production Server Compiler app.
1. In MATLAB, cd to the example directory.
```
cd examples/context_propagation/matlab
```
2. Set environment variable PRODSERVER_ROUTES_FILE to point to the routes file.
```
setenv("PRODSERVER_ROUTES_FILE", "routes.json")
```
3. Start Production Server Compiler app.
```
productionServerCompiler
```
4. In the app, select Type as "Deployable Archive (.ctf)", and add mymagic.m as an exported function.
5. Specify "mymagic" as the archive name.
6. Click on the "Test Client" button.
7. Ensure the port is 9910, then start the test.
8. Start the C++ client from a command prompt.
```
cd build/examples/context_propagation/Release
contextprop_example_client
```
9. Check for expected spans in the OpenTelemetry Collector or in a specified tracing backend.
## Deploying the Example
1. If testing works, proceed to deploy the example. [Create](https://www.mathworks.com/help/mps/server/creating-a-server.html) and [start](https://www.mathworks.com/help/mps/qs/starting-and-stopping.html) a MATLAB Production Server instance.
2. [Deploy](https://www.mathworks.com/help/mps/qs/share-a-ctf-archive-on-the-server-instance.html) archive mymagic.ctf to server instance by copying to the auto_deploy directory.
3. If using a MATLAB release before R2023b, [copy](https://www.mathworks.com/help/mps/server/use-web-handler-for-custom-routes-and-custom-payloads.html) matlab/routes.json to the config directory of the server instance.
4. Start the C++ client from a command prompt.
```
cd cpp/build/Release
http_client
cd build/examples/context_propagation/Release
contextprop_example_client
```
5. Check for expected spans in the OpenTelemetry Collector or in a specified tracing backend.
12 changes: 9 additions & 3 deletions examples/webread/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

set(WEBREAD_EXAMPLE_TARGET webread_example_server)
add_executable(${WEBREAD_EXAMPLE_TARGET} cpp/server.cc)
add_dependencies(${WEBREAD_EXAMPLE_TARGET} ${OTEL_CPP_PROJECT_NAME})
if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
add_dependencies(${WEBREAD_EXAMPLE_TARGET} ${OTEL_CPP_PROJECT_NAME})
endif()

target_include_directories(${WEBREAD_EXAMPLE_TARGET} PRIVATE ${OTEL_CPP_PREFIX}/include)
target_link_libraries(${WEBREAD_EXAMPLE_TARGET} PRIVATE ${OPENTELEMETRY_PROXY_LINK_LIBRARIES})
Expand All @@ -10,5 +12,9 @@ if(UNIX AND NOT APPLE AND NOT CYGWIN)
elseif(APPLE)
set_target_properties(${WEBREAD_EXAMPLE_TARGET} PROPERTIES BUILD_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBMEXCLASS_PROXY_INSTALLED_DIR}")
endif()
# use the same C++ standard as OpenTelemetry-cpp
target_compile_features(${WEBREAD_EXAMPLE_TARGET} PRIVATE cxx_std_${OTEL_CPP_CXX_STANDARD})
# use the same C++ standard as OpenTelemetry-cpp if known, otherwise just use the default C++14
if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
target_compile_features(${WEBREAD_EXAMPLE_TARGET} PRIVATE cxx_std_${OTEL_CPP_CXX_STANDARD})
else()
target_compile_features(${WEBREAD_EXAMPLE_TARGET} PRIVATE cxx_std_14)
endif()

0 comments on commit 0f18ae6

Please sign in to comment.