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

Get logzio-index-failure when using scoped variables #39

Open
advapiIT opened this issue Nov 7, 2023 · 2 comments
Open

Get logzio-index-failure when using scoped variables #39

advapiIT opened this issue Nov 7, 2023 · 2 comments
Assignees

Comments

@advapiIT
Copy link

advapiIT commented Nov 7, 2023

Hello,
I'm using Serilog + Serilog.Sinks.Logz.io to send event to Logzio (europe).
I've been contacted by the support since they told me that I've tons of log message that cannot be indexed since I used the Scope.

In particular consider this case
image

They wrote me :" Im still checking, but it looks to be from the field "properties.Scope_list". The field is getting sent as an array and causing index failures"

My code is thefollowing, since I have those properties that needs to be attached to all the nested logs starting from the using:

            foreach (var productInventoryIdByExternalProductId in filtered)
            {
                _logger.BeginScope(new Dictionary<string, string>()
                {
                    { "ProductInventoryId", productInventoryIdByExternalProductId.Key.ToString() },
                    {"ExternalProductId",  productInventoryIdByExternalProductId.Value}
                });

                _logger.LogInformation($"Started processing ProductInventoryId: {productInventoryIdByExternalProductId.Key} .[{count}/{total}]");

What am I doing wrong?
Thanks

@mantasaudickas
Copy link
Collaborator

To be honest - for me all these things looks legit, as ElasticSearch/OpenSearch supports arrays without any issues, see: https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html
However - maybe the issue is that you have these arrays create in multiple places with the same name, but inside you have different properties?

@mantasaudickas
Copy link
Collaborator

mantasaudickas commented Nov 8, 2023

By looking more closely.. it seems like with a single log message you need only one pair of ProductInventoryId and ExternalProductId, is that right?
Because now.. since you are not disposing scope - every log line gets more and more these entries.
So one way would be (see added using):

foreach (var productInventoryIdByExternalProductId in filtered)
            {
                using var scope = _logger.BeginScope(new Dictionary<string, string>()
                {
                    { "ProductInventoryId", productInventoryIdByExternalProductId.Key.ToString() },
                    {"ExternalProductId",  productInventoryIdByExternalProductId.Value}
                });

                _logger.LogInformation($"Started processing ProductInventoryId: {productInventoryIdByExternalProductId.Key} .[{count}/{total}]");

Another option:

foreach (var productInventoryIdByExternalProductId in filtered)
{
     _logger.LogInformation("Started processing ProductInventoryId = {ProductInventoryId}. ExternalProductId = {ExternalProductId}. [{Count}/{Total}]", productInventoryIdByExternalProductId.Key, productInventoryIdByExternalProductId.Value, count, total);

@mantasaudickas mantasaudickas self-assigned this Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants