Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Poc config yaml #2518

Draft
wants to merge 112 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
636b85c
POC
marcalff Jan 23, 2024
b90ce1c
POC
marcalff Jan 24, 2024
1532b26
POC. Abstracted parsing from YAML.
marcalff Jan 25, 2024
34b8575
POC, continued.
marcalff Jan 28, 2024
da2f173
POC, trace signal.
marcalff Jan 28, 2024
04f2f6f
POC, continued.
marcalff Jan 31, 2024
90e6418
POC, yaml tests.
marcalff Jan 31, 2024
469bc0e
POC
marcalff Feb 1, 2024
8af0eed
POC, continued.
marcalff Feb 2, 2024
1f9a90c
Merge branch 'main' into poc_config_yaml
marcalff Feb 5, 2024
de49146
CI
marcalff Feb 5, 2024
9d12c76
POC - Registry
marcalff Feb 6, 2024
083e9f1
Code cleanup
marcalff Feb 7, 2024
11a51d8
POC, continued.
marcalff Feb 8, 2024
aa21bd6
POC - propagators
marcalff Feb 11, 2024
853c696
POC - text map propagetors
marcalff Feb 11, 2024
bc394cf
POC - cleanup
marcalff Feb 12, 2024
c8c1668
POC - replacing Yaml-cpp with Rapidyaml
marcalff Feb 15, 2024
7c81b0b
POC - replace Yaml-cpp with Ryml
marcalff Feb 17, 2024
df13b50
Merge branch 'main' into poc_config_yaml
marcalff Feb 17, 2024
eb1155d
POC - CI
marcalff Feb 17, 2024
172e212
CI
marcalff Feb 18, 2024
09d8122
CI
marcalff Feb 18, 2024
e537287
Cleanup
marcalff Feb 18, 2024
5351d20
POC - Implemented extension points (sampler, span processor, span exp…
marcalff Feb 20, 2024
fde1025
CMakeFormat
marcalff Feb 20, 2024
3c0465f
POC - env var substitution
marcalff Feb 25, 2024
0bfbe8f
Merge branch 'main' into poc_config_yaml
marcalff Feb 25, 2024
d147b62
Add yaml test cases
marcalff Feb 25, 2024
5d65ac2
POC - Now starting on metrics
marcalff Feb 28, 2024
ee0cc1e
env var substitution, with unit tests.
marcalff Feb 29, 2024
91fccb3
CI cleanup
marcalff Mar 2, 2024
ecf6f1c
Remove service_name, per configuration PR 68
marcalff Mar 4, 2024
9987f23
YAML parser for metrics
marcalff Mar 5, 2024
2a76bda
Merge branch 'main' into poc_config_yaml
marcalff Mar 8, 2024
62f0d35
WIP
marcalff Apr 3, 2024
1d8d0d0
Merge branch 'main' into poc_config_yaml
marcalff Apr 3, 2024
3a431c7
Merge branch 'main' into poc_config_yaml
marcalff Apr 19, 2024
b33fc82
Fixed shellcheck issues.
marcalff Apr 19, 2024
1960d29
Fix CI after merge.
marcalff Apr 19, 2024
c3db04b
Merge branch 'main' into poc_config_yaml
marcalff Apr 27, 2024
92a6849
Merge branch 'main' into poc_config_yaml
marcalff Apr 29, 2024
4765975
Merge branch 'main' into poc_config_yaml
marcalff May 14, 2024
4bb5fe4
Remove all code for yaml-cpp
marcalff May 14, 2024
1b2fcf4
Merge branch 'main' into poc_config_yaml
marcalff May 29, 2024
559153c
include-what-you-use to cover WITH_CONFIGURATION
marcalff May 30, 2024
c199ff9
Add rapidyaml in iwyu
marcalff May 30, 2024
c463d8e
Merge branch 'main' into poc_config_yaml
marcalff May 30, 2024
2c8d8a7
Merge branch 'main' into poc_config_yaml
marcalff Jun 1, 2024
f86e9a7
Log signal
marcalff Jun 1, 2024
5ee15b5
Merge branch 'main' into poc_config_yaml
marcalff Jun 7, 2024
932e26e
WIP
marcalff Jun 7, 2024
5ff727d
Merge branch 'main' into poc_config_yaml
marcalff Jun 12, 2024
cc95c00
Adjust after merge from main
marcalff Jun 12, 2024
8c4330b
Use clang 18
marcalff Jun 12, 2024
87a62f7
Merge branch 'main' into poc_config_yaml
marcalff Jun 25, 2024
84dda0e
build cleanup
marcalff Jun 25, 2024
9d3c36a
cleanup
marcalff Jun 26, 2024
fc24357
cleanup
marcalff Jun 27, 2024
179444c
build cleanup
marcalff Jun 27, 2024
2a5fc7b
build cleanup
marcalff Jun 27, 2024
fcaea7f
warning cleanup
marcalff Jun 27, 2024
d25ead0
build cleanup, deprecated code
marcalff Jun 27, 2024
c8d3980
build warnings
marcalff Jun 27, 2024
98752aa
Merge branch 'main' into poc_config_yaml
marcalff Jul 6, 2024
ab95a6b
include-what-you-use cleanup
marcalff Jul 6, 2024
dfcdc87
more iwyu cleanup
marcalff Jul 6, 2024
6007bd4
Continue log record implementation.
marcalff Jul 6, 2024
cbbe913
Cleanup
marcalff Jul 9, 2024
075b27a
Expanded variable substitution.
marcalff Jul 9, 2024
52234d0
Fixed build warning.
marcalff Jul 10, 2024
9a8b829
Merge branch 'main' into poc_config_yaml
marcalff Jul 17, 2024
e4ff2c4
Cleanup after merge.
marcalff Jul 17, 2024
a42704d
Fix clang-tidy
marcalff Jul 17, 2024
75758a5
Merge branch 'main' into poc_config_yaml
marcalff Jul 29, 2024
d3a9986
cleanup
marcalff Jul 30, 2024
6ac6fe2
Continued.
marcalff Aug 3, 2024
a3e5e05
format
marcalff Aug 3, 2024
560fa50
Merge branch 'main' into poc_config_yaml
marcalff Aug 3, 2024
c6f1503
Implemented builder for metrics (in progress)
marcalff Aug 4, 2024
a768f8d
Split MetricExporterConfiguration into:
marcalff Aug 4, 2024
1f7110e
Add prometheus exporter builder
marcalff Aug 5, 2024
a204780
Add metric builders: console and otlp
marcalff Aug 5, 2024
86a0b3b
Build cleanup
marcalff Aug 7, 2024
15fec29
Build cleanup for resource
marcalff Aug 7, 2024
466f541
Split OTLP builders into:
marcalff Aug 10, 2024
44d86f0
Merge branch 'main' into poc_config_yaml
marcalff Aug 10, 2024
2c15009
cleanup
marcalff Aug 10, 2024
4076d43
Merge branch 'main' into poc_config_yaml
marcalff Aug 24, 2024
87b034b
Require ryml 0.7.1
marcalff Aug 25, 2024
8ee0dba
Merge branch 'main' into poc_config_yaml
marcalff Aug 25, 2024
9e71e01
Use ryml 0.7.1 in CI
marcalff Aug 25, 2024
51c7ee0
Work around for broken ryml tag v0.7.1
marcalff Aug 25, 2024
4c964fd
Implemented resource schema changes.
marcalff Aug 26, 2024
b11105d
Merge branch 'main' into poc_config_yaml
marcalff Aug 26, 2024
10f1bc2
Upgrade to ryml 0.7.2
marcalff Aug 28, 2024
cb9e0d0
Merge branch 'main' into poc_config_yaml
marcalff Sep 14, 2024
96bf29b
Merge branch 'main' into poc_config_yaml
marcalff Oct 31, 2024
b6fcc19
Merge branch 'main' into poc_config_yaml
marcalff Nov 8, 2024
75e3816
WIP
marcalff Nov 20, 2024
b7b66ec
Merge branch 'main' into poc_config_yaml
marcalff Nov 20, 2024
a1471e0
Merge branch 'main' into poc_config_yaml
marcalff Nov 28, 2024
a020ef9
Merge branch 'main' into poc_config_yaml
marcalff Dec 3, 2024
be9d57d
General cleanup.
marcalff Dec 3, 2024
54d7b1e
WIP
marcalff Dec 7, 2024
5e5fb5c
Merge branch 'main' into poc_config_yaml
marcalff Dec 7, 2024
d2f6c6e
Cppcheck cleanup
marcalff Dec 7, 2024
faf756f
Cppcheck
marcalff Dec 7, 2024
2d4388d
Merge branch 'main' into poc_config_yaml
marcalff Dec 8, 2024
2cfdc09
iwyu cleanup
marcalff Dec 10, 2024
3b58494
cleanup
marcalff Dec 17, 2024
8420c89
Merge branch 'main' into poc_config_yaml
marcalff Dec 17, 2024
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
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,40 @@ jobs:
run: |
(cd ./functional/otlp; ./run_test.sh)

cmake_clang_yaml_config:
name: CMake clang 18 (maintainer mode, yaml config)
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: setup
env:
CC: /usr/bin/clang-18
CXX: /usr/bin/clang++-18
PROTOBUF_VERSION: 21.12
run: |
sudo apt remove needrestart #refer: https://github.com/actions/runner-images/issues/9937
sudo -E ./ci/setup_googletest.sh
sudo -E ./ci/setup_ci_environment.sh
sudo -E ./ci/install_protobuf.sh
sudo -E ./ci/install_ryml.sh
- name: run cmake clang (maintainer mode, sync)
env:
CC: /usr/bin/clang-18
CXX: /usr/bin/clang++-18
run: |
./ci/do_ci.sh cmake.maintainer.yaml.test
- name: generate test cert
env:
CFSSL_VERSION: 1.6.3
run: |
sudo -E ./tools/setup-cfssl.sh
(cd ./functional/cert; ./generate_cert.sh)
- name: run func test
run: |
(cd ./functional/otlp; ./run_test.sh)

cmake_clang_maintainer_async_test:
name: CMake clang 18 (maintainer mode, async)
runs-on: ubuntu-24.04
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/clang-tidy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
libgmock-dev \
libgtest-dev \
libbenchmark-dev
sudo ./ci/install_ryml.sh

if ! command -v clang-tidy &> /dev/null; then
echo "clang-tidy could not be found"
Expand Down Expand Up @@ -61,6 +62,7 @@ jobs:
-DBUILD_W3CTRACECONTEXT_TEST=ON \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_CONFIGURATION=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON

- name: Run clang-tidy
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
libgmock-dev \
libgtest-dev \
libbenchmark-dev
sudo ./ci/install_ryml.sh

- name: Prepare CMake
run: |
Expand All @@ -39,6 +40,7 @@ jobs:
-DCMAKE_CXX_STANDARD=14 \
-DWITH_STL=CXX14 \
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \
-DWITH_CONFIGURATION=ON \
-DBUILD_TESTING=ON \
-DBUILD_W3CTRACECONTEXT_TEST=ON \
-DWITH_OTLP_GRPC=OFF \
Expand Down
10 changes: 10 additions & 0 deletions .iwyu.imp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
{ "include": ["<bits/types/struct_tm.h>", "private", "<time.h>", "public"] },
{ "include": ["<bits/types/struct_FILE.h>", "private", "<stdio.h>", "public"] },

# Work around for ryml
{ "include": ["<c4/std/string.hpp>", "private", "<ryml_std.hpp>", "public"] },

{ "include": ["<c4/yml/node.hpp>", "private", "<ryml.hpp>", "public"] },
{ "include": ["<c4/yml/parse.hpp>", "private", "<ryml.hpp>", "public"] },
{ "include": ["<c4/yml/parse_engine.hpp>", "private", "<ryml.hpp>", "public"] },
{ "include": ["<c4/yml/tree.hpp>", "private", "<ryml.hpp>", "public"] },
{ "include": ["<c4/substr.hpp>", "private", "<ryml.hpp>", "public"] },
{ "include": ["<c4/substr_fwd.hpp>", "private", "<ryml.hpp>", "public"] },

# Local opentelemetry-cpp style

# We prefer to include <gtest/gtest.h> for simplicity
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ endif()
option(WITH_ABI_VERSION_1 "ABI version 1" ON)
option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF)

option(WITH_CONFIGURATION "EXPERIMENTAL: YAML configuration file" OFF)

file(READ "${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h"
OPENTELEMETRY_CPP_HEADER_VERSION_H)

Expand Down Expand Up @@ -507,6 +509,18 @@ if((NOT WITH_API_ONLY) AND USE_NLOHMANN_JSON)
include(cmake/nlohmann-json.cmake)
endif()

#
# Do we need RapidYaml ?
#

if((NOT WITH_API_ONLY) AND WITH_CONFIGURATION)
find_package(ryml 0.7.2 REQUIRED)
message(
STATUS
"Found ryml: include ${RYML_INCLUDE_DIR}, lib ${RYML_LIB_DIR}, version ${ryml_VERSION}"
)
endif()

if(OTELCPP_MAINTAINER_MODE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Building with gcc in maintainer mode.")
Expand Down
23 changes: 23 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,29 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then
eval "$MAKE_COMMAND"
make test
exit 0
elif [[ "$1" == "cmake.maintainer.yaml.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake "${CMAKE_OPTIONS[@]}" \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_FILE=ON \
-DWITH_PROMETHEUS=ON \
-DWITH_EXAMPLES=ON \
-DWITH_EXAMPLES_HTTP=ON \
-DWITH_ZIPKIN=ON \
-DBUILD_W3CTRACECONTEXT_TEST=ON \
-DWITH_ELASTICSEARCH=ON \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_ASYNC_EXPORT_PREVIEW=OFF \
-DOTELCPP_MAINTAINER_MODE=ON \
-DWITH_NO_DEPRECATED_CODE=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_CONFIGURATION=ON \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
exit 0
elif [[ "$1" == "cmake.with_async_export.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
Expand Down
32 changes: 32 additions & 0 deletions ci/install_ryml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

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

set -ex
export DEBIAN_FRONTEND=noninteractive
[ -z "${RYML_VERSION}" ] && export RYML_VERSION="v0.7.2"

BUILD_DIR=/tmp/
INSTALL_DIR=/usr/local/
pushd $BUILD_DIR
git clone --recursive -b ${RYML_VERSION} https://github.com/biojppm/rapidyaml.git

cd rapidyaml
RYML_BUILD_OPTIONS=(
"-DBUILD_TESTING=OFF"
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
"-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR"
)

if [ ! -z "${CXX_STANDARD}" ]; then
RYML_BUILD_OPTIONS=(${RYML_BUILD_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=${CXX_STANDARD}")
fi

mkdir build && pushd build
cmake "${RYML_BUILD_OPTIONS[@]}" ..
make -j $(nproc)
make install
popd
popd
export PATH=${INSTALL_DIR}/bin:$PATH # ensure to use the installed ryml
4 changes: 4 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ add_subdirectory(multi_processor)
if(WITH_EXAMPLES_HTTP)
add_subdirectory(http)
endif()

if(WITH_CONFIGURATION)
add_subdirectory(yaml)
endif()
59 changes: 59 additions & 0 deletions examples/yaml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

if(DEFINED OPENTELEMETRY_BUILD_DLL)
add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL)
endif()

include_directories(${CMAKE_SOURCE_DIR}/sdk/include)

add_executable(
example_yaml
main.cc
custom_sampler.cc
custom_sampler_builder.cc
custom_span_exporter.cc
custom_span_exporter_builder.cc
custom_span_processor.cc
custom_span_processor_builder.cc)

target_link_libraries(
example_yaml
${CMAKE_THREAD_LIBS_INIT}
common_metrics_foo_library
common_logs_foo_library
opentelemetry_exporter_ostream_span
opentelemetry_exporter_ostream_metrics
opentelemetry_exporter_ostream_logs)

if(WITH_OTLP_HTTP)
include_directories(${CMAKE_SOURCE_DIR}/exporters/otlp/include)
add_definitions(-DOTEL_HAVE_OTLP_HTTP)
target_link_libraries(example_yaml opentelemetry_otlp_http_builder)
endif()

if(WITH_OTLP_GRPC)
include_directories(${CMAKE_SOURCE_DIR}/exporters/otlp/include)
add_definitions(-DOTEL_HAVE_OTLP_GRPC)
target_link_libraries(example_yaml opentelemetry_otlp_grpc_builder)
endif()

if(WITH_ZIPKIN)
include_directories(${CMAKE_SOURCE_DIR}/exporters/zipkin/include)
add_definitions(-DOTEL_HAVE_ZIPKIN)
target_link_libraries(example_yaml opentelemetry_exporter_zipkin_trace)
endif()

if(WITH_PROMETHEUS)
include_directories(${CMAKE_SOURCE_DIR}/exporters/prometheus/include)
add_definitions(-DOTEL_HAVE_PROMETHEUS)
target_link_libraries(example_yaml opentelemetry_exporter_prometheus)
endif()

if(DEFINED OPENTELEMETRY_BUILD_DLL)
target_link_libraries(example_yaml opentelemetry_cpp)
else()
target_link_libraries(
example_yaml opentelemetry_configuration opentelemetry_init
opentelemetry_common opentelemetry_trace opentelemetry_logs)
endif()
45 changes: 45 additions & 0 deletions examples/yaml/anchors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

# anchors.yaml demonstrates anchor substitution to reuse OTLP exporter configuration across signals.

file_format: "0.1"
exporters:
otlp: &otlp-exporter
protocol: http/protobuf
endpoint: http://localhost:4318
certificate: /app/cert.pem
client_key: /app/cert.pem
client_certificate: /app/cert.pem
headers:
api-key: !!str 1234
compression: gzip
timeout: 10000

logger_provider:
processors:
- batch:
exporter:
otlp:
# expand the otlp-exporter anchor
<<: *otlp-exporter

meter_provider:
readers:
- periodic:
interval: 5000
timeout: 30000
exporter:
otlp:
# expand the otlp-exporter anchor and add metric specific configuration
<<: *otlp-exporter
temporality_preference: delta
default_histogram_aggregation: base2_exponential_bucket_histogram

tracer_provider:
processors:
- batch:
exporter:
otlp:
# expand the otlp-exporter anchor
<<: *otlp-exporter
36 changes: 36 additions & 0 deletions examples/yaml/custom_sampler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <map>
#include <memory>

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/trace/span_context.h"
#include "opentelemetry/trace/trace_state.h"

#include "custom_sampler.h"

opentelemetry::sdk::trace::SamplingResult CustomSampler::ShouldSample(
const opentelemetry::trace::SpanContext &parent_context,
opentelemetry::trace::TraceId /* trace_id */,
opentelemetry::nostd::string_view /* name */,
opentelemetry::trace::SpanKind /* span_kind */,
const opentelemetry::common::KeyValueIterable & /* attributes */,
const opentelemetry::trace::SpanContextKeyValueIterable & /* links */) noexcept
{
if (!parent_context.IsValid())
{
return {opentelemetry::sdk::trace::Decision::RECORD_AND_SAMPLE, nullptr,
opentelemetry::trace::TraceState::GetDefault()};
}
else
{
return {opentelemetry::sdk::trace::Decision::RECORD_AND_SAMPLE, nullptr,
parent_context.trace_state()};
}
}

opentelemetry::nostd::string_view CustomSampler::GetDescription() const noexcept
{
return "CustomSampler";
}
31 changes: 31 additions & 0 deletions examples/yaml/custom_sampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <string>

#include "opentelemetry/common/key_value_iterable.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/trace/sampler.h"
#include "opentelemetry/trace/span_context.h"
#include "opentelemetry/trace/span_context_kv_iterable.h"
#include "opentelemetry/trace/span_metadata.h"
#include "opentelemetry/trace/trace_id.h"

class CustomSampler : public opentelemetry::sdk::trace::Sampler
{
public:
CustomSampler(const std::string & /* comment */) {}
~CustomSampler() override = default;

opentelemetry::sdk::trace::SamplingResult ShouldSample(
const opentelemetry::trace::SpanContext &parent_context,
opentelemetry::trace::TraceId trace_id,
opentelemetry::nostd::string_view name,
opentelemetry::trace::SpanKind span_kind,
const opentelemetry::common::KeyValueIterable &attributes,
const opentelemetry::trace::SpanContextKeyValueIterable &links) noexcept override;

opentelemetry::nostd::string_view GetDescription() const noexcept override;
};
28 changes: 28 additions & 0 deletions examples/yaml/custom_sampler_builder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <string>

#include "opentelemetry/sdk/configuration/document_node.h"
#include "opentelemetry/sdk/init/registry.h"

#include "custom_sampler.h"
#include "custom_sampler_builder.h"

std::unique_ptr<opentelemetry::sdk::trace::Sampler> CustomSamplerBuilder::Build(
const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration *model) const
{
// Read yaml attributes
std::string comment = model->node->GetRequiredString("comment");

std::unique_ptr<opentelemetry::sdk::trace::Sampler> sdk(new CustomSampler(comment));

return sdk;
}

static CustomSamplerBuilder singleton;

void CustomSamplerBuilder::Register(opentelemetry::sdk::init::Registry *registry)
{
registry->AddExtensionSamplerBuilder("my_custom_sampler", &singleton);
}
Loading
Loading