Skip to content

Commit

Permalink
Replace typedef with type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 committed Nov 15, 2024
1 parent e02d1c5 commit a8a04e5
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include <functional>
#include <string>
#include <type_traits>

Expand Down Expand Up @@ -158,6 +159,8 @@ class InstrumentationScope
InstrumentationScopeAttributes attributes_;
};

template <class T>
using ScopeConfigurator = std::function<T(const InstrumentationScope &)>;
} // namespace instrumentationscope
} // namespace sdk

Expand Down
10 changes: 2 additions & 8 deletions sdk/include/opentelemetry/sdk/trace/tracer_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#pragma once

#include <functional>
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/version.h"

Expand All @@ -12,11 +11,6 @@ namespace sdk
{
namespace trace
{
// Forward declaration to support typedef creation
class TracerConfig;

typedef std::function<TracerConfig(const instrumentationscope::InstrumentationScope &)>
TracerConfigurator;
/**
* TracerConfig defines various configurable aspects of a Tracer's behavior.
*/
Expand All @@ -33,14 +27,14 @@ class TracerConfig
static TracerConfig Disabled();
static TracerConfig Enabled();
static TracerConfig Default();
static const TracerConfigurator &DefaultConfigurator();
static const instrumentationscope::ScopeConfigurator<TracerConfig> &DefaultConfigurator();

private:
explicit TracerConfig(const bool disabled = false) : disabled_(disabled) {}
bool disabled_;
static const TracerConfig kDefaultConfig;
static const TracerConfig kDisabledConfig;
static const TracerConfigurator kDefaultTracerConfigurator;
static const instrumentationscope::ScopeConfigurator<TracerConfig> kDefaultTracerConfigurator;
};
} // namespace trace
} // namespace sdk
Expand Down
9 changes: 5 additions & 4 deletions sdk/include/opentelemetry/sdk/trace/tracer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class TracerContext
std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
std::unique_ptr<IdGenerator> id_generator =
std::unique_ptr<IdGenerator>(new RandomIdGenerator()),
std::unique_ptr<TracerConfigurator> tracer_configurator =
std::make_unique<TracerConfigurator>(TracerConfig::DefaultConfigurator())) noexcept;
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator =
std::make_unique<instrumentationscope::ScopeConfigurator<TracerConfig>>(
TracerConfig::DefaultConfigurator())) noexcept;

virtual ~TracerContext() = default;

Expand Down Expand Up @@ -82,7 +83,7 @@ class TracerContext
*/
const opentelemetry::sdk::resource::Resource &GetResource() const noexcept;

TracerConfigurator &GetTracerConfigurator() const noexcept;
instrumentationscope::ScopeConfigurator<TracerConfig> &GetTracerConfigurator() const noexcept;

/**
* Obtain the Id Generator associated with this tracer context.
Expand All @@ -107,7 +108,7 @@ class TracerContext
std::unique_ptr<Sampler> sampler_;
std::unique_ptr<IdGenerator> id_generator_;
std::unique_ptr<SpanProcessor> processor_;
std::unique_ptr<TracerConfigurator> tracer_configurator_;
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator_;
};

} // namespace trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class OPENTELEMETRY_EXPORT TracerContextFactory
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<TracerConfigurator> tracer_configurator);
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator);
};

} // namespace trace
Expand Down
10 changes: 6 additions & 4 deletions sdk/include/opentelemetry/sdk/trace/tracer_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class OPENTELEMETRY_EXPORT TracerProvider final : public opentelemetry::trace::T
std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
std::unique_ptr<IdGenerator> id_generator =
std::unique_ptr<IdGenerator>(new RandomIdGenerator()),
std::unique_ptr<TracerConfigurator> tracer_configurator =
std::make_unique<TracerConfigurator>(TracerConfig::DefaultConfigurator())) noexcept;
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator =
std::make_unique<instrumentationscope::ScopeConfigurator<TracerConfig>>(
TracerConfig::DefaultConfigurator())) noexcept;

explicit TracerProvider(
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
Expand All @@ -61,8 +62,9 @@ class OPENTELEMETRY_EXPORT TracerProvider final : public opentelemetry::trace::T
std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler),
std::unique_ptr<IdGenerator> id_generator =
std::unique_ptr<IdGenerator>(new RandomIdGenerator()),
std::unique_ptr<TracerConfigurator> tracer_configurator =
std::make_unique<TracerConfigurator>(TracerConfig::DefaultConfigurator())) noexcept;
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator =
std::make_unique<instrumentationscope::ScopeConfigurator<TracerConfig>>(
TracerConfig::DefaultConfigurator())) noexcept;

/**
* Initialize a new tracer provider with a specified context
Expand Down
4 changes: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class OPENTELEMETRY_EXPORT TracerProviderFactory
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<TracerConfigurator> tracer_configurator);
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator);

/* Series of creator methods with a single processor. */

Expand All @@ -80,7 +80,7 @@ class OPENTELEMETRY_EXPORT TracerProviderFactory
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<TracerConfigurator> tracer_configurator);
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator);

/* Create with a tracer context. */

Expand Down
7 changes: 4 additions & 3 deletions sdk/src/trace/tracer_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ namespace trace
const TracerConfig TracerConfig::kDefaultConfig = TracerConfig();
const TracerConfig TracerConfig::kDisabledConfig = TracerConfig(true);

const TracerConfigurator TracerConfig::kDefaultTracerConfigurator =
[](const instrumentationscope::InstrumentationScope &) { return Default(); };
const instrumentationscope::ScopeConfigurator<TracerConfig>
TracerConfig::kDefaultTracerConfigurator =
[](const instrumentationscope::InstrumentationScope &) { return Default(); };

TracerConfig TracerConfig::Disabled()
{
Expand All @@ -31,7 +32,7 @@ TracerConfig TracerConfig::Default()
return kDefaultConfig;
}

const TracerConfigurator &TracerConfig::DefaultConfigurator()
const instrumentationscope::ScopeConfigurator<TracerConfig> &TracerConfig::DefaultConfigurator()
{
return kDefaultTracerConfigurator;
}
Expand Down
6 changes: 4 additions & 2 deletions sdk/src/trace/tracer_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ TracerContext::TracerContext(std::vector<std::unique_ptr<SpanProcessor>> &&proce
const resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<TracerConfigurator> tracer_configurator) noexcept
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>>
tracer_configurator) noexcept
: resource_(resource),
sampler_(std::move(sampler)),
id_generator_(std::move(id_generator)),
Expand All @@ -44,7 +45,8 @@ const resource::Resource &TracerContext::GetResource() const noexcept
return resource_;
}

TracerConfigurator &TracerContext::GetTracerConfigurator() const noexcept
instrumentationscope::ScopeConfigurator<TracerConfig> &TracerContext::GetTracerConfigurator()
const noexcept
{
return *tracer_configurator_;
}
Expand Down
5 changes: 3 additions & 2 deletions sdk/src/trace/tracer_context_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ std::unique_ptr<TracerContext> TracerContextFactory::Create(
std::unique_ptr<IdGenerator> id_generator)
{
auto tracer_configurator =
std::make_unique<TracerConfigurator>(TracerConfig::DefaultConfigurator());
std::make_unique<instrumentationscope::ScopeConfigurator<TracerConfig>>(
TracerConfig::DefaultConfigurator());
return Create(std::move(processors), resource, std::move(sampler), std::move(id_generator),
std::move(tracer_configurator));
}
Expand All @@ -63,7 +64,7 @@ std::unique_ptr<TracerContext> TracerContextFactory::Create(
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<TracerConfigurator> tracer_configurator)
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator)
{
std::unique_ptr<TracerContext> context(
new TracerContext(std::move(processors), resource, std::move(sampler),
Expand Down
24 changes: 14 additions & 10 deletions sdk/src/trace/tracer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ TracerProvider::TracerProvider(std::unique_ptr<TracerContext> context) noexcept
OTEL_INTERNAL_LOG_DEBUG("[TracerProvider] TracerProvider created.");
}

TracerProvider::TracerProvider(std::unique_ptr<SpanProcessor> processor,
const resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<TracerConfigurator> tracer_configurator) noexcept
TracerProvider::TracerProvider(
std::unique_ptr<SpanProcessor> processor,
const resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>>
tracer_configurator) noexcept
{
std::vector<std::unique_ptr<SpanProcessor>> processors;
processors.push_back(std::move(processor));
Expand All @@ -52,11 +54,13 @@ TracerProvider::TracerProvider(std::unique_ptr<SpanProcessor> processor,
std::move(id_generator), std::move(tracer_configurator));
}

TracerProvider::TracerProvider(std::vector<std::unique_ptr<SpanProcessor>> &&processors,
const resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<TracerConfigurator> tracer_configurator) noexcept
TracerProvider::TracerProvider(
std::vector<std::unique_ptr<SpanProcessor>> &&processors,
const resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>>
tracer_configurator) noexcept
{
context_ =
std::make_shared<TracerContext>(std::move(processors), resource, std::move(sampler),
Expand Down
10 changes: 6 additions & 4 deletions sdk/src/trace/tracer_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ std::unique_ptr<opentelemetry::sdk::trace::TracerProvider> TracerProviderFactory
std::unique_ptr<IdGenerator> id_generator)
{
auto tracer_configurator =
std::make_unique<TracerConfigurator>(TracerConfig::DefaultConfigurator());
std::make_unique<instrumentationscope::ScopeConfigurator<TracerConfig>>(
TracerConfig::DefaultConfigurator());
return Create(std::move(processor), resource, std::move(sampler), std::move(id_generator),
std::move(tracer_configurator));
}
Expand All @@ -64,7 +65,7 @@ std::unique_ptr<opentelemetry::sdk::trace::TracerProvider> TracerProviderFactory
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<TracerConfigurator> tracer_configurator)
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator)
{
std::unique_ptr<opentelemetry::sdk::trace::TracerProvider> provider(
new opentelemetry::sdk::trace::TracerProvider(std::move(processor), resource,
Expand Down Expand Up @@ -104,7 +105,8 @@ std::unique_ptr<opentelemetry::sdk::trace::TracerProvider> TracerProviderFactory
std::unique_ptr<IdGenerator> id_generator)
{
auto tracer_configurator =
std::make_unique<TracerConfigurator>(TracerConfig::DefaultConfigurator());
std::make_unique<instrumentationscope::ScopeConfigurator<TracerConfig>>(
TracerConfig::DefaultConfigurator());
return Create(std::move(processors), resource, std::move(sampler), std::move(id_generator),
std::move(tracer_configurator));
}
Expand All @@ -114,7 +116,7 @@ std::unique_ptr<opentelemetry::sdk::trace::TracerProvider> TracerProviderFactory
const opentelemetry::sdk::resource::Resource &resource,
std::unique_ptr<Sampler> sampler,
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<TracerConfigurator> tracer_configurator)
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator)
{
std::unique_ptr<opentelemetry::sdk::trace::TracerProvider> provider(
new opentelemetry::sdk::trace::TracerProvider(std::move(processors), resource,
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/trace/tracer_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DefaultTracerConfiguratorTestFixture
TEST_P(DefaultTracerConfiguratorTestFixture, VerifyDefaultConfiguratorBehavior)
{
instrumentation_scope::InstrumentationScope *scope = GetParam();
trace_sdk::TracerConfigurator default_configurator =
instrumentation_scope::ScopeConfigurator<trace_sdk::TracerConfig> default_configurator =
trace_sdk::TracerConfig::DefaultConfigurator();

ASSERT_EQ(default_configurator(*scope), trace_sdk::TracerConfig::Default());
Expand Down

0 comments on commit a8a04e5

Please sign in to comment.