|
1 | 1 | 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; |
6 | 3 | using GeneXus.Services; |
7 | | -using System.Diagnostics; |
8 | | -using Azure.Monitor.OpenTelemetry.Exporter; |
| 4 | +using GeneXus.Services.OpenTelemetry; |
9 | 5 | using log4net; |
| 6 | +using Microsoft.Extensions.DependencyInjection; |
| 7 | +using Microsoft.Extensions.Logging; |
10 | 8 |
|
11 | 9 | namespace GeneXus.OpenTelemetry.Azure |
12 | 10 | { |
13 | 11 | public class AzureAppInsights : IOpenTelemetryProvider |
14 | 12 | { |
15 | 13 | 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"; |
19 | 15 |
|
20 | 16 | public AzureAppInsights(GXService s) |
21 | 17 | { |
22 | 18 | } |
23 | 19 |
|
24 | | - private static readonly ActivitySource GXActivitySource = new ActivitySource(ACTIVITY_SOURCE); |
25 | | - |
26 | | - public bool InstrumentAspNetCoreApplication(IServiceCollection _) |
| 20 | + public bool InstrumentAspNetCoreApplication(IServiceCollection services) |
27 | 21 | { |
28 | | - string oltpEndpoint = Environment.GetEnvironmentVariable(AZURE_OTEL_EXPORTER_CONNECTIONSTRING); |
| 22 | + string oltpEndpoint = Environment.GetEnvironmentVariable(APPLICATIONINSIGHTS_CONNECTION_STRING); |
29 | 23 |
|
30 | 24 | if (!string.IsNullOrEmpty(oltpEndpoint)) |
31 | | - { |
32 | | - using var tracerProvider = Sdk.CreateTracerProviderBuilder() |
33 | | - .AddAzureMonitorTraceExporter(o => |
| 25 | + { |
| 26 | + services.AddOpenTelemetry() |
| 27 | + .UseAzureMonitor( o => |
34 | 28 | { |
35 | 29 | o.ConnectionString = oltpEndpoint; |
36 | | - }) |
37 | | - .AddSource(ACTIVITY_SOURCE) |
38 | | - .AddGxAspNetInstrumentation() |
39 | | - .Build(); |
| 30 | + }); |
40 | 31 |
|
41 | | - using (var activity = GXActivitySource.StartActivity(ACTIVITY_NAME)) |
42 | | - { |
43 | | - } |
44 | 32 | return true; |
45 | 33 | } |
46 | 34 | else |
47 | 35 | { |
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"); |
49 | 37 | return false; |
50 | 38 | } |
51 | 39 | } |
|
0 commit comments