Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS] Example for authentication and troubleshooting #416

Merged
merged 3 commits into from
Aug 2, 2024
Merged
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
47 changes: 46 additions & 1 deletion docs/data-shippers/serilog.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Writing to `Elasticsearch`
ConcurrentConsumers = 10
};
};
}, transport =>
{
// transport.Authentication(new BasicAuthentication(username, password)); // Basic Auth
// transport.Authentication(new ApiKey(base64EncodedApiKey)); // ApiKey
})

----
Expand Down Expand Up @@ -77,6 +81,43 @@ Note that you can also pass `ElasticsearchSinkOptions` directly

This allows you to reuse the `Transport` used by the Elasticsearch Client for instance.

==== Authentication

When {es} security features are enabled, requests without a valid authentication header will be rejected.
You can enable authentication via one of the methods below:

**Basic Auth**

[source,csharp]
----
.WriteTo.Elasticsearch(new [] { new Uri("http://localhost:9200" )}, opts =>
{
...
}, transport =>
{
transport.Authentication(new BasicAuthentication(username, password)); <1>
})

----
<1> Basic authentication

**API Key**

[source,csharp]
----
.WriteTo.Elasticsearch(new [] { new Uri("http://localhost:9200" )}, opts =>
{
...
}, transport =>
{
transport.Authentication(new ApiKey(base64EncodedApiKey)); <1>
})

----
<1> API Key

To learn more about authentication with the {stack}, see {ref}/setting-up-authentication.html[User Authentication].

==== ECS Aware Message Templates

This sink by proxy of its formatter allows you to set ECS fields directly from the message template using properties that adhere to the
Expand All @@ -91,6 +132,10 @@ Log.Information("The time is {TraceId}", "my-trace-id");

Will override `trace.id` on the resulting ECS json document.

==== Troubleshooting

In case of issues, you can enable the [Serilog Self-Log feature](https://github.com/serilog/serilog/wiki/Debugging-and-Diagnostics#selflog) to expose any error you might have encountered.

==== Comparison with https://github.com/serilog-contrib/serilog-sinks-elasticsearch[`Serilog.Sinks.Elasticsearch`]

* `Serilog.Sinks.Elasticsearch` is an amazing community led sink that has a ton of options and works against older Elasticsearch versions `< 8.0`.
Expand All @@ -107,6 +152,6 @@ Will override `trace.id` on the resulting ECS json document.
* That doesn't mean you can not introduce your own additional properties though.
* `Elastic.Serilog.Sinks` has no durable mode.
* If you need higher guarantees on log delivery use https://github.com/serilog/serilog-sinks-file[`Serilog.Sinks.File`] with our https://www.nuget.org/packages/Elastic.CommonSchema.Serilog/[ECS log formatter] for Serilog and use https://www.elastic.co/beats/filebeat[filebeat] to ship these logs.
* Check out {fleet-ref}/fleet-overview.html[Elastic Agent and Fleet] to simplify collecting logs and metrics on the edge.
* Check out {fleet-guide}/fleet-overview.html[Elastic Agent and Fleet] to simplify collecting logs and metrics on the edge.

If you miss a particular feature from `Serilog.Sinks.Elasticsearch` in `Elastic.Serilog.Sinks` please open a https://github.com/elastic/ecs-dotnet/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=%5BFEATURE%5D[feature request]! We'd love to grow this sink organically moving forward.