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

[Code health] include-what-you-use cleanup, part 2 #2704

Merged
merged 20 commits into from
Jul 6, 2024
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 .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ jobs:
TOPDIR=`pwd`
mkdir build && cd build
CC="clang" CXX="clang++" cmake \
-DCMAKE_CXX_STANDARD=14 \
-DWITH_STL=CXX14 \
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \
-DBUILD_TESTING=OFF \
-DWITH_DEPRECATED_SDK_FACTORY=OFF \
-DBUILD_W3CTRACECONTEXT_TEST=OFF \
-DWITH_OTLP_GRPC=OFF \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_FILE=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_ZIPKIN=ON \
-DWITH_PROMETHEUS=OFF \
..

- name: iwyu_tool
Expand Down
4 changes: 3 additions & 1 deletion api/include/opentelemetry/std/shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#pragma once

#include <memory>
// IWYU pragma: private, include "opentelemetry/nostd/shared_ptr.h"

#include <memory> // IWYU pragma: export

#include "opentelemetry/version.h"

Expand Down
2 changes: 2 additions & 0 deletions api/include/opentelemetry/std/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

// IWYU pragma: private, include "opentelemetry/nostd/span.h"

#include "opentelemetry/version.h"

// Standard library implementation requires at least C++17 compiler.
Expand Down
2 changes: 2 additions & 0 deletions api/include/opentelemetry/std/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

// IWYU pragma: private, include "opentelemetry/nostd/string_view.h"

#include <string_view>

#include "opentelemetry/version.h"
Expand Down
2 changes: 2 additions & 0 deletions api/include/opentelemetry/std/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

// IWYU pragma: private, include "opentelemetry/nostd/type_traits.h"

#include <type_traits>

#include "opentelemetry/version.h"
Expand Down
4 changes: 3 additions & 1 deletion api/include/opentelemetry/std/unique_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#pragma once

#include <memory>
// IWYU pragma: private, include "opentelemetry/nostd/unique_ptr.h"

#include <memory> // IWYU pragma: export

#include "opentelemetry/version.h"

Expand Down
2 changes: 2 additions & 0 deletions api/include/opentelemetry/std/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

// IWYU pragma: private, include "opentelemetry/nostd/utility.h"

#include <cstddef>
#include <utility>

Expand Down
2 changes: 2 additions & 0 deletions api/include/opentelemetry/std/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

// IWYU pragma: private, include "opentelemetry/nostd/variant.h"

#include "opentelemetry/version.h"

#include <cstddef>
Expand Down
6 changes: 6 additions & 0 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ add_library(
${LOGS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_PB_CPP_FILE})

# Disable include-what-you-use on generated code.
set_target_properties(
opentelemetry_proto
PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ""
)

if(WITH_ABSEIL)
target_link_libraries(opentelemetry_proto PUBLIC absl::bad_variant_access)
endif()
Expand Down
5 changes: 1 addition & 4 deletions examples/batch/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
#include <stdio.h>
#include <chrono>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <utility>

#include "opentelemetry/exporters/ostream/span_exporter_factory.h"
#include "opentelemetry/nostd/detail/decay.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/sdk/trace/batch_span_processor_factory.h"
Expand All @@ -30,7 +28,6 @@ namespace trace_api = opentelemetry::trace;
namespace resource = opentelemetry::sdk::resource;
namespace trace_sdk = opentelemetry::sdk::trace;
namespace trace_exporter = opentelemetry::exporter::trace;
namespace nostd = opentelemetry::nostd;

namespace
{
Expand Down Expand Up @@ -69,7 +66,7 @@ void CleanupTracer()
trace_api::Provider::SetTracerProvider(none);
}

nostd::shared_ptr<trace_api::Tracer> get_tracer()
opentelemetry::nostd::shared_ptr<trace_api::Tracer> get_tracer()
{
auto provider = trace_api::Provider::GetTracerProvider();
return provider->GetTracer("foo_library");
Expand Down
1 change: 0 additions & 1 deletion examples/common/foo_library/foo_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "opentelemetry/context/context_value.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/sdk/version/version.h"
#include "opentelemetry/trace/provider.h"
#include "opentelemetry/trace/scope.h"
Expand Down
5 changes: 2 additions & 3 deletions examples/common/logs_foo_library/foo_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@

namespace logs = opentelemetry::logs;
namespace trace = opentelemetry::trace;
namespace nostd = opentelemetry::nostd;

namespace
{
nostd::shared_ptr<trace::Tracer> get_tracer()
opentelemetry::nostd::shared_ptr<trace::Tracer> get_tracer()
{
auto provider = trace::Provider::GetTracerProvider();
return provider->GetTracer("foo_library", OPENTELEMETRY_SDK_VERSION);
}

nostd::shared_ptr<logs::Logger> get_logger()
opentelemetry::nostd::shared_ptr<logs::Logger> get_logger()
{
auto provider = logs::Provider::GetLoggerProvider();
return provider->GetLogger("foo_library_logger", "foo_library");
Expand Down
36 changes: 19 additions & 17 deletions examples/common/metrics_foo_library/foo_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/metrics/observer_result.h"
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/metrics/sync_instruments.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/nostd/variant.h"

namespace nostd = opentelemetry::nostd;
namespace metrics_api = opentelemetry::metrics;

namespace
{

static nostd::shared_ptr<metrics_api::ObservableInstrument> double_observable_counter;
static opentelemetry::nostd::shared_ptr<metrics_api::ObservableInstrument>
double_observable_counter;

std::map<std::string, std::string> get_random_attr()
{
Expand All @@ -45,13 +45,15 @@ class MeasurementFetcher
public:
static void Fetcher(opentelemetry::metrics::ObserverResult observer_result, void * /* state */)
{
if (nostd::holds_alternative<
nostd::shared_ptr<opentelemetry::metrics::ObserverResultT<double>>>(observer_result))
if (opentelemetry::nostd::holds_alternative<
opentelemetry::nostd::shared_ptr<opentelemetry::metrics::ObserverResultT<double>>>(
observer_result))
{
double random_incr = (rand() % 5) + 1.1;
value_ += random_incr;
std::map<std::string, std::string> labels = get_random_attr();
nostd::get<nostd::shared_ptr<opentelemetry::metrics::ObserverResultT<double>>>(
opentelemetry::nostd::get<
opentelemetry::nostd::shared_ptr<opentelemetry::metrics::ObserverResultT<double>>>(
observer_result)
->Observe(value_, labels);
}
Expand All @@ -63,10 +65,10 @@ double MeasurementFetcher::value_ = 0.0;

void foo_library::counter_example(const std::string &name)
{
std::string counter_name = name + "_counter";
auto provider = metrics_api::Provider::GetMeterProvider();
nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
auto double_counter = meter->CreateDoubleCounter(counter_name);
std::string counter_name = name + "_counter";
auto provider = metrics_api::Provider::GetMeterProvider();
opentelemetry::nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
auto double_counter = meter->CreateDoubleCounter(counter_name);

for (uint32_t i = 0; i < 20; ++i)
{
Expand All @@ -78,10 +80,10 @@ void foo_library::counter_example(const std::string &name)

void foo_library::observable_counter_example(const std::string &name)
{
std::string counter_name = name + "_observable_counter";
auto provider = metrics_api::Provider::GetMeterProvider();
nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
double_observable_counter = meter->CreateDoubleObservableCounter(counter_name);
std::string counter_name = name + "_observable_counter";
auto provider = metrics_api::Provider::GetMeterProvider();
opentelemetry::nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
double_observable_counter = meter->CreateDoubleObservableCounter(counter_name);
double_observable_counter->AddCallback(MeasurementFetcher::Fetcher, nullptr);
for (uint32_t i = 0; i < 20; ++i)
{
Expand All @@ -91,9 +93,9 @@ void foo_library::observable_counter_example(const std::string &name)

void foo_library::histogram_example(const std::string &name)
{
std::string histogram_name = name + "_histogram";
auto provider = metrics_api::Provider::GetMeterProvider();
nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
std::string histogram_name = name + "_histogram";
auto provider = metrics_api::Provider::GetMeterProvider();
opentelemetry::nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
auto histogram_counter = meter->CreateDoubleHistogram(histogram_name, "des", "unit");
auto context = opentelemetry::context::Context{};
for (uint32_t i = 0; i < 20; ++i)
Expand Down
5 changes: 1 addition & 4 deletions examples/multithreaded/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

#include <algorithm>
#include <memory>
#include <string>
#include <thread>
#include <utility>
#include <vector>

#include "opentelemetry/exporters/ostream/span_exporter_factory.h"
#include "opentelemetry/nostd/detail/decay.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/sdk/trace/processor.h"
Expand All @@ -25,7 +23,6 @@

namespace trace_api = opentelemetry::trace;
namespace trace_sdk = opentelemetry::sdk::trace;
namespace nostd = opentelemetry::nostd;

namespace
{
Expand All @@ -46,7 +43,7 @@ void CleanupTracer()
trace_api::Provider::SetTracerProvider(none);
}

nostd::shared_ptr<trace_api::Tracer> get_tracer()
opentelemetry::nostd::shared_ptr<trace_api::Tracer> get_tracer()
{
auto provider = trace_api::Provider::GetTracerProvider();
return provider->GetTracer("foo_library");
Expand Down
19 changes: 12 additions & 7 deletions examples/otlp/file_log_main.cc
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <functional>
#include <iostream>
#include <string>
#include <utility>

#include "opentelemetry/exporters/otlp/otlp_file_client_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h"
#include "opentelemetry/logs/log_record.h"
#include "opentelemetry/logs/logger_provider.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/logs/logger_provider.h"
#include "opentelemetry/sdk/logs/logger_provider_factory.h"
#include "opentelemetry/sdk/logs/processor.h"
#include "opentelemetry/sdk/logs/recordable.h"
#include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/recordable.h"
#include "opentelemetry/sdk/trace/simple_processor_factory.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/sdk/trace/tracer_provider_factory.h"
#include "opentelemetry/trace/provider.h"

#include <iostream>
#include <string>
#include <utility>
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/tracer_provider.h"

#ifdef BAZEL_BUILD
# include "examples/common/logs_foo_library/foo_library.h"
Expand Down
13 changes: 9 additions & 4 deletions examples/otlp/file_main.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <memory>
#include <string>
#include <utility>

#include "opentelemetry/exporters/otlp/otlp_file_client_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/recordable.h"
#include "opentelemetry/sdk/trace/simple_processor_factory.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/sdk/trace/tracer_provider_factory.h"
#include "opentelemetry/trace/provider.h"

#include <iostream>
#include <string>
#include <utility>
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/tracer_provider.h"

#ifdef BAZEL_BUILD
# include "examples/common/foo_library/foo_library.h"
Expand Down
25 changes: 15 additions & 10 deletions examples/otlp/file_metric_main.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <chrono>
#include <memory>
#include <string>
#include <thread>
#include <utility>

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/exporters/otlp/otlp_file_client_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h"
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h"
#include "opentelemetry/sdk/metrics/meter.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h"
#include "opentelemetry/sdk/metrics/meter_context.h"
#include "opentelemetry/sdk/metrics/meter_context_factory.h"
#include "opentelemetry/sdk/metrics/meter_provider.h"
#include "opentelemetry/sdk/metrics/meter_provider_factory.h"

#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <utility>
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h"

#ifdef BAZEL_BUILD
# include "examples/common/metrics_foo_library/foo_library.h"
Expand Down
Loading