Skip to content

Commit

Permalink
feat(graphql): configure opentelemetry (#1343)
Browse files Browse the repository at this point in the history
<!--- 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>
  • Loading branch information
arealmaas and knuhau authored Oct 24, 2024
1 parent 5ec3b84 commit e31c08b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Digdir.Domain.Dialogporten.GraphQL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;

// Using two-stage initialization to catch startup errors.
var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Warning()
.Enrich.FromLogContext()
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
.WriteTo.ApplicationInsights(
TelemetryConfiguration.CreateDefault(),
TelemetryConverter.Traces)
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces)
.CreateBootstrapLogger();

try
{
BuildAndRun(args);
BuildAndRun(args, telemetryConfiguration);
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
Expand All @@ -41,7 +41,7 @@
Log.CloseAndFlush();
}

static void BuildAndRun(string[] args)
static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfiguration)
{
var builder = WebApplication.CreateBuilder(args);

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

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

var thisAssembly = Assembly.GetExecutingAssembly();

builder.ConfigureTelemetry();

builder.Services
// Options setup
.ConfigureOptions<AuthorizationOptionsSetup>()
Expand All @@ -77,7 +77,6 @@ static void BuildAndRun(string[] args)
.WithPubCapabilities()
.Build()
.AddAutoMapper(Assembly.GetExecutingAssembly())
.AddApplicationInsightsTelemetry()
.AddScoped<IUser, ApplicationUser>()
.AddValidatorsFromAssembly(thisAssembly, ServiceLifetime.Transient, includeInternalTypes: true)
.AddAzureAppConfiguration()
Expand Down

0 comments on commit e31c08b

Please sign in to comment.