Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ functional/cert/server_cert_b.csr
functional/cert/server_cert_b.pem
functional/cert/server_cert_b-key.pem
functional/cert/unreadable.pem

# CodeQL build artifacts
_codeql_build_dir/
_codeql_detected_source_root
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,71 @@ namespace sdk
namespace logs
{

namespace batch_log_record_processor_options_env
{

/// @brief Returns the max queue size from the OTEL_BLRP_MAX_QUEUE_SIZE environment variable
/// or the default value (2048) if not set.
OPENTELEMETRY_EXPORT size_t GetMaxQueueSizeFromEnv();

/// @brief Returns the schedule delay from the OTEL_BLRP_SCHEDULE_DELAY environment variable
/// or the default value (1000ms) if not set.
OPENTELEMETRY_EXPORT std::chrono::milliseconds GetScheduleDelayFromEnv();

/// @brief Returns the export timeout from the OTEL_BLRP_EXPORT_TIMEOUT environment variable
/// or the default value (30000ms) if not set.
OPENTELEMETRY_EXPORT std::chrono::milliseconds GetExportTimeoutFromEnv();

/// @brief Returns the max export batch size from the OTEL_BLRP_MAX_EXPORT_BATCH_SIZE environment
/// variable or the default value (512) if not set.
OPENTELEMETRY_EXPORT size_t GetMaxExportBatchSizeFromEnv();

} // namespace batch_log_record_processor_options_env

/**
* Struct to hold batch LogRecordProcessor options.
*
* This is an aggregate type that supports C++20 designated initializers.
* Default values are read from environment variables when an instance is created:
* - OTEL_BLRP_MAX_QUEUE_SIZE (default: 2048)
* - OTEL_BLRP_SCHEDULE_DELAY (default: 1000ms)
* - OTEL_BLRP_EXPORT_TIMEOUT (default: 30000ms)
* - OTEL_BLRP_MAX_EXPORT_BATCH_SIZE (default: 512)
*
* Usage notes:
* - If you use default initialization (e.g., `BatchLogRecordProcessorOptions opts{}`), all fields
* are set by reading the environment variables (or hardcoded defaults if unset).
* - If you use aggregate initialization with explicit values (positional or designated),
* those values override the environment variable defaults for the specified fields.
* - With C++20 designated initializers, you can override only specific fields; unspecified
* fields will use environment variables or hardcoded defaults.
*/
struct OPENTELEMETRY_EXPORT BatchLogRecordProcessorOptions
{
BatchLogRecordProcessorOptions();
/**
* The maximum buffer/queue size. After the size is reached, spans are
* The maximum buffer/queue size. After the size is reached, log records are
* dropped.
*/
size_t max_queue_size;
size_t max_queue_size = batch_log_record_processor_options_env::GetMaxQueueSizeFromEnv();

/* The time interval between two consecutive exports. */
std::chrono::milliseconds schedule_delay_millis;
std::chrono::milliseconds schedule_delay_millis =
batch_log_record_processor_options_env::GetScheduleDelayFromEnv();

/**
* It is the time duration of how long the export can run before it is cancelled
* It is not currently used by the SDK and the parameter is ignored
* The maximum time allowed to export data.
* It is not currently used by the SDK and the parameter is ignored.
* TODO: Implement the parameter in BatchLogRecordProcessor
*/
std::chrono::milliseconds export_timeout_millis;
std::chrono::milliseconds export_timeout_millis =
batch_log_record_processor_options_env::GetExportTimeoutFromEnv();

/**
* The maximum batch size of every export. It must be smaller or
* equal to max_queue_size.
*/
size_t max_export_batch_size;
size_t max_export_batch_size =
batch_log_record_processor_options_env::GetMaxExportBatchSizeFromEnv();
};

} // namespace logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <chrono>
#include <cstddef>

#include "opentelemetry/version.h"

Expand All @@ -14,33 +15,77 @@ namespace sdk
namespace trace
{

namespace batch_span_processor_options_env
{

/// @brief Returns the max queue size from the OTEL_BSP_MAX_QUEUE_SIZE environment variable
/// or the default value (2048) if not set.
OPENTELEMETRY_EXPORT size_t GetMaxQueueSizeFromEnv();

/// @brief Returns the schedule delay from the OTEL_BSP_SCHEDULE_DELAY environment variable
/// or the default value (5000ms) if not set.
OPENTELEMETRY_EXPORT std::chrono::milliseconds GetScheduleDelayFromEnv();

/// @brief Returns the export timeout from the OTEL_BSP_EXPORT_TIMEOUT environment variable
/// or the default value (30000ms) if not set.
OPENTELEMETRY_EXPORT std::chrono::milliseconds GetExportTimeoutFromEnv();

/// @brief Returns the max export batch size from the OTEL_BSP_MAX_EXPORT_BATCH_SIZE environment
/// variable or the default value (512) if not set.
OPENTELEMETRY_EXPORT size_t GetMaxExportBatchSizeFromEnv();

} // namespace batch_span_processor_options_env

/**
* Struct to hold batch SpanProcessor options.
*
* This is an aggregate type that supports C++20 designated initializers.
* Default values are read from environment variables when an instance is created:
* - OTEL_BSP_MAX_QUEUE_SIZE (default: 2048)
* - OTEL_BSP_SCHEDULE_DELAY (default: 5000ms)
* - OTEL_BSP_EXPORT_TIMEOUT (default: 30000ms)
* - OTEL_BSP_MAX_EXPORT_BATCH_SIZE (default: 512)
*
* Usage notes:
* - If you use default initialization (e.g., `BatchSpanProcessorOptions opts{}`), all fields
* are set by reading the environment variables (or hardcoded defaults if unset).
* - If you use aggregate initialization with explicit values (positional or designated),
* those values override the environment variable defaults for the specified fields.
* - With C++20 designated initializers, you can override only specific fields; unspecified
* fields will use environment variables or hardcoded defaults.
*
* Examples:
* // All fields use env vars or hardcoded defaults
* BatchSpanProcessorOptions opts1{};
*
* // C++20: Only max_queue_size overridden, other fields read from env vars/defaults
* BatchSpanProcessorOptions opts3{.max_queue_size = 100};
*/
struct OPENTELEMETRY_EXPORT BatchSpanProcessorOptions
{
BatchSpanProcessorOptions();
/**
* The maximum buffer/queue size. After the size is reached, spans are
* dropped.
*/
size_t max_queue_size;
size_t max_queue_size = batch_span_processor_options_env::GetMaxQueueSizeFromEnv();

/* The time interval between two consecutive exports. */
std::chrono::milliseconds schedule_delay_millis;
std::chrono::milliseconds schedule_delay_millis =
batch_span_processor_options_env::GetScheduleDelayFromEnv();

/**
* The maximum time allowed to to export data
* It is not currently used by the SDK and the parameter is ignored
* The maximum time allowed to export data.
* It is not currently used by the SDK and the parameter is ignored.
* TODO: Implement the parameter in BatchSpanProcessor
*/
std::chrono::milliseconds export_timeout;
std::chrono::milliseconds export_timeout =
batch_span_processor_options_env::GetExportTimeoutFromEnv();

/**
* The maximum batch size of every export. It must be smaller or
* equal to max_queue_size.
*/
size_t max_export_batch_size;
size_t max_export_batch_size = batch_span_processor_options_env::GetMaxExportBatchSizeFromEnv();
};

} // namespace trace
Expand Down
52 changes: 29 additions & 23 deletions sdk/src/logs/batch_log_record_processor_options.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <stddef.h>
#include <chrono>
#include <cstddef>
#include <cstdint>

#include "opentelemetry/sdk/common/env_variables.h"
Expand All @@ -14,18 +14,20 @@ namespace sdk
{
namespace logs
{
namespace batch_log_record_processor_options_env
{

constexpr const char *kMaxQueueSizeEnv = "OTEL_BLRP_MAX_QUEUE_SIZE";
constexpr const char *kScheduleDelayEnv = "OTEL_BLRP_SCHEDULE_DELAY";
constexpr const char *kExportTimeoutEnv = "OTEL_BLRP_EXPORT_TIMEOUT";
constexpr const char *kMaxExportBatchSizeEnv = "OTEL_BLRP_MAX_EXPORT_BATCH_SIZE";
// Environment variable names
static constexpr const char *kMaxQueueSizeEnv = "OTEL_BLRP_MAX_QUEUE_SIZE";
static constexpr const char *kScheduleDelayEnv = "OTEL_BLRP_SCHEDULE_DELAY";
static constexpr const char *kExportTimeoutEnv = "OTEL_BLRP_EXPORT_TIMEOUT";
static constexpr const char *kMaxExportBatchSizeEnv = "OTEL_BLRP_MAX_EXPORT_BATCH_SIZE";

const size_t kDefaultMaxQueueSize = 2048;
const std::chrono::milliseconds kDefaultScheduleDelayMillis = std::chrono::milliseconds(1000);
const std::chrono::milliseconds kDefaultExportTimeout = std::chrono::milliseconds(30000);
const size_t kDefaultMaxExportBatchSize = 512;
// Default values
static constexpr size_t kDefaultMaxQueueSize = 2048;
static constexpr size_t kDefaultMaxExportBatchSize = 512;

inline size_t GetMaxQueueSizeFromEnv()
size_t GetMaxQueueSizeFromEnv()
{
std::uint32_t value{};
if (!opentelemetry::sdk::common::GetUintEnvironmentVariable(kMaxQueueSizeEnv, value))
Expand All @@ -35,19 +37,29 @@ inline size_t GetMaxQueueSizeFromEnv()
return static_cast<size_t>(value);
}

inline std::chrono::milliseconds GetDurationFromEnv(
const char *env_var,
const std::chrono::milliseconds &default_duration)
std::chrono::milliseconds GetScheduleDelayFromEnv()
{
static const std::chrono::milliseconds kDefaultScheduleDelay{1000};
std::chrono::system_clock::duration duration{0};
if (!opentelemetry::sdk::common::GetDurationEnvironmentVariable(env_var, duration))
if (!opentelemetry::sdk::common::GetDurationEnvironmentVariable(kScheduleDelayEnv, duration))
{
return default_duration;
return kDefaultScheduleDelay;
}
return std::chrono::duration_cast<std::chrono::milliseconds>(duration);
}

inline size_t GetMaxExportBatchSizeFromEnv()
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))
Expand All @@ -57,13 +69,7 @@ inline size_t GetMaxExportBatchSizeFromEnv()
return static_cast<size_t>(value);
}

BatchLogRecordProcessorOptions::BatchLogRecordProcessorOptions()
: max_queue_size(GetMaxQueueSizeFromEnv()),
schedule_delay_millis(GetDurationFromEnv(kScheduleDelayEnv, kDefaultScheduleDelayMillis)),
export_timeout_millis(GetDurationFromEnv(kExportTimeoutEnv, kDefaultExportTimeout)),
max_export_batch_size(GetMaxExportBatchSizeFromEnv())
{}

} // namespace batch_log_record_processor_options_env
} // namespace logs
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
52 changes: 29 additions & 23 deletions sdk/src/trace/batch_span_processor_options.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <stddef.h>
#include <chrono>
#include <cstddef>
#include <cstdint>

#include "opentelemetry/sdk/common/env_variables.h"
Expand All @@ -14,18 +14,20 @@ namespace sdk
{
namespace trace
{
namespace batch_span_processor_options_env
{

constexpr const char *kMaxQueueSizeEnv = "OTEL_BSP_MAX_QUEUE_SIZE";
constexpr const char *kScheduleDelayEnv = "OTEL_BSP_SCHEDULE_DELAY";
constexpr const char *kExportTimeoutEnv = "OTEL_BSP_EXPORT_TIMEOUT";
constexpr const char *kMaxExportBatchSizeEnv = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE";
// 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";

const size_t kDefaultMaxQueueSize = 2084;
const std::chrono::milliseconds kDefaultScheduleDelayMillis = std::chrono::milliseconds(5000);
const std::chrono::milliseconds kDefaultExportTimeout = std::chrono::milliseconds(3000);
const size_t kDefaultMaxExportBatchSize = 512;
// Default values
static constexpr size_t kDefaultMaxQueueSize = 2048;
static constexpr size_t kDefaultMaxExportBatchSize = 512;

inline size_t GetMaxQueueSizeFromEnv()
size_t GetMaxQueueSizeFromEnv()
{
std::uint32_t value{};
if (!opentelemetry::sdk::common::GetUintEnvironmentVariable(kMaxQueueSizeEnv, value))
Expand All @@ -35,19 +37,29 @@ inline size_t GetMaxQueueSizeFromEnv()
return static_cast<size_t>(value);
}

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

inline size_t GetMaxExportBatchSizeFromEnv()
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))
Expand All @@ -57,13 +69,7 @@ inline size_t GetMaxExportBatchSizeFromEnv()
return static_cast<size_t>(value);
}

BatchSpanProcessorOptions::BatchSpanProcessorOptions()
: max_queue_size(GetMaxQueueSizeFromEnv()),
schedule_delay_millis(GetDurationFromEnv(kScheduleDelayEnv, kDefaultScheduleDelayMillis)),
export_timeout(GetDurationFromEnv(kExportTimeoutEnv, kDefaultExportTimeout)),
max_export_batch_size(GetMaxExportBatchSizeFromEnv())
{}

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