borisermakof / serilog-sinks-fluentd Goto Github PK
View Code? Open in Web Editor NEWA Sink that writes logs into Fluentd
License: Apache License 2.0
A Sink that writes logs into Fluentd
License: Apache License 2.0
The version hosted on nuget.org is not up-to-date and does not have the latest fixes and features
We found a serious memory leak on sending logs to the collector. As the project is dead (no PR accepted in recent years) and because of other serious issues like this, a quick fix could be:
public static readonly SerializationContext SerializationContext
= new SerializationContext(PackerCompatibilityOptions.PackBinaryAsRaw);
public FluentdEmitter(Stream stream)
{
//actual fix is here: allow generated stuff to be GC collected
SerializationContext.SerializerOptions.GeneratorOption = SerializationMethodGeneratorOption.CanCollect;
SerializationContext.Serializers.Register(new OrdinaryDictionarySerializer());
_packer = Packer.Create(stream);
}
BTW, the serializer used there is also dead :)
I do not intend to publish a nuget package with this fix or open my fork and I recommend you to do the same. This lib has too many existing flaws. In my opinion, it has to be re-written from scratch using a different MskPack serializer to get a stable production-ready solution.
Due to the MessagePackSerializer<IDictionary<string, object>>
, property of nested objects are incorrectly rendered on msgpack:
log.LogInformation("this is cool data: {@data}", new {a = new {b = "test"}, c = "contoso", d = new {site = "a" }});
It does not render anything.
However, when MessagePackSerializer used Dictionary<string, object>
as its "T", it does correctly:
Also, for boolean values, it gets rendered as string and fluentd get some issues into STREAM filtering.
Can I upload a PR to fix those issues?
Also, I saw another issue telling that there are memory leaks in this library and there's another fork (#22 and https://github.com/iNiScorporation/custom-serilog-sinks-fluentd)
Can you please tell us if this project is dead? And if not, is it possible to get those fixes from the links above?
Plugin works. It is good. But looks like it uses tcp socket for transfer data into fluentd
.
It will be good, if it can additionally support sending data via unix socket files.
Format of sending logs it is the same (Fluentd plugins in_forward
and in_unix
have the same transport protocol for input records).
When the server(fluentd) becomes unavailable for a short time, the client does not understand that the tcp-connection is broken and continues to send messages to the void. Why don't you use connection check with SelectMode.SelectRead? Adding this check allows you to immediately know about a broken connection.
Looks like it is good plugin. But more information about using this plugin and some configurational options for this plugin or fluentd application will be better (maybe some example of code).
I get extra quotes in Fluentd if I write log statements with string properties:
log.Information("Got Foo: {Foo}", "Bar");
...which results in this in the FluentD json logs (note the extra quotes in "Bar"):
{"Level":"Information","mt":"Got Foo: {Foo}", "Foo": "\"Bar\""}
I confirmed that this is the behavior of this line in FluentSinkClient
:
record.Add(log.Key, log.Value.ToString());
Because log.Value.ToString()
produces a string that itself contains quotes.
You can see a similar issue here: serilog/serilog#936
The fix suggested there is the equivalent of:
if (IsString(log.Value))
{
record.Add(log.Key, ((ScalarValue)log.Value).Value);
}
else
{
record.Add(log.Key, log.Value.ToString());
}
I tried that out and it produced output without extra quotes.
Is the current behavior intentional, or would you accept a PR addressing this?
As an addendum--and I'm kind of new to both Serilog and Fluentd--I'd have expected the serializer to have synthesized an @l
value too, a field that inlines the arguments into the message. In the example above, that would result in "Got Foo: Bar". Is that something that makes sense to support, or should some downstream piece of Fluentd handle that?
I've just started looking at fluentd & was keen to try spin up a dotnet core sample that logs to fluentd.
I've setup a Elastic Search, Kibana & Fluentd stack on docker locally (https://docs.fluentd.org/v0.12/articles/docker-logging-efk-compose) and everything is working fine (forwarding docker logs from an apache container through fluentd into kibana & logstash).
I then installed Serilog.AspNetCore
, Serilog.Sinks.Console
& Serilog.Sinks.Fluentd
.
Console logging works fine, but as soon as I try to log to Fluentd I get the following error:
Unhandled Exception: System.Net.Sockets.SocketException: Invalid argument
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
at System.Net.Sockets.Socket.SetLingerOption(LingerOption lref)
at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Object optionValue)
at Serilog.Sinks.Fluentd.FluentdSink..ctor(FluentdSinkOptions options)
at Serilog.LoggerConfigurationFluentdExtensions.Fluentd(LoggerSinkConfiguration loggerSinkConfiguration, FluentdSinkOptions option)
at app.Program.Main(String[] args) in /Users/andy/Development/experiments/dotnet/TodoApi/Program.cs:line 19
This is what my program.cs file looks like:
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.Fluentd;
namespace app
{
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Fluentd(new FluentdSinkOptions("0.0.0.0",24224))
.WriteTo.Console()
.CreateLogger();
Log.Information("Starting web host");
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseSerilog()
.UseStartup<Startup>()
.Build();
}
}
I've tried with our without the FluentdSinkOptions, but I consistently get the error.
I'm relatively new to dotnet core, and totally new to fluentd, so I could well be missing something, but couldn't find any usage examples for the fluentd sink, and would be hugely appreciative if you could help me out.
I'm on a mac, running dotnet core 2.0, and nuget installed and referenced Serilog.Sinks.Fluentd Version 0.2.0.
Thanks so much
I'd like to use this sink to communicate with fluentd over a mutual tls authenticated connection. How can I archive that with this sink?
Preface. I'm not a .NET developer but our devs are trying to use this library on some hosts that are .NET Core on both windows and Linux (Docker) based.. works fine on windows. same code doesn't work at all on Linux. No output is received by fluentd. Nothing is received by the fluentd server.. Even tried to send to a local listening TCP socket and nothing..
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.