Skip to content

Commit 0f18ae6

Browse files
committed
Update readme of context propagation example with testing instructions, fixes #24
1 parent d01f306 commit 0f18ae6

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

examples/context_propagation/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ option(USE_BATCH_FOR_MCC "Running on GitHub Actions workflows requires calling m
44
# C++ target
55
set(CONTEXTPROP_EXAMPLE_CPP_TARGET contextprop_example_client)
66
add_executable(${CONTEXTPROP_EXAMPLE_CPP_TARGET} cpp/client.cc)
7-
add_dependencies(${CONTEXTPROP_EXAMPLE_CPP_TARGET} ${OTEL_CPP_PROJECT_NAME})
7+
if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
8+
add_dependencies(${CONTEXTPROP_EXAMPLE_CPP_TARGET} ${OTEL_CPP_PROJECT_NAME})
9+
endif()
810

911
target_include_directories(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE ${OTEL_CPP_PREFIX}/include)
1012
target_link_libraries(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE ${OPENTELEMETRY_PROXY_LINK_LIBRARIES})
@@ -13,8 +15,12 @@ if(UNIX AND NOT APPLE AND NOT CYGWIN)
1315
elseif(APPLE)
1416
set_target_properties(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PROPERTIES BUILD_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBMEXCLASS_PROXY_INSTALLED_DIR}")
1517
endif()
16-
# use the same C++ standard as OpenTelemetry-cpp
17-
target_compile_features(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE cxx_std_${OTEL_CPP_CXX_STANDARD})
18+
# use the same C++ standard as OpenTelemetry-cpp if known, otherwise just use the default C++14
19+
if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
20+
target_compile_features(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE cxx_std_${OTEL_CPP_CXX_STANDARD})
21+
else()
22+
target_compile_features(${CONTEXTPROP_EXAMPLE_CPP_TARGET} PRIVATE cxx_std_14)
23+
endif()
1824

1925
# MATLAB target
2026
find_package(Matlab REQUIRED COMPONENTS MCC_COMPILER MAIN_PROGRAM)

examples/context_propagation/README.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,38 @@ In this example, a C++ client calls a MATLAB function hosted on MATLAB Productio
99
cmake --build build --config Release
1010
```
1111
The built examples can be found in build/examples/context_propagation and subdirectories.
12-
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.
13-
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.
14-
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.
15-
6. Start an instance of [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector).
16-
7. Start the C++ client.
12+
## Testing the Example
13+
1. Start an instance of [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector).
14+
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.
15+
1. In MATLAB, cd to the example directory.
16+
```
17+
cd examples/context_propagation/matlab
18+
```
19+
2. Set environment variable PRODSERVER_ROUTES_FILE to point to the routes file.
20+
```
21+
setenv("PRODSERVER_ROUTES_FILE", "routes.json")
22+
```
23+
3. Start Production Server Compiler app.
24+
```
25+
productionServerCompiler
26+
```
27+
4. In the app, select Type as "Deployable Archive (.ctf)", and add mymagic.m as an exported function.
28+
5. Specify "mymagic" as the archive name.
29+
6. Click on the "Test Client" button.
30+
7. Ensure the port is 9910, then start the test.
31+
8. Start the C++ client from a command prompt.
32+
```
33+
cd build/examples/context_propagation/Release
34+
contextprop_example_client
35+
```
36+
9. Check for expected spans in the OpenTelemetry Collector or in a specified tracing backend.
37+
## Deploying the Example
38+
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.
39+
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.
40+
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.
41+
4. Start the C++ client from a command prompt.
1742
```
18-
cd cpp/build/Release
19-
http_client
43+
cd build/examples/context_propagation/Release
44+
contextprop_example_client
2045
```
46+
5. Check for expected spans in the OpenTelemetry Collector or in a specified tracing backend.

examples/webread/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

22
set(WEBREAD_EXAMPLE_TARGET webread_example_server)
33
add_executable(${WEBREAD_EXAMPLE_TARGET} cpp/server.cc)
4-
add_dependencies(${WEBREAD_EXAMPLE_TARGET} ${OTEL_CPP_PROJECT_NAME})
4+
if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
5+
add_dependencies(${WEBREAD_EXAMPLE_TARGET} ${OTEL_CPP_PROJECT_NAME})
6+
endif()
57

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

0 commit comments

Comments
 (0)