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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Increment the:

## [Unreleased]

* [CONFIGURATION] Build the configured resource detectors in SdkBuilder, apply
the `detection.attributes` include/exclude filter to the detected attributes,
and merge the resource per the resource SDK specification.
[#4411](https://github.com/open-telemetry/opentelemetry-cpp/issues/4411)
* Behavior change: `SetResource` no longer runs `OTELResourceDetector` and no
longer injects a default `service.name`, since neither is part of the
configuration model. Use the `service` detector or set the attributes in
the configuration file instead.
* [CONFIGURATION] Add a resource detector extension example
[#4419](https://github.com/open-telemetry/opentelemetry-cpp/issues/4419)

Expand Down
1 change: 1 addition & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ elif [[ "$1" == "cmake.maintainer.yaml.test" ]]; then
-DWITH_OTLP_RETRY_PREVIEW=ON \
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
-DWITH_CONFIGURATION=ON \
-DWITH_RESOURCE_DETECTORS_PREVIEW=ON \
"${SRC_DIR}"
cmake --build . "${CMAKE_BUILD_ARGS[@]}"
ctest --output-on-failure
Expand Down
3 changes: 2 additions & 1 deletion examples/configuration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ if(BUILD_TESTING)
if(WITH_OTLP_HTTP
AND WITH_OTLP_GRPC
AND WITH_OTLP_FILE
AND WITH_PROMETHEUS)
AND WITH_PROMETHEUS
AND WITH_RESOURCE_DETECTORS_PREVIEW)
add_test(NAME examples.example_yaml_kitchen_sink
COMMAND $<TARGET_FILE:example_yaml> --test --yaml
${CMAKE_CURRENT_SOURCE_DIR}/kitchen-sink.yaml)
Expand Down
15 changes: 9 additions & 6 deletions examples/configuration/kitchen-sink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1057,17 +1057,20 @@ resource:
# Configure resource detectors.
# Resource detector names are dependent on the SDK language ecosystem. Please consult documentation for each respective language.
# If omitted or null, no resource detectors are enabled.
# A configured detector must have a builder registered in the Registry,
# or building the SDK fails. The detectors without a registered builder
# are commented out.
detectors:
- # Enable the container resource detector, which populates container.* attributes.
container:
- # Enable the host resource detector, which populates host.* and os.* attributes.
host:
# - # Enable the host resource detector, which populates host.* and os.* attributes.
# host:
- # Enable the process resource detector, which populates process.* attributes.
process:
- # Enable the service detector, which populates service.name based on the OTEL_SERVICE_NAME environment variable and service.instance.id.
service:
- # Enable an extension resource detector registered by name.
my_custom_detector:
# - # Enable the service detector, which populates service.name based on the OTEL_SERVICE_NAME environment variable and service.instance.id.
# service:
# - # Enable an extension resource detector registered by name.
# my_custom_detector:
# Configure resource schema URL.
# If omitted or null, no schema URL is used.
schema_url: https://opentelemetry.io/schemas/1.16.0
Expand Down
22 changes: 17 additions & 5 deletions examples/configuration/sdk-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,21 @@ resource:
attributes:
- name: service.name
value: sdk-builtin-test
attributes_list: "service.namespace=sdk-builtin-namespace,service.version=1.0.0"
schema_url: https://opentelemetry.io/schemas/1.16.0
# Exercise the detection node with just the sdk: the attribute filter is
# configured, and no detectors are enabled. A configured detector must have
# a builder registered in the Registry, or building the SDK fails. This
# example does not register the built-in detector builders, so the
# detectors below are commented out.
detection/development:
detectors:
- container: # Registry::SetContainerResourceDetectorBuilder
- host: # Registry::SetHostResourceDetectorBuilder
- process: # Registry::SetProcessResourceDetectorBuilder
- service: # Registry::SetServiceResourceDetectorBuilder
attributes:
included:
- "*"
excluded:
- process.command_args
# detectors:
# - container: # Registry::SetContainerResourceDetectorBuilder
# - host: # Registry::SetHostResourceDetectorBuilder
# - process: # Registry::SetProcessResourceDetectorBuilder
# - service: # Registry::SetServiceResourceDetectorBuilder
31 changes: 31 additions & 0 deletions sdk/include/opentelemetry/sdk/configuration/sdk_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
#include "opentelemetry/sdk/configuration/configured_sdk.h"
#include "opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/container_resource_detector_configuration.h"
#include "opentelemetry/sdk/configuration/double_array_attribute_value_configuration.h"
#include "opentelemetry/sdk/configuration/double_attribute_value_configuration.h"
#include "opentelemetry/sdk/configuration/explicit_bucket_histogram_aggregation_configuration.h"
#include "opentelemetry/sdk/configuration/extension_pull_metric_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/extension_push_metric_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/extension_resource_detector_configuration.h"
#include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/extension_span_processor_configuration.h"
#include "opentelemetry/sdk/configuration/host_resource_detector_configuration.h"
#include "opentelemetry/sdk/configuration/integer_array_attribute_value_configuration.h"
#include "opentelemetry/sdk/configuration/integer_attribute_value_configuration.h"
#include "opentelemetry/sdk/configuration/logger_configurator_configuration.h"
Expand All @@ -39,11 +42,15 @@
#include "opentelemetry/sdk/configuration/otlp_http_span_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h"
#include "opentelemetry/sdk/configuration/probability_sampler_configuration.h"
#include "opentelemetry/sdk/configuration/process_resource_detector_configuration.h"
#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/pull_metric_reader_configuration.h"
#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/registry.h"
#include "opentelemetry/sdk/configuration/resource_detection_configuration.h"
#include "opentelemetry/sdk/configuration/resource_detector_configuration.h"
#include "opentelemetry/sdk/configuration/service_resource_detector_configuration.h"
#include "opentelemetry/sdk/configuration/simple_span_processor_configuration.h"
#include "opentelemetry/sdk/configuration/span_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/string_array_attribute_value_configuration.h"
Expand All @@ -57,6 +64,7 @@
#include "opentelemetry/sdk/metrics/meter_config.h"
#include "opentelemetry/sdk/metrics/meter_provider.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/sdk/resource/resource_detector.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/sampler.h"
Expand Down Expand Up @@ -280,6 +288,29 @@ class SdkBuilder
const std::unique_ptr<opentelemetry::sdk::configuration::LoggerProviderConfiguration> &model,
const opentelemetry::sdk::resource::Resource &resource) const;

std::unique_ptr<opentelemetry::sdk::resource::ResourceDetector> CreateContainerResourceDetector(
const opentelemetry::sdk::configuration::ContainerResourceDetectorConfiguration *model) const;

std::unique_ptr<opentelemetry::sdk::resource::ResourceDetector> CreateHostResourceDetector(
const opentelemetry::sdk::configuration::HostResourceDetectorConfiguration *model) const;

std::unique_ptr<opentelemetry::sdk::resource::ResourceDetector> CreateProcessResourceDetector(
const opentelemetry::sdk::configuration::ProcessResourceDetectorConfiguration *model) const;

std::unique_ptr<opentelemetry::sdk::resource::ResourceDetector> CreateServiceResourceDetector(
const opentelemetry::sdk::configuration::ServiceResourceDetectorConfiguration *model) const;

std::unique_ptr<opentelemetry::sdk::resource::ResourceDetector> CreateExtensionResourceDetector(
const opentelemetry::sdk::configuration::ExtensionResourceDetectorConfiguration *model) const;

std::unique_ptr<opentelemetry::sdk::resource::ResourceDetector> CreateResourceDetector(
const std::unique_ptr<opentelemetry::sdk::configuration::ResourceDetectorConfiguration>
&model) const;

opentelemetry::sdk::resource::Resource CreateDetectedResource(
const std::unique_ptr<opentelemetry::sdk::configuration::ResourceDetectionConfiguration>
&model) const;

void SetResourceAttribute(
opentelemetry::sdk::resource::ResourceAttributes &resource_attributes,
const std::string &name,
Expand Down
Loading
Loading