Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,14 @@ jobs:
OPENTELEMETRY_CPP_INSTALL: "${{ github.workspace }}/otel_cpp_install"
OPENTELEMETRY_MATLAB_INSTALL: "${{ github.workspace }}/otel_matlab_install"
OPENTELEMETRY_COLLECTOR_INSTALL: "${{ github.workspace }}/otelcol"
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
SYSTEM_LIBSTDCPP_PATH: "/usr/lib/x86_64-linux-gnu/libstdc++.so.6"
steps:
- name: Download OpenTelemetry-Matlab source
uses: actions/checkout@v3
with:
path: opentelemetry-matlab
- name: Download vcpkg
uses: actions/checkout@v3
with:
repository: microsoft/vcpkg
path: vcpkg
- name: Install MATLAB
uses: matlab-actions/setup-matlab@v1
- name: Install vcpkg packages
run: |
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg install curl nlohmann-json protobuf zlib
- name: Download OpenTelemetry Collector binary
run: |
mkdir otelcol && cd otelcol
Expand Down
150 changes: 111 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,62 @@ cmake_minimum_required(VERSION 3.7.0)

cmake_policy(SET CMP0074 NEW)

# Autodetect vcpkg toolchain from VCPKG_ROOT environment variable
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
string(REPLACE "\\" "/" CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
endif()

set(CLIENT_PROJECT_NAME otel-matlab)
# ###########################
# vcpkg
# ###########################

project(${CLIENT_PROJECT_NAME} VERSION 0.1.0)
include(FetchContent)

# check if VCPKG_ROOT is defined, which should point to an existing installation
if(DEFINED ENV{VCPKG_ROOT})
# Autodetect vcpkg toolchain
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
string(REPLACE "\\" "/" CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
endif()
else()
# VCPKG_ROOT not defined, get it using FetchContent

if(DEFINED VCPKG_PREFIX})
# download location specified
string(REPLACE "\\" "/" VCPKG_PREFIX "${VCPKG_PREFIX}")
else()
set(VCPKG_PREFIX ${CMAKE_BINARY_DIR}/vcpkg)
endif()

# On Mac, there is a conflict between libcurl and the version in MATLAB, so
# use libcurl as a shared library and load the MATLAB version at runtime
if(APPLE)
# run uname -m to determine whether arm64 or x86_64
exec_program(uname ARGS -m OUTPUT_VARIABLE MAC_HOST_SYSTEM)
set(VCPKG_OTEL_TRIPLET ${MAC_HOST_SYSTEM}-osx-otel-matlab)
set(VCPKG_OVERLAY_TRIPLETS ${CMAKE_SOURCE_DIR}/cmake/vcpkg_triplets)
set(VCPKG_TARGET_TRIPLET ${VCPKG_OTEL_TRIPLET})
endif()

set(VCPKG_FETCH_CONTENT_NAME vcpkg)
set(VCPKG_GIT_REPOSITORY "https://github.com/microsoft/vcpkg.git")
set(VCPKG_GIT_TAG "9edb1b8")
FetchContent_Declare(
${VCPKG_FETCH_CONTENT_NAME}
GIT_REPOSITORY ${VCPKG_GIT_REPOSITORY}
GIT_TAG ${VCPKG_GIT_TAG}
PREFIX ${VCPKG_PREFIX}
UPDATE_DISCONNECTED 1
)

FetchContent_MakeAvailable(
${VCPKG_FETCH_CONTENT_NAME}
)

FetchContent_GetProperties(${VCPKG_FETCH_CONTENT_NAME})
string(REPLACE "\\" "/" CMAKE_TOOLCHAIN_FILE "${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake")

endif()

if(NOT DEFINED VCPKG_INSTALLED_DIR)
set(DVCPKG_INSTALLED_DIR ${CMAKE_BINARY_DIR}/vcpkg_installed)
endif()

# ######################################
# Options
Expand All @@ -24,8 +72,25 @@ if(APPLE)
option(SKIP_OTEL_CPP_PATCH "Whether to skip patching OpenTelemetry-cpp" OFF)
endif()

# set vcpkg features depending on specified options
set(VCPKG_MANIFEST_FEATURES "") # start with empty
if(WITH_OTLP_HTTP)
set(VCPKG_MANIFEST_FEATURES ${VCPKG_MANFIEST_FEATURES} "otlp-http")
endif()
if(WITH_OTLP_GRPC)
set(VCPKG_MANIFEST_FEATURES ${VCPKG_MANIFEST_FEATURES} "otlp-grpc")
endif()

# ######################################
# libmexclass FetchContent Configuration
# Project Declaration
# ######################################

set(CLIENT_PROJECT_NAME otel-matlab)

project(${CLIENT_PROJECT_NAME} VERSION 0.1.0)

# ######################################
# libmexclass
# ######################################

set(LIBMEXCLASS_FETCH_CONTENT_NAME libmexclass)
Expand All @@ -36,7 +101,6 @@ set(LIBMEXCLASS_FETCH_CONTENT_GIT_TAG "77f3d72")

set(LIBMEXCLASS_FETCH_CONTENT_SOURCE_SUBDIR "libmexclass/cpp")

include(FetchContent)
FetchContent_Declare(
${LIBMEXCLASS_FETCH_CONTENT_NAME}
GIT_REPOSITORY ${LIBMEXCLASS_FETCH_CONTENT_GIT_REPOSITORY}
Expand All @@ -47,44 +111,52 @@ FetchContent_MakeAvailable(
${LIBMEXCLASS_FETCH_CONTENT_NAME}
)


# ###########################
# OpenTelemetry-cpp
# ###########################
include(ExternalProject)
set(OTEL_CPP_PROJECT_NAME opentelemetry-cpp)
set(OTEL_CPP_GIT_REPOSITORY "https://github.com/open-telemetry/opentelemetry-cpp.git")
set(OTEL_CPP_GIT_TAG "11d5d9e")

if(DEFINED OTEL_CPP_PREFIX)
string(REPLACE "\\" "/" OTEL_CPP_PREFIX ${OTEL_CPP_PREFIX})
if(DEFINED OTEL_CPP_INSTALLED_DIR)
# OTEL_CPP_INSTALLED_DIR should point to an installed location of OpenTelemetry-cpp
string(REPLACE "\\" "/" OTEL_CPP_PREFIX ${OTEL_CPP_INSTALLED_DIR})
else()
set(OTEL_CPP_PREFIX ${CMAKE_BINARY_DIR}/otel-cpp)
# No installed location supplied. Fetch it as an external project
include(ExternalProject)
set(OTEL_CPP_PROJECT_NAME opentelemetry-cpp)
set(OTEL_CPP_GIT_REPOSITORY "https://github.com/open-telemetry/opentelemetry-cpp.git")
set(OTEL_CPP_GIT_TAG "11d5d9e")

if(DEFINED OTEL_CPP_PREFIX)
string(REPLACE "\\" "/" OTEL_CPP_PREFIX ${OTEL_CPP_PREFIX})
else()
set(OTEL_CPP_PREFIX ${CMAKE_BINARY_DIR}/otel-cpp)
endif()

if(WITH_OTLP_GRPC)
set(OTEL_CPP_CXX_STANDARD 14) # Abseil requires at least Cxx14
else()
set(OTEL_CPP_CXX_STANDARD 11)
endif()

if(NOT APPLE OR SKIP_OTEL_CPP_PATCH)
set(patch_command "")
else()
set(patch_command git apply ${CMAKE_SOURCE_DIR}/otel-cpp.patch)
endif()

ExternalProject_Add(
${OTEL_CPP_PROJECT_NAME}
GIT_REPOSITORY ${OTEL_CPP_GIT_REPOSITORY}
GIT_TAG ${OTEL_CPP_GIT_TAG}
PREFIX ${OTEL_CPP_PREFIX}
UPDATE_DISCONNECTED 1
PATCH_COMMAND ${patch_command}
CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DWITH_OTLP_HTTP=${WITH_OTLP_HTTP} -DWITH_OTLP_GRPC=${WITH_OTLP_GRPC} -DBUILD_TESTING=OFF -DWITH_BENCHMARK=OFF -DOPENTELEMETRY_INSTALL=ON -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_CXX_STANDARD=${OTEL_CPP_CXX_STANDARD} -DVCPKG_INSTALLED_DIR=${VCPKG_INSTALLED_DIR}
INSTALL_DIR ${OTEL_CPP_PREFIX}
INSTALL_COMMAND ${CMAKE_COMMAND} --install . --prefix ${OTEL_CPP_PREFIX}
)
endif()

if(WITH_OTLP_GRPC)
set(OTEL_CPP_CXX_STANDARD 14) # Abseil requires at least Cxx14
else()
set(OTEL_CPP_CXX_STANDARD 11)
endif()

if(NOT APPLE OR SKIP_OTEL_CPP_PATCH)
set(patch_command "")
else()
set(patch_command git apply ${CMAKE_SOURCE_DIR}/otel-cpp.patch)
endif()

ExternalProject_Add(
${OTEL_CPP_PROJECT_NAME}
GIT_REPOSITORY ${OTEL_CPP_GIT_REPOSITORY}
GIT_TAG ${OTEL_CPP_GIT_TAG}
PREFIX ${OTEL_CPP_PREFIX}
UPDATE_DISCONNECTED 1
PATCH_COMMAND ${patch_command}
CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DWITH_OTLP_HTTP=${WITH_OTLP_HTTP} -DWITH_OTLP_GRPC=${WITH_OTLP_GRPC} -DBUILD_TESTING=OFF -DWITH_BENCHMARK=OFF -DOPENTELEMETRY_INSTALL=ON -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_CXX_STANDARD=${OTEL_CPP_CXX_STANDARD}
INSTALL_DIR ${OTEL_CPP_PREFIX}
INSTALL_COMMAND ${CMAKE_COMMAND} --install . --prefix ${OTEL_CPP_PREFIX}
)

# ###########################
# OpenTelemetry Proxy Library
# ###########################
Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,14 @@ Installation instructions
Before proceeding, ensure that the below products are installed:
* [MATLAB](https://www.mathworks.com/products/matlab.html)

1. Download [vcpkg](https://vcpkg.io). Install the following packages:
- curl
- nlohmann-json
- protobuf
- zlib

2. Set VCPKG_ROOT environment variable to point to installed location of vcpkg.

3. Download, Build and install OpenTelemetry MATLAB
1. Download, Build and install OpenTelemetry MATLAB
```
cd <opentelemetry-matlab-root>
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=<opentelemetry-matlab-installdir>
cmake --build build --config Release --target install

```
4. Download [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector-releases/releases). You can just obtain a pre-built binary for your platform.
2. Download [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector-releases/releases). You can just obtain a pre-built binary for your platform.

## Getting Started
1. Start OpenTelemetry Collector
Expand Down
10 changes: 10 additions & 0 deletions cmake/vcpkg_triplets/arm64-osx-otel-matlab.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
if(${PORT} MATCHES "(curl|zlib)")
set(VCPKG_LIBRARY_LINKAGE dynamic)
else()
set(VCPKG_LIBRARY_LINKAGE static)
endif()

set(VCPKG_CMAKE_SYSTEM_NAME Darwin)
set(VCPKG_OSX_ARCHITECTURES arm64)
10 changes: 10 additions & 0 deletions cmake/vcpkg_triplets/x86_64-osx-otel-matlab.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
if(${PORT} MATCHES "(curl|zlib)")
set(VCPKG_LIBRARY_LINKAGE dynamic)
else()
set(VCPKG_LIBRARY_LINKAGE static)
endif()

set(VCPKG_CMAKE_SYSTEM_NAME Darwin)
set(VCPKG_OSX_ARCHITECTURES x86_64)
17 changes: 14 additions & 3 deletions test/commonSetupOnce.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@ function commonSetupOnce(testCase)
testCase.ListPid = @(name)"tasklist /fi ""IMAGENAME eq " + name + ".exe""";
testCase.ReadPidList = @(file)readtable(file, "VariableNamingRule", "preserve", "NumHeaderLines", 3, "MultipleDelimsAsOne", true, "Delimiter", " ");
testCase.ExtractPid = @(table)table.Var2;
windows_killroot = string(getenv("WINDOWS_KILL_INSTALL"));
assert(~isempty(windows_killroot), "WINDOWS_KILL_INSTALL environment must be defined.")
testCase.Sigint = @(id)fullfile(windows_killroot,"windows-kill") + " -SIGINT " + id;
windows_killroot = getenv("WINDOWS_KILL_INSTALL");
windows_killname = "windows-kill";
if isempty(windows_killroot)
% windows_kill not pre-installed
windows_kill_url = "https://github.com/ElyDotDev/windows-kill/releases/download/1.1.4";
windows_kill_zipfilename = "windows-kill_x64_1.1.4_lib_release";
windows_killroot = fullfile(tempdir, windows_kill_zipfilename);

% look for it in tempdir, download and install if it doesn't exist
if ~exist(fullfile(windows_killroot, windows_killname + ".exe"),"file")
unzip(fullfile(windows_kill_url, windows_kill_zipfilename + ".zip"), tempdir);
end
end
testCase.Sigint = @(id)fullfile(windows_killroot,windows_killname) + " -SIGINT " + id;
testCase.Sigterm = @(id)"taskkill /F /pid " + id;
elseif isunix && ~ismac
testCase.ListPid = @(name)"ps -C " + name;
Expand Down
13 changes: 13 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "opentelemetry-matlab",
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
"protobuf",
"zlib",
"nlohmann-json"
],
"features": {
"otlp-http": {"description": "Otlp HTTP Exporter", "dependencies": ["curl"]},
"otlp-grpc": {"description": "Otlp gRPC Exporter", "dependencies": ["grpc", "abseil", "c-ares", "re2", "openssl", "upb"]}
}
}