summaryrefslogtreecommitdiffstats
path: root/contrib/libs/opentelemetry-cpp/api/include/opentelemetry/baggage/baggage_context.h
blob: e3eedf019f048bf6fdacf47be0c26a91867b2394 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/baggage/baggage.h"
#include "opentelemetry/context/context.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE

namespace baggage
{

static const std::string kBaggageHeader = "baggage";

inline nostd::shared_ptr<Baggage> GetBaggage(const context::Context &context) noexcept
{
  context::ContextValue context_value = context.GetValue(kBaggageHeader);

  if (const nostd::shared_ptr<Baggage> *value =
          nostd::get_if<nostd::shared_ptr<Baggage>>(&context_value))
  {
    return *value;
  }
  static nostd::shared_ptr<Baggage> empty_baggage{new Baggage()};
  return empty_baggage;
}

inline context::Context SetBaggage(context::Context &context,
                                   const nostd::shared_ptr<Baggage> &baggage) noexcept
{
  return context.SetValue(kBaggageHeader, baggage);
}

}  // namespace baggage
OPENTELEMETRY_END_NAMESPACE