Skip to content

Commit

Permalink
Merge pull request #794 from skadefro/master
Browse files Browse the repository at this point in the history
Fix logging attributes
  • Loading branch information
skadefro authored Feb 6, 2025
2 parents b8a5e4a + 2d5ce64 commit fff4e20
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 21 deletions.
3 changes: 3 additions & 0 deletions OpenRPA.SetupProject/compMain.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
<File Id="OpenTelemetry.Api.ProviderBuilderExtensions.dll" Source="!(wix.MainSource)\OpenTelemetry.Api.ProviderBuilderExtensions.dll" />



<File Id="Google.Protobuf.dll" Source="!(wix.MainSource)\Google.Protobuf.dll" />
<File Id="Grpc.Core.Api.dll" Source="!(wix.MainSource)\Grpc.Core.Api.dll" />
<File Id="Grpc.Core.dll" Source="!(wix.MainSource)\Grpc.Core.dll" />
Expand All @@ -204,7 +205,9 @@
<File Id="Microsoft.Extensions.Configuration.Abstractions.dll" Source="!(wix.MainSource)\Microsoft.Extensions.Configuration.Abstractions.dll" />
<File Id="Microsoft.Extensions.Configuration.Binder.dll" Source="!(wix.MainSource)\Microsoft.Extensions.Configuration.Binder.dll" />
<File Id="Microsoft.Extensions.Configuration.dll" Source="!(wix.MainSource)\Microsoft.Extensions.Configuration.dll" />
<File Id="Microsoft.Extensions.DependencyInjection.dll" Source="!(wix.MainSource)\Microsoft.Extensions.DependencyInjection.dll" />
<File Id="Microsoft.Extensions.DependencyInjection.Abstractions.dll" Source="!(wix.MainSource)\Microsoft.Extensions.DependencyInjection.Abstractions.dll" />
<File Id="Microsoft.Extensions.Diagnostics.Abstractions.dll" Source="!(wix.MainSource)\Microsoft.Extensions.Diagnostics.Abstractions.dll" />
<File Id="Microsoft.Extensions.Logging.Abstractions.dll" Source="!(wix.MainSource)\Microsoft.Extensions.Logging.Abstractions.dll" />
<File Id="Microsoft.Extensions.Logging.Configuration.dll" Source="!(wix.MainSource)\Microsoft.Extensions.Logging.Configuration.dll" />
<File Id="Microsoft.Extensions.Logging.dll" Source="!(wix.MainSource)\Microsoft.Extensions.Logging.dll" />
Expand Down
20 changes: 17 additions & 3 deletions OpenRPA.sln
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSspi", "vb5250\NSspi\NSspi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatchVSCode", "PatchVSCode\PatchVSCode.csproj", "{DCB604FC-D13D-4403-B3E8-972754B1329B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRPA.Storage.LiteDB", "OpenRPA.Storage.LiteDB\OpenRPA.Storage.LiteDB.csproj", "{67A40B0C-454D-46E8-B4DF-C402336F9FA1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenRPA.Storage.LiteDB", "OpenRPA.Storage.LiteDB\OpenRPA.Storage.LiteDB.csproj", "{67A40B0C-454D-46E8-B4DF-C402336F9FA1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRPA.Storage.Filesystem", "OpenRPA.Storage.Filesystem\OpenRPA.Storage.Filesystem.csproj", "{FA3B5892-998E-49C1-BC2F-2E5B10F2B422}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenRPA.Storage.Filesystem", "OpenRPA.Storage.Filesystem\OpenRPA.Storage.Filesystem.csproj", "{FA3B5892-998E-49C1-BC2F-2E5B10F2B422}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenRPA.v2WorkItems.Activities", "OpenRPA.v2WorkItems\OpenRPA.v2WorkItems.Activities.csproj", "{C4717E00-4049-44AE-A321-48B912170404}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -572,6 +574,18 @@ Global
{FA3B5892-998E-49C1-BC2F-2E5B10F2B422}.Release|Any CPU.Build.0 = Release|Any CPU
{FA3B5892-998E-49C1-BC2F-2E5B10F2B422}.Release|x86.ActiveCfg = Release|Any CPU
{FA3B5892-998E-49C1-BC2F-2E5B10F2B422}.Release|x86.Build.0 = Release|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.All|Any CPU.ActiveCfg = Debug|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.All|Any CPU.Build.0 = Debug|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.All|x86.ActiveCfg = Debug|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.All|x86.Build.0 = Debug|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.Debug|x86.ActiveCfg = Debug|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.Debug|x86.Build.0 = Debug|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.Release|Any CPU.Build.0 = Release|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.Release|x86.ActiveCfg = Release|Any CPU
{C4717E00-4049-44AE-A321-48B912170404}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -586,7 +600,7 @@ Global
{4B4CD933-BF62-4F92-B8FA-6771758C5197} = {86A0EDE3-9272-4CA5-A499-F2E1190A80EE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {40D49710-F666-4479-96E1-FFC3BA0D3D5A}
BuildVersion_StartDate = 2000/1/1
SolutionGuid = {40D49710-F666-4479-96E1-FFC3BA0D3D5A}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion OpenRPA/OpenRPA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Description>Base UI of OpenRPA, used as part of OpenRPA robot</Description>
<PackageLicenseExpression>MPL-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/open-rpa/openrpa</PackageProjectUrl>
<Version>1.4.57.10</Version>
<Version>1.4.57.11</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>openrpa.png</PackageIcon>
<Configurations>Debug;Release;ReleaseNuget;PrepInstaller</Configurations>
Expand Down
27 changes: 24 additions & 3 deletions OpenRPA/RobotInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using System.Management.Instrumentation;
using Microsoft.Extensions.Options;
using OpenTelemetry;
using Microsoft.CodeAnalysis;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace OpenRPA
{
Expand Down Expand Up @@ -1466,7 +1468,7 @@ await global.webSocketClient.Watch("openrpa",
}
try
{
foreach (var d in Plugins.detectorPlugins)
foreach (var d in Plugins.detectorPlugins.ToList())
{
var _d = d.Entity as Detector;
if (global.webSocketClient != null && global.webSocketClient.isConnected && global.webSocketClient.signedin) await _d.RegisterExchange();
Expand Down Expand Up @@ -2168,6 +2170,24 @@ private bool InitializeOTEL()
}
if (LocalLogProvider == null && !string.IsNullOrEmpty(Config.local.otel_log_url))
{
var fqdn = System.Net.Dns.GetHostEntry(Environment.MachineName).HostName.ToLower();
var username = Environment.UserName;
if(!string.IsNullOrEmpty(Config.local.username))
{
username = Config.local.username;
}
if (global.webSocketClient != null && global.webSocketClient.user != null && !string.IsNullOrEmpty(global.webSocketClient.user.name))
{
username = global.webSocketClient.user.name;
}
var _tags = new TagList();
_tags.Add(new KeyValuePair<string, object>("ofid", Config.local.openflow_uniqueid));
_tags.Add(new KeyValuePair<string, object>("host", WorkflowTrackingParticipant.hostname));
_tags.Add(new KeyValuePair<string, object>("fqdn", fqdn));
_tags.Add(new KeyValuePair<string, object>("username", username));
_tags.Add(new KeyValuePair<string, object>("version", global.version));
tags = _tags;

var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry((opt) =>
Expand All @@ -2176,7 +2196,7 @@ private bool InitializeOTEL()
opt.IncludeScopes = true;
opt.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(
serviceName: "OpenRPA",
serviceVersion: global.version));
serviceVersion: global.version).AddAttributes(_tags));
var protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
var processorType = ExportProcessorType.Batch;
opt.AddOtlpExporter((exporterOptions, processorOptions) =>
Expand All @@ -2198,7 +2218,8 @@ private bool InitializeOTEL()
});

LocalLogProvider = loggerFactory.CreateLogger<Tracing>();
LocalLogProvider.LogInformation("Tracing initialized on {app} runnig as {windowsuser} / {username} version {version}", WorkflowTrackingParticipant.hostname, Environment.UserName, Config.local.username, global.version);
// LocalLogProvider.LogInformation("Tracing initialized on {app} runnig as {windowsuser} / {username} version {version}", WorkflowTrackingParticipant.hostname, Environment.UserName, Config.local.username, global.version);
(new LoggerEntry("Tracing initialized on " + WorkflowTrackingParticipant.hostname + " for OpenRPA version " + global.version)).Information();

}
return true;
Expand Down
88 changes: 74 additions & 14 deletions OpenRPA/Tracing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,76 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.CodeAnalysis;
using OpenTelemetry.Logs;
using System.Diagnostics.Metrics;

namespace OpenRPA.Interfaces
{
//public static partial class LoggerExtensions
//{
// [LoggerMessage(
// Level = LogLevel.Critical,
// Message = "Could not open socket to `{e}`")]
// static partial void SocketError(this ILogger<Tracing> logger, LoggerEntry e);

// [LoggerMessage(Level = LogLevel.Critical)]
// static partial void Critical(this ILogger<Tracing> logger, [LogProperties()] in LoggerEntry e);
// [LoggerMessage(Level = LogLevel.Error)]
// static partial void Error(this ILogger<Tracing> logger, [LogProperties()] in LoggerEntry e);
// [LoggerMessage(Level = LogLevel.Warning)]
// static partial void Warning(this ILogger<Tracing> logger, [LogProperties()] in LoggerEntry e);
// [LoggerMessage(Level = LogLevel.Debug)]
// static partial void Debug(this ILogger<Tracing> logger, [LogProperties()] in LoggerEntry e);
// [LoggerMessage(Level = LogLevel.Trace)]
// static partial void Trace(this ILogger<Tracing> logger, [LogProperties()] in LoggerEntry e);
//}
public class LoggerEntry
{
public LoggerEntry(string message)
{
this.message = message;
this.project = null;
this.workflow = null;
ofid = Config.local.openflow_uniqueid;
host = Environment.MachineName.ToLower();
fqdn = System.Net.Dns.GetHostEntry(Environment.MachineName).HostName.ToLower();
}
public LoggerEntry(string message, IProject project, IWorkflow workflow)
{
this.message = message;
this.project = null;
if (project != null) this.project = project.name;
this.workflow = null;
if (workflow != null) this.workflow = workflow.name;
ofid = Config.local.openflow_uniqueid;
host = Environment.MachineName.ToLower();
fqdn = System.Net.Dns.GetHostEntry(Environment.MachineName).HostName.ToLower();
}
public string message { get; set; }
public string project{ get; set; }
public string workflow { get; set; }
public string ofid { get; set; }
public string fqdn { get; set; }
public string host { get; set; }
public void Critical() { Log(LogLevel.Critical); }
public void Error() { Log(LogLevel.Error); }
public void Warning() { Log(LogLevel.Warning); }
public void Information() { Log(LogLevel.Information); }
public void Debug() { Log(LogLevel.Debug); }
public void Trace() { Log(LogLevel.Trace); }
public void Log(LogLevel logLevel)
{
message = message.Replace("{", "(").Replace("}", ")");
if (!string.IsNullOrEmpty(project) && !string.IsNullOrEmpty(workflow))
{
RobotInstance.LocalLogProvider?.Log(logLevel, "[{project}][{workflow}] " + message, project, workflow);
}
else
{
RobotInstance.LocalLogProvider?.Log(logLevel, message);
}
}
}
public class Tracing : TraceListener, System.ComponentModel.INotifyPropertyChanged //, ILogEventSink
{
// private int maxLines = 20;
Expand Down Expand Up @@ -133,42 +200,35 @@ public override void WriteLine(string message, string category)
if (category == "Error")
{
lvl = 0;
if(project != null) RobotInstance.LocalLogProvider?.LogError("[{projectname}][{workflowname}][{workflowname}] " + message, project.name, workflow.name);
if (project == null) RobotInstance.LocalLogProvider?.LogError(message);
(new LoggerEntry(message, project, workflow)).Error();
}
else if (category == "Warning")
{
lvl = 1;
if (project != null) RobotInstance.LocalLogProvider?.LogWarning("[{projectname}][{workflowname}] " + message, project.name, workflow.name);
if (project == null) RobotInstance.LocalLogProvider?.LogWarning(message);
(new LoggerEntry(message, project, workflow)).Warning();
}
else if (category == "Output" || category == "Information" || category == "")
{
lvl = 2;
if (project != null) RobotInstance.LocalLogProvider?.LogInformation("[{projectname}][{workflowname}] " + message, project.name, workflow.name);
if (project == null) RobotInstance.LocalLogProvider?.LogInformation(message);
(new LoggerEntry(message, project, workflow)).Information();
}
else if (category == "Debug")
{
lvl = 3;
if (project != null) RobotInstance.LocalLogProvider?.LogDebug("[{projectname}][{workflowname}] " + message, project.name, workflow.name);
if (project == null) RobotInstance.LocalLogProvider?.LogDebug(message);
(new LoggerEntry(message, project, workflow)).Debug();
}
else if (category == "Verbose")
{
lvl = 4;
if (project != null) RobotInstance.LocalLogProvider?.LogTrace("[{projectname}][{workflowname}] " + message, project.name, workflow.name);
if (project == null) RobotInstance.LocalLogProvider?.LogTrace(message);
(new LoggerEntry(message, project, workflow)).Trace();
}
else if (category == "network")
{
if (project != null) RobotInstance.LocalLogProvider?.LogTrace("[{projectname}][{workflowname}] " + message, project.name, workflow.name);
if (project == null) RobotInstance.LocalLogProvider?.LogTrace(message);
(new LoggerEntry(message, project, workflow)).Trace();
}
else
{
if (project != null) RobotInstance.LocalLogProvider?.LogTrace("[{projectname}][{workflowname}] " + message, project.name, workflow.name);
if (project == null) RobotInstance.LocalLogProvider?.LogTrace(message);
(new LoggerEntry(message, project, workflow)).Trace();
}

if (InstanceId.IsValueCreated)
Expand Down

0 comments on commit fff4e20

Please sign in to comment.