66#include " trace_context.hpp"
77#include " batch_exporter.hpp"
88
9+ #include < fstream>
10+
911extern ngx_module_t gHttpModule ;
1012
1113namespace {
@@ -26,6 +28,8 @@ struct MainConfBase {
2628
2729struct MainConf : MainConfBase {
2830 std::map<StrView, StrView> resourceAttrs;
31+ bool ssl;
32+ std::string trustedCert;
2933};
3034
3135struct SpanAttr {
@@ -44,6 +48,7 @@ struct LocationConf {
4448char * setExporter (ngx_conf_t * cf, ngx_command_t * cmd, void * conf);
4549char * addResourceAttr (ngx_conf_t * cf, ngx_command_t * cmd, void * conf);
4650char * addSpanAttr (ngx_conf_t * cf, ngx_command_t * cmd, void * conf);
51+ char * setTrustedCertificate (ngx_conf_t * cf, ngx_command_t * cmd, void * conf);
4752
4853namespace Propagation {
4954
@@ -111,6 +116,10 @@ ngx_command_t gExporterCommands[] = {
111116 0 ,
112117 offsetof (MainConfBase, endpoint) },
113118
119+ { ngx_string (" trusted_certificate" ),
120+ NGX_CONF_TAKE1,
121+ setTrustedCertificate },
122+
114123 { ngx_string (" interval" ),
115124 NGX_CONF_TAKE1,
116125 ngx_conf_set_msec_slot,
@@ -569,6 +578,8 @@ ngx_int_t initWorkerProcess(ngx_cycle_t* cycle)
569578 try {
570579 gExporter .reset (new BatchExporter (
571580 toStrView (mcf->endpoint ),
581+ mcf->ssl ,
582+ mcf->trustedCert ,
572583 mcf->batchSize ,
573584 mcf->batchCount ,
574585 mcf->resourceAttrs ));
@@ -671,9 +682,7 @@ char* setExporter(ngx_conf_t* cf, ngx_command_t* cmd, void* conf)
671682 }
672683
673684 if (iremovePrefix (&mcf->endpoint , " https://" )) {
674- ngx_conf_log_error (NGX_LOG_EMERG, cf, 0 ,
675- " \" otel_exporter\" doesn't support \" https\" endpoints" );
676- return (char *)NGX_CONF_ERROR;
685+ mcf->ssl = true ;
677686 } else {
678687 iremovePrefix (&mcf->endpoint , " http://" );
679688 }
@@ -702,6 +711,36 @@ char* addResourceAttr(ngx_conf_t* cf, ngx_command_t* cmd, void* conf)
702711 return NGX_CONF_OK;
703712}
704713
714+ char * setTrustedCertificate (ngx_conf_t * cf, ngx_command_t * cmd, void * conf) {
715+ auto path = ((ngx_str_t *)cf->args ->elts )[1 ];
716+ auto mcf = getMainConf (cf);
717+
718+ if (ngx_get_full_name (cf->pool , &cf->cycle ->conf_prefix , &path) != NGX_OK) {
719+ return (char *)NGX_CONF_ERROR;
720+ }
721+
722+ try {
723+ std::ifstream file{(const char *)path.data , std::ios::binary};
724+ if (!file.is_open ()) {
725+ ngx_conf_log_error (NGX_LOG_EMERG, cf, ngx_errno,
726+ " failed to open \" %V\" " , &path);
727+ return (char *)NGX_CONF_ERROR;
728+ }
729+ file.exceptions (std::ios::failbit | std::ios::badbit);
730+ file.seekg (0 , std::ios::end);
731+ size_t size = file.tellg ();
732+ mcf->trustedCert .resize (size);
733+ file.seekg (0 );
734+ file.read (&mcf->trustedCert [0 ], mcf->trustedCert .size ());
735+ } catch (const std::exception& e) {
736+ ngx_conf_log_error (NGX_LOG_EMERG, cf, 0 ,
737+ " failed to read \" %V\" : %s" , &path, e.what ());
738+ return (char *)NGX_CONF_ERROR;
739+ }
740+
741+ return NGX_CONF_OK;
742+ }
743+
705744void * createMainConf (ngx_conf_t * cf)
706745{
707746 auto cln = ngx_pool_cleanup_add (cf->pool , sizeof (MainConf));
0 commit comments