Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/EvaluationDataToApplicationInsights/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Wire up evaluation event emission
builder.Services.AddFeatureManagement()
.WithTargeting<HttpContextTargetingContextAccessor>()
.AddApplicationInsightsTelemetryPublisher();
.AddApplicationInsightsTelemetry();

//
// Default code from .NET template below
Expand Down
2 changes: 1 addition & 1 deletion examples/VariantServiceDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
builder.Services.AddFeatureManagement()
.WithTargeting<HttpContextTargetingContextAccessor>()
.WithVariantService<ICalculator>("Calculator")
.AddApplicationInsightsTelemetryPublisher();
.AddApplicationInsightsTelemetry();

var app = builder.Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand Down Expand Up @@ -55,6 +57,12 @@ public static IFeatureManagementBuilder UseDisabledFeaturesHandler(this IFeature
/// <returns>A <see cref="IFeatureManagementBuilder"/> that can be used to customize feature management functionality.</returns>
public static IFeatureManagementBuilder WithTargeting(this IFeatureManagementBuilder builder)
{
// Add HttpContextAccessor if it doesn't already exist
if (!builder.Services.Any(service => service.ServiceType == typeof(IHttpContextAccessor)))
{
builder.Services.AddHttpContextAccessor();
}

//
// Register the targeting context accessor with the same lifetime as the feature manager
if (builder.Services.Any(descriptor => descriptor.ServiceType == typeof(IFeatureManager) && descriptor.Lifetime == ServiceLifetime.Scoped))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.FeatureManagement.Telemetry.ApplicationInsights;

Expand All @@ -13,11 +15,11 @@ namespace Microsoft.FeatureManagement
public static class FeatureManagementBuilderExtensions
{
/// <summary>
/// Adds the <see cref="ApplicationInsightsEventPublisher"/> using <see cref="ApplicationInsightsHostedService"/> to the feature management builder.
/// Adds the <see cref="TargetingTelemetryInitializer"/> and the <see cref="ApplicationInsightsEventPublisher"/> using <see cref="ApplicationInsightsHostedService"/> to the feature management builder.
/// </summary>
/// <param name="builder">The feature management builder.</param>
/// <returns>The feature management builder.</returns>
public static IFeatureManagementBuilder AddApplicationInsightsTelemetryPublisher(this IFeatureManagementBuilder builder)
public static IFeatureManagementBuilder AddApplicationInsightsTelemetry(this IFeatureManagementBuilder builder)
{
if (builder == null)
{
Expand All @@ -29,6 +31,8 @@ public static IFeatureManagementBuilder AddApplicationInsightsTelemetryPublisher
throw new ArgumentException($"The provided builder's services must not be null.", nameof(builder));
}

builder.Services.AddSingleton<ITelemetryInitializer, TargetingTelemetryInitializer>();
Copy link
Contributor

@zhiyuanliang-ms zhiyuanliang-ms Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add telemetry initialier here. The method name could be changed to AddApplicationInsightsTelemetry or something similar. And the comment in Line 18 should be updated.

Adding the telemetry initializer will make all telemetry be tagged with targeting id. Is there any valid reason that the user won't want to have targeting id in some of telemetry?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like @zhiyuanliang-ms suggestion here. AddApplicationInsightsTelemetry


builder.Services.AddSingleton<ApplicationInsightsEventPublisher>();

if (!builder.Services.Any((ServiceDescriptor d) => d.ServiceType == typeof(IHostedService) && d.ImplementationType == typeof(ApplicationInsightsHostedService)))
Expand Down
Loading