Skip to content

Commit

Permalink
Merge branch 'main' into release_1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff committed Oct 7, 2024
2 parents c156894 + 35e8d17 commit 35bb4ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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

0 comments on commit 35bb4ff

Please sign in to comment.