Skip to content

Commit 04a8ddd

Browse files
authored
[CONFIGURATION] SDK default component builder libraries and example (#4367)
1 parent 768d04d commit 04a8ddd

53 files changed

Lines changed: 2201 additions & 591 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ Increment the:
168168

169169
Breaking changes:
170170

171+
* [CONFIGURATION] SDK default component builder libraries and example
172+
[#4367](https://github.com/open-telemetry/opentelemetry-cpp/pull/4367)
173+
* The declaritive configuration registry is now empty on construction and
174+
the default SDK component builders are provided optionally through
175+
the `opentelemetry-cpp::configuration_registry_factory` library and
176+
the `opentelemetry::sdk::configuration::RegistryFactory::Create()` method.
177+
171178
* [BUILD] Install an explicit list of ext headers instead of the whole
172179
directory
173180
[#4327](https://github.com/open-telemetry/opentelemetry-cpp/pull/4327)

‎examples/configuration/BUILD‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ cc_test(
4242
"//exporters/prometheus:prometheus_exporter_builder",
4343
"//sdk:headers",
4444
"//sdk/src/configuration",
45+
"//sdk/src/configuration:configuration_registry_factory",
4546
"//sdk/src/logs",
4647
"//sdk/src/metrics",
4748
"//sdk/src/trace",
@@ -72,6 +73,38 @@ cc_test(
7273
"//exporters/ostream:ostream_span_exporter_builder",
7374
"//sdk:headers",
7475
"//sdk/src/configuration",
76+
"//sdk/src/configuration:configuration_registry_factory",
77+
"//sdk/src/logs",
78+
"//sdk/src/metrics",
79+
"//sdk/src/trace",
80+
"@com_google_googletest//:gtest_main",
81+
],
82+
)
83+
84+
cc_test(
85+
name = "example_yaml_sdk_default",
86+
size = "medium",
87+
srcs = glob(["*.cc"]) + glob(["*.h"]),
88+
args = [
89+
"--test",
90+
"--yaml",
91+
"$(location sdk-default.yaml)",
92+
],
93+
data = ["sdk-default.yaml"],
94+
tags = [
95+
"test",
96+
"yaml",
97+
],
98+
deps = [
99+
"//api",
100+
"//examples/common/logs_foo_library:common_logs_foo_library",
101+
"//examples/common/metrics_foo_library:common_metrics_foo_library",
102+
"//exporters/ostream:ostream_log_record_exporter_builder",
103+
"//exporters/ostream:ostream_metric_exporter_builder",
104+
"//exporters/ostream:ostream_span_exporter_builder",
105+
"//sdk:headers",
106+
"//sdk/src/configuration",
107+
"//sdk/src/configuration:configuration_registry_factory",
75108
"//sdk/src/logs",
76109
"//sdk/src/metrics",
77110
"//sdk/src/trace",

‎examples/configuration/CMakeLists.txt‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ add_executable(
2222
target_link_libraries(
2323
example_yaml
2424
PRIVATE ${CMAKE_THREAD_LIBS_INIT}
25+
opentelemetry-cpp::configuration_registry_factory
26+
opentelemetry-cpp::configuration
2527
common_metrics_foo_library
2628
common_logs_foo_library
2729
opentelemetry-cpp::ostream_span_exporter_builder
@@ -61,18 +63,6 @@ if(WITH_PROMETHEUS)
6163
PRIVATE opentelemetry-cpp::prometheus_exporter_builder)
6264
endif()
6365

64-
if(DEFINED OPENTELEMETRY_BUILD_DLL)
65-
target_compile_definitions(example_yaml
66-
PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL)
67-
target_link_libraries(example_yaml
68-
PRIVATE opentelemetry-cpp::opentelemetry_cpp)
69-
else()
70-
target_link_libraries(
71-
example_yaml
72-
PRIVATE opentelemetry-cpp::configuration opentelemetry-cpp::common
73-
opentelemetry-cpp::trace opentelemetry-cpp::logs)
74-
endif()
75-
7666
if(BUILD_TESTING)
7767
if(WITH_OTLP_HTTP
7868
AND WITH_OTLP_GRPC
@@ -86,4 +76,8 @@ if(BUILD_TESTING)
8676
add_test(NAME examples.example_yaml_extensions
8777
COMMAND $<TARGET_FILE:example_yaml> --test --yaml
8878
${CMAKE_CURRENT_SOURCE_DIR}/extensions.yaml)
79+
80+
add_test(NAME examples.example_yaml_sdk_default
81+
COMMAND $<TARGET_FILE:example_yaml> --test --yaml
82+
${CMAKE_CURRENT_SOURCE_DIR}/sdk-default.yaml)
8983
endif()

‎examples/configuration/main.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "opentelemetry/sdk/configuration/configuration.h"
1515
#include "opentelemetry/sdk/configuration/configured_sdk.h"
1616
#include "opentelemetry/sdk/configuration/registry.h"
17+
#include "opentelemetry/sdk/configuration/registry_factory.h"
1718
#include "opentelemetry/sdk/configuration/yaml_configuration_parser.h"
1819

1920
#include "custom_log_record_exporter_builder.h"
@@ -166,7 +167,7 @@ void InitOtel(const std::string &config_file)
166167
/* 1 - Create a registry */
167168

168169
std::shared_ptr<opentelemetry::sdk::configuration::Registry> registry(
169-
new opentelemetry::sdk::configuration::Registry);
170+
opentelemetry::sdk::configuration::RegistryFactory::Create());
170171

171172
/* 2 - Populate the registry with the core components supported */
172173

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Exercises the built-in SDK component builders.
5+
#
6+
# The Registry provides one builder per SDK component type. Each builder constructs its component from the parsed configuration model.
7+
# RegistryFactory::Create() pre-loads all the SDK default builders shown in this file.
8+
# Call Set*Builder() on the Registry to swap in your own implementation before calling ConfiguredSdk::Create:
9+
#
10+
# auto registry = RegistryFactory::Create();
11+
# registry->SetBatchSpanProcessorBuilder(std::make_unique<MyBatchSpanProcessorBuilder>());
12+
# auto sdk = ConfiguredSdk::Create(registry, model);
13+
14+
file_format: "1.1"
15+
disabled: false
16+
17+
# --- Logs ---
18+
logger_provider:
19+
processors:
20+
- batch: # Registry::SetBatchLogRecordProcessorBuilder
21+
exporter:
22+
console: # Registry::SetConsoleLogRecordBuilder
23+
- simple: # Registry::SetSimpleLogRecordProcessorBuilder
24+
exporter:
25+
console: # Registry::SetConsoleLogRecordBuilder
26+
logger_configurator/development: # Registry::SetLoggerConfiguratorBuilder
27+
default_config:
28+
enabled: true
29+
30+
# --- Metrics ---
31+
meter_provider:
32+
readers:
33+
- periodic: # Registry::SetPeriodicMetricReaderBuilder
34+
exporter:
35+
console: # Registry::SetConsolePushMetricExporterBuilder
36+
meter_configurator/development: # Registry::SetMeterConfiguratorBuilder
37+
default_config:
38+
enabled: true
39+
40+
# --- Propagators ---
41+
propagator:
42+
composite:
43+
- tracecontext: # Registry::SetTextMapPropagatorBuilder("tracecontext")
44+
- baggage: # Registry::SetTextMapPropagatorBuilder("baggage")
45+
- b3: # Registry::SetTextMapPropagatorBuilder("b3")
46+
- b3multi: # Registry::SetTextMapPropagatorBuilder("b3multi")
47+
- jaeger: # Registry::SetTextMapPropagatorBuilder("jaeger")
48+
49+
# --- Traces ---
50+
tracer_provider:
51+
processors:
52+
- batch: # Registry::SetBatchSpanProcessorBuilder
53+
exporter:
54+
console: # Registry::SetConsoleSpanBuilder
55+
- simple: # Registry::SetSimpleSpanProcessorBuilder
56+
exporter:
57+
console: # Registry::SetConsoleSpanBuilder
58+
sampler: # See kitchen-sink.yaml for sampler field semantics.
59+
parent_based: # Registry::SetParentBasedSamplerBuilder
60+
root:
61+
composite/development:
62+
rule_based: # Registry::SetComposableRuleBasedSamplerBuilder
63+
rules:
64+
- span_kinds:
65+
- internal
66+
sampler:
67+
always_on: # Registry::SetComposableAlwaysOnSamplerBuilder
68+
- attribute_patterns:
69+
key: http.url
70+
included:
71+
- .*/health*
72+
excluded:
73+
- .*/healthz/live
74+
sampler:
75+
always_off: # Registry::SetComposableAlwaysOffSamplerBuilder
76+
- attribute_values:
77+
key: http.response.status_code
78+
values:
79+
- "500"
80+
- "503"
81+
sampler:
82+
always_on: # Registry::SetComposableAlwaysOnSamplerBuilder
83+
- span_kinds:
84+
- server
85+
- consumer
86+
parent:
87+
- none
88+
sampler:
89+
parent_threshold: # Registry::SetComposableParentThresholdSamplerBuilder
90+
root:
91+
probability: # Registry::SetComposableProbabilitySamplerBuilder
92+
ratio: 0.25
93+
- sampler:
94+
probability: # Registry::SetComposableProbabilitySamplerBuilder
95+
ratio: 0.01
96+
remote_parent_sampled:
97+
always_on: # Registry::SetAlwaysOnSamplerBuilder
98+
remote_parent_not_sampled:
99+
trace_id_ratio_based: # Registry::SetTraceIdRatioBasedSamplerBuilder
100+
ratio: 0.001
101+
local_parent_sampled:
102+
always_off: # Registry::SetAlwaysOffSamplerBuilder
103+
local_parent_not_sampled:
104+
probability/development: # Registry::SetProbabilitySamplerBuilder
105+
ratio: 0.001
106+
107+
tracer_configurator/development: # Registry::SetTracerConfiguratorBuilder
108+
default_config:
109+
enabled: false
110+
111+
resource:
112+
attributes:
113+
- name: service.name
114+
value: sdk-builtin-test
115+
detection/development:
116+
detectors:
117+
- container: # Registry::SetContainerResourceDetectorBuilder
118+
- host: # Registry::SetHostResourceDetectorBuilder
119+
- process: # Registry::SetProcessResourceDetectorBuilder
120+
- service: # Registry::SetServiceResourceDetectorBuilder

‎install/test/cmake/component_tests/configuration/CMakeLists.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ include(GoogleTest)
1717
add_executable(configuration_test ${INSTALL_TEST_SRC_DIR}/test_configuration.cc)
1818
target_link_libraries(
1919
configuration_test
20-
PRIVATE opentelemetry-cpp::configuration
20+
PRIVATE opentelemetry-cpp::configuration_registry_factory
21+
opentelemetry-cpp::configuration
2122
opentelemetry-cpp::ostream_log_record_exporter_builder
2223
opentelemetry-cpp::ostream_metrics_exporter_builder
2324
opentelemetry-cpp::ostream_span_exporter_builder

‎install/test/cmake/component_tests/sdk/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ target_link_libraries(
2525
opentelemetry-cpp::metrics
2626
opentelemetry-cpp::logs
2727
opentelemetry-cpp::configuration_core
28+
opentelemetry-cpp::configuration_trace_builders
29+
opentelemetry-cpp::configuration_metrics_builders
30+
opentelemetry-cpp::configuration_logs_builders
31+
opentelemetry-cpp::configuration_registry_factory
2832
GTest::gtest
2933
GTest::gtest_main)
3034

‎install/test/cmake/fetch_content_test/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ target_link_libraries(
7979
opentelemetry-cpp::trace
8080
opentelemetry-cpp::logs
8181
opentelemetry-cpp::configuration_core
82+
opentelemetry-cpp::configuration_trace_builders
83+
opentelemetry-cpp::configuration_metrics_builders
84+
opentelemetry-cpp::configuration_logs_builders
85+
opentelemetry-cpp::configuration_registry_factory
8286
opentelemetry-cpp::configuration
8387
opentelemetry-cpp::resource_detectors
8488
opentelemetry-cpp::http_client

‎install/test/src/test_configuration.cc‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
#include "opentelemetry/sdk/configuration/configuration.h"
1111
#include "opentelemetry/sdk/configuration/configured_sdk.h"
1212
#include "opentelemetry/sdk/configuration/registry.h"
13+
#include "opentelemetry/sdk/configuration/registry_factory.h"
1314
#include "opentelemetry/sdk/configuration/yaml_configuration_parser.h"
1415

1516
TEST(ConfigurationInstallTest, ConfigurationCheck)
1617
{
17-
std::shared_ptr<opentelemetry::sdk::configuration::Registry> registry(
18-
new opentelemetry::sdk::configuration::Registry);
18+
std::shared_ptr<opentelemetry::sdk::configuration::Registry> registry =
19+
opentelemetry::sdk::configuration::RegistryFactory::Create();
1920
EXPECT_NE(registry, nullptr);
2021

2122
opentelemetry::exporter::trace::ConsoleSpanBuilder::Register(registry.get());

0 commit comments

Comments
 (0)