Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions dotnet/DotNetStandardClasses.sln
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,24 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GXAmazonSQS", "src\dotnetco
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "apiattractions", "src\extensions\Azure\test\apiattractions\apiattractions.csproj", "{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GXMessageBroker", "src\dotnetcore\Providers\Messaging\GXMessageBroker\GXMessageBroker.csproj", "{3B1B5706-E896-4CEB-A551-E30226303BDB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GXMessageBroker", "src\dotnetcore\Providers\Messaging\GXMessageBroker\GXMessageBroker.csproj", "{3B1B5706-E896-4CEB-A551-E30226303BDB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GXAzureServiceBus", "src\dotnetcore\Providers\Messaging\GXAzureServiceBus\GXAzureServiceBus.csproj", "{F8ABEA82-F823-4E9C-96FA-26AF24C932E0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GXAzureServiceBus", "src\dotnetcore\Providers\Messaging\GXAzureServiceBus\GXAzureServiceBus.csproj", "{F8ABEA82-F823-4E9C-96FA-26AF24C932E0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectHealthTest", "test\ProjectHealthTest\ProjectHealthTest.csproj", "{65048104-212A-4819-AECF-89CA9C08C83F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetRedisTest", "test\DotNetRedisTest\DotNetRedisTest.csproj", "{48430E50-043A-47A2-8278-B86A4420758A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCoreWebUnitTest", "test\DotNetCoreWebUnitTest\DotNetCoreWebUnitTest.csproj", "{531863CA-93A0-42AA-AB5C-FA0E672C03B8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "opentelemetry", "opentelemetry", "{BBE020D4-C0FF-41A9-9EB1-D1EE12CC4BB8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneXus.OpenTelemetry.Lightstep.AspNet", "src\dotnetcore\Providers\OpenTelemetry\OpenTelemetryLightStep\GeneXus.OpenTelemetry.Lightstep.AspNet.csproj", "{27D54041-BDD5-428E-8CA6-C96D519F5451}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneXus.OpenTelemetry.AWS.AspNet", "src\dotnetcore\Providers\OpenTelemetry\OpenTelemetryAWSOtel\GeneXus.OpenTelemetry.AWS.AspNet.csproj", "{B5A9DEA7-67EC-49E4-924E-4729C34286EC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneXus.OpenTelemetry", "src\dotnetcore\Providers\OpenTelemetry\OpenTelemetry\GeneXus.OpenTelemetry.csproj", "{00B1FA38-7D0B-47E4-860C-23490249A4D6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -520,14 +528,6 @@ Global
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Release|Any CPU.Build.0 = Release|Any CPU
{65048104-212A-4819-AECF-89CA9C08C83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65048104-212A-4819-AECF-89CA9C08C83F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65048104-212A-4819-AECF-89CA9C08C83F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65048104-212A-4819-AECF-89CA9C08C83F}.Release|Any CPU.Build.0 = Release|Any CPU
{48430E50-043A-47A2-8278-B86A4420758A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48430E50-043A-47A2-8278-B86A4420758A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48430E50-043A-47A2-8278-B86A4420758A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48430E50-043A-47A2-8278-B86A4420758A}.Release|Any CPU.Build.0 = Release|Any CPU
{3B1B5706-E896-4CEB-A551-E30226303BDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B1B5706-E896-4CEB-A551-E30226303BDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B1B5706-E896-4CEB-A551-E30226303BDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -536,10 +536,30 @@ Global
{F8ABEA82-F823-4E9C-96FA-26AF24C932E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8ABEA82-F823-4E9C-96FA-26AF24C932E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8ABEA82-F823-4E9C-96FA-26AF24C932E0}.Release|Any CPU.Build.0 = Release|Any CPU
{65048104-212A-4819-AECF-89CA9C08C83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65048104-212A-4819-AECF-89CA9C08C83F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65048104-212A-4819-AECF-89CA9C08C83F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65048104-212A-4819-AECF-89CA9C08C83F}.Release|Any CPU.Build.0 = Release|Any CPU
{48430E50-043A-47A2-8278-B86A4420758A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48430E50-043A-47A2-8278-B86A4420758A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48430E50-043A-47A2-8278-B86A4420758A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48430E50-043A-47A2-8278-B86A4420758A}.Release|Any CPU.Build.0 = Release|Any CPU
{531863CA-93A0-42AA-AB5C-FA0E672C03B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{531863CA-93A0-42AA-AB5C-FA0E672C03B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{531863CA-93A0-42AA-AB5C-FA0E672C03B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{531863CA-93A0-42AA-AB5C-FA0E672C03B8}.Release|Any CPU.Build.0 = Release|Any CPU
{27D54041-BDD5-428E-8CA6-C96D519F5451}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27D54041-BDD5-428E-8CA6-C96D519F5451}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27D54041-BDD5-428E-8CA6-C96D519F5451}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27D54041-BDD5-428E-8CA6-C96D519F5451}.Release|Any CPU.Build.0 = Release|Any CPU
{B5A9DEA7-67EC-49E4-924E-4729C34286EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5A9DEA7-67EC-49E4-924E-4729C34286EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5A9DEA7-67EC-49E4-924E-4729C34286EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5A9DEA7-67EC-49E4-924E-4729C34286EC}.Release|Any CPU.Build.0 = Release|Any CPU
{00B1FA38-7D0B-47E4-860C-23490249A4D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00B1FA38-7D0B-47E4-860C-23490249A4D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00B1FA38-7D0B-47E4-860C-23490249A4D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00B1FA38-7D0B-47E4-860C-23490249A4D6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -642,11 +662,15 @@ Global
{DCEC0B38-93B6-4003-81E6-9FBC2BB4F163} = {7BA5A2CE-7992-4F87-9D84-91AE4D046F5A}
{F8BA0D65-267D-491F-BFAB-33F5E5B61AD7} = {30159B0F-BE61-4DB7-AC02-02851426BE4B}
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3} = {7BA5A2CE-7992-4F87-9D84-91AE4D046F5A}
{65048104-212A-4819-AECF-89CA9C08C83F} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{48430E50-043A-47A2-8278-B86A4420758A} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{3B1B5706-E896-4CEB-A551-E30226303BDB} = {4C43F2DA-59E5-46F5-B691-195449498555}
{F8ABEA82-F823-4E9C-96FA-26AF24C932E0} = {30159B0F-BE61-4DB7-AC02-02851426BE4B}
{65048104-212A-4819-AECF-89CA9C08C83F} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{48430E50-043A-47A2-8278-B86A4420758A} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{531863CA-93A0-42AA-AB5C-FA0E672C03B8} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{BBE020D4-C0FF-41A9-9EB1-D1EE12CC4BB8} = {2261B65E-3757-4E5B-9DCD-EAE8D1E236A3}
{27D54041-BDD5-428E-8CA6-C96D519F5451} = {BBE020D4-C0FF-41A9-9EB1-D1EE12CC4BB8}
{B5A9DEA7-67EC-49E4-924E-4729C34286EC} = {BBE020D4-C0FF-41A9-9EB1-D1EE12CC4BB8}
{00B1FA38-7D0B-47E4-860C-23490249A4D6} = {BBE020D4-C0FF-41A9-9EB1-D1EE12CC4BB8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Diagnostics;
using System.Reflection;


namespace GeneXus.Diagnostics
{
public static class GxHttpActivitySourceHelper
{
public static string GX_HTTP_INSTRUMENTATION = "GeneXus.Instrumentation.Http";
private static ActivitySource ActivitySource { get; } = CreateActivitySource();

public const string ThreadIdTagName = "thread.id";
public const string StatusCodeTagName = "otel.status_code";

private static ActivitySource CreateActivitySource()
{
Assembly assembly = typeof(GxHttpActivitySourceHelper).Assembly;
string version = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()!.Version;
return new ActivitySource(GX_HTTP_INSTRUMENTATION, version);
}

public static void SetException(Activity activity, Exception exception)
{
string description = exception.Message;
activity?.SetStatus(ActivityStatusCode.Error, description);
activity?.SetTag(StatusCodeTagName, "ERROR");
activity?.SetTag("otel.status_description", description);
activity?.AddEvent(new ActivityEvent("exception", tags: new ActivityTagsCollection
{
{ "exception.type", exception.GetType().FullName },
{ "exception.message", exception.Message },
{ "exception.source", exception.Source },
{ "exception.stacktrace", exception.ToString() },
}));
}
}
}
1 change: 1 addition & 0 deletions dotnet/src/dotnetcore/GxClasses/GxClasses.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Compile Include="..\..\dotnetframework\GxClasses\Dialog\IProcess.cs" Link="Helpers\Process\IProcess.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Attributes\GXApi.cs" Link="Attributes\GXApi.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Configuration\ConfigurationManager.cs" Link="Configuration\ConfigurationManager.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Configuration\LogConfiguration.cs" Link="Configuration\LogConfiguration.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Configuration\ExternalStorage.cs" Link="Configuration\ExternalStorage.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Cryptography\GXAsymmetricEncryption.cs" Link="Helpers\Cryptography\GXAsymmetricEncryption.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Cryptography\GXCertificate.cs" Link="Helpers\Cryptography\GXCertificate.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using GxClasses.Helpers;
using log4net;

namespace GeneXus.Services.OpenTelemetry
{
public interface IOpenTelemetryProvider
{
bool InstrumentAspNetCoreApplication(Microsoft.Extensions.DependencyInjection.IServiceCollection services);
}

public static class OpenTelemetryService
{
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(OpenTelemetryService));
private static string OPENTELEMETRY_SERVICE = "Observability";
public static string GX_ACTIVITY_SOURCE_NAME = "GeneXus.Tracing";

private static IOpenTelemetryProvider GetOpenTelemetryProvider()
{
IOpenTelemetryProvider otelProvider = null;
GXService providerService = GXServices.Instance?.Get(OPENTELEMETRY_SERVICE);

if (providerService != null)
{
try
{
GXLogging.Debug(log, "Loading OpenTelemetry provider:", providerService.ClassName);
#if !NETCORE
Type type = Type.GetType(providerService.ClassName, true, true);
#else
Type type = AssemblyLoader.GetType(providerService.ClassName);
#endif
otelProvider = (IOpenTelemetryProvider)Activator.CreateInstance(type, new object[] { providerService });
}
catch (Exception e)
{
GXLogging.Error(log, "Couldn´t create OpenTelemetry provider.", e.Message, e);
throw e;
}
}
return otelProvider;
}

internal static void Setup(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
{
IOpenTelemetryProvider provider = GetOpenTelemetryProvider();
if (provider != null)
{
bool started = provider.InstrumentAspNetCoreApplication(services);
if (started)
{
log.Info("OpenTelemetry instrumentation started");
}
}
}
}


}
94 changes: 94 additions & 0 deletions dotnet/src/dotnetcore/GxClasses/Services/ServiceSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using GeneXus.Encryption;
using log4net;

namespace GeneXus.Services.Common
{
public class ServiceSettingsReader
{
static readonly ILog logger = log4net.LogManager.GetLogger(typeof(ServiceSettingsReader));

internal GXService service;
public string serviceNameResolver { get; }
public string name { get; }

public ServiceSettingsReader(string serviceNameResolver, string name, GXService gXService)
{
this.serviceNameResolver = serviceNameResolver;
this.name = name;
this.service = gXService;
}

public string GetEncryptedPropertyValue(string propertyName)
{
String value = GetEncryptedPropertyValue(propertyName, null);
if (value == null)
{
String errorMessage = String.Format($"Service configuration error - Property name {ResolvePropertyName(propertyName)} must be defined");
logger.Fatal(errorMessage);
throw new Exception(errorMessage);
}
return value;
}
public string GetEncryptedPropertyValue(string propertyName, string defaultValue)
{
String value = GetPropertyValue(propertyName, defaultValue);
if (!String.IsNullOrEmpty(value))
{
try
{
string ret = String.Empty;
if (CryptoImpl.Decrypt(ref ret, value))
{
value = ret;
}
}
catch (Exception)
{
logger.Warn($"Could not decrypt property name: {ResolvePropertyName(propertyName)}");
}
}
return value;
}

public string GetPropertyValue(string propertyName)
{
String value = GetPropertyValue(propertyName, null);
if (value == null)
{
String errorMessage = String.Format($"Service configuration error - Property name {ResolvePropertyName(propertyName)} must be defined");
logger.Fatal(errorMessage);
throw new Exception(errorMessage);
}
return value;
}

public string GetPropertyValue(string propertyName, string defaultValue)
{
String value = null;
value = string.IsNullOrEmpty(value) ? GetPropertyValueImpl(ResolvePropertyName(propertyName)) : value;
value = string.IsNullOrEmpty(value) ? GetPropertyValueImpl(propertyName) : value;
value = string.IsNullOrEmpty(value) ? defaultValue : value;
return value;
}

internal string GetPropertyValueImpl(string propertyName)
{
String value = null;
if (!string.IsNullOrEmpty(propertyName))
{
value = Environment.GetEnvironmentVariable(propertyName);
if (service != null && value == null)
{
value = service.Properties.Get(propertyName);
}
}
return value;
}

internal string ResolvePropertyName(string propertyName)
{
return $"${serviceNameResolver}_{name}_{propertyName}";
}
}
}
8 changes: 6 additions & 2 deletions dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GeneXus.Http;
using GeneXus.HttpHandlerFactory;
using GeneXus.Services;
using GeneXus.Services.OpenTelemetry;
using GeneXus.Utils;
using GxClasses.Web.Middleware;
using log4net;
Expand All @@ -28,6 +29,7 @@
using Microsoft.Extensions.Logging;
using StackExchange.Redis;


namespace GeneXus.Application
{
public class Program
Expand Down Expand Up @@ -62,7 +64,7 @@ public static void Main(string[] args)
Console.Error.WriteLine("ERROR:");
Console.Error.WriteLine("Web Host terminated unexpectedly: {0}", e.Message);
Console.Read();
}
}
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
Expand Down Expand Up @@ -135,6 +137,8 @@ public Startup(IConfiguration configuration, IHostingEnvironment env)
}
public void ConfigureServices(IServiceCollection services)
{
OpenTelemetryService.Setup(services);

services.AddMvc(option => option.EnableEndpointRouting = false);
services.Configure<KestrelServerOptions>(options =>
{
Expand Down Expand Up @@ -265,7 +269,7 @@ private void ConfigureSessionService(IServiceCollection services, ISessionServic
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, ILoggerFactory loggerFactory)
{
string baseVirtualPath = string.IsNullOrEmpty(VirtualPath) ? VirtualPath : $"/{VirtualPath}";

LogConfiguration.SetupLog4Net();
var provider = new FileExtensionContentTypeProvider();
//mappings
provider.Mappings[".json"] = "application/json";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>GeneXus.OpenTelemetry</AssemblyName>
<PackageTags>OpenTelemetry GeneXus DotNet </PackageTags>
<PackageId>GeneXus.OpenTelemetry.OpenTelemetry</PackageId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry.Api" Version="1.4.0-alpha.1" NoWarn="NU5104"/>
<PackageReference Include="OpenTelemetry" Version="1.4.0-alpha.1" NoWarn="NU5104"/>
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.4.0-alpha.1" NoWarn="NU5104"/>
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.4.0-alpha.1" NoWarn="NU5104" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9.5" NoWarn="NU5104" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.5" NoWarn="NU5104"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc9.5" NoWarn="NU5104"/>
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.0.0-rc9.5" NoWarn="NU5104"/>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\GxClasses\GxClasses.csproj" />
</ItemGroup>

</Project>
Loading