-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing delay in configuring Adaptive Sampling
- Loading branch information
1 parent
3309c1c
commit f79ea0b
Showing
6 changed files
with
130 additions
and
8 deletions.
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
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
45 changes: 45 additions & 0 deletions
45
...icrosoft.Azure.WebJobs.Logging.ApplicationInsights/Processors/DelayedSamplingProcessor.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,45 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.ApplicationInsights.Channel; | ||
using Microsoft.ApplicationInsights.Extensibility; | ||
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.WebJobs.Logging.ApplicationInsights | ||
{ | ||
internal class DelayedSamplingProcessor : ITelemetryProcessor | ||
{ | ||
private readonly AdaptiveSamplingTelemetryProcessor _samplingProcessor; | ||
private ITelemetryProcessor _next; | ||
private bool _isSamplingEnabled = false; | ||
|
||
public DelayedSamplingProcessor(ITelemetryProcessor next, ApplicationInsightsLoggerOptions options) | ||
{ | ||
_next = next; | ||
_samplingProcessor = TelemetryProcessorFactory.CreateAdaptiveSamplingProcessor(options, next); | ||
|
||
// Start a timer to enable sampling after a delay | ||
Task.Delay(options.AdaptiveSamplingInitializationDelay).ContinueWith(t => EnableSampling()); | ||
} | ||
|
||
public void Process(ITelemetry item) | ||
{ | ||
if (_isSamplingEnabled) | ||
{ | ||
// Forward to Adaptive Sampling processor | ||
_samplingProcessor.Process(item); | ||
} | ||
else | ||
{ | ||
// Bypass sampling | ||
_next.Process(item); | ||
} | ||
} | ||
|
||
private void EnableSampling() | ||
{ | ||
_isSamplingEnabled = true; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...soft.Azure.WebJobs.Logging.ApplicationInsights/Processors/TelemetryProcessorExtensions.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,27 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.ApplicationInsights.Extensibility; | ||
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel; | ||
|
||
namespace Microsoft.Azure.WebJobs.Logging.ApplicationInsights | ||
{ | ||
internal static class TelemetryProcessorFactory | ||
{ | ||
internal static AdaptiveSamplingTelemetryProcessor CreateAdaptiveSamplingProcessor(ApplicationInsightsLoggerOptions options, ITelemetryProcessor next = null) | ||
{ | ||
// Create the sampling processor | ||
var samplingProcessor = new AdaptiveSamplingTelemetryProcessor(options.SamplingSettings, null, next); | ||
|
||
if (options.SamplingExcludedTypes != null) | ||
{ | ||
samplingProcessor.ExcludedTypes = options.SamplingExcludedTypes; | ||
} | ||
if (options.SamplingIncludedTypes != null) | ||
{ | ||
samplingProcessor.IncludedTypes = options.SamplingIncludedTypes; | ||
} | ||
return samplingProcessor; | ||
} | ||
} | ||
} |
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
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