-
Notifications
You must be signed in to change notification settings - Fork 3.6k
ABP Telemetry Collection #23343
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
Merged
Merged
ABP Telemetry Collection #23343
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cc0effe
data collection implementation
ekaradev 5654f9b
simplify device manager error handling and remove unused comments
ekaradev 610ff90
Update ActivityPropertyNames.cs
ekaradev 2a9d93a
Filter null activities after deserialization
ekaradev 039a928
Update ActivityNameConsts.cs
ekaradev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...rc/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/TelemetryApplicationMetricsEnricher.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Volo.Abp.Application.Services; | ||
using Volo.Abp.DependencyInjection; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Volo.Abp.Internal.Telemetry.Activity; | ||
using Volo.Abp.Internal.Telemetry.Activity.Contracts; | ||
using Volo.Abp.Internal.Telemetry.Activity.Providers; | ||
using Volo.Abp.Internal.Telemetry.Constants; | ||
using Volo.Abp.Internal.Telemetry.Constants.Enums; | ||
using Volo.Abp.Reflection; | ||
|
||
namespace Volo.Abp.AspNetCore.Mvc; | ||
|
||
[ExposeServices(typeof(ITelemetryActivityEventEnricher), typeof(IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher>))] | ||
public sealed class TelemetryApplicationMetricsEnricher : TelemetryActivityEventEnricher, IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher> | ||
{ | ||
private readonly ITypeFinder _typeFinder; | ||
public TelemetryApplicationMetricsEnricher(ITypeFinder typeFinder, IServiceProvider serviceProvider) : base(serviceProvider) | ||
{ | ||
_typeFinder = typeFinder; | ||
} | ||
|
||
protected override Task<bool> CanExecuteAsync(ActivityContext context) | ||
{ | ||
return Task.FromResult(context.SessionType == SessionType.ApplicationRuntime); | ||
} | ||
|
||
protected override Task ExecuteAsync(ActivityContext context) | ||
{ | ||
var appServiceCount = _typeFinder.Types.Count(t => | ||
typeof(IApplicationService).IsAssignableFrom(t) && | ||
t is { IsAbstract: false, IsInterface: false } && | ||
!t.AssemblyQualifiedName!.StartsWith(TelemetryConsts.VoloNameSpaceFilter)); | ||
|
||
var controllerCount = _typeFinder.Types.Count(t => | ||
typeof(ControllerBase).IsAssignableFrom(t) && | ||
!t.IsAbstract && | ||
!t.AssemblyQualifiedName!.StartsWith(TelemetryConsts.VoloNameSpaceFilter)); | ||
|
||
|
||
context.Current[ActivityPropertyNames.AppServiceCount] = appServiceCount; | ||
context.Current[ActivityPropertyNames.ControllerCount] = controllerCount; | ||
return Task.CompletedTask; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
framework/src/Volo.Abp.Authorization.Abstractions/Properties/AssemblyInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Volo.Abp.Authorization.Abstractions")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: InternalsVisibleTo("Volo.Abp.Authorization")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("83632bec-2f60-4c2b-b964-30e8b37fa9d8")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...o.Abp.Authorization/Volo/Abp/Authorization/Permissions/TelemetryPermissionInfoEnricher.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Internal.Telemetry.Activity; | ||
using Volo.Abp.Internal.Telemetry.Activity.Contracts; | ||
using Volo.Abp.Internal.Telemetry.Activity.Providers; | ||
using Volo.Abp.Internal.Telemetry.Constants; | ||
|
||
namespace Volo.Abp.Authorization.Permissions; | ||
|
||
[ExposeServices(typeof(ITelemetryActivityEventEnricher), typeof(IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher>))] | ||
public sealed class TelemetryPermissionInfoEnricher : TelemetryActivityEventEnricher, IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher> | ||
{ | ||
private readonly IPermissionDefinitionManager _permissionDefinitionManager; | ||
|
||
public TelemetryPermissionInfoEnricher(IPermissionDefinitionManager permissionDefinitionManager, | ||
IServiceProvider serviceProvider) : base(serviceProvider) | ||
{ | ||
_permissionDefinitionManager = permissionDefinitionManager; | ||
} | ||
|
||
protected override Task<bool> CanExecuteAsync(ActivityContext context) | ||
{ | ||
return Task.FromResult(context.ProjectId.HasValue); | ||
} | ||
|
||
protected async override Task ExecuteAsync(ActivityContext context) | ||
{ | ||
var permissions = await _permissionDefinitionManager.GetPermissionsAsync(); | ||
|
||
var userDefinedPermissionsCount = permissions.Count(IsUserDefinedPermission); | ||
|
||
context.Current[ActivityPropertyNames.PermissionCount] = userDefinedPermissionsCount; | ||
} | ||
|
||
private static bool IsUserDefinedPermission(PermissionDefinition permission) | ||
{ | ||
return permission.Properties.TryGetValue(PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName, out var providerName) && | ||
providerName is string && | ||
!providerName.ToString()!.StartsWith(TelemetryConsts.VoloNameSpaceFilter); | ||
} | ||
|
||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/ActivityContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Volo.Abp.Internal.Telemetry.Constants; | ||
using Volo.Abp.Internal.Telemetry.Constants.Enums; | ||
|
||
namespace Volo.Abp.Internal.Telemetry.Activity; | ||
|
||
public class ActivityContext | ||
{ | ||
public ActivityEvent Current { get; } | ||
public Dictionary<string, object> ExtraProperties { get; } = new(); | ||
public bool IsTerminated { get; private set; } | ||
|
||
public Guid? ProjectId => Current.Get<Guid?>(ActivityPropertyNames.ProjectId); | ||
|
||
public Guid? SolutionId => Current.Get<Guid?>(ActivityPropertyNames.SolutionId); | ||
|
||
public SessionType? SessionType => Current.Get<SessionType?>(ActivityPropertyNames.SessionType); | ||
|
||
public string? DeviceId => Current.Get<string?>(ActivityPropertyNames.DeviceId); | ||
|
||
public string? SolutionPath => ExtraProperties.TryGetValue(ActivityPropertyNames.SolutionPath, out var solutionPath) | ||
? solutionPath?.ToString() | ||
: null; | ||
|
||
private ActivityContext(ActivityEvent current) | ||
{ | ||
Current = current; | ||
} | ||
|
||
public static ActivityContext Create(string activityName, string? details = null, | ||
Action<Dictionary<string, object>>? additionalProperties = null) | ||
{ | ||
var activity = new ActivityEvent(activityName, details); | ||
|
||
if (additionalProperties is not null) | ||
{ | ||
var additionalPropertiesDict = new Dictionary<string, object>(); | ||
activity[ActivityPropertyNames.AdditionalProperties] = additionalPropertiesDict; | ||
additionalProperties.Invoke(additionalPropertiesDict); | ||
} | ||
|
||
return new ActivityContext(activity); | ||
} | ||
|
||
public void Terminate() | ||
{ | ||
IsTerminated = true; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.