Skip to content

Commit

Permalink
Fix resource and scope of new Logs SDK implementation. (#1881)
Browse files Browse the repository at this point in the history
  • Loading branch information
owent authored Dec 23, 2022
1 parent c0deb40 commit 94a6783
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
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

1 comment on commit 94a6783

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 94a6783 Previous: c0deb40 Ratio
BM_ProcYieldSpinLockThrashing/2/process_time/real_time 1.0999794006347656 ms/iter 0.24479585927683156 ms/iter 4.49
BM_NaiveSpinLockThrashing/2/process_time/real_time 1.1749247874110198 ms/iter 0.24586253696017796 ms/iter 4.78

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.