Skip to content

Commit e31c08b

Browse files
arealmaasknuhau
andauthored
feat(graphql): configure opentelemetry (#1343)
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> Adds opentelemetry for GraphQL ## Related Issue(s) - #1262 ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved error handling during application startup. - Enhanced telemetry management for logging. - **Bug Fixes** - Refined error logging to filter out specific exceptions. - **Refactor** - Streamlined the initialization process for better consistency in telemetry configuration usage. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Knut Haug <knut.espen.haug@digdir.no>
1 parent 5ec3b84 commit e31c08b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Digdir.Domain.Dialogporten.GraphQL/Program.cs

+8-9
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
using Microsoft.AspNetCore.Authorization;
1919
using Microsoft.Extensions.Options;
2020

21+
// Using two-stage initialization to catch startup errors.
22+
var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
2123
Log.Logger = new LoggerConfiguration()
2224
.MinimumLevel.Warning()
2325
.Enrich.FromLogContext()
2426
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
25-
.WriteTo.ApplicationInsights(
26-
TelemetryConfiguration.CreateDefault(),
27-
TelemetryConverter.Traces)
27+
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces)
2828
.CreateBootstrapLogger();
2929

3030
try
3131
{
32-
BuildAndRun(args);
32+
BuildAndRun(args, telemetryConfiguration);
3333
}
3434
catch (Exception ex) when (ex is not OperationCanceledException)
3535
{
@@ -41,7 +41,7 @@
4141
Log.CloseAndFlush();
4242
}
4343

44-
static void BuildAndRun(string[] args)
44+
static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfiguration)
4545
{
4646
var builder = WebApplication.CreateBuilder(args);
4747

@@ -51,9 +51,7 @@ static void BuildAndRun(string[] args)
5151
.ReadFrom.Services(services)
5252
.Enrich.FromLogContext()
5353
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
54-
.WriteTo.ApplicationInsights(
55-
services.GetRequiredService<TelemetryConfiguration>(),
56-
TelemetryConverter.Traces));
54+
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces));
5755

5856
builder.Configuration
5957
.AddAzureConfiguration(builder.Environment.EnvironmentName)
@@ -67,6 +65,8 @@ static void BuildAndRun(string[] args)
6765

6866
var thisAssembly = Assembly.GetExecutingAssembly();
6967

68+
builder.ConfigureTelemetry();
69+
7070
builder.Services
7171
// Options setup
7272
.ConfigureOptions<AuthorizationOptionsSetup>()
@@ -77,7 +77,6 @@ static void BuildAndRun(string[] args)
7777
.WithPubCapabilities()
7878
.Build()
7979
.AddAutoMapper(Assembly.GetExecutingAssembly())
80-
.AddApplicationInsightsTelemetry()
8180
.AddScoped<IUser, ApplicationUser>()
8281
.AddValidatorsFromAssembly(thisAssembly, ServiceLifetime.Transient, includeInternalTypes: true)
8382
.AddAzureAppConfiguration()

0 commit comments

Comments
 (0)