-
Notifications
You must be signed in to change notification settings - Fork 10
feat(telemetry): add telemetry support for user agent parsing #90
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
Changes from 2 commits
3d1abc6
26636f1
770ece1
081727e
055ed40
3ac5975
44f030f
1e97351
067b733
0478999
e79daff
1a109d0
58bf7c5
6abf2bd
deb5cc7
d93adb6
9b3f2a6
462267a
6a1e03b
f658e00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,84 @@ | ||
| { | ||
| "version": "2.0.0", | ||
| "tasks": [ | ||
| { | ||
| "label": "dotnet: restore", | ||
| "type": "shell", | ||
| "command": "dotnet", | ||
| "args": [ | ||
| "restore" | ||
| ], | ||
| "problemMatcher": "$msCompile", | ||
| "presentation": { | ||
| "reveal": "silent", | ||
| "panel": "dedicated", | ||
| "close": true, | ||
| "showReuseMessage": false | ||
| } | ||
| }, | ||
| { | ||
| "label": "dotnet: build", | ||
| "type": "shell", | ||
| "command": "dotnet", | ||
| "args": [ | ||
| "build", | ||
| "--no-restore" | ||
| ], | ||
| "problemMatcher": "$msCompile", | ||
| "dependsOn": "dotnet: restore", | ||
| "presentation": { | ||
| "reveal": "always", | ||
| "panel": "dedicated", | ||
| "close": true, | ||
| "showReuseMessage": false | ||
| }, | ||
| "group": "build" | ||
| }, | ||
| { | ||
| "label": "dotnet: test", | ||
| "type": "shell", | ||
| "command": "dotnet", | ||
| "args": [ | ||
| "test", | ||
| "--no-build", | ||
| "--nologo" | ||
| ], | ||
| "problemMatcher": "$msCompile", | ||
| "dependsOn": "dotnet: build", | ||
| "presentation": { | ||
| "reveal": "always", | ||
| "panel": "dedicated", | ||
| "close": true, | ||
| "showReuseMessage": false | ||
| } | ||
| }, | ||
| { | ||
| "label": "test", | ||
| "type": "shell", | ||
| "command": "dotnet test --nologo", | ||
| "args": [], | ||
| "problemMatcher": [ | ||
| "$msCompile" | ||
| ], | ||
| "group": "build" | ||
| "isBackground": false | ||
| }, | ||
| { | ||
| "label": "test", | ||
| "type": "shell", | ||
| "command": "dotnet test --nologo", | ||
| "args": [], | ||
| "isBackground": false | ||
| }, | ||
| { | ||
| "label": "test", | ||
| "type": "shell", | ||
| "command": "dotnet test --nologo", | ||
| "args": [], | ||
| "isBackground": false | ||
| }, | ||
| { | ||
| "label": "test", | ||
| "type": "shell", | ||
| "command": "dotnet test --nologo", | ||
| "args": [], | ||
| "isBackground": false | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright © https://myCSharp.de - all rights reserved | ||
|
|
||
| using MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; | ||
| using MyCSharp.HttpUserAgentParser.DependencyInjection; | ||
|
|
||
| namespace MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; | ||
|
|
||
| /// <summary> | ||
| /// Fluent extensions to enable telemetry for the AspNetCore package. | ||
| /// </summary> | ||
| public static class HttpUserAgentParserDependencyInjectionOptionsTelemetryExtensions | ||
| { | ||
| /// <summary> | ||
| /// Enables EventCounter telemetry for the AspNetCore package. | ||
| /// </summary> | ||
| public static HttpUserAgentParserDependencyInjectionOptions WithAspNetCoreTelemetry( | ||
| this HttpUserAgentParserDependencyInjectionOptions options) | ||
| { | ||
| HttpUserAgentParserAspNetCoreTelemetry.Enable(); | ||
| return options; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright © https://myCSharp.de - all rights reserved | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Diagnostics.Tracing; | ||
|
|
||
| namespace MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry; | ||
|
|
||
| /// <summary> | ||
| /// EventSource for EventCounters emitted by MyCSharp.HttpUserAgentParser.AspNetCore. | ||
| /// </summary> | ||
| [EventSource(Name = EventSourceName)] | ||
| [ExcludeFromCodeCoverage] | ||
| public sealed class HttpUserAgentParserAspNetCoreEventSource : EventSource | ||
| { | ||
| /// <summary> | ||
| /// The EventSource name used for EventCounters. | ||
| /// </summary> | ||
| public const string EventSourceName = "MyCSharp.HttpUserAgentParser.AspNetCore"; | ||
|
|
||
| internal static HttpUserAgentParserAspNetCoreEventSource Log { get; } = new(); | ||
|
|
||
| private readonly IncrementingEventCounter _userAgentPresent; | ||
| private readonly IncrementingEventCounter _userAgentMissing; | ||
|
|
||
| private HttpUserAgentParserAspNetCoreEventSource() | ||
| { | ||
| _userAgentPresent = new IncrementingEventCounter("useragent-present", this) | ||
| { | ||
| DisplayName = "User-Agent header present", | ||
| DisplayUnits = "calls", | ||
| }; | ||
|
|
||
| _userAgentMissing = new IncrementingEventCounter("useragent-missing", this) | ||
| { | ||
| DisplayName = "User-Agent header missing", | ||
| DisplayUnits = "calls", | ||
| }; | ||
| } | ||
|
|
||
| [NonEvent] | ||
| internal void UserAgentPresent() | ||
| { | ||
| if (!IsEnabled()) return; | ||
| _userAgentPresent?.Increment(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we don't write an event, should we use metrics (via meter factory) instead?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are too many projects that do not use OTEL - even I/we currently still use native app insights in almost all projects because OTEL features are missing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we would still enforce everybody to use OTEL as foundation... I am not happy with that. |
||
| } | ||
|
|
||
| [NonEvent] | ||
| internal void UserAgentMissing() | ||
| { | ||
| if (!IsEnabled()) return; | ||
| _userAgentMissing?.Increment(); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override void Dispose(bool disposing) | ||
| { | ||
| if (disposing) | ||
| { | ||
| _userAgentPresent?.Dispose(); | ||
| _userAgentMissing?.Dispose(); | ||
| } | ||
|
|
||
| base.Dispose(disposing); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.