Skip to content

Commit 6217b44

Browse files
authored
[CI] Add CI for instrumentation/glog (#425)
1 parent 6102ea9 commit 6217b44

File tree

5 files changed

+107
-40
lines changed

5 files changed

+107
-40
lines changed

.github/workflows/glog.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: glog
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
path:
8+
- 'instrumentation/glog/**'
9+
- '.github/workflows/glog.yml'
10+
pull_request:
11+
branches: [main]
12+
paths:
13+
- 'instrumentation/glog/**'
14+
- '.github/workflows/glog.yml'
15+
16+
jobs:
17+
cmake_linux:
18+
name: CMake Linux
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: checkout googletest
22+
uses: actions/checkout@v3
23+
with:
24+
repository: "google/googletest"
25+
ref: "release-1.12.1"
26+
path: "googletest"
27+
- name: checkout glog
28+
uses: actions/checkout@v3
29+
with:
30+
repository: "google/glog"
31+
ref: "v0.7.0"
32+
path: "glog"
33+
- name: checkout opentelemetry-cpp-contrib
34+
uses: actions/checkout@v3
35+
with:
36+
path: opentelemetry-cpp-contrib
37+
- name: checkout opentelemetry-cpp
38+
uses: actions/checkout@v3
39+
with:
40+
repository: "open-telemetry/opentelemetry-cpp"
41+
ref: "v1.14.2"
42+
path: "opentelemetry-cpp"
43+
submodules: "recursive"
44+
- name: setup dependencies
45+
run: |
46+
sudo apt update -y
47+
sudo apt install -y --no-install-recommends --no-install-suggests \
48+
build-essential \
49+
cmake \
50+
ninja-build \
51+
libssl-dev \
52+
libcurl4-openssl-dev \
53+
libprotobuf-dev \
54+
protobuf-compiler \
55+
libgmock-dev \
56+
libgtest-dev \
57+
libbenchmark-dev
58+
59+
# This is needed because libgmock-dev libgtest-dev installs 1.11,
60+
# and 1.11 breaks the build.
61+
- name: build googletest 1.12
62+
run: |
63+
mkdir -p "${GITHUB_WORKSPACE}/googletest/build"
64+
cd "${GITHUB_WORKSPACE}/googletest/build"
65+
cmake .. -G Ninja
66+
cmake --build . -j$(nproc)
67+
cmake --install . --prefix="${GITHUB_WORKSPACE}/sandbox"
68+
69+
- name: build glog
70+
run: |
71+
mkdir -p "${GITHUB_WORKSPACE}/glog/build"
72+
cd "${GITHUB_WORKSPACE}/glog/build"
73+
cmake .. -G Ninja
74+
cmake --build . -j$(nproc)
75+
cmake --install . --prefix="${GITHUB_WORKSPACE}/sandbox"
76+
77+
- name: build opentelemetry-cpp
78+
run: |
79+
mkdir -p "${GITHUB_WORKSPACE}/opentelemetry-cpp/build"
80+
cd "${GITHUB_WORKSPACE}/opentelemetry-cpp/build"
81+
cmake .. -G Ninja -DBUILD_TESTING=OFF -DWITH_BENCHMARK=OFF -DOPENTELEMETRY_INSTALL=ON
82+
cmake --build . -j$(nproc)
83+
cmake --install . --prefix="${GITHUB_WORKSPACE}/sandbox"
84+
85+
- name: build instrumentation/glog contrib
86+
run: |
87+
mkdir -p "${GITHUB_WORKSPACE}/instrumentation-glog/build"
88+
cd "${GITHUB_WORKSPACE}/instrumentation-glog/build"
89+
cmake ../../opentelemetry-cpp-contrib/instrumentation/glog \
90+
-G Ninja \
91+
-DCMAKE_PREFIX_PATH="${GITHUB_WORKSPACE}/sandbox" \
92+
-DBUILD_TESTING=ON \
93+
-DWITH_EXAMPLES=ON \
94+
-DOPENTELEMETRY_INSTALL=ON
95+
cmake --build . -j$(nproc)
96+
ctest -j1 --output-on-failure
97+
cmake --install . --prefix="${GITHUB_WORKSPACE}/sandbox"
98+

instrumentation/glog/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(this_target opentelemetry_glog_sink)
88
project(${this_target})
99

1010
find_package(opentelemetry-cpp REQUIRED)
11-
find_package(glog REQUIRED)
11+
find_package(glog 0.7.0 REQUIRED)
1212

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

@@ -69,6 +69,10 @@ if(OPENTELEMETRY_INSTALL)
6969
endif() # OPENTELEMETRY_INSTALL
7070

7171
if(BUILD_TESTING)
72+
find_package(GTest 1.12 REQUIRED)
73+
74+
enable_testing()
75+
7276
set(testname sink_test)
7377

7478
include(GoogleTest)
@@ -81,8 +85,8 @@ if(BUILD_TESTING)
8185
)
8286

8387
target_link_libraries(${testname} PRIVATE
84-
gmock
85-
gtest
88+
GTest::gmock
89+
GTest::gtest
8690
glog::glog
8791
opentelemetry-cpp::ostream_log_record_exporter
8892
${this_target}

instrumentation/glog/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
- Current release tested only with Ubuntu 20.04.6 LTS
1111
- OpenTelemetry >= v1.12.0
12-
- glog >= v0.3.5
12+
- glog >= v0.7.0
1313

1414
### Usage
1515

instrumentation/glog/include/opentelemetry/instrumentation/glog/sink.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
namespace google
1313
{
1414

15-
// The LogMessageTime class was introduced sometime in v0.6.0
16-
// Since there is no versioning available in this lib, we identify it based on the presence of this
17-
// include guard that was added in the required version
18-
#if defined(GLOG_EXPORT_H)
19-
# define GLOG_VERSION_HAS_LOGMESSAGETIME
20-
#endif
21-
2215
class OpenTelemetrySink : public google::LogSink
2316
{
2417
public:
@@ -41,23 +34,13 @@ class OpenTelemetrySink : public google::LogSink
4134
}
4235
}
4336

44-
#if defined(GLOG_VERSION_HAS_LOGMESSAGETIME)
4537
void send(google::LogSeverity,
4638
const char *,
4739
const char *,
4840
int,
4941
const google::LogMessageTime &,
5042
const char *,
5143
size_t) override;
52-
#else
53-
void send(google::LogSeverity,
54-
const char *,
55-
const char *,
56-
int,
57-
const struct ::tm *,
58-
const char *,
59-
size_t) override;
60-
#endif
6144
};
6245

6346
} // namespace google

instrumentation/glog/src/sink.cc

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace google
1515
{
1616

17-
#if defined(GLOG_VERSION_HAS_LOGMESSAGETIME)
1817
void OpenTelemetrySink::send(google::LogSeverity severity,
1918
const char *full_filename,
2019
const char * /* base_filename */,
@@ -23,18 +22,6 @@ void OpenTelemetrySink::send(google::LogSeverity severity,
2322
const char *message,
2423
size_t message_len)
2524
{
26-
#else
27-
void OpenTelemetrySink::send(google::LogSeverity severity,
28-
const char *full_filename,
29-
const char * /* base_filename */,
30-
int line,
31-
const struct std::tm * /* time_tm */,
32-
const char *message,
33-
size_t message_len)
34-
{
35-
// Compensate for the lack of precision in older versions
36-
const auto timestamp = std::chrono::system_clock::now();
37-
#endif
3825

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

51-
#if defined(GLOG_VERSION_HAS_LOGMESSAGETIME)
52-
static constexpr auto secs_to_msecs = duration_cast<microseconds>(seconds{1}).count();
53-
const auto timestamp = microseconds(secs_to_msecs * logmsgtime.timestamp() + logmsgtime.usec());
54-
#endif
55-
5638
log_record->SetSeverity(levelToSeverity(severity));
5739
log_record->SetBody(opentelemetry::nostd::string_view(message, message_len));
58-
log_record->SetTimestamp(system_clock::time_point(timestamp));
40+
log_record->SetTimestamp(logmsgtime.when());
5941
log_record->SetAttribute(kCodeFilepath, full_filename);
6042
log_record->SetAttribute(kCodeLineno, line);
6143
logger->EmitLogRecord(std::move(log_record));

0 commit comments

Comments
 (0)