This repository was archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Work-around heartbeat interval initialization bug in AI #321
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/NuGet.Services.Logging/ApplicationInsightsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.ApplicationInsights.Extensibility; | ||
using Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing; | ||
|
||
namespace NuGet.Services.Logging | ||
{ | ||
public sealed class ApplicationInsightsConfiguration | ||
{ | ||
internal ApplicationInsightsConfiguration( | ||
TelemetryConfiguration telemetryConfiguration, | ||
DiagnosticsTelemetryModule diagnosticsTelemetryModule) | ||
{ | ||
TelemetryConfiguration = telemetryConfiguration ?? throw new ArgumentNullException(nameof(telemetryConfiguration)); | ||
DiagnosticsTelemetryModule = diagnosticsTelemetryModule ?? throw new ArgumentNullException(nameof(diagnosticsTelemetryModule)); | ||
} | ||
|
||
/// <summary> | ||
/// Contains the initialized <see cref="Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration"/>. | ||
/// Used to initialize new <see cref="Microsoft.ApplicationInsights.TelemetryClient"/> instances. | ||
/// Allows tweaking telemetry initializers. | ||
/// </summary> | ||
/// <remarks> | ||
/// Needs to be disposed when gracefully shutting down the application. | ||
/// </remarks> | ||
public TelemetryConfiguration TelemetryConfiguration { get; } | ||
|
||
/// <summary> | ||
/// Contains the initialized <see cref="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule"/>. | ||
/// Allows tweaking Application Insights heartbeat telemetry. | ||
/// </summary> | ||
public DiagnosticsTelemetryModule DiagnosticsTelemetryModule { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/NuGet.Services.Logging.Tests/ApplicationInsightsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Xunit; | ||
|
||
namespace NuGet.Services.Logging.Tests | ||
{ | ||
public class ApplicationInsightsTests | ||
{ | ||
private const string InstrumentationKey = "abcdef12-3456-7890-abcd-ef123456789"; | ||
|
||
[Fact] | ||
public void InitializeReturnsApplicationInsightsConfiguration() | ||
{ | ||
var applicationInsightsConfiguration = ApplicationInsights.Initialize(InstrumentationKey); | ||
|
||
Assert.NotNull(applicationInsightsConfiguration); | ||
Assert.Equal(InstrumentationKey, applicationInsightsConfiguration.TelemetryConfiguration.InstrumentationKey); | ||
} | ||
|
||
[Fact] | ||
public void InitializeRegistersTelemetryContextInitializer() | ||
{ | ||
var applicationInsightsConfiguration = ApplicationInsights.Initialize(InstrumentationKey); | ||
Assert.Contains(applicationInsightsConfiguration.TelemetryConfiguration.TelemetryInitializers, ti => ti is TelemetryContextInitializer); | ||
} | ||
|
||
[Fact] | ||
public void InitializeSetsHeartbeatIntervalAndDiagnosticsTelemetryModule() | ||
{ | ||
var heartbeatInterval = TimeSpan.FromMinutes(1); | ||
|
||
var applicationInsightsConfiguration = ApplicationInsights.Initialize(InstrumentationKey, heartbeatInterval); | ||
|
||
Assert.NotNull(applicationInsightsConfiguration.DiagnosticsTelemetryModule); | ||
Assert.Equal(heartbeatInterval, applicationInsightsConfiguration.DiagnosticsTelemetryModule.HeartbeatInterval); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Source: microsoft/ApplicationInsights-dotnet#1152 (comment)