Skip to content

Commit

Permalink
feat(service): configure opentelemetry (#1342)
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 -->

Configures opentelemetry for Service. Copy pasta from WebAPI.

Dependent on #1341

## 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**
- Enhanced logging and telemetry configuration during application
startup.
	- Introduced a modular approach to configuring telemetry settings.

- **Bug Fixes**
- Improved error handling during application startup to ensure
exceptions are logged appropriately.

- **Refactor**
- Updated method signature for improved telemetry configuration
handling.
- Removed direct call to Application Insights, streamlining telemetry
integration.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
arealmaas authored Oct 29, 2024
1 parent 97cee9a commit 513d5e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0"/>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 8 additions & 9 deletions src/Digdir.Domain.Dialogporten.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
using Digdir.Library.Utils.AspNet;
using MassTransit;

// 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 @@ -34,7 +34,7 @@
Log.CloseAndFlush();
}

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

Expand All @@ -43,9 +43,7 @@ static void BuildAndRun(string[] args)
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.WriteTo.ApplicationInsights(
services.GetRequiredService<TelemetryConfiguration>(),
TelemetryConverter.Traces));
.WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces));

builder.Configuration
.AddAzureConfiguration(builder.Environment.EnvironmentName)
Expand All @@ -64,8 +62,9 @@ static void BuildAndRun(string[] args)
)
.ToArray();

builder.ConfigureTelemetry();

builder.Services
.AddApplicationInsightsTelemetry()
.AddAzureAppConfiguration()
.AddApplication(builder.Configuration, builder.Environment)
.AddInfrastructure(builder.Configuration, builder.Environment)
Expand Down

0 comments on commit 513d5e4

Please sign in to comment.