Skip to content

Commit dd6978f

Browse files
committed
use Azure.Monitor.OpenTelemetry.AspNetCore because it automatically collects telemetry data
1 parent 0932ffe commit dd6978f

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

dotnet/src/dotnetcore/Providers/OpenTelemetry/OpenTelemetryAzureMonitor/AzureAppInsights.cs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,39 @@
11
using System;
2-
using GeneXus.Services.OpenTelemetry;
3-
using Microsoft.Extensions.DependencyInjection;
4-
using OpenTelemetry;
5-
using OpenTelemetry.Trace;
2+
using Azure.Monitor.OpenTelemetry.AspNetCore;
63
using GeneXus.Services;
7-
using System.Diagnostics;
8-
using Azure.Monitor.OpenTelemetry.Exporter;
4+
using GeneXus.Services.OpenTelemetry;
95
using log4net;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Logging;
108

119
namespace GeneXus.OpenTelemetry.Azure
1210
{
1311
public class AzureAppInsights : IOpenTelemetryProvider
1412
{
1513
private static readonly ILog log = LogManager.GetLogger(typeof(AzureAppInsights));
16-
private const string AZURE_OTEL_EXPORTER_CONNECTIONSTRING = "APPLICATIONINSIGHTS_CONNECTION_STRING";
17-
private const string ACTIVITY_SOURCE = "OTel.AzureMonitor.GXApp";
18-
private const string ACTIVITY_NAME = "GeneXusApplicationActivity";
14+
private const string APPLICATIONINSIGHTS_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING";
1915

2016
public AzureAppInsights(GXService s)
2117
{
2218
}
2319

24-
private static readonly ActivitySource GXActivitySource = new ActivitySource(ACTIVITY_SOURCE);
25-
26-
public bool InstrumentAspNetCoreApplication(IServiceCollection _)
20+
public bool InstrumentAspNetCoreApplication(IServiceCollection services)
2721
{
28-
string oltpEndpoint = Environment.GetEnvironmentVariable(AZURE_OTEL_EXPORTER_CONNECTIONSTRING);
22+
string oltpEndpoint = Environment.GetEnvironmentVariable(APPLICATIONINSIGHTS_CONNECTION_STRING);
2923

3024
if (!string.IsNullOrEmpty(oltpEndpoint))
31-
{
32-
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
33-
.AddAzureMonitorTraceExporter(o =>
25+
{
26+
services.AddOpenTelemetry()
27+
.UseAzureMonitor( o =>
3428
{
3529
o.ConnectionString = oltpEndpoint;
36-
})
37-
.AddSource(ACTIVITY_SOURCE)
38-
.AddGxAspNetInstrumentation()
39-
.Build();
30+
});
4031

41-
using (var activity = GXActivitySource.StartActivity(ACTIVITY_NAME))
42-
{
43-
}
4432
return true;
4533
}
4634
else
4735
{
48-
log.Warn("OpenTelemetry Azure Monitor was not initialized due to missing 'AZURE_OTEL_EXPORTER_CONNECTIONSTRING' Environment Variable");
36+
log.Warn("OpenTelemetry Azure Monitor was not initialized due to missing 'APPLICATIONINSIGHTS_CONNECTION_STRING' Environment Variable");
4937
return false;
5038
}
5139
}

dotnet/src/dotnetcore/Providers/OpenTelemetry/OpenTelemetryAzureMonitor/GeneXus.OpenTelemetry.Azure.AppInsights.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>net6.0</TargetFrameworks>
44
<DefineConstants>NETCORE;</DefineConstants>
@@ -10,7 +10,7 @@
1010
<NoWarn>NU1605</NoWarn>
1111
</PropertyGroup>
1212
<ItemGroup>
13-
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.0.0-beta.10" NoWarn="NU5104"/>
13+
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.0.0-beta.4" NoWarn="NU5104"/>
1414
</ItemGroup>
1515
<ItemGroup>
1616
<ProjectReference Include="..\..\..\GxClasses\GxClasses.csproj" />

0 commit comments

Comments
 (0)