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

Fix resource and scope of new Logs SDK implementation. #1881

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 14 additions & 3 deletions exporters/otlp/test/otlp_http_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
opentelemetry::trace::SpanId span_id{span_id_bin};

const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"};
auto logger = provider->GetLogger("test", "", "opentelelemtry_library", "", schema_url);
auto logger = provider->GetLogger("test", "", "opentelelemtry_library", "1.2.0", schema_url);

trace_id.ToLowerBase16(MakeSpan(trace_id_hex));
report_trace_id.assign(trace_id_hex, sizeof(trace_id_hex));
Expand All @@ -244,9 +244,16 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false);
auto resource_logs = *check_json["resource_logs"].begin();
auto scope_logs = *resource_logs["scope_logs"].begin();
auto schema_url = scope_logs["schema_url"].get<std::string>();
auto scope = scope_logs["scope"];
auto scope_name = scope["name"];
auto scope_version = scope["version"];
auto log = *scope_logs["log_records"].begin();
auto received_trace_id = log["trace_id"].get<std::string>();
auto received_span_id = log["span_id"].get<std::string>();
EXPECT_EQ(schema_url, "https://opentelemetry.io/schemas/1.2.0");
EXPECT_EQ(scope_name, "opentelelemtry_library");
EXPECT_EQ(scope_version, "1.2.0");
EXPECT_EQ(received_trace_id, report_trace_id);
EXPECT_EQ(received_span_id, report_span_id);
EXPECT_EQ("Log message", log["body"]["string_value"].get<std::string>());
Expand Down Expand Up @@ -325,7 +332,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
opentelemetry::trace::SpanId span_id{span_id_bin};

const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"};
auto logger = provider->GetLogger("test", "", "opentelelemtry_library", "", schema_url);
auto logger = provider->GetLogger("test", "", "opentelelemtry_library", "1.2.0", schema_url);

report_trace_id.assign(reinterpret_cast<const char *>(trace_id_bin), sizeof(trace_id_bin));
report_span_id.assign(reinterpret_cast<const char *>(span_id_bin), sizeof(span_id_bin));
Expand All @@ -339,7 +346,11 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test
opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body;
request_body.ParseFromArray(&mock_session->GetRequest()->body_[0],
static_cast<int>(mock_session->GetRequest()->body_.size()));
auto received_log = request_body.resource_logs(0).scope_logs(0).log_records(0);
auto scope_log = request_body.resource_logs(0).scope_logs(0);
EXPECT_EQ(scope_log.schema_url(), "https://opentelemetry.io/schemas/1.2.0");
EXPECT_EQ(scope_log.scope().name(), "opentelelemtry_library");
EXPECT_EQ(scope_log.scope().version(), "1.2.0");
auto received_log = scope_log.log_records(0);
EXPECT_EQ(received_log.trace_id(), report_trace_id);
EXPECT_EQ(received_log.span_id(), report_span_id);
EXPECT_EQ("Log message", received_log.body().string_value());
Expand Down
7 changes: 6 additions & 1 deletion sdk/src/logs/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ void Logger::EmitLogRecord(nostd::unique_ptr<opentelemetry::logs::LogRecord> &&l
return;
}

std::unique_ptr<Recordable> recordable =
std::unique_ptr<Recordable>(static_cast<Recordable *>(log_record.release()));
recordable->SetResource(context_->GetResource());
recordable->SetInstrumentationScope(GetInstrumentationScope());

auto &processor = context_->GetProcessor();

// TODO: Sampler (should include check for minSeverity)

// Send the log recordable to the processor
processor.OnEmit(std::unique_ptr<Recordable>(static_cast<Recordable *>(log_record.release())));
processor.OnEmit(std::move(recordable));
}

const opentelemetry::sdk::instrumentationscope::InstrumentationScope &
Expand Down