Skip to content

Commit

Permalink
Log to Azure Monitor
Browse files Browse the repository at this point in the history
- Export logs to Azure Monitor.
- Group OpenTelemetry package updates.
  • Loading branch information
martincostello committed Apr 26, 2024
1 parent 0ebec18 commit 08fe598
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ updates:
- package-ecosystem: nuget
directory: "/"
groups:
polly:
OpenTelemetry:
patterns:
- OpenTelemetry*
Polly:
patterns:
- Polly*
xunit:
Expand Down
6 changes: 6 additions & 0 deletions src/LondonTravel.Site/Extensions/ILoggingBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Martin Costello, 2017. All rights reserved.
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using Azure.Monitor.OpenTelemetry.Exporter;
using OpenTelemetry.Logs;

namespace MartinCostello.LondonTravel.Site.Extensions;
Expand All @@ -24,6 +25,11 @@ public static ILoggingBuilder AddTelemetry(this ILoggingBuilder builder)
p.IncludeFormattedMessage = true;
p.IncludeScopes = true;

if (TelemetryExtensions.IsAzureMonitorConfigured())
{
p.AddAzureMonitorLogExporter();
}

if (TelemetryExtensions.IsOtlpCollectorConfigured())
{
p.AddOtlpExporter();
Expand Down
3 changes: 1 addition & 2 deletions src/LondonTravel.Site/Extensions/TelemetryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using AspNet.Security.OAuth.Amazon;
using AspNet.Security.OAuth.Apple;
using AspNet.Security.OAuth.GitHub;
using Azure.Identity;
using Azure.Monitor.OpenTelemetry.AspNetCore;
using Microsoft.AspNetCore.Authentication.Facebook;
using Microsoft.AspNetCore.Authentication.Google;
Expand Down Expand Up @@ -86,7 +85,7 @@ public static void AddTelemetry(this IServiceCollection services, IWebHostEnviro
internal static bool IsOtlpCollectorConfigured()
=> !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT"));

private static bool IsAzureMonitorConfigured()
internal static bool IsAzureMonitorConfigured()
=> !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING"));

private static void EnrichHttpActivity(Activity activity, HttpRequestMessage request)
Expand Down

0 comments on commit 08fe598

Please sign in to comment.