Skip to content

Commit

Permalink
remove type SpanPtr
Browse files Browse the repository at this point in the history
Signed-off-by: thomas.ebner <[email protected]>
  • Loading branch information
samohte committed Oct 18, 2023
1 parent ca77aee commit b2a9fc6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Tracing::SpanPtr Driver::startSpan(const Tracing::Config& config,
SpanContextExtractor extractor(trace_context);
if (!extractor.propagationHeaderPresent()) {
// No propagation header, so we can create a fresh span with the given decision.
std::unique_ptr<Tracing::Span> new_open_telemetry_span =
Tracing::SpanPtr new_open_telemetry_span =
tracer.startSpan(config, operation_name, stream_info.startTime(), tracing_decision);
return new_open_telemetry_span;
} else {
Expand Down
40 changes: 20 additions & 20 deletions source/extensions/tracers/opentelemetry/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,56 +155,56 @@ Tracing::SpanPtr Tracer::startSpan(const Tracing::Config& config, const std::str
SystemTime start_time,
const Tracing::Decision tracing_decision) {
// Create an Tracers::OpenTelemetry::Span class that will contain the OTel span.
SpanPtr new_span = std::make_unique<Span>(config, operation_name, start_time, time_source_, *this);
new_span->setSampled(tracing_decision.traced);
Span new_span = Span(config, operation_name, start_time, time_source_, *this);
new_span.setSampled(tracing_decision.traced);
uint64_t trace_id_high = random_.random();
uint64_t trace_id = random_.random();
new_span->setTraceId(absl::StrCat(Hex::uint64ToHex(trace_id_high), Hex::uint64ToHex(trace_id)));
new_span.setTraceId(absl::StrCat(Hex::uint64ToHex(trace_id_high), Hex::uint64ToHex(trace_id)));
uint64_t span_id = random_.random();
new_span->setId(Hex::uint64ToHex(span_id));
new_span.setId(Hex::uint64ToHex(span_id));

if (sampler_) {
absl::StatusOr<SpanContext> span_context = absl::InvalidArgumentError("no parent span");
auto sampling_result = sampler_->shouldSample(span_context, operation_name, new_span->getTraceIdAsHex(), new_span->spankind(), {}, {});
new_span->setSampled(sampling_result.isSampled());
auto sampling_result = sampler_->shouldSample(span_context, operation_name, new_span.getTraceIdAsHex(), new_span.spankind(), {}, {});
new_span.setSampled(sampling_result.isSampled());
if (sampling_result.attributes) {
for (auto const &attribute: *sampling_result.attributes) {
new_span->setTag(attribute.first, attribute.second);
new_span->setTracestate(sampling_result.trace_state);
new_span.setTag(attribute.first, attribute.second);
new_span.setTracestate(sampling_result.trace_state);
}
}
}
return new_span;
return std::make_unique<Span>(new_span);
}

Tracing::SpanPtr Tracer::startSpan(const Tracing::Config& config, const std::string& operation_name,
SystemTime start_time,
const SpanContext& previous_span_context) {
// Create a new span and populate details from the span context.
SpanPtr new_span = std::make_unique<Span>(config, operation_name, start_time, time_source_, *this);
new_span->setSampled(previous_span_context.sampled());
new_span->setTraceId(previous_span_context.traceId());
Span new_span = Span(config, operation_name, start_time, time_source_, *this);
new_span.setSampled(previous_span_context.sampled());
new_span.setTraceId(previous_span_context.traceId());
if (!previous_span_context.parentId().empty()) {
new_span->setParentId(previous_span_context.parentId());
new_span.setParentId(previous_span_context.parentId());
}
// Generate a new identifier for the span id.
uint64_t span_id = random_.random();
new_span->setId(Hex::uint64ToHex(span_id));
new_span.setId(Hex::uint64ToHex(span_id));
// Respect the previous span's sampled flag.
new_span->setSampled(previous_span_context.sampled());
new_span.setSampled(previous_span_context.sampled());
if (!previous_span_context.tracestate().empty()) {
new_span->setTracestate(std::string{previous_span_context.tracestate()});
new_span.setTracestate(std::string{previous_span_context.tracestate()});
}

if (sampler_) {
absl::StatusOr<SpanContext> span_context = previous_span_context;
auto sampling_result = sampler_->shouldSample(span_context, operation_name, new_span->getTraceIdAsHex(), new_span->spankind(), {}, {});
auto sampling_result = sampler_->shouldSample(span_context, operation_name, new_span.getTraceIdAsHex(), new_span.spankind(), {}, {});
for (auto const &attribute: *sampling_result.attributes) {
new_span->setTag(attribute.first, attribute.second);
new_span->setTracestate(sampling_result.trace_state);
new_span.setTag(attribute.first, attribute.second);
new_span.setTracestate(sampling_result.trace_state);
}
}
return new_span;
return std::make_unique<Span>(new_span);
}

} // namespace OpenTelemetry
Expand Down
1 change: 0 additions & 1 deletion source/extensions/tracers/opentelemetry/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class Span : Logger::Loggable<Logger::Id::tracing>, public Tracing::Span {
bool sampled_;
};

using SpanPtr = std::unique_ptr<Span>;
using TracerPtr = std::unique_ptr<Tracer>;

} // namespace OpenTelemetry
Expand Down

0 comments on commit b2a9fc6

Please sign in to comment.