Program Listing for File tracer_context.h

Return to documentation for file (/home/docs/checkouts/readthedocs.org/user_builds/opentelemetry-cpp/checkouts/v1.4.1/sdk/include/opentelemetry/sdk/trace/tracer_context.h)

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

#pragma once

#include "opentelemetry/sdk/common/atomic_unique_ptr.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/random_id_generator.h"
#include "opentelemetry/sdk/trace/samplers/always_on.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace trace
{

class TracerContext
{
public:
  explicit TracerContext(
      std::vector<std::unique_ptr<SpanProcessor>> &&processor,
      opentelemetry::sdk::resource::Resource resource =
          opentelemetry::sdk::resource::Resource::Create({}),
      std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
      std::unique_ptr<IdGenerator> id_generator =
          std::unique_ptr<IdGenerator>(new RandomIdGenerator())) noexcept;

  void AddProcessor(std::unique_ptr<SpanProcessor> processor) noexcept;

  Sampler &GetSampler() const noexcept;

  SpanProcessor &GetProcessor() const noexcept;

  const opentelemetry::sdk::resource::Resource &GetResource() const noexcept;

  opentelemetry::sdk::trace::IdGenerator &GetIdGenerator() const noexcept;

  bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept;

  bool Shutdown() noexcept;

private:
  //  order of declaration is important here - resource object should be destroyed after processor.
  opentelemetry::sdk::resource::Resource resource_;
  std::unique_ptr<Sampler> sampler_;
  std::unique_ptr<IdGenerator> id_generator_;
  std::unique_ptr<SpanProcessor> processor_;
};

}  // namespace trace
}  // namespace sdk
OPENTELEMETRY_END_NAMESPACE