Skip to content

Commit

Permalink
[EXPORTER] Add possibility to give custom HttpHeaders for (#3083)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowMaxLeb authored Oct 7, 2024
1 parent 3910b04 commit 35e8d17
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

1 comment on commit 35e8d17

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 35e8d17 Previous: 3910b04 Ratio
BM_SpinLockThrashing/4/process_time/real_time 1.3168110297276423 ms/iter 0.4313964907540924 ms/iter 3.05

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.