-
Notifications
You must be signed in to change notification settings - Fork 118
Activity Based TargetingId Persistance #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
64c6e60
956c99a
ca04dd3
4d61d15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
|
||
using Microsoft.ApplicationInsights.Channel; | ||
using Microsoft.ApplicationInsights.DataContracts; | ||
using Microsoft.ApplicationInsights.Extensibility; | ||
using System.Diagnostics; | ||
|
||
namespace Microsoft.FeatureManagement.Telemetry.ApplicationInsights | ||
{ | ||
/// <summary> | ||
/// Used to add targeting information to outgoing Application Insights telemetry. | ||
/// </summary> | ||
public class TargetingTelemetryInitializer : ITelemetryInitializer | ||
{ | ||
private const string TargetingIdKey = $"Microsoft.FeatureManagement.TargetingId"; | ||
|
||
/// <summary> | ||
/// When telemetry is initialized, adds targeting information to all relevant telemetry. | ||
/// </summary> | ||
/// <param name="telemetry">The <see cref="ITelemetry"/> to be initialized.</param> | ||
/// <exception cref="ArgumentNullException">Thrown if the any param is null.</exception> | ||
public void Initialize(ITelemetry telemetry) | ||
{ | ||
if (telemetry == null) | ||
{ | ||
throw new ArgumentNullException(nameof(telemetry)); | ||
} | ||
|
||
// Extract the targeting id from the current activity's baggage | ||
string targetingId = Activity.Current?.Baggage.FirstOrDefault(t => t.Key == TargetingIdKey).Value; | ||
|
||
// Don't modify telemetry if there's no available targeting id | ||
if (string.IsNullOrEmpty(targetingId)) | ||
{ | ||
return; | ||
} | ||
|
||
// Telemetry.Properties is deprecated in favor of ISupportProperties | ||
if (telemetry is ISupportProperties telemetryWithSupportProperties) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a case that this wouldn't be true, perhaps if a user used an old version of app insights? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is no, that they will always be available. The deprecation message for telemetry.Properties says:
They were added in v2.21.0. .NET 6 and above should use at least v2.21.0, so I think we can assume this will be available. The versions before that are all deprecated (actually including v2.21.0 as well). v2.22.0 is the latest. |
||
{ | ||
telemetryWithSupportProperties.Properties["TargetingId"] = targetingId; | ||
} | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.