Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace logs
*/
struct ElasticsearchExporterOptions
{
using HttpHeaders = std::multimap<std::string, std::string>;

// Configuration options to establish Elasticsearch connection
std::string host_;
int port_;
Expand All @@ -37,6 +39,9 @@ struct ElasticsearchExporterOptions
// Whether to print the status of the exporter in the console
bool console_debug_;

/** Additional HTTP headers. */
HttpHeaders http_headers_;

/**
* Constructor for the ElasticsearchExporterOptions. By default, the endpoint is
* localhost:9200/logs with a timeout of 30 seconds and disabled console debugging
Expand All @@ -47,16 +52,18 @@ struct ElasticsearchExporterOptions
* from elasticsearch
* @param console_debug If true, print the status of the exporter methods in the console
*/
ElasticsearchExporterOptions(std::string host = "localhost",
int port = 9200,
std::string index = "logs",
int response_timeout = 30,
bool console_debug = false)
ElasticsearchExporterOptions(std::string host = "localhost",
int port = 9200,
std::string index = "logs",
int response_timeout = 30,
bool console_debug = false,
HttpHeaders http_headers = {})
: host_{host},
port_{port},
index_{index},
response_timeout_{response_timeout},
console_debug_{console_debug}
console_debug_{console_debug},
http_headers_{http_headers}
{}
};

Expand Down
7 changes: 7 additions & 0 deletions exporters/elasticsearch/src/es_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ sdk::common::ExportResult ElasticsearchLogRecordExporter::Export(
request->SetUri(options_.index_ + "/_bulk?pretty");
request->SetMethod(http_client::Method::Post);
request->AddHeader("Content-Type", "application/json");

// Add options headers
for (auto it = options_.http_headers_.cbegin(); it != options_.http_headers_.cend(); ++it)
{
request->AddHeader(it->first, it->second);
}

request->SetTimeoutMs(std::chrono::milliseconds(1000 * options_.response_timeout_));

// Create the request body
Expand Down