Skip to content

Commit 0e31712

Browse files
authored
[SPDLOG] Add support for latest opentelemetry version(s) (open-telemetry#593)
1 parent 36fd159 commit 0e31712

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

.github/workflows/spdlog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: actions/checkout@v5
3636
with:
3737
repository: "open-telemetry/opentelemetry-cpp"
38-
ref: "v1.19.0"
38+
ref: "v1.24.0"
3939
path: "opentelemetry-cpp"
4040
submodules: "recursive"
4141
- name: setup dependencies

instrumentation/spdlog/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ find_package(spdlog REQUIRED)
1313
add_library(${this_target} src/sink.cc)
1414

1515
target_compile_options(${this_target} PUBLIC
16-
-Wall -Wextra -Werror -Wpedantic -fPIC
16+
-Wall -Wextra -Wpedantic -fPIC
1717
)
1818

1919
set_target_properties(${this_target} PROPERTIES EXPORT_NAME ${this_target})

instrumentation/spdlog/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
## Requirements
99

1010
- Current release tested only with Ubuntu 20.04.6 LTS
11-
- OpenTelemetry >= v1.12.0
11+
- OpenTelemetry >= v1.21.0
1212
- spdlog >= v1.5.0
1313

1414
### Usage

instrumentation/spdlog/src/sink.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include <opentelemetry/instrumentation/spdlog/sink.h>
77

88
#include <opentelemetry/logs/provider.h>
9-
#include <opentelemetry/trace/semantic_conventions.h>
9+
#include <opentelemetry/semconv/code_attributes.h>
10+
#include <opentelemetry/semconv/incubating/thread_attributes.h>
1011
#include <opentelemetry/version.h>
1112

1213
namespace spdlog
@@ -25,15 +26,16 @@ void OpenTelemetrySink<Mutex>::sink_it_(const spdlog::details::log_msg &msg)
2526

2627
if (log_record)
2728
{
28-
using namespace opentelemetry::trace::SemanticConventions;
29+
using namespace opentelemetry::semconv::code;
30+
using namespace opentelemetry::semconv::thread;
2931

3032
log_record->SetSeverity(levelToSeverity(msg.level));
3133
log_record->SetBody(opentelemetry::nostd::string_view(msg.payload.data(), msg.payload.size()));
3234
log_record->SetTimestamp(msg.time);
3335
if (!msg.source.empty())
3436
{
35-
log_record->SetAttribute(kCodeFilepath, msg.source.filename);
36-
log_record->SetAttribute(kCodeLineno, msg.source.line);
37+
log_record->SetAttribute(kCodeFilePath, msg.source.filename);
38+
log_record->SetAttribute(kCodeLineNumber, msg.source.line);
3739
}
3840
log_record->SetAttribute(kThreadId, msg.thread_id);
3941
logger->EmitLogRecord(std::move(log_record));

instrumentation/spdlog/test/sink_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ TEST_F(OpenTelemetrySinkTest, Log_Success)
143143
ASSERT_TRUE(timestamp.time_since_epoch() >= pre_log.time_since_epoch());
144144
ASSERT_TRUE(timestamp.time_since_epoch() <= post_log.time_since_epoch());
145145
}));
146-
EXPECT_CALL(*logrecord_mock, SetAttribute(nostd::string_view("code.lineno"), _))
146+
EXPECT_CALL(*logrecord_mock, SetAttribute(nostd::string_view("code.line.number"), _))
147147
.WillOnce(Invoke([](nostd::string_view, const common::AttributeValue &line_number) {
148148
ASSERT_TRUE(nostd::holds_alternative<int>(line_number));
149149
ASSERT_GE(nostd::get<int>(line_number), 0);
150150
}));
151-
EXPECT_CALL(*logrecord_mock, SetAttribute(nostd::string_view("code.filepath"), _))
151+
EXPECT_CALL(*logrecord_mock, SetAttribute(nostd::string_view("code.file.path"), _))
152152
.WillOnce(Invoke([](nostd::string_view, const common::AttributeValue &file_name) {
153153
ASSERT_TRUE(nostd::holds_alternative<const char *>(file_name));
154154
ASSERT_TRUE(std::strstr(nostd::get<const char *>(file_name), "sink_test.cc") != nullptr);

0 commit comments

Comments
 (0)