1
#include "source/extensions/tracers/opentelemetry/samplers/cel/config.h"
2

            
3
#include <memory>
4

            
5
#include "envoy/extensions/tracers/opentelemetry/samplers/v3/cel_sampler.pb.validate.h"
6

            
7
#include "source/common/config/utility.h"
8
#include "source/common/protobuf/utility.h"
9
#include "source/extensions/tracers/opentelemetry/samplers/cel/cel_sampler.h"
10

            
11
namespace Envoy {
12
namespace Extensions {
13
namespace Tracers {
14
namespace OpenTelemetry {
15

            
16
SamplerSharedPtr
17
CELSamplerFactory::createSampler(const Protobuf::Message& config,
18
16
                                 Server::Configuration::TracerFactoryContext& context) {
19
16
  auto mptr = Envoy::Config::Utility::translateAnyToFactoryConfig(
20
16
      dynamic_cast<const Protobuf::Any&>(config), context.messageValidationVisitor(), *this);
21

            
22
16
  const auto& proto_config = MessageUtil::downcastAndValidate<
23
16
      const envoy::extensions::tracers::opentelemetry::samplers::v3::CELSamplerConfig&>(
24
16
      *mptr, context.messageValidationVisitor());
25

            
26
16
  return std::make_unique<CELSampler>(
27
16
      context.serverFactoryContext().localInfo(),
28
16
      Extensions::Filters::Common::Expr::getBuilder(context.serverFactoryContext()),
29
16
      proto_config.expression());
30
16
}
31

            
32
/**
33
 * Static registration for the Env sampler factory. @see RegisterFactory.
34
 */
35
REGISTER_FACTORY(CELSamplerFactory, SamplerFactory);
36

            
37
} // namespace OpenTelemetry
38
} // namespace Tracers
39
} // namespace Extensions
40
} // namespace Envoy