mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-27 08:35:53 +03:00
[GH-ISSUE #1867] Add support for Elasticsearch with Bulk API and data stream #800
Labels
No labels
Bug
Documentation
Feature
Needs Work
Support
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/monolog#800
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @muratpurc on GitHub (Jan 17, 2024).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1867
Summary of problem or feature request
We use the
Monolog\Handler\ElasticsearchHandlerto write log entries to Elasticsearch (Bulk API and data stream) with Monolog.It is not possible for us to use Monolog ElasticsearchHandler with the Elasticsearch PHP client in order to write entries into Elasticsearch by using Bulk API and data stream.
The versions used are:
Code snippet of problem
Our Monolog setup looks like this:
The Elasticsearch documentation says the following about Bulk API and data stream in it:
To automatically create a data stream, Elasticsearch expects the following request:
In the current configuration, the request from above is sent as
POST, which leads to an Elasticsearch error.We can get around this by creating the data stream manually using an HttpClient that calls the API with the following request:
After that is is possible to add entries with the following request:
It doesn't matter whether we create the data stream automatically or create it manually beforehand.
When we want to add a log entry (
$logger->info()), a parameter array is created inMonolog\Handler\ElasticsearchHandler->bulkSend(), which is not compatible with the Elasticsearch Bulk API and data stream.In order for the function
Elastic\Elasticsearch\Traits\ClientEndpointsTrait->bulk()to create a request that is accepted by Elasticsearch, it needs some changes inMonolog\Handler\ElasticsearchHandler->bulkSend(). We managed this by adjustingbulkSend()as follows:I'm not sure if that's the correct place and if it has any side effects to other Monolog-Elasticsearch-setups. It also seems to be necessary to make certain adjustments to the Elasticsearch PHP client. More on this is below. Therefore I didn't create a pull-request.
The
Elastic\Elasticsearch\Traits\ClientEndpointsTrait->bulk()creates the followingPOSTrequest, which according to the documentation should bePUT, but it still works:The Elasticsearch PHP client should also be adapted to create a
PUTrequest for Bulk API with data stream.I've created a ticket 1389 to address the issue on the Elasticsearch PHP client side.
It would be very desirable if both packages support the Elasticsearch Bulk API with data stream.
System details
@muratpurc commented on GitHub (Jan 18, 2024):
The issue was with the used Monolog version 2.9.2, it works with Monolog >=3.3.
The ticket can be closed.