File: text_map_propagator.h

package info (click to toggle)
opentelemetry-cpp 1.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,372 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 36; python: 31
file content (59 lines) | stat: -rw-r--r-- 2,040 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/context/context.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace context
{
namespace propagation
{

// TextMapCarrier is the storage medium used by TextMapPropagator.
class TextMapCarrier
{
public:
  // returns the value associated with the passed key.
  virtual nostd::string_view Get(nostd::string_view key) const noexcept = 0;

  // stores the key-value pair.
  virtual void Set(nostd::string_view key, nostd::string_view value) noexcept = 0;

  /* list of all the keys in the carrier.
   By default, it returns true without invoking callback */
  virtual bool Keys(nostd::function_ref<bool(nostd::string_view)> /* callback */) const noexcept
  {
    return true;
  }
  virtual ~TextMapCarrier() = default;
};

// The TextMapPropagator class provides an interface that enables extracting and injecting
// context into carriers that travel in-band across process boundaries. HTTP frameworks and clients
// can integrate with TextMapPropagator by providing the object containing the
// headers, and a getter and setter function for the extraction and
// injection of values, respectively.

class TextMapPropagator
{
public:
  // Returns the context that is stored in the carrier with the TextMapCarrier as extractor.
  virtual context::Context Extract(const TextMapCarrier &carrier,
                                   context::Context &context) noexcept = 0;

  // Sets the context for carrier with self defined rules.
  virtual void Inject(TextMapCarrier &carrier, const context::Context &context) noexcept = 0;

  // Gets the fields set in the carrier by the `inject` method
  virtual bool Fields(nostd::function_ref<bool(nostd::string_view)> callback) const noexcept = 0;

  virtual ~TextMapPropagator() = default;
};
}  // namespace propagation
}  // namespace context
OPENTELEMETRY_END_NAMESPACE