mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Report metrics to Application Insights
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Podsync.Helpers;
|
||||
using Podsync.Services.Links;
|
||||
@@ -14,12 +15,14 @@ namespace Podsync.Controllers
|
||||
private readonly IResolverService _resolverService;
|
||||
private readonly ILinkService _linkService;
|
||||
private readonly IStorageService _storageService;
|
||||
private readonly TelemetryClient _telemetry;
|
||||
|
||||
public DownloadController(IResolverService resolverService, ILinkService linkService, IStorageService storageService)
|
||||
public DownloadController(IResolverService resolverService, ILinkService linkService, IStorageService storageService, TelemetryClient telemetry)
|
||||
{
|
||||
_resolverService = resolverService;
|
||||
_linkService = linkService;
|
||||
_storageService = storageService;
|
||||
_telemetry = telemetry;
|
||||
}
|
||||
|
||||
// Main video download endpoint, don't forget to reflect any changes in LinkService.Download
|
||||
@@ -38,6 +41,9 @@ namespace Podsync.Controllers
|
||||
|
||||
var redirectUrl = await _resolverService.Resolve(url, metadata.Quality);
|
||||
|
||||
// Report metrics
|
||||
_telemetry.TrackEvent("Download");
|
||||
|
||||
return Redirect(redirectUrl.ToString());
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Podsync.Helpers;
|
||||
using Podsync.Services;
|
||||
@@ -27,12 +29,14 @@ namespace Podsync.Controllers
|
||||
private readonly IRssBuilder _rssBuilder;
|
||||
private readonly ILinkService _linkService;
|
||||
private readonly IStorageService _storageService;
|
||||
private readonly TelemetryClient _telemetry;
|
||||
|
||||
public FeedController(IRssBuilder rssBuilder, ILinkService linkService, IStorageService storageService)
|
||||
public FeedController(IRssBuilder rssBuilder, ILinkService linkService, IStorageService storageService, TelemetryClient telemetry)
|
||||
{
|
||||
_rssBuilder = rssBuilder;
|
||||
_linkService = linkService;
|
||||
_storageService = storageService;
|
||||
_telemetry = telemetry;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -51,14 +55,36 @@ namespace Podsync.Controllers
|
||||
PageSize = request.PageSize ?? DefaultPageSize
|
||||
};
|
||||
|
||||
if (!User.EnablePatreonFeatures())
|
||||
// Check if user eligible for Patreon features
|
||||
var enablePatreonFeatures = User.EnablePatreonFeatures();
|
||||
if (!enablePatreonFeatures)
|
||||
{
|
||||
feed.Quality = ResolveType.VideoHigh;
|
||||
feed.PageSize = DefaultPageSize;
|
||||
}
|
||||
|
||||
var feedId = await _storageService.Save(feed);
|
||||
return _linkService.Feed(Request.GetBaseUrl(), feedId);
|
||||
var url = _linkService.Feed(Request.GetBaseUrl(), feedId);
|
||||
|
||||
// Report metrics
|
||||
var properties = new Dictionary<string, string>
|
||||
{
|
||||
["Provider"] = linkInfo.Provider.ToString(),
|
||||
["Patreon"] = enablePatreonFeatures.ToString(),
|
||||
["Format"] = feed.Quality == ResolveType.AudioHigh || feed.Quality == ResolveType.AudioLow ? "Audio" : "Video",
|
||||
["Quality"] = feed.Quality == ResolveType.AudioHigh || feed.Quality == ResolveType.VideoHigh ? "Hight" : "Low",
|
||||
["PageSize"] = feed.PageSize.ToString()
|
||||
};
|
||||
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
properties.Add("User", User.GetClaim(ClaimTypes.NameIdentifier));
|
||||
properties.Add("Email", User.GetClaim(ClaimTypes.Email));
|
||||
}
|
||||
|
||||
_telemetry.TrackEvent("CreateFeed", properties);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -90,6 +116,9 @@ namespace Podsync.Controllers
|
||||
body = writer.ToString();
|
||||
}
|
||||
|
||||
// Report metrics
|
||||
_telemetry.TrackEvent("GetFeed");
|
||||
|
||||
return Content(body, "application/rss+xml; charset=UTF-8");
|
||||
}
|
||||
}
|
||||
|
@@ -68,7 +68,7 @@ namespace Podsync.Helpers
|
||||
?? "noname :(";
|
||||
}
|
||||
|
||||
private static string GetClaim(this ClaimsPrincipal claimsPrincipal, string type)
|
||||
public static string GetClaim(this ClaimsPrincipal claimsPrincipal, string type)
|
||||
{
|
||||
return claimsPrincipal.Claims.FirstOrDefault(x => x.Type == type)?.Value;
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ApplicationInsightsResourceId>/subscriptions/6ced39ae-0008-4531-bf42-4c517d4fb309/resourcegroups/podsync_group/providers/microsoft.insights/components/podsync</ApplicationInsightsResourceId>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<DnxInvisibleContent Include=".bowerrc" />
|
||||
|
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider",
|
||||
"Version": "7.15.1215.1",
|
||||
"GettingStartedDocument": {
|
||||
"Uri": "https://go.microsoft.com/fwlink/?LinkID=798432"
|
||||
}
|
||||
}
|
@@ -32,6 +32,7 @@ namespace Podsync
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
builder.AddUserSecrets();
|
||||
builder.AddApplicationInsightsSettings(true);
|
||||
}
|
||||
|
||||
Configuration = builder.Build();
|
||||
@@ -56,6 +57,7 @@ namespace Podsync
|
||||
services.AddAuthentication(config => config.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
|
||||
// Add framework services
|
||||
services.AddApplicationInsightsTelemetry(Configuration);
|
||||
services.AddMvc();
|
||||
}
|
||||
|
||||
@@ -65,6 +67,9 @@ namespace Podsync
|
||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
loggerFactory.AddDebug();
|
||||
|
||||
app.UseApplicationInsightsRequestTelemetry();
|
||||
app.UseApplicationInsightsExceptionTelemetry();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
@@ -21,7 +21,8 @@
|
||||
<environment Names="Staging,Production">
|
||||
<link rel="stylesheet" href="css/site.min.css" asp-append-version="true" />
|
||||
</environment>
|
||||
|
||||
|
||||
@Html.ApplicationInsightsJavaScript(TelemetryConfiguration)
|
||||
</head>
|
||||
<body>
|
||||
<div class="background-image">
|
||||
|
@@ -1,2 +1,4 @@
|
||||
@using Podsync
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
||||
@inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration
|
@@ -1,4 +1,4 @@
|
||||
{
|
||||
{
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"LogLevel": {
|
||||
@@ -7,12 +7,14 @@
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
},
|
||||
|
||||
"Podsync": {
|
||||
"YouTubeApiKey": "",
|
||||
"RedisConnectionString": "localhost",
|
||||
"BaseUrl": "",
|
||||
"PatreonClientId": "",
|
||||
"PatreonSecret": ""
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
"InstrumentationKey": ""
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,8 @@
|
||||
{
|
||||
{
|
||||
"dependencies": {
|
||||
"Google.Apis.YouTube.v3": "1.16.0.582",
|
||||
"Hashids.net": "1.2.2",
|
||||
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
|
||||
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
|
||||
"Microsoft.AspNetCore.Authentication.OAuth": "1.0.0",
|
||||
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
|
||||
|
Reference in New Issue
Block a user