Skip to content

Commit

Permalink
Merge branch 'main' into relative-docs-links
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Jul 1, 2022
2 parents 3c4f1cc + 4c08919 commit 797426e
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class OtlpRecordable final : public opentelemetry::sdk::trace::Recordable
const std::string GetResourceSchemaURL() const noexcept;
const std::string GetInstrumentationLibrarySchemaURL() const noexcept;

proto::common::v1::InstrumentationLibrary GetProtoInstrumentationLibrary() const noexcept;
proto::common::v1::InstrumentationScope GetProtoInstrumentationScope() const noexcept;

void SetIdentity(const opentelemetry::trace::SpanContext &span_context,
opentelemetry::trace::SpanId parent_span_id) noexcept override;
Expand Down
10 changes: 5 additions & 5 deletions exporters/otlp/src/otlp_recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ const std::string OtlpRecordable::GetInstrumentationLibrarySchemaURL() const noe
return schema_url;
}

proto::common::v1::InstrumentationLibrary OtlpRecordable::GetProtoInstrumentationLibrary()
proto::common::v1::InstrumentationScope OtlpRecordable::GetProtoInstrumentationScope()
const noexcept
{
proto::common::v1::InstrumentationLibrary instrumentation_library;
proto::common::v1::InstrumentationScope instrumentation_scope;
if (instrumentation_library_)
{
instrumentation_library.set_name(instrumentation_library_->GetName());
instrumentation_library.set_version(instrumentation_library_->GetVersion());
instrumentation_scope.set_name(instrumentation_library_->GetName());
instrumentation_scope.set_version(instrumentation_library_->GetVersion());
}
return instrumentation_library;
return instrumentation_scope;
}

void OtlpRecordable::SetResource(const sdk::resource::Resource &resource) noexcept
Expand Down
10 changes: 5 additions & 5 deletions exporters/otlp/src/otlp_recordable_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ void OtlpRecordableUtils::PopulateRequest(
for (auto &recordable : spans)
{
auto rec = std::unique_ptr<OtlpRecordable>(static_cast<OtlpRecordable *>(recordable.release()));
auto resource_span = request->add_resource_spans();
auto instrumentation_lib = resource_span->add_instrumentation_library_spans();
auto resource_span = request->add_resource_spans();
auto scope_spans = resource_span->add_scope_spans();

*instrumentation_lib->add_spans() = std::move(rec->span());
*instrumentation_lib->mutable_instrumentation_library() = rec->GetProtoInstrumentationLibrary();
*scope_spans->add_spans() = std::move(rec->span());
*scope_spans->mutable_scope() = rec->GetProtoInstrumentationScope();

instrumentation_lib->set_schema_url(rec->GetInstrumentationLibrarySchemaURL());
scope_spans->set_schema_url(rec->GetInstrumentationLibrarySchemaURL());

*resource_span->mutable_resource() = rec->ProtoResource();
resource_span->set_schema_url(rec->GetResourceSchemaURL());
Expand Down
11 changes: 5 additions & 6 deletions exporters/otlp/test/otlp_http_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest)
.WillOnce([&mock_session,
report_trace_id](opentelemetry::ext::http::client::EventHandler &callback) {
auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false);
auto resource_span = *check_json["resource_spans"].begin();
auto instrumentation_library_span = *resource_span["instrumentation_library_spans"].begin();
auto span = *instrumentation_library_span["spans"].begin();
auto received_trace_id = span["trace_id"].get<std::string>();
auto resource_span = *check_json["resource_spans"].begin();
auto scope_span = *resource_span["scope_spans"].begin();
auto span = *scope_span["spans"].begin();
auto received_trace_id = span["trace_id"].get<std::string>();
EXPECT_EQ(received_trace_id, report_trace_id);

auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");
Expand Down Expand Up @@ -222,8 +222,7 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest)
opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body;
request_body.ParseFromArray(&mock_session->GetRequest()->body_[0],
static_cast<int>(mock_session->GetRequest()->body_.size()));
auto received_trace_id =
request_body.resource_spans(0).instrumentation_library_spans(0).spans(0).trace_id();
auto received_trace_id = request_body.resource_spans(0).scope_spans(0).spans(0).trace_id();
EXPECT_EQ(received_trace_id, report_trace_id);

auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/test/otlp_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TEST(OtlpRecordable, SetInstrumentationLibrary)
OtlpRecordable rec;
auto inst_lib = trace_sdk::InstrumentationLibrary::Create("test", "v1");
rec.SetInstrumentationLibrary(*inst_lib);
auto proto_instr_libr = rec.GetProtoInstrumentationLibrary();
auto proto_instr_libr = rec.GetProtoInstrumentationScope();
EXPECT_EQ(proto_instr_libr.name(), inst_lib->GetName());
EXPECT_EQ(proto_instr_libr.version(), inst_lib->GetVersion());
}
Expand Down
6 changes: 6 additions & 0 deletions sdk/include/opentelemetry/sdk/trace/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ struct SamplingResult
std::unique_ptr<const std::map<std::string, opentelemetry::common::AttributeValue>> attributes;
// The tracestate used by the span.
nostd::shared_ptr<opentelemetry::trace::TraceState> trace_state;

inline bool IsRecording()
{
return decision == Decision::RECORD_ONLY || decision == Decision::RECORD_AND_SAMPLE;
}
inline bool IsSampled() { return decision == Decision::RECORD_AND_SAMPLE; }
};

/**
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/trace/samplers/trace_id_ratio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ SamplingResult TraceIdRatioBasedSampler::ShouldSample(
const trace_api::SpanContextKeyValueIterable & /*links*/) noexcept
{
if (threshold_ == 0)
return {Decision::DROP, nullptr};
return {Decision::DROP, nullptr, {}};

if (CalculateThresholdFromBuffer(trace_id) <= threshold_)
{
return {Decision::RECORD_AND_SAMPLE, nullptr};
return {Decision::RECORD_AND_SAMPLE, nullptr, {}};
}

return {Decision::DROP, nullptr};
return {Decision::DROP, nullptr, {}};
}

nostd::string_view TraceIdRatioBasedSampler::GetDescription() const noexcept
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/trace/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ nostd::shared_ptr<trace_api::Span> Tracer::StartSpan(

auto sampling_result = context_->GetSampler().ShouldSample(parent_context, trace_id, name,
options.kind, attributes, links);
auto trace_flags = sampling_result.decision == Decision::DROP
? trace_api::TraceFlags{}
: trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled};
auto trace_flags = sampling_result.IsSampled()
? trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}
: trace_api::TraceFlags{};

auto span_context = std::unique_ptr<trace_api::SpanContext>(new trace_api::SpanContext(
trace_id, span_id, trace_flags, false,
sampling_result.trace_state ? sampling_result.trace_state
: is_parent_span_valid ? parent_context.trace_state()
: trace_api::TraceState::GetDefault()));

if (sampling_result.decision == Decision::DROP)
if (!sampling_result.IsRecording())
{
// create no-op span with valid span-context.

Expand Down

0 comments on commit 797426e

Please sign in to comment.