serilog-sinks-elasticsearch icon indicating copy to clipboard operation
serilog-sinks-elasticsearch copied to clipboard

The given key 'error' was not present in the dictionary.

Open nvivo opened this issue 6 years ago • 7 comments
trafficstars

Some events are missing from ElasticSearch and I'm investigating what is happening. Looking into the selflog I get this error every few minutes:

2019-08-23T17:40:38.4905634Z Exception while emitting periodic batch from Serilog.Sinks.Elasticsearch.ElasticsearchSink: System.Collections.Generic.KeyNotFoundException: The given key 'error' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Serilog.Sinks.Elasticsearch.ElasticsearchSink.EmitBatch(IEnumerable`1 events)
   at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(IEnumerable`1 events)
   at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.OnTick()

Is this a bug or I might be causing it from my code?

nvivo avatar Aug 23 '19 18:08 nvivo

Can you give it a go with the latest alpha nuget package? There was some fix in the dynamic error message that is returned from the batch operation.

Op 23 aug. 2019 om 20:21 heeft Natan Vivo [email protected] het volgende geschreven:

Some events are missing from ElasticSearch and I'm investigating what is happening. Looking into the selflog I get this error every few minutes:

2019-08-23T17:40:38.4905634Z Exception while emitting periodic batch from Serilog.Sinks.Elasticsearch.ElasticsearchSink: System.Collections.Generic.KeyNotFoundException: The given key 'error' was not present in the dictionary. at System.Collections.Generic.Dictionary2.get_Item(TKey key) at Serilog.Sinks.Elasticsearch.ElasticsearchSink.EmitBatch(IEnumerable1 events) at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(IEnumerable`1 events) at Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.OnTick() Is this a bug or I might be causing it from my code?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

mivano avatar Aug 23 '19 18:08 mivano

I just got the latest dev branch and ran with debug symbols.

The issue is here: https://github.com/serilog/serilog-sinks-elasticsearch/blob/9d9930e2e5e960dc8c1b230fc7eaaac5c84e3dc9/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs#L75

Looks like the ["error"] is not present. Should it always be there?

nvivo avatar Aug 23 '19 19:08 nvivo

Ok, I got what is happening.

The response from ElasticSearch contains all items, not only the ones with errors. This is part of the response:

image

While DynamicResponse uses TryGetValue for the "index" part, the value itself is another dictionary and that one complains about trying to get "error" without a check.

nvivo avatar Aug 23 '19 20:08 nvivo

Hmm, that is unfortunate, I recently merged this one (https://github.com/serilog/serilog-sinks-elasticsearch/pull/266/files) into dev. So if you tried the dev branch, then it still has issues. Would you care for a PR?

mivano avatar Aug 24 '19 21:08 mivano

See #271

mivano avatar Aug 26 '19 14:08 mivano

Is this still an issue with the latest nuget package?

mivano avatar Oct 08 '19 08:10 mivano

I was having the same issue with 8.0.0. Updated to alpha0002 and no longer have the problem.

estoces avatar Nov 01 '19 16:11 estoces