diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h index d516ad0f22..b2780a005a 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h @@ -65,9 +65,9 @@ template SpanType *new_span(TracerType *objPtr, nostd::string_view name, const opentelemetry::trace::StartSpanOptions &options, - const opentelemetry::trace::SpanContext &span_context) + std::unique_ptr span_context) { - return new (std::nothrow) SpanType{*objPtr, name, options, span_context}; + return new (std::nothrow) SpanType{*objPtr, name, options, std::move(span_context)}; } /** @@ -419,9 +419,13 @@ class Tracer : public opentelemetry::trace::Tracer, auto traceId = parentContext.IsValid() ? parentContext.trace_id() : traceId_; // Sampling based on attributes is not supported for now, so passing empty below. + std::map empty_attributes = {{}}; opentelemetry::sdk::trace::SamplingResult sampling_result = GetSampler(tracerProvider_) - .ShouldSample(parentContext, traceId, name, options.kind, {}, links); + .ShouldSample(parentContext, traceId, name, options.kind, + opentelemetry::common::KeyValueIterableView>( + empty_attributes), + links); opentelemetry::trace::TraceFlags trace_flags = sampling_result.decision == opentelemetry::sdk::trace::Decision::DROP @@ -433,8 +437,8 @@ class Tracer : public opentelemetry::trace::Tracer, traceId, GetIdGenerator(tracerProvider_).GenerateSpanId(), trace_flags, false, sampling_result.trace_state ? sampling_result.trace_state - : parentContext.IsValid ? parentContext.trace_state() - : opentelemetry::trace::TraceState::GetDefault())); + : parentContext.IsValid() ? parentContext.trace_state() + : opentelemetry::trace::TraceState::GetDefault())); if (sampling_result.decision == sdk::trace::Decision::DROP) { @@ -459,11 +463,9 @@ class Tracer : public opentelemetry::trace::Tracer, // This template pattern allows us to forward-declare the etw::Span, // create an instance of it, then assign it to tracer::Span result. - auto currentSpan = new_span(this, name, options, spanContext); + auto currentSpan = new_span(this, name, options, std::move(spanContext)); nostd::shared_ptr result = to_span_ptr(currentSpan); - // auto spanContext = result->GetContext(); - // Decorate with additional standard fields std::string eventName = name.data(); @@ -478,13 +480,13 @@ class Tracer : public opentelemetry::trace::Tracer, { evt[ETW_FIELD_SPAN_PARENTID] = ToLowerBase16(parentContext.span_id()); } - evt[ETW_FIELD_SPAN_ID] = ToLowerBase16(spanContext.span_id()); + evt[ETW_FIELD_SPAN_ID] = ToLowerBase16(result.get()->GetContext().span_id()); } // Populate Etw.Payload["TraceId"] attribute if (cfg.enableTraceId) { - evt[ETW_FIELD_TRACE_ID] = ToLowerBase16(spanContext.trace_id()); + evt[ETW_FIELD_TRACE_ID] = ToLowerBase16(result.get()->GetContext().trace_id()); } // Populate Etw.ActivityId at envelope level if enabled @@ -708,7 +710,7 @@ class Span : public opentelemetry::trace::Span */ Span *GetParent() const { return parent_; } - opentelemetry::trace::SpanContext context_; + std::unique_ptr context_; public: /** @@ -762,12 +764,12 @@ class Span : public opentelemetry::trace::Span Span(Tracer &owner, nostd::string_view name, const opentelemetry::trace::StartSpanOptions &options, - const opentelemetry::trace::SpanContext &span_context, + std::unique_ptr span_context, Span *parent = nullptr) noexcept : opentelemetry::trace::Span(), start_time_(std::chrono::system_clock::now()), owner_(owner), - context_(span_context), + context_(std::move(span_context)), parent_(parent) { name_ = name; @@ -886,7 +888,7 @@ class Span : public opentelemetry::trace::Span * @brief Obtain SpanContext * @return */ - opentelemetry::trace::SpanContext GetContext() const noexcept override { return context_; } + opentelemetry::trace::SpanContext GetContext() const noexcept override { return *context_.get(); } /** * @brief Check if Span is recording data.