Program Listing for File scope.h

Return to documentation for file (include/opentelemetry/trace/scope.h)

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/context/runtime_context.h"
#include "opentelemetry/trace/span.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
class Scope final
{
public:
  Scope(const nostd::shared_ptr<Span> &span) noexcept
      : token_(context::RuntimeContext::Attach(
            context::RuntimeContext::GetCurrent().SetValue(kSpanKey, span)))
  {}

private:
  nostd::unique_ptr<context::Token> token_;
};

}  // namespace trace
OPENTELEMETRY_END_NAMESPACE