Skip to content

Commit 715bab8

Browse files
gnm444DebajitDas
andauthored
Apache and Ngnix OtelExporterOtlpHeaders changes (#240)
* Apache OtelExporterHeaders changes commit -1 Apache OtelExporterHeaders changes commit -1 * Update ApacheConfig.cpp Added OTLP headers in getProcessConfig * OtelExportHeader config count changes config count added , env_config added * appd_set_otelExporterOtlpHeaders correction appd_set_otelExporterOtlpHeaders ApacheModuleOtelExporterHeaders are added * Changes related OTLP headers Added Tenant config changes * Merge conflicts resolved regarding appd namespace Merge conflicts resolved regarding appd namespace * updating comments updating comments * Removed space Removed extra space * headers variable is correctly added Added metadata asper the structure * Adding otlp headers Added Otlp headers instead of string * Correcting typo Correcting mistake in declaration * Export headers tokenization Export headers tokens parsing * Changes for tokenization Changes for tokenization * appd to otel name change appd to otel name change * appd to otel name change * appd name change appd name change * corrections in name space appd to otel * Ngnix changes for OTEL Http Headers Ngnix changes for OTEL Http Headers * Declaration of ngx_str_t ngx_str_t * Updating variable variable name * Disabling OTEL headers This is only for production not for dev * Review comments addressed Review comments added, name changes done * Review comments -2 Changes in naming * Api Utils change Changes in ApiUtils to read from env * Reverted unwanted space Reverted unwanted space in Integration test * Enabling the otel headers config Enabling the otel headers config * Checking for empty strings Empty headers * Disable OTLP headers Disable OTLP headers * Adding a check to fix IT Integration test * Reverting the check Reverting some changes * Initializaing the otelExporterEndpoint otelExporterEndpoint initialization * Updating README updated the new about the new directive ApacheModuleOtelExporterHeaders * Read me updated for OTEL exporter headers directive Added Read me info on OTEL exporter headers Co-authored-by: DEBAJIT DAS <[email protected]>
1 parent 5313411 commit 715bab8

File tree

14 files changed

+98
-4
lines changed

14 files changed

+98
-4
lines changed

instrumentation/otel-webserver-module/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Monitoring individual modules is crucial to the instrumentation of Apache web se
5858
|*ApacheModuleWebserverContext* | | OPTIONAL: Takes 3 values(space-seperated) ServiceName, ServiceNamespace and ServiceInstanceId|
5959
|*ApacheModuleSegmentType* | | OPTIONAL: Specify the string (FIRST/LAST/CUSTOM) to be filtered for Span Name Creation|
6060
|*ApacheModuleSegmentParameter* | | OPTIONAL: Specify the segment count or segment numbers that you want to display for Span Creation|
61+
|*ApacheModuleOtelExporterHeaders* | | OPTIONAL: OTEL Exporter header info or Metadata like API key for OTLP endpoint. a list of key value pairs, and these are expected to be represented in a format matching to the W3C Correlation-Context, except that additional semi-colon delimited metadata is not supported, i.e.: key1=value1,key2=value2. |
6162

6263
A sample configuration is mentioned in [opentelemetry_module.conf](https://github.com/cisco-open/otel-webserver-module/blob/main/opentelemetry_module.conf)
6364

@@ -174,6 +175,7 @@ Currently, Nginx Webserver module monitores some fixed set of modules, which get
174175
|*NginxModuleSegmentParameter* | | OPTIONAL: Specify the segment count or segment numbers that you want to display for Span Creation|
175176
|*NginxModuleRequestHeaders* | | OPTIONAL: Specify the request headers to be captured in the span attributes. The headers are Case-Sensitive and should be comma-separated. e.g.```NginxModuleRequestHeaders Accept-Charset,Accept-Encoding,User-Agent;```|
176177
|*NginxModuleResponseHeaders* | | OPTIONAL: Specify the response headers to be captured in the span attributes. The headers are Case-Sensitive and should be comma-separated. e.g.```NginxModuleResponseHeaders Content-Length,Content-Type;```|
178+
|*NginxModuleOtelExporterOtlpHeaders* | | OPTIONAL: OTEL exporter headers like Meta data related exposrted end point. a list of key value pairs, and these are expected to be represented in a format matching to the W3C Correlation-Context, except that additional semi-colon delimited metadata is not supported, i.e.: key1=value1,key2=value2.|
177179

178180
### Build and Installation
179181
#### Prerequisites

instrumentation/otel-webserver-module/conf/nginx/opentelemetry_module.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ NginxModuleEnabled ON;
22
#NginxModule Otel Exporter details
33
NginxModuleOtelSpanExporter otlp;
44
NginxModuleOtelExporterEndpoint docker.for.mac.localhost:4317;
5+
#NginxModuleOtelExporterOtlpHeaders Authorization=AuthorizationToken;
56
# SSL Certificates
67
#NginxModuleOtelSslEnabled ON
78
#NginxModuleOtelSslCertificatePath

instrumentation/otel-webserver-module/include/apache/ApacheConfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class otel_cfg
3939
const char* getOtelExporterEndpoint() { return otelExporterEndpoint; }
4040
int getOtelExporterEndpointInitialized() { return otelExporterEndpoint_initialized; }
4141

42+
const char* getOtelExporterOtlpHeaders() { return otelExporterOtlpHeaders; }
43+
int otelExporterOtlpHeadersInitialized() { return otelExporterOtlpHeaders_initialized; }
44+
4245
int getOtelSslEnabled() { return otelSslEnabled; }
4346
int getOtelSslEnabledInitialized() { return otelSslEnabled_initialized; }
4447

@@ -123,6 +126,9 @@ class otel_cfg
123126
const char *otelExporterEndpoint; // REQUIRED: Collector endpoint where the OpenTelemetry Exporter inside OTel SDK sends traces
124127
int otelExporterEndpoint_initialized;
125128

129+
const char *otelExporterOtlpHeaders; // OPTIONAL: AppDynamics Custom metadata for OTEL Exporter EX: OTEL_EXPORTER_OTLP_HEADERS="api-key=key,other-config-value=value"
130+
int otelExporterOtlpHeaders_initialized;
131+
126132
int otelSslEnabled; // OPTIONAL: Decision whether connection to the Exporter endpoint is secured
127133
int otelSslEnabled_initialized;
128134

@@ -224,6 +230,7 @@ class ApacheConfigHandlers
224230
static const char* otel_set_enabled(cmd_parms *cmd, void *conf, const char *arg);
225231
static const char* otel_set_otelExporterType(cmd_parms *cmd, void *conf, const char *arg);
226232
static const char* otel_set_otelExporterEndpoint(cmd_parms *cmd, void *conf, const char *arg);
233+
static const char* otel_set_otelExporterOtlpHeaders(cmd_parms *cmd, void *conf, const char *arg);
227234
static const char* otel_set_otelSslEnabled(cmd_parms *cmd, void *conf, const char *arg);
228235
static const char* otel_set_otelSslCertificatePath(cmd_parms *cmd, void *conf, const char *arg);
229236
static const char* otel_set_otelProcessorType(cmd_parms *cmd, void *conf, const char *arg);

instrumentation/otel-webserver-module/include/apache/ApacheHooks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ApacheHooks
3333
static const char* OTEL_INTERACTION_HANDLE_KEY;
3434
static const char* OTEL_REQ_HANDLE_KEY;
3535
static const int LOWEST_HTTP_ERROR_CODE = 400;
36+
static const int CONFIG_COUNT = 17; // Number of key value pairs in config
3637
static const std::initializer_list<const char*> httpHeaders;
3738
static void registerHooks(apr_pool_t *p);
3839

instrumentation/otel-webserver-module/include/core/api/OpentelemetrySdk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/* {{{ For API user: environment variables to specify Controller connectivity */
2828
#define OTEL_SDK_ENV_OTEL_EXPORTER_TYPE "OTEL_SDK_ENV_OTEL_EXPORTER_TYPE"
2929
#define OTEL_SDK_ENV_OTEL_EXPORTER_ENDPOINT "OTEL_SDK_ENV_OTEL_EXPORTER_ENDPOINT" /*required*/
30+
#define OTEL_SDK_ENV_OTEL_EXPORTER_OTLPHEADERS "OTEL_SDK_ENV_OTEL_EXPORTER_OTLPHEADERS" /*optional*/
3031
#define OTEL_SDK_ENV_OTEL_SSL_ENABLED "OTEL_SDK_ENV_OTEL_SSL_ENABLED" /*optional*/
3132
#define OTEL_SDK_ENV_OTEL_SSL_CERTIFICATE_PATH "OTEL_SDK_ENV_OTEL_SSL_CERTIFICATE_PATH" /*optional*/
3233
#define OTEL_SDK_ENV_OTEL_PROCESSOR_TYPE "OTEL_SDK_ENV_OTEL_PROCESSOR_TYPE"
@@ -53,6 +54,7 @@
5354
#define OTEL_SDK_ENV_SEGMENT_TYPE "OTEL_SDK_ENV_SEGMENT_TYPE"
5455
#define OTEL_SDK_ENV_SEGMENT_PARAMETER "OTEL_SDK_ENV_SEGMENT_PARAMETER"
5556

57+
5658
/* {{{ For API user: API User logger */
5759
#define OTEL_LOG_API_USER_LOGGER "api_user" /*logging at the level of sdk function call*/
5860
#define OTEL_LOG_API_LOGGER "api" /*logging at the level of sdk core functionality*/

instrumentation/otel-webserver-module/include/core/api/TenantConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class TenantConfig
4545
const std::string& getOtelLibraryVersion() const {return otelLibraryVersion;}
4646
const std::string& getOtelExporterType() const {return otelExporterType;}
4747
const std::string& getOtelExporterEndpoint() const {return otelExporterEndpoint;}
48+
const std::string& getOtelExporterOtlpHeaders() const {return otelExporterOtlpHeaders;}
4849
const std::string& getOtelProcessorType() const {return otelProcessorType;}
4950
const unsigned getOtelMaxQueueSize() const {return otelMaxQueueSize;}
5051
const unsigned getOtelScheduledDelayMillis() const {return otelScheduledDelayMillis;}
@@ -61,6 +62,7 @@ class TenantConfig
6162
void setServiceInstanceId(const std::string& serviceInstanceId) { this->serviceInstanceId = serviceInstanceId; }
6263
void setOtelExporterType(const std::string& otelExporterType) { this->otelExporterType = otelExporterType; }
6364
void setOtelExporterEndpoint(const std::string& otelExporterEndpoint) { this->otelExporterEndpoint = otelExporterEndpoint; }
65+
void setOtelExporterOtlpHeaders(const std::string& otelExporterOtlpHeaders) { this->otelExporterOtlpHeaders = otelExporterOtlpHeaders; }
6466
void setOtelProcessorType(const std::string& otelProcessorType) { this->otelProcessorType = otelProcessorType; }
6567
void setOtelMaxQueueSize(const unsigned int otelMaxQueueSize) { this->otelMaxQueueSize = otelMaxQueueSize; }
6668
void setOtelScheduledDelayMillis(const unsigned int otelScheduledDelayMillis) { this->otelScheduledDelayMillis = otelScheduledDelayMillis; }
@@ -80,6 +82,7 @@ class TenantConfig
8082

8183
std::string otelExporterType;
8284
std::string otelExporterEndpoint;
85+
std::string otelExporterOtlpHeaders;
8386
bool otelSslEnabled;
8487
std::string otelSslCertPath;
8588

@@ -108,6 +111,7 @@ inline std::ostream& operator<< (std::ostream &os, const otel::core::TenantConfi
108111
<< "\n OtelSamplerType " << config.getOtelSamplerType()
109112
<< "\n OtelSslEnabled " << config.getOtelSslEnabled()
110113
<< "\n OtelSslCertPath " << config.getOtelSslCertPath()
114+
<< "\n OtelExportOtlpHeaders " << config.getOtelExporterOtlpHeaders()
111115
<< "";
112116
return os;
113117
}

instrumentation/otel-webserver-module/opentelemetry_module.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ApacheModuleEnabled ON
1414
#ApacheModule Otel Exporter details
1515
ApacheModuleOtelSpanExporter otlp
1616
ApacheModuleOtelExporterEndpoint collector:4317
17+
#ApacheModuleOtelExporterHeaders api-key=abc123
1718

1819
# SSL Certificates
1920
#ApacheModuleOtelSslEnabled ON

instrumentation/otel-webserver-module/src/apache/ApacheConfig.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ const char* ApacheConfigHandlers::otel_set_otelExporterEndpoint(cmd_parms *cmd,
121121
return helperChar(cmd, cfg, arg, cfg->otelExporterEndpoint, cfg->otelExporterEndpoint_initialized, "otel_set_otelExporterEndpoint");
122122
}
123123

124+
// char *otelExporterOtlpHeaders;
125+
// int otelExporterOtlpHeaders_initialized;
126+
const char* ApacheConfigHandlers::otel_set_otelExporterOtlpHeaders(cmd_parms *cmd, void *conf, const char *arg)
127+
{
128+
otel_cfg* cfg = (otel_cfg*) conf;
129+
return helperChar(cmd, cfg, arg, cfg->otelExporterOtlpHeaders, cfg->otelExporterOtlpHeaders_initialized, "otel_set_otelExporterOtlpHeaders");
130+
}
131+
124132
// char *otelSslEnabled;
125133
// int otelSslEnabled_initialized;
126134
const char* ApacheConfigHandlers::otel_set_otelSslEnabled(cmd_parms *cmd, void *conf, const char *arg)
@@ -432,6 +440,10 @@ void otel_cfg::init()
432440
otelExporterEndpoint = "";
433441
otelExporterEndpoint_initialized = 0;
434442

443+
// otelExporterOtlpHeaders Optional: OTLP headers as key value pairs
444+
otelExporterOtlpHeaders = "";
445+
otelExporterOtlpHeaders_initialized = 0;
446+
435447
// otelSslEnabled OPTIONAL: Decides whether the connection to the endpoint is secured
436448
otelSslEnabled = 0;
437449
otelSslEnabled_initialized = 0;
@@ -771,6 +783,9 @@ otel_cfg* ApacheConfigHandlers::getProcessConfig(const request_rec* r)
771783
process_cfg->otelExporterEndpoint = apr_pstrdup(r->server->process->pool, our_config->otelExporterEndpoint);
772784
process_cfg->otelExporterEndpoint_initialized = our_config->otelExporterEndpoint_initialized;
773785

786+
process_cfg->otelExporterOtlpHeaders = apr_pstrdup(r->server->process->pool, our_config->otelExporterOtlpHeaders);
787+
process_cfg->otelExporterOtlpHeaders_initialized = our_config->otelExporterOtlpHeaders_initialized;
788+
774789
process_cfg->otelSslEnabled = our_config->otelSslEnabled;
775790
process_cfg->otelSslEnabled_initialized = our_config->otelSslEnabled_initialized;
776791

instrumentation/otel-webserver-module/src/apache/ApacheHooks.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,11 @@ bool ApacheHooks::initialize_opentelemetry(const request_rec *r)
339339
wsAgent.initDependency();
340340

341341
// ENV RECORDS SIZE TO INCLUDE THE LOG PATH AND THE AGGREGATOR DIRECTORY
342-
//
343-
// Update the apr_pcalloc if we add another parameter to the input array!
342+
// Update the CONFIG_COUNT in apr_pcalloc if we add another parameter to the input array!
343+
344344
OTEL_SDK_ENV_RECORD* env_config =
345-
(OTEL_SDK_ENV_RECORD*) apr_pcalloc(r->pool, 16 * sizeof(OTEL_SDK_ENV_RECORD));
345+
(OTEL_SDK_ENV_RECORD*) apr_pcalloc(r->pool, CONFIG_COUNT * sizeof(OTEL_SDK_ENV_RECORD));
346+
346347
int ix = 0;
347348

348349
// Otel Exporter Type
@@ -425,6 +426,11 @@ bool ApacheHooks::initialize_opentelemetry(const request_rec *r)
425426
env_config[ix].value = our_config->getSegmentParameter();
426427
++ix;
427428

429+
// Segment Parameter
430+
env_config[ix].name = OTEL_SDK_ENV_OTEL_EXPORTER_OTLPHEADERS;
431+
env_config[ix].value = our_config->getOtelExporterOtlpHeaders();
432+
++ix;
433+
428434
// !!!
429435
// Remember to update the apr_pcalloc call size if we add another parameter to the input array!
430436
// !!!

instrumentation/otel-webserver-module/src/apache/mod_apache_otel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ static const command_rec otel_cmds[] =
6464
NULL,
6565
OR_ALL,
6666
"Collector Endpoint where the OpenTelemetry Exporter inside OTel SDK sends traces"),
67+
AP_INIT_TAKE1(
68+
"apacheModuleOtelExporterHeaders",
69+
(CMD_HAND_TYPE)ApacheConfigHandlers::otel_set_otelExporterOtlpHeaders,
70+
NULL,
71+
OR_ALL,
72+
"AppDynamics Otel export Headers key value pairs"),
6773
AP_INIT_TAKE1(
6874
"apacheModuleOtelSslEnabled",
6975
(CMD_HAND_TYPE)ApacheConfigHandlers::otel_set_otelSslEnabled,

0 commit comments

Comments
 (0)