summaryrefslogtreecommitdiffstats
path: root/contrib/libs/opentelemetry-cpp/sdk/src/trace/batch_span_processor_options.cc
blob: e935a40350de7a155b2068a7b264766565de503e (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <chrono>
#include <cstddef>
#include <cstdint>

#include "opentelemetry/sdk/common/env_variables.h"
#include "opentelemetry/sdk/trace/batch_span_processor_options.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace trace
{
namespace batch_span_processor_options_env
{

// Environment variable names
static constexpr const char *kMaxQueueSizeEnv       = "OTEL_BSP_MAX_QUEUE_SIZE";
static constexpr const char *kScheduleDelayEnv      = "OTEL_BSP_SCHEDULE_DELAY";
static constexpr const char *kExportTimeoutEnv      = "OTEL_BSP_EXPORT_TIMEOUT";
static constexpr const char *kMaxExportBatchSizeEnv = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE";

// Default values
static constexpr size_t kDefaultMaxQueueSize       = 2048;
static constexpr size_t kDefaultMaxExportBatchSize = 512;

size_t GetMaxQueueSizeFromEnv()
{
  std::uint32_t value{};
  if (!opentelemetry::sdk::common::GetUintEnvironmentVariable(kMaxQueueSizeEnv, value))
  {
    return kDefaultMaxQueueSize;
  }
  return static_cast<size_t>(value);
}

std::chrono::milliseconds GetScheduleDelayFromEnv()
{
  static const std::chrono::milliseconds kDefaultScheduleDelay{5000};
  std::chrono::system_clock::duration duration{0};
  if (!opentelemetry::sdk::common::GetDurationEnvironmentVariable(kScheduleDelayEnv, duration))
  {
    return kDefaultScheduleDelay;
  }
  return std::chrono::duration_cast<std::chrono::milliseconds>(duration);
}

std::chrono::milliseconds GetExportTimeoutFromEnv()
{
  static const std::chrono::milliseconds kDefaultExportTimeout{30000};
  std::chrono::system_clock::duration duration{0};
  if (!opentelemetry::sdk::common::GetDurationEnvironmentVariable(kExportTimeoutEnv, duration))
  {
    return kDefaultExportTimeout;
  }
  return std::chrono::duration_cast<std::chrono::milliseconds>(duration);
}

size_t GetMaxExportBatchSizeFromEnv()
{
  std::uint32_t value{};
  if (!opentelemetry::sdk::common::GetUintEnvironmentVariable(kMaxExportBatchSizeEnv, value))
  {
    return kDefaultMaxExportBatchSize;
  }
  return static_cast<size_t>(value);
}

}  // namespace batch_span_processor_options_env
}  // namespace trace
}  // namespace sdk
OPENTELEMETRY_END_NAMESPACE