Line data Source code
1 : #include "source/extensions/tracers/xray/config.h" 2 : 3 : #include <string> 4 : 5 : #include "envoy/config/core/v3/address.pb.h" 6 : #include "envoy/config/trace/v3/xray.pb.h" 7 : #include "envoy/config/trace/v3/xray.pb.validate.h" 8 : #include "envoy/registry/registry.h" 9 : 10 : #include "source/common/common/utility.h" 11 : #include "source/common/config/datasource.h" 12 : #include "source/extensions/tracers/xray/xray_tracer_impl.h" 13 : 14 : namespace Envoy { 15 : namespace Extensions { 16 : namespace Tracers { 17 : namespace XRay { 18 : 19 2 : XRayTracerFactory::XRayTracerFactory() : FactoryBase("envoy.tracers.xray") {} 20 : 21 : Tracing::DriverSharedPtr 22 : XRayTracerFactory::createTracerDriverTyped(const envoy::config::trace::v3::XRayConfig& proto_config, 23 0 : Server::Configuration::TracerFactoryContext& context) { 24 0 : std::string sampling_rules_json; 25 0 : TRY_NEEDS_AUDIT { 26 0 : sampling_rules_json = Config::DataSource::read(proto_config.sampling_rule_manifest(), true, 27 0 : context.serverFactoryContext().api()); 28 0 : } 29 0 : END_TRY catch (EnvoyException& e) { 30 0 : ENVOY_LOG(error, "Failed to read sampling rules manifest because of {}.", e.what()); 31 0 : } 32 : 33 0 : if (proto_config.daemon_endpoint().protocol() != envoy::config::core::v3::SocketAddress::UDP) { 34 0 : throw EnvoyException("X-Ray daemon endpoint must be a UDP socket address"); 35 0 : } 36 : 37 0 : if (proto_config.daemon_endpoint().port_specifier_case() != 38 0 : envoy::config::core::v3::SocketAddress::PortSpecifierCase::kPortValue) { 39 0 : throw EnvoyException("X-Ray daemon port must be specified as number. Not a named port."); 40 0 : } 41 : 42 0 : const std::string endpoint = fmt::format("{}:{}", proto_config.daemon_endpoint().address(), 43 0 : proto_config.daemon_endpoint().port_value()); 44 : 45 0 : auto aws = absl::flat_hash_map<std::string, ProtobufWkt::Value>{}; 46 0 : for (const auto& field : proto_config.segment_fields().aws().fields()) { 47 0 : aws.emplace(field.first, field.second); 48 0 : } 49 0 : const auto& origin = proto_config.segment_fields().origin(); 50 0 : XRayConfiguration xconfig{endpoint, proto_config.segment_name(), sampling_rules_json, origin, 51 0 : std::move(aws)}; 52 : 53 0 : return std::make_shared<XRay::Driver>(xconfig, context); 54 0 : } 55 : 56 : /** 57 : * Static registration for the XRay tracer. @see RegisterFactory. 58 : */ 59 : REGISTER_FACTORY(XRayTracerFactory, Server::Configuration::TracerFactory); 60 : 61 : } // namespace XRay 62 : } // namespace Tracers 63 : } // namespace Extensions 64 : } // namespace Envoy