Skip to content
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

[CI] Add CI for instrumentation/glog #425

Merged
merged 9 commits into from
Apr 16, 2024
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
98 changes: 98 additions & 0 deletions .github/workflows/glog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: glog

on:
push:
branches:
- '*'
path:
- 'instrumentation/glog/**'
- '.github/workflows/glog.yml'
pull_request:
branches: [main]
paths:
- 'instrumentation/glog/**'
- '.github/workflows/glog.yml'

jobs:
cmake_linux:
name: CMake Linux
runs-on: ubuntu-latest
steps:
- name: checkout googletest
uses: actions/checkout@v3
with:
repository: "google/googletest"
ref: "release-1.12.1"
path: "googletest"
- name: checkout glog
uses: actions/checkout@v3
with:
repository: "google/glog"
ref: "v0.7.0"
path: "glog"
- name: checkout opentelemetry-cpp-contrib
uses: actions/checkout@v3
with:
path: opentelemetry-cpp-contrib
- name: checkout opentelemetry-cpp
uses: actions/checkout@v3
with:
repository: "open-telemetry/opentelemetry-cpp"
ref: "v1.14.2"
path: "opentelemetry-cpp"
submodules: "recursive"
- name: setup dependencies
run: |
sudo apt update -y
sudo apt install -y --no-install-recommends --no-install-suggests \
build-essential \
cmake \
ninja-build \
libssl-dev \
libcurl4-openssl-dev \
libprotobuf-dev \
protobuf-compiler \
libgmock-dev \
libgtest-dev \
marcalff marked this conversation as resolved.
Show resolved Hide resolved
libbenchmark-dev

# This is needed because libgmock-dev libgtest-dev installs 1.11,
# and 1.11 breaks the build.
- name: build googletest 1.12
run: |
mkdir -p "${GITHUB_WORKSPACE}/googletest/build"
cd "${GITHUB_WORKSPACE}/googletest/build"
cmake .. -G Ninja
cmake --build . -j$(nproc)
cmake --install . --prefix="${GITHUB_WORKSPACE}/sandbox"

- name: build glog
run: |
mkdir -p "${GITHUB_WORKSPACE}/glog/build"
cd "${GITHUB_WORKSPACE}/glog/build"
cmake .. -G Ninja
cmake --build . -j$(nproc)
cmake --install . --prefix="${GITHUB_WORKSPACE}/sandbox"

- name: build opentelemetry-cpp
run: |
mkdir -p "${GITHUB_WORKSPACE}/opentelemetry-cpp/build"
cd "${GITHUB_WORKSPACE}/opentelemetry-cpp/build"
cmake .. -G Ninja -DBUILD_TESTING=OFF -DWITH_BENCHMARK=OFF -DOPENTELEMETRY_INSTALL=ON
cmake --build . -j$(nproc)
cmake --install . --prefix="${GITHUB_WORKSPACE}/sandbox"

- name: build instrumentation/glog contrib
run: |
mkdir -p "${GITHUB_WORKSPACE}/instrumentation-glog/build"
cd "${GITHUB_WORKSPACE}/instrumentation-glog/build"
cmake ../../opentelemetry-cpp-contrib/instrumentation/glog \
-G Ninja \
-DCMAKE_PREFIX_PATH="${GITHUB_WORKSPACE}/sandbox" \
-DBUILD_TESTING=ON \
-DWITH_EXAMPLES=ON \
-DOPENTELEMETRY_INSTALL=ON
cmake --build . -j$(nproc)
ctest -j1 --output-on-failure
cmake --install . --prefix="${GITHUB_WORKSPACE}/sandbox"

10 changes: 7 additions & 3 deletions instrumentation/glog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(this_target opentelemetry_glog_sink)
project(${this_target})

find_package(opentelemetry-cpp REQUIRED)
find_package(glog REQUIRED)
find_package(glog 0.7.0 REQUIRED)

add_library(${this_target} src/sink.cc)

Expand Down Expand Up @@ -69,6 +69,10 @@ if(OPENTELEMETRY_INSTALL)
endif() # OPENTELEMETRY_INSTALL

if(BUILD_TESTING)
marcalff marked this conversation as resolved.
Show resolved Hide resolved
find_package(GTest 1.12 REQUIRED)

enable_testing()

set(testname sink_test)

include(GoogleTest)
Expand All @@ -81,8 +85,8 @@ if(BUILD_TESTING)
)

target_link_libraries(${testname} PRIVATE
gmock
gtest
GTest::gmock
GTest::gtest
glog::glog
opentelemetry-cpp::ostream_log_record_exporter
${this_target}
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/glog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

- Current release tested only with Ubuntu 20.04.6 LTS
- OpenTelemetry >= v1.12.0
- glog >= v0.3.5
- glog >= v0.7.0

### Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
namespace google
{

// The LogMessageTime class was introduced sometime in v0.6.0
// Since there is no versioning available in this lib, we identify it based on the presence of this
// include guard that was added in the required version
#if defined(GLOG_EXPORT_H)
# define GLOG_VERSION_HAS_LOGMESSAGETIME
#endif

class OpenTelemetrySink : public google::LogSink
{
public:
Expand All @@ -41,23 +34,13 @@ class OpenTelemetrySink : public google::LogSink
}
}

#if defined(GLOG_VERSION_HAS_LOGMESSAGETIME)
void send(google::LogSeverity,
const char *,
const char *,
int,
const google::LogMessageTime &,
const char *,
size_t) override;
#else
void send(google::LogSeverity,
const char *,
const char *,
int,
const struct ::tm *,
const char *,
size_t) override;
#endif
};

} // namespace google
20 changes: 1 addition & 19 deletions instrumentation/glog/src/sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace google
{

#if defined(GLOG_VERSION_HAS_LOGMESSAGETIME)
void OpenTelemetrySink::send(google::LogSeverity severity,
const char *full_filename,
const char * /* base_filename */,
Expand All @@ -23,18 +22,6 @@ void OpenTelemetrySink::send(google::LogSeverity severity,
const char *message,
size_t message_len)
{
#else
void OpenTelemetrySink::send(google::LogSeverity severity,
const char *full_filename,
const char * /* base_filename */,
int line,
const struct std::tm * /* time_tm */,
const char *message,
size_t message_len)
{
// Compensate for the lack of precision in older versions
const auto timestamp = std::chrono::system_clock::now();
#endif

static constexpr auto kLoggerName = "Google logger";
static constexpr auto kLibraryName = "glog";
Expand All @@ -48,14 +35,9 @@ void OpenTelemetrySink::send(google::LogSeverity severity,
using namespace opentelemetry::trace::SemanticConventions;
using namespace std::chrono;

#if defined(GLOG_VERSION_HAS_LOGMESSAGETIME)
static constexpr auto secs_to_msecs = duration_cast<microseconds>(seconds{1}).count();
const auto timestamp = microseconds(secs_to_msecs * logmsgtime.timestamp() + logmsgtime.usec());
#endif

log_record->SetSeverity(levelToSeverity(severity));
log_record->SetBody(opentelemetry::nostd::string_view(message, message_len));
log_record->SetTimestamp(system_clock::time_point(timestamp));
log_record->SetTimestamp(logmsgtime.when());
log_record->SetAttribute(kCodeFilepath, full_filename);
log_record->SetAttribute(kCodeLineno, line);
logger->EmitLogRecord(std::move(log_record));
Expand Down
Loading