Skip to content

Commit 35e8d17

Browse files
authored
[EXPORTER] Add possibility to give custom HttpHeaders for (#3083)
1 parent 3910b04 commit 35e8d17

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace logs
2626
*/
2727
struct ElasticsearchExporterOptions
2828
{
29+
using HttpHeaders = std::multimap<std::string, std::string>;
30+
2931
// Configuration options to establish Elasticsearch connection
3032
std::string host_;
3133
int port_;
@@ -37,6 +39,9 @@ struct ElasticsearchExporterOptions
3739
// Whether to print the status of the exporter in the console
3840
bool console_debug_;
3941

42+
/** Additional HTTP headers. */
43+
HttpHeaders http_headers_;
44+
4045
/**
4146
* Constructor for the ElasticsearchExporterOptions. By default, the endpoint is
4247
* localhost:9200/logs with a timeout of 30 seconds and disabled console debugging
@@ -47,16 +52,18 @@ struct ElasticsearchExporterOptions
4752
* from elasticsearch
4853
* @param console_debug If true, print the status of the exporter methods in the console
4954
*/
50-
ElasticsearchExporterOptions(std::string host = "localhost",
51-
int port = 9200,
52-
std::string index = "logs",
53-
int response_timeout = 30,
54-
bool console_debug = false)
55+
ElasticsearchExporterOptions(std::string host = "localhost",
56+
int port = 9200,
57+
std::string index = "logs",
58+
int response_timeout = 30,
59+
bool console_debug = false,
60+
HttpHeaders http_headers = {})
5561
: host_{host},
5662
port_{port},
5763
index_{index},
5864
response_timeout_{response_timeout},
59-
console_debug_{console_debug}
65+
console_debug_{console_debug},
66+
http_headers_{http_headers}
6067
{}
6168
};
6269

exporters/elasticsearch/src/es_log_record_exporter.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ sdk::common::ExportResult ElasticsearchLogRecordExporter::Export(
330330
request->SetUri(options_.index_ + "/_bulk?pretty");
331331
request->SetMethod(http_client::Method::Post);
332332
request->AddHeader("Content-Type", "application/json");
333+
334+
// Add options headers
335+
for (auto it = options_.http_headers_.cbegin(); it != options_.http_headers_.cend(); ++it)
336+
{
337+
request->AddHeader(it->first, it->second);
338+
}
339+
333340
request->SetTimeoutMs(std::chrono::milliseconds(1000 * options_.response_timeout_));
334341

335342
// Create the request body

0 commit comments

Comments
 (0)