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

Introduce a logger provider that counts warnings and errors #54846

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

amcasey
Copy link
Member

@amcasey amcasey commented Mar 29, 2024

...if an IMeterFactory is present (and does nothing otherwise). This will provide insight into things like how often unknown key identifiers are encountered.

Part of #53654

...if an `IMeterFactory` is present (and does nothing otherwise).  This will provide insight into things like how often unknown key identifiers are encountered.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-dataprotection Includes: DataProtection label Mar 29, 2024
@amcasey amcasey requested a review from JamesNK March 29, 2024 21:32
@amcasey
Copy link
Member Author

amcasey commented Mar 29, 2024

I'm almost certain the names are wrong but, before I fix that, I wanted to check whether this approach even made sense.

internal sealed class MetricsLoggerProvider : ILoggerProvider
{
public const string MeterName = "Microsoft.AspNetCore.DataProtection";
private const string CategoryNamePrefix = "Microsoft.AspNetCore.DataProtection";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I include a dot at the end? It's a namespace we "own", so I'm not that worried about picking up, e.g., "DataProtection2".

@amcasey
Copy link
Member Author

amcasey commented Apr 1, 2024

@noahfalk might have thoughts on how this plays with the other kinds of events in the dotnet ecosystem.

@noahfalk
Copy link
Member

noahfalk commented Apr 2, 2024

@noahfalk might have thoughts on how this plays with the other kinds of events in the dotnet ecosystem.

I have seen other people interested in converting error/warning logs to metrics, but I am not aware that anyone has built one yet. I think the main thing to decide is if this is building a general-purpose mechanism or a specialized one just for DataProtection logs? If you built a special purpose one maybe it would eventually become obsolete in the future if a general-purpose option is created.

_meter = meterFactory.Create(MeterName);

var counter = _meter.CreateCounter<long>(
"aspnetcore.data_protection.log_messages",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We went with "rate_limiting", so I went with "data_protection", rather than "dataprotection".


var tags = new TagList(
[
new("aspnetcore.data_protection.log_message_id", eventId.Name ?? eventId.Id.ToString(CultureInfo.InvariantCulture)),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, these should be dotnet- or Microsoft.Extensions- scoped, but that seems premature.

Copy link

@reyang reyang Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just personal thoughts, maybe use "aspnetcore.data_protection.logs.event_name" and "aspnetcore.data_protection.logs.log_level"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me

@amcasey
Copy link
Member Author

amcasey commented Apr 3, 2024

@noahfalk might have thoughts on how this plays with the other kinds of events in the dotnet ecosystem.

I have seen other people interested in converting error/warning logs to metrics, but I am not aware that anyone has built one yet. I think the main thing to decide is if this is building a general-purpose mechanism or a specialized one just for DataProtection logs? If you built a special purpose one maybe it would eventually become obsolete in the future if a general-purpose option is created.

It definitely seems like a general purpose need, but I guess I'd be interested in seeing how it plays out in a specific scenario before making a shared one. Personally, I was going to scope it to exactly DataProtection, but @JamesNK may have thoughts on whether it makes more sense to cover all of AspNetCore? My feeling was that this will generate relatively little clutter for consumers if we have to keep producing it forever after it becomes obsolete.

@noahfalk
Copy link
Member

noahfalk commented Apr 3, 2024

No opposition from me if you want to make this one specific to DataProtection :)

@amcasey amcasey marked this pull request as ready for review April 4, 2024 22:00
@amcasey
Copy link
Member Author

amcasey commented Apr 4, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Apr 11, 2024
Co-authored-by: Reiley Yang <[email protected]>
@amcasey amcasey mentioned this pull request Jul 18, 2024
1 task
@amcasey amcasey marked this pull request as draft July 29, 2024 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dataprotection Includes: DataProtection pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants