Enhancing telemetry in Seq and fixes namespaces
This commit is contained in:
parent
5568007237
commit
9f4996bc8f
65 changed files with 1122 additions and 1139 deletions
|
|
@ -1,21 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="App.ts" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Core.csproj" />
|
||||
<ProjectReference Include="..\Database\Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Views\Components\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using Microsoft.AspNetCore.Mvc.Razor;
|
||||
|
||||
namespace Application.Common
|
||||
namespace PlanTempus.Application.Common
|
||||
{
|
||||
public class ComponentsViewLocationExpander : IViewLocationExpander
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Components.Navigation
|
||||
namespace PlanTempus.Application.Components.Navigation
|
||||
{
|
||||
public class NavigationViewComponent : ViewComponent
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
@page
|
||||
@model IndexModel
|
||||
@model PlanTempus.Application.Pages.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Home page";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using Microsoft.ApplicationInsights;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace PlanTempus.Pages
|
||||
namespace PlanTempus.Application.Pages
|
||||
{
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
|
|
|
|||
21
Application/PlanTempus.Application.csproj
Normal file
21
Application/PlanTempus.Application.csproj
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="App.ts" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\PlanTempus.Core.csproj" />
|
||||
<ProjectReference Include="..\Database\PlanTempus.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Views\Components\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
using Application;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using PlanTempus.Application;
|
||||
|
||||
var host = Host.CreateDefaultBuilder(args)
|
||||
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
using Autofac;
|
||||
using Core.Configurations.JsonConfigProvider;
|
||||
using Core.Configurations;
|
||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||
using PlanTempus.Core.Configurations;
|
||||
using PlanTempus.Core.ModuleRegistry;
|
||||
|
||||
namespace Application
|
||||
namespace PlanTempus.Application
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
|
|
@ -39,9 +40,9 @@ namespace Application
|
|||
ConnectionString = ConfigurationRoot.GetConnectionString("ptdb")
|
||||
});
|
||||
|
||||
builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule
|
||||
builder.RegisterModule(new TelemetryModule
|
||||
{
|
||||
TelemetryConfig = ConfigurationRoot.GetSection(nameof(Core.ModuleRegistry.TelemetryConfig)).ToObject<Core.ModuleRegistry.TelemetryConfig>()
|
||||
TelemetryConfig = ConfigurationRoot.GetSection(nameof(TelemetryConfig)).ToObject<TelemetryConfig>()
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,7 @@
|
|||
"ptdb": "Host=localhost;Port=5433;Database=ptdb01;User Id=sathumper;Password=3911;"
|
||||
},
|
||||
"TelemetryConfig": {
|
||||
"ConnectionString": "InstrumentationKey=07d2a2b9-5e8e-4924-836e-264f8438f6c5;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=56748c39-2fa3-4880-a1e2-24068e791548"
|
||||
},
|
||||
"Feature": {
|
||||
"Enabled": true,
|
||||
"RolloutPercentage": 25,
|
||||
"AllowedUserGroups": [ "beta" ]
|
||||
"ConnectionString": "InstrumentationKey=07d2a2b9-5e8e-4924-836e-264f8438f6c5;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=56748c39-2fa3-4880-a1e2-24068e791548",
|
||||
"UseSeqLoggingTelemetryChannel": true
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.Configurations.Common
|
||||
namespace PlanTempus.Core.Configurations.Common
|
||||
{
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
namespace Core.Configurations
|
||||
namespace PlanTempus.Core.Configurations
|
||||
{
|
||||
public interface IConfigurationBuilder
|
||||
{
|
||||
|
|
@ -133,7 +133,7 @@ namespace Core.Configurations
|
|||
public interface IConfigurationProvider
|
||||
{
|
||||
void Build();
|
||||
Newtonsoft.Json.Linq.JObject Configuration();
|
||||
JObject Configuration();
|
||||
}
|
||||
|
||||
public class ConfigurationSection : IConfigurationSection
|
||||
|
|
@ -148,6 +148,6 @@ namespace Core.Configurations
|
|||
{
|
||||
string Path { get; }
|
||||
string Key { get; }
|
||||
Newtonsoft.Json.Linq.JToken Value { get; set; }
|
||||
JToken Value { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.Configurations
|
||||
namespace PlanTempus.Core.Configurations
|
||||
{
|
||||
/// <summary>
|
||||
/// Marker interface for application configurations that should be automatically registered in the DI container.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.Configurations
|
||||
namespace PlanTempus.Core.Configurations
|
||||
{
|
||||
public interface IConfigurationRoot : IConfiguration { }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
using Core.Exceptions;
|
||||
using PlanTempus.Core.Exceptions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PlanTempus.Core.Configurations;
|
||||
|
||||
namespace Core.Configurations.JsonConfigProvider
|
||||
namespace PlanTempus.Core.Configurations.JsonConfigProvider
|
||||
{
|
||||
public static class JsonConfigExtension
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.Configurations.SmartConfigProvider;
|
||||
namespace PlanTempus.Core.Configurations.SmartConfigProvider;
|
||||
public class AppConfiguration
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.Configurations.SmartConfigProvider;
|
||||
namespace PlanTempus.Core.Configurations.SmartConfigProvider;
|
||||
public interface IConfigurationRepository
|
||||
{
|
||||
string ConnectionString { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Data;
|
||||
using Insight.Database;
|
||||
|
||||
namespace Core.Configurations.SmartConfigProvider.Repositories;
|
||||
namespace PlanTempus.Core.Configurations.SmartConfigProvider.Repositories;
|
||||
public class PostgresConfigurationRepository : IConfigurationRepository
|
||||
{
|
||||
private IDbConnection _connection;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
namespace Core.Configurations.SmartConfigProvider
|
||||
using PlanTempus.Core.Configurations;
|
||||
|
||||
namespace PlanTempus.Core.Configurations.SmartConfigProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for adding smart configuration providers to IConfigurationBuilder.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.Configurations.SmartConfigProvider
|
||||
namespace PlanTempus.Core.Configurations.SmartConfigProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration options for setting up smart configuration providers.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
using Core.Configurations.JsonConfigProvider;
|
||||
using Core.Exceptions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||
using PlanTempus.Core.Exceptions;
|
||||
|
||||
namespace Core.Configurations.SmartConfigProvider
|
||||
namespace PlanTempus.Core.Configurations.SmartConfigProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration provider that loads configuration from a smart configuration source (e.g. database).
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.Entities.Users
|
||||
namespace PlanTempus.Core.Entities.Users
|
||||
{
|
||||
public class User
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.Entities.Users
|
||||
namespace PlanTempus.Core.Entities.Users
|
||||
{
|
||||
public static class PasswordHasher
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.Exceptions
|
||||
namespace PlanTempus.Core.Exceptions
|
||||
{
|
||||
internal class ConfigurationException : Exception
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
using Core.Telemetry;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using PlanTempus.Core.Telemetry;
|
||||
|
||||
namespace Core.Logging
|
||||
namespace PlanTempus.Core.Logging
|
||||
{
|
||||
public class SeqBackgroundService : BackgroundService
|
||||
{
|
||||
private readonly IMessageChannel<ITelemetry> _messageChannel;
|
||||
private readonly TelemetryClient _telemetryClient;
|
||||
private readonly SeqLogger _seqLogger;
|
||||
private readonly SeqLogger<SeqBackgroundService> _seqLogger;
|
||||
|
||||
public SeqBackgroundService(TelemetryClient telemetryClient,
|
||||
IMessageChannel<ITelemetry> messageChannel,
|
||||
SeqLogger seqlogger)
|
||||
SeqLogger<SeqBackgroundService> seqlogger)
|
||||
{
|
||||
_telemetryClient = telemetryClient;
|
||||
_messageChannel = messageChannel;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using System.Text;
|
||||
|
||||
namespace Core.Logging
|
||||
namespace PlanTempus.Core.Logging
|
||||
{
|
||||
public record SeqConfiguration(string IngestionEndpoint, string ApiKey, string Environment);
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
namespace Core.Logging
|
||||
namespace PlanTempus.Core.Logging
|
||||
{
|
||||
public class SeqHttpClient
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using System.Text;
|
||||
|
||||
namespace Core.Logging
|
||||
namespace PlanTempus.Core.Logging
|
||||
{
|
||||
public class SeqLogger
|
||||
public class SeqLogger<T>
|
||||
{
|
||||
private readonly SeqHttpClient _httpClient;
|
||||
private readonly string _environmentName;
|
||||
|
|
@ -13,8 +13,6 @@ namespace Core.Logging
|
|||
public SeqLogger(SeqHttpClient httpClient, string environmentName, SeqConfiguration configuration)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_environmentName = configuration.Environment;
|
||||
_machineName = Environment.MachineName;
|
||||
}
|
||||
|
||||
public async Task LogAsync(TraceTelemetry trace, CancellationToken cancellationToken = default)
|
||||
|
|
@ -29,9 +27,10 @@ namespace Core.Logging
|
|||
};
|
||||
|
||||
foreach (var prop in trace.Properties)
|
||||
{
|
||||
seqEvent.Add(prop.Key, prop.Value);
|
||||
}
|
||||
seqEvent.Add($"prop_{prop.Key}", prop.Value);
|
||||
|
||||
foreach (var prop in trace.Context.GlobalProperties)
|
||||
seqEvent.Add($"global_{prop.Key}", prop.Value);
|
||||
|
||||
await SendToSeqAsync(seqEvent, cancellationToken);
|
||||
}
|
||||
|
|
@ -48,14 +47,13 @@ namespace Core.Logging
|
|||
};
|
||||
|
||||
foreach (var prop in evt.Properties)
|
||||
{
|
||||
seqEvent.Add(prop.Key, prop.Value);
|
||||
}
|
||||
seqEvent.Add($"prop_{prop.Key}", prop.Value);
|
||||
|
||||
foreach (var prop in evt.Context.GlobalProperties)
|
||||
seqEvent.Add($"global_{prop.Key}", prop.Value);
|
||||
|
||||
foreach (var metric in evt.Metrics)
|
||||
{
|
||||
seqEvent.Add($"metric_{metric.Key}", metric.Value);
|
||||
}
|
||||
|
||||
await SendToSeqAsync(seqEvent, cancellationToken);
|
||||
}
|
||||
|
|
@ -74,9 +72,10 @@ namespace Core.Logging
|
|||
};
|
||||
|
||||
foreach (var prop in ex.Properties)
|
||||
{
|
||||
seqEvent.Add(prop.Key, prop.Value);
|
||||
}
|
||||
seqEvent.Add($"prop_{prop.Key}", prop.Value);
|
||||
|
||||
foreach (var prop in ex.Context.GlobalProperties)
|
||||
seqEvent.Add($"global_{prop.Key}", prop.Value);
|
||||
|
||||
await SendToSeqAsync(seqEvent, cancellationToken);
|
||||
}
|
||||
|
|
@ -96,73 +95,65 @@ namespace Core.Logging
|
|||
};
|
||||
|
||||
foreach (var prop in dep.Properties)
|
||||
{
|
||||
seqEvent.Add(prop.Key, prop.Value);
|
||||
}
|
||||
seqEvent.Add($"prop_{prop.Key}", prop.Value);
|
||||
|
||||
foreach (var prop in dep.Context.GlobalProperties)
|
||||
seqEvent.Add($"global_{prop.Key}", prop.Value);
|
||||
|
||||
await SendToSeqAsync(seqEvent, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task LogAsync(RequestTelemetry req, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var seqEvent = new Dictionary<string, object>
|
||||
{
|
||||
{ "@t", req.Timestamp.UtcDateTime.ToString("o") },
|
||||
{ "@mt",$"{req.Properties["httpMethod"]} {req.Name}" },
|
||||
{ "@l", req.Success??true ? "Information" : "Error" },
|
||||
{ "Environment", _environmentName },
|
||||
{ "MachineName", _machineName },
|
||||
{ "Url", req.Url },
|
||||
{ "ResponseCode", req.ResponseCode },
|
||||
{ "Application", "sadasd" },
|
||||
{ "RequestMethod", req.Properties["httpMethod"] },
|
||||
{ "RequestId", req.Id },
|
||||
{ "ItemTypeFlag", req.ItemTypeFlag.ToString() },
|
||||
{ "@sp", "12"},
|
||||
{ "@tr", "23344"},
|
||||
{ "@sk","Server" },
|
||||
{ "@st", req.Timestamp.UtcDateTime.Subtract(req.Duration).ToString("o") }
|
||||
};
|
||||
req.Properties.Remove("httpMethod");
|
||||
|
||||
//we should add a property with name { "Application", "<...>" } other the Seq Span is not looking ok
|
||||
foreach (var prop in req.Properties)
|
||||
{
|
||||
seqEvent.Add(prop.Key, prop.Value);
|
||||
}
|
||||
|
||||
await SendToSeqAsync(seqEvent, cancellationToken);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public async Task LogAsync(Microsoft.ApplicationInsights.Extensibility.IOperationHolder<RequestTelemetry> operationHolder, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var req = operationHolder.Telemetry;
|
||||
|
||||
//https://docs.datalust.co/v2025.1/docs/posting-raw-events
|
||||
var seqEvent = new Dictionary<string, object>
|
||||
{
|
||||
|
||||
{ "@t", req.Timestamp.UtcDateTime.ToString("o") },
|
||||
{ "@mt",$"{req.Properties["httpMethod"]} {req.Name}" },
|
||||
{ "@mt",req.Name },
|
||||
{ "@l", req.Success??true ? "Information" : "Error" },
|
||||
{ "Environment", _environmentName },
|
||||
{ "MachineName", _machineName },
|
||||
{ "@sp", req.Id }, //Span id Unique identifier of a span Yes, if the event is a span
|
||||
{ "@tr", req.Context.Operation.Id}, //Trace id An identifier that groups all spans and logs that are in the same trace Yes, if the event is a span
|
||||
{ "@sk","Server" }, //Span kind Describes the relationship of the span to others in the trace: Client, Server, Internal, Producer, or Consumer
|
||||
{ "@st", req.Timestamp.UtcDateTime.Subtract(req.Duration).ToString("o") }, //Start The start ISO 8601 timestamp of this span Yes, if the event is a span
|
||||
{ "SourceContext", typeof(T).FullName },
|
||||
{ "Url", req.Url },
|
||||
{ "ResponseCode", req.ResponseCode },
|
||||
{ "Application", "sadasd" },
|
||||
{ "RequestMethod", req.Properties["httpMethod"] },
|
||||
{ "RequestId", req.Id },
|
||||
{ "ItemTypeFlag", req.ItemTypeFlag.ToString() },
|
||||
{ "@sp", "12"},
|
||||
{ "@tr", "23344"},
|
||||
{ "@sk","Server" },
|
||||
{ "@st", req.Timestamp.UtcDateTime.Subtract(req.Duration).ToString("o") }
|
||||
{ "ItemTypeFlag", req.ItemTypeFlag.ToString() }
|
||||
};
|
||||
req.Properties.Remove("httpMethod");
|
||||
|
||||
//we should add a property with name { "Application", "<...>" } other the Seq Span is not looking ok
|
||||
foreach (var prop in req.Properties)
|
||||
|
||||
if (!string.IsNullOrEmpty(req.ResponseCode))
|
||||
{
|
||||
seqEvent.Add(prop.Key, prop.Value);
|
||||
if (int.TryParse(req.ResponseCode, out int statusCode))
|
||||
{
|
||||
if (Enum.IsDefined(typeof(System.Net.HttpStatusCode), statusCode))
|
||||
seqEvent["StatusCode"] = $"{statusCode} {(System.Net.HttpStatusCode)statusCode}";
|
||||
else
|
||||
seqEvent["StatusCode"] = $"{statusCode} Unknown";
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(req.Context.Operation.ParentId))
|
||||
seqEvent["@ps"] = req.Context.Operation.ParentId;
|
||||
|
||||
if (req.Properties.TryGetValue("httpMethod", out string method))
|
||||
{
|
||||
seqEvent["RequestMethod"] = method;
|
||||
seqEvent["@mt"] = $"{req.Properties["httpMethod"]} {req.Name}";
|
||||
req.Properties.Remove("httpMethod");
|
||||
}
|
||||
|
||||
foreach (var prop in req.Properties)
|
||||
seqEvent.Add($"prop_{prop.Key}", prop.Value);
|
||||
|
||||
foreach (var prop in req.Context.GlobalProperties)
|
||||
seqEvent.Add($"global_{prop.Key}", prop.Value);
|
||||
|
||||
await SendToSeqAsync(seqEvent, cancellationToken);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
using Autofac;
|
||||
using Core.Logging;
|
||||
using Core.Telemetry;
|
||||
using PlanTempus.Core.Logging;
|
||||
using PlanTempus.Core.Telemetry;
|
||||
|
||||
namespace Core.ModuleRegistry
|
||||
namespace PlanTempus.Core.ModuleRegistry
|
||||
{
|
||||
public class SeqLoggingModule : Module
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,71 +1,48 @@
|
|||
using Autofac;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
|
||||
|
||||
namespace Core.ModuleRegistry
|
||||
namespace PlanTempus.Core.ModuleRegistry
|
||||
{
|
||||
public class TelemetryModule : Module
|
||||
{
|
||||
public TelemetryConfig TelemetryConfig { get; set; }
|
||||
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
if (TelemetryConfig == null)
|
||||
throw new Exceptions.ConfigurationException("TelemetryConfig is missing");
|
||||
|
||||
//builder.Register(c =>
|
||||
//{
|
||||
// var channel = new Telemetry.DualTelemetryChannel("C:\\logs\\telemetry.log");
|
||||
// channel.DeveloperMode = true;
|
||||
// var config = new TelemetryConfiguration
|
||||
// {
|
||||
|
||||
// ConnectionString = TelemetryConfig.ConnectionString,
|
||||
// TelemetryChannel = channel
|
||||
// };
|
||||
// return new TelemetryClient(config);
|
||||
//}).InstancePerLifetimeScope();
|
||||
var configuration = TelemetryConfiguration.CreateDefault();
|
||||
configuration.ConnectionString = TelemetryConfig.ConnectionString;
|
||||
configuration.TelemetryChannel.DeveloperMode = true;
|
||||
|
||||
var telemetryChannel = new InMemoryChannel
|
||||
{
|
||||
DeveloperMode = true
|
||||
};
|
||||
if (TelemetryConfig.UseSeqLoggingTelemetryChannel)
|
||||
configuration.TelemetryChannel = new Telemetry.SeqLoggingTelemetryChannel(); ;
|
||||
|
||||
//var configuration = new TelemetryConfiguration
|
||||
//{
|
||||
// ConnectionString = TelemetryConfig.ConnectionString,
|
||||
// TelemetryChannel = telemetryChannel
|
||||
//};
|
||||
|
||||
//telemetryChannel.Initialize(configuration);
|
||||
|
||||
|
||||
var tmc = Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CreateDefault();
|
||||
tmc.ConnectionString = TelemetryConfig.ConnectionString;
|
||||
tmc.TelemetryChannel.DeveloperMode = true;
|
||||
var channel = new Telemetry.SeqLoggingTelemetryChannel("C:\\logs\\telemetry.log");
|
||||
|
||||
tmc.TelemetryChannel = channel;
|
||||
|
||||
////var r = new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(tmc);
|
||||
////r.Use(next => new Domain.EventTelemetryEnrichers.EnrichWithMetaTelemetry(next));
|
||||
////r.Build();
|
||||
var r = new Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryProcessorChainBuilder(configuration);
|
||||
r.Use(next => new Telemetry.Enrichers.EnrichWithMetaTelemetry(next));
|
||||
r.Build();
|
||||
|
||||
//builder.RegisterInstance(configuration);
|
||||
builder.Register(c => new TelemetryClient(tmc)).InstancePerLifetimeScope();
|
||||
|
||||
//builder.RegisterType<Microsoft.ApplicationInsights.TelemetryClient>()
|
||||
// .InstancePerLifetimeScope();
|
||||
|
||||
//builder.RegisterType<Microsoft.ApplicationInsights.TelemetryClient>()
|
||||
// .As<Telemetry.ITelemetryClient>()
|
||||
// .InstancePerLifetimeScope();
|
||||
var client = new Microsoft.ApplicationInsights.TelemetryClient(configuration);
|
||||
client.Context.GlobalProperties["Application"] = GetType().Namespace.Split('.')[0];
|
||||
client.Context.GlobalProperties["MachineName"] = Environment.MachineName;
|
||||
client.Context.GlobalProperties["Version"] = Environment.Version.ToString();
|
||||
client.Context.GlobalProperties["ProcessorCount"] = Environment.ProcessorCount.ToString();
|
||||
|
||||
builder.Register(c => client).InstancePerLifetimeScope();
|
||||
}
|
||||
}
|
||||
|
||||
public class TelemetryConfig
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
public bool UseSeqLoggingTelemetryChannel { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.MultiKeyEncryption
|
||||
namespace PlanTempus.Core.MultiKeyEncryption
|
||||
{
|
||||
internal class MasterKey
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Security.Cryptography;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.MultiKeyEncryption
|
||||
namespace PlanTempus.Core.MultiKeyEncryption
|
||||
{
|
||||
public class SecureConnectionString
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
22
Core/Telemetry/Enrichers/EnrichWithMetaTelemetry.cs
Normal file
22
Core/Telemetry/Enrichers/EnrichWithMetaTelemetry.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
|
||||
namespace PlanTempus.Core.Telemetry.Enrichers
|
||||
{
|
||||
|
||||
public class EnrichWithMetaTelemetry : ITelemetryProcessor
|
||||
{
|
||||
private readonly ITelemetryProcessor _next;
|
||||
|
||||
public EnrichWithMetaTelemetry(ITelemetryProcessor next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public void Process(ITelemetry item)
|
||||
{
|
||||
//nothing going on here yet :)
|
||||
_next.Process(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
using System.Threading.Channels;
|
||||
namespace Core.Telemetry
|
||||
namespace PlanTempus.Core.Telemetry
|
||||
{
|
||||
public interface IMessageChannel<T> : IDisposable
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using Microsoft.ApplicationInsights.Channel;
|
||||
using System.Threading.Channels;
|
||||
|
||||
namespace Core.Telemetry
|
||||
namespace PlanTempus.Core.Telemetry
|
||||
{
|
||||
public class MessageChannel : IMessageChannel<ITelemetry>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
using Microsoft.ApplicationInsights.Channel;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace Core.Telemetry
|
||||
namespace PlanTempus.Core.Telemetry
|
||||
{
|
||||
public class SeqLoggingTelemetryChannel : InMemoryChannel, ITelemetryChannel
|
||||
{
|
||||
private readonly string _filePath;
|
||||
public ITelemetryChannel _defaultChannel;
|
||||
static HttpClient _client = new HttpClient();
|
||||
|
||||
|
|
@ -22,9 +21,8 @@ namespace Core.Telemetry
|
|||
}
|
||||
|
||||
|
||||
public SeqLoggingTelemetryChannel(string filePath)
|
||||
public SeqLoggingTelemetryChannel()
|
||||
{
|
||||
_filePath = filePath;
|
||||
}
|
||||
public new void Send(ITelemetry telemetry)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Database.Common
|
||||
namespace PlanTempus.Database.Common
|
||||
{
|
||||
internal class Validations
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
using Insight.Database;
|
||||
using PlanTempus.Database.Core;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.ConfigurationManagementSystem;
|
||||
namespace PlanTempus.Database.ConfigurationManagementSystem;
|
||||
|
||||
public class SetupConfiguration : Core.IDbConfigure<SetupConfiguration.Command>
|
||||
public class SetupConfiguration : IDbConfigure<SetupConfiguration.Command>
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
using System.Data;
|
||||
using Database.Common;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Database.Common;
|
||||
using PlanTempus.Database.Core;
|
||||
|
||||
namespace Database.Core.DCL
|
||||
namespace PlanTempus.Database.Core.DCL
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
using System.Data;
|
||||
using Database.Common;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Database.Common;
|
||||
using PlanTempus.Database.Core;
|
||||
|
||||
namespace Database.Core.DCL
|
||||
namespace PlanTempus.Database.Core.DCL
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
using System.Data;
|
||||
using Database.Common;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Database.Common;
|
||||
using PlanTempus.Database.Core;
|
||||
|
||||
namespace Database.Core.DCL
|
||||
namespace PlanTempus.Database.Core.DCL
|
||||
{
|
||||
public class SetupOrganization : IDbConfigure<SetupOrganization.Command>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
using Insight.Database;
|
||||
using PlanTempus.Database.Core;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.Core.DDL
|
||||
namespace PlanTempus.Database.Core.DDL
|
||||
{
|
||||
/// <summary>
|
||||
/// This is by purpose not async await
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Database.Core
|
||||
namespace PlanTempus.Database.Core
|
||||
{
|
||||
public interface IDbConfigure<T>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
using Core.Entities.Users;
|
||||
using Insight.Database;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Core.Entities.Users;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.Core
|
||||
namespace PlanTempus.Database.Core
|
||||
{
|
||||
public class UserService
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using Autofac;
|
||||
using Npgsql;
|
||||
using System.Data;
|
||||
namespace Database.ModuleRegistry
|
||||
namespace PlanTempus.Database.ModuleRegistry
|
||||
{
|
||||
public class DbPostgreSqlModule : Module
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using Insight.Database;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.NavigationSystem
|
||||
namespace PlanTempus.Database.NavigationSystem
|
||||
{
|
||||
internal class Setup
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Core.csproj" />
|
||||
<ProjectReference Include="..\Core\PlanTempus.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
using System.Data;
|
||||
using Database.Common;
|
||||
using Insight.Database;
|
||||
|
||||
namespace Database.RolesPermissionSystem
|
||||
namespace PlanTempus.Database.RolesPermissionSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// This is by purpose not async await
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using Insight.Database;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.Tenants
|
||||
namespace PlanTempus.Database.Tenants
|
||||
{
|
||||
internal class InitializeOrganizationData
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.35013.160
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{7B554252-1CE4-44BD-B108-B0BDCCB24742}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Core", "Core\PlanTempus.Core.csproj", "{7B554252-1CE4-44BD-B108-B0BDCCB24742}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{85614050-CFB0-4E39-81D3-7D99946449D9}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Tests", "Tests\PlanTempus.Tests.csproj", "{85614050-CFB0-4E39-81D3-7D99946449D9}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Application\Application.csproj", "{111CE8AE-E637-4376-A5A3-88D33E77EA88}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Application", "Application\PlanTempus.Application.csproj", "{111CE8AE-E637-4376-A5A3-88D33E77EA88}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Database", "Database\Database.csproj", "{D5096A7F-E6D4-4C87-874E-2D9A6BEAD57F}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.Database", "Database\PlanTempus.Database.csproj", "{D5096A7F-E6D4-4C87-874E-2D9A6BEAD57F}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SetupInfrastructure", "SetupInfrastructure\SetupInfrastructure.csproj", "{48300227-BCBB-45A3-8359-9064DA85B1F9}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanTempus.SetupInfrastructure", "SetupInfrastructure\PlanTempus.SetupInfrastructure.csproj", "{48300227-BCBB-45A3-8359-9064DA85B1F9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Database\Database.csproj" />
|
||||
<ProjectReference Include="..\Database\PlanTempus.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
using Autofac;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Database.ConfigurationManagementSystem;
|
||||
using PlanTempus.Database.Core.DCL;
|
||||
using PlanTempus.Database.Core.DDL;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SetupInfrastructure
|
||||
namespace PlanTempus.SetupInfrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// SETUP APPLICATION USER NAMED sathumper
|
||||
|
|
@ -51,8 +54,8 @@ namespace SetupInfrastructure
|
|||
|
||||
Console.Write("Database.Core.DCL.SetupDbAdmin...");
|
||||
sw.Start();
|
||||
var setupDbAdmin = _container.Resolve<Database.Core.DCL.SetupDbAdmin>();
|
||||
setupDbAdmin.With(new Database.Core.DCL.SetupDbAdmin.Command { Password = "3911", Schema = "system", User = "heimdall" });
|
||||
var setupDbAdmin = _container.Resolve<SetupDbAdmin>();
|
||||
setupDbAdmin.With(new SetupDbAdmin.Command { Password = "3911", Schema = "system", User = "heimdall" });
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
|
|
@ -64,16 +67,16 @@ namespace SetupInfrastructure
|
|||
//create new container with application user, we use that role from now.
|
||||
_container = new Startup().ConfigureContainer(new Startup.ConnectionStringTemplateParameters("heimdall", "3911"));
|
||||
|
||||
var setupIdentitySystem = _container.Resolve<Database.Core.DDL.SetupIdentitySystem>();
|
||||
setupIdentitySystem.With(new Database.Core.DDL.SetupIdentitySystem.Command { Schema = "system"});
|
||||
var setupIdentitySystem = _container.Resolve<SetupIdentitySystem>();
|
||||
setupIdentitySystem.With(new SetupIdentitySystem.Command { Schema = "system" });
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
Console.WriteLine("::");
|
||||
Console.WriteLine("::");
|
||||
Console.Write("Database.ConfigurationManagementSystem.SetupConfiguration...");
|
||||
sw.Restart();
|
||||
var setupConfigurationSystem = _container.Resolve<Database.ConfigurationManagementSystem.SetupConfiguration>();
|
||||
setupConfigurationSystem.With(new Database.ConfigurationManagementSystem.SetupConfiguration.Command());
|
||||
var setupConfigurationSystem = _container.Resolve<SetupConfiguration>();
|
||||
setupConfigurationSystem.With(new SetupConfiguration.Command());
|
||||
Console.Write($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
|
|
@ -81,8 +84,8 @@ namespace SetupInfrastructure
|
|||
Console.WriteLine("::");
|
||||
Console.Write("Database.Core.DCL.SetupApplicationUser...");
|
||||
sw.Start();
|
||||
var setupApplicationUser = _container.Resolve<Database.Core.DCL.SetupApplicationUser>();
|
||||
setupApplicationUser.With(new Database.Core.DCL.SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" });
|
||||
var setupApplicationUser = _container.Resolve<SetupApplicationUser>();
|
||||
setupApplicationUser.With(new SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" });
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
using Autofac;
|
||||
using Core.Configurations;
|
||||
using Core.Configurations.JsonConfigProvider;
|
||||
using PlanTempus.Core.Configurations;
|
||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||
using PlanTempus.Core.ModuleRegistry;
|
||||
using PlanTempus.Database.Core;
|
||||
|
||||
|
||||
namespace SetupInfrastructure
|
||||
namespace PlanTempus.SetupInfrastructure
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
|
|
@ -27,13 +28,13 @@ namespace SetupInfrastructure
|
|||
ConnectionString = configuration.GetConnectionString("DefaultConnection").Replace("{usr}", ctp.user).Replace("{pwd}", ctp.pwd)
|
||||
});
|
||||
|
||||
builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule
|
||||
builder.RegisterModule(new TelemetryModule
|
||||
{
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<Core.ModuleRegistry.TelemetryConfig>()
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<TelemetryConfig>()
|
||||
});
|
||||
|
||||
builder.RegisterAssemblyTypes(typeof(Database.Core.IDbConfigure<>).Assembly)
|
||||
.AsClosedTypesOf(typeof(Database.Core.IDbConfigure<>))
|
||||
builder.RegisterAssemblyTypes(typeof(IDbConfigure<>).Assembly)
|
||||
.AsClosedTypesOf(typeof(IDbConfigure<>))
|
||||
.AsSelf();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
using Core.Configurations;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Core.Configurations.JsonConfigProvider;
|
||||
using Core.Configurations.SmartConfigProvider;
|
||||
using PlanTempus.Tests;
|
||||
using PlanTempus.Core.Configurations;
|
||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||
using PlanTempus.Core.Configurations.SmartConfigProvider;
|
||||
|
||||
namespace Tests.ConfigurationTests
|
||||
namespace PlanTempus.Tests.ConfigurationTests
|
||||
{
|
||||
[TestClass]
|
||||
public class JsonConfigurationProviderTests : TestFixture
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using Core.Configurations.Common;
|
||||
using PlanTempus.Core.Configurations.Common;
|
||||
using PlanTempus.Tests;
|
||||
|
||||
namespace Tests.ConfigurationTests;
|
||||
namespace PlanTempus.Tests.ConfigurationTests;
|
||||
|
||||
[TestClass]
|
||||
public class ConfigurationTests : TestFixture
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
using Core.Configurations;
|
||||
using FluentAssertions;
|
||||
using Core.Configurations.JsonConfigProvider;
|
||||
using FluentAssertions;
|
||||
using Autofac;
|
||||
using System.Data;
|
||||
using Insight.Database;
|
||||
using Npgsql;
|
||||
using Core.Configurations.SmartConfigProvider;
|
||||
using PlanTempus.Tests;
|
||||
using PlanTempus.Core.Configurations;
|
||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||
using PlanTempus.Core.Configurations.SmartConfigProvider;
|
||||
|
||||
namespace Tests.ConfigurationTests
|
||||
namespace PlanTempus.Tests.ConfigurationTests
|
||||
{
|
||||
[TestClass]
|
||||
public class SmartConfigProviderTests : TestFixture
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;"
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/",
|
||||
"UseSeqLoggingTelemetryChannel": true
|
||||
},
|
||||
"Authentication": "SHA256",
|
||||
"Feature": {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
using Autofac;
|
||||
using Core.Telemetry;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Core.Logging;
|
||||
using PlanTempus.Core.Logging;
|
||||
using PlanTempus.Core.Telemetry;
|
||||
|
||||
namespace Tests.Logging
|
||||
namespace PlanTempus.Tests.Logging
|
||||
{
|
||||
[TestClass]
|
||||
public class SeqBackgroundServiceTest : TestFixture
|
||||
|
|
@ -23,9 +23,7 @@ namespace Tests.Logging
|
|||
var config = new SeqConfiguration("http://localhost:5341", null, "MSTEST");
|
||||
|
||||
var httpClient = new SeqHttpClient(config);
|
||||
var logger = new SeqLogger(httpClient, Environment.MachineName, config);
|
||||
|
||||
|
||||
var logger = new SeqLogger<SeqBackgroundService>(httpClient, Environment.MachineName, config);
|
||||
|
||||
_service = new SeqBackgroundService(telemetryClient, _messageChannel, logger);
|
||||
_cts = new CancellationTokenSource();
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
using Autofac;
|
||||
using Core.Logging;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using PlanTempus.Core.Logging;
|
||||
|
||||
namespace Tests.Logging
|
||||
namespace PlanTempus.Tests.Logging
|
||||
{
|
||||
[TestClass]
|
||||
public class SeqLoggerTests : TestFixture
|
||||
{
|
||||
private SeqLogger _logger;
|
||||
private SeqLogger<SeqLoggerTests> _logger;
|
||||
private SeqHttpClient _httpClient;
|
||||
private readonly string _testId;
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ namespace Tests.Logging
|
|||
_testId = Guid.NewGuid().ToString();
|
||||
var config = new SeqConfiguration("http://localhost:5341", null, "MSTEST");
|
||||
_httpClient = new SeqHttpClient(config);
|
||||
_logger = new SeqLogger(_httpClient, Environment.MachineName, config);
|
||||
_logger = new SeqLogger<SeqLoggerTests>(_httpClient, Environment.MachineName, config);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
@ -113,24 +113,22 @@ namespace Tests.Logging
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task LogRequestTelemetry_SendsCorrectData()
|
||||
public async Task LogRequestTelemetryInOperationHolderWithParentChild_SendsCorrectData()
|
||||
{
|
||||
var telemetryClient = Container.Resolve<TelemetryClient>();
|
||||
|
||||
var operationId = "op123";
|
||||
|
||||
using (Microsoft.ApplicationInsights.Extensibility.IOperationHolder<RequestTelemetry> operation = telemetryClient.StartOperation<RequestTelemetry>("GET /api/parent"))
|
||||
using (Microsoft.ApplicationInsights.Extensibility.IOperationHolder<RequestTelemetry> parent = telemetryClient.StartOperation<RequestTelemetry>("Parent First"))
|
||||
{
|
||||
|
||||
using (var child = telemetryClient.StartOperation<RequestTelemetry>("api/test"))
|
||||
// Arrange
|
||||
{
|
||||
parent.Telemetry.Duration = TimeSpan.FromMilliseconds(250);
|
||||
parent.Telemetry.Url = new Uri("http://parent.test.com/api/test");
|
||||
|
||||
//child.Telemetry.Name = "/api/test";
|
||||
using (var child = telemetryClient.StartOperation<RequestTelemetry>("Child 1"))
|
||||
{
|
||||
child.Telemetry.Success = true;
|
||||
child.Telemetry.ResponseCode = "200";
|
||||
child.Telemetry.Duration = TimeSpan.FromMilliseconds(50);
|
||||
child.Telemetry.Url = new Uri("http://test.com/api/test");
|
||||
child.Telemetry.Url = new Uri("http://child.test.com/api/test");
|
||||
child.Telemetry.Timestamp = DateTimeOffset.UtcNow;
|
||||
|
||||
child.Telemetry.Properties.Add("httpMethod", HttpMethod.Get.ToString());
|
||||
|
|
@ -139,8 +137,8 @@ namespace Tests.Logging
|
|||
await _logger.LogAsync(child);
|
||||
};
|
||||
|
||||
}
|
||||
// Act
|
||||
await _logger.LogAsync(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,8 @@
|
|||
using Autofac;
|
||||
using System.Data;
|
||||
using Insight.Database;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Core.Telemetry;
|
||||
using Core.Entities.Users;
|
||||
using System.Diagnostics;
|
||||
using Sodium;
|
||||
using PlanTempus.Core.Entities.Users;
|
||||
|
||||
namespace Tests
|
||||
namespace PlanTempus.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class PasswordHasherTests : TestFixture
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Application\Application.csproj" />
|
||||
<ProjectReference Include="..\Database\Database.csproj" />
|
||||
<ProjectReference Include="..\Application\PlanTempus.Application.csproj" />
|
||||
<ProjectReference Include="..\Database\PlanTempus.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -1,11 +1,8 @@
|
|||
using Autofac;
|
||||
using System.Data;
|
||||
using Insight.Database;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Core.Telemetry;
|
||||
|
||||
namespace Tests
|
||||
namespace PlanTempus.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class PostgresTests : TestFixture
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
using Autofac;
|
||||
using System.Data;
|
||||
using Insight.Database;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Core.Telemetry;
|
||||
|
||||
namespace Tests
|
||||
|
||||
namespace PlanTempus.Tests
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Autofac;
|
||||
using Core.Configurations;
|
||||
using Core.ModuleRegistry;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Core.Configurations.JsonConfigProvider;
|
||||
namespace Tests
|
||||
using PlanTempus.Core.Configurations;
|
||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||
using PlanTempus.Core.ModuleRegistry;
|
||||
namespace PlanTempus.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Act as base class for tests. Avoids duplication of test setup code
|
||||
|
|
@ -72,9 +72,9 @@ namespace Tests
|
|||
ConnectionString = configuration.GetConnectionString("DefaultConnection")
|
||||
});
|
||||
|
||||
builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule
|
||||
builder.RegisterModule(new TelemetryModule
|
||||
{
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<Core.ModuleRegistry.TelemetryConfig>()
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<TelemetryConfig>()
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;"
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/",
|
||||
"UseSeqLoggingTelemetryChannel": true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue