-
Notifications
You must be signed in to change notification settings - Fork 129
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
Support collections as constructor arguments #405
Support collections as constructor arguments #405
Conversation
Thanks for sending this! It'd be great to nail down/discuss how this applies to other Serilog sinks, and what the expected limitations are. For example, many sinks accept Since we'd likely need to do the same extensive testing around this change as around that one, and the code overlaps substantially, would it be possible to consider it here? It wouldn't necessarily need to be in the same PR, but doing that would help to ensure everything lines up. |
Yeah, I did overlook interfaces. I can try using Users may also want to explicitly specify an implementation to use. I think most collections accept an I had not intended for dictionaries to be included inside this pull request, but I can see how it is similar. For dictionaries I think it would be better to implement a special case, that looks for an "resourceAttributes": {
"key1": "value1",
"key2": "value2"
} I think this will be the most intuitive solution for users. It does assume that the keys are of type string, I think this is probably fine, because System.Text.Json also supports a limited set of types, see docs. For As an alternative, dictionaries can be viewed as "resourceAttributes": [
{ "key": "key1", "value": "value1" },
{ "key": "key2", "value": "value2" }
] Another problem that Another thing that is bugging me about the current implementation is that most things have to be implemented twice. Once inside I updated the branch to include support for using default implementations for common collection interfaces and support for dictionaries. I will see what I can do about improving the test cases next. |
Hi @ChristofferGersen - just checking in to make sure I understood your message above correctly, and you're not waiting on anything from me -- let me know if that's not the case 😄 Also, @0xced any thoughts on the direction of this? I know you've done some thinking along similar lines, and you seem to always be a step or two ahead of me when it comes to this project 😅 |
No I am not waiting on you. I am just waiting on some more time to work on this. The implementation is more or less what I intended it to be, so if there are improvements you would like to see, let me know. Next I will work on improving the test cases for |
@nblumhardt It would be really nice to have this feature released soon, the OpenTelemetry Sink is more or less unusable without and I dont want to switch to Microsoft.Extensions.Logging ;) |
@prochnowc More test cases are required, to ensure that my changes do not break existing use cases. I am working on that, but I am doing this in my free time, since I do not require this for my work. As a result, this may not go as fast as you would expect. While working on the test cases last weekend I already found a bug in the dictionary conversion code. I just pushed another commit to fix the bug that I found. If you really want this now, then you can just clone my branch and build a version of this library that includes the changes. That way you can use this feature before it is released. But be aware that I am still testing this code further, so there may still be subtle bugs that I have not discovered yet. On a side note. While fixing the bug, I also found out that it is not too difficult to also support dictionaries with keys that are not strings, by running them through StringArgumentValue. I only see this being used with primitives and enums, but it could be anything that StringArgumentValue supports. |
Thank you very much taking the time in your free time and implementing this feature. I need this for Serilog.Sinks.OpenTelemetry package and I would like to ask you how far you are? Can I help you somehow? Regards |
I am currently waiting for #409 to be merged. I believe that is waiting for @0xced to review my intended changes. After that merge my intention is to update this pull request to look like my removed-linq-expressions branch. So I believe there is not much more to be done, unless it turns out that I should implement the features differently. |
To avoid JSON001 Invalid JSON pattern analyzer errors in IDE
ead2d93
to
64a0130
Compare
I updated by branch with the required changes, the old branch is still available under support-collection-arguments-old. The first commit contains the actual changes. The second one places all JSON strings into its own variable first, before passing it on to |
Awesome! 🎉 While we give the other reviewers a chance to weigh in - is anyone on this thread able to grab the CI packages from https://ci.appveyor.com/project/serilog/serilog-settings-configuration/builds/49262471/job/1lb4arqp3k8jvtut/artifacts, and test this out in a real-world config? 😎 |
All good to merge this @0xced? I'll send it through in 24h so we can start testing it out in the prerelease packages :) |
I'll try to have a look this week. |
Hi @0xced, shall I merge this one and start getting some feedback? Cheers! |
Hey folks! Assuming everyone has their hands full, I'm hoping to keep things rolling :-) Serilog.Sinks.OpenTelemetry v2 just shipped, with a couple of key parameters using dictionary types, so it'd be nice to have the whole scenario work end-to-end there. I have some time aside to make sure everything hangs together, so perhaps we leave this weekend as a window for any further feedback, and otherwise aim to publish this in the |
Have been running it since the 2.0.0-preview with no issues. Thank you for your work on this @ChristofferGersen , @0xced, @nblumhardt |
I'm unable to specify the This is what I have in my config:
Is this the correct way to do it? |
Looks ok to me. I'd double check that Serilog.Settings.Configuration is v8.0.1 |
Thank you very much! |
Support collections and arrays as constructor arguments.
Closes #314