Created
October 12, 2020 11:08
-
-
Save shibayan/b16a693cb3b6032b6920b0e7019197ef to your computer and use it in GitHub Desktop.
Azure Functions App Version Initializer
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
using System.Reflection; | |
using Microsoft.ApplicationInsights.Channel; | |
using Microsoft.ApplicationInsights.Extensibility; | |
namespace FunctionApp19 | |
{ | |
public class ApplicationVersionInitializer<TStartup> : ITelemetryInitializer | |
{ | |
public ApplicationVersionInitializer() | |
{ | |
ApplicationVersion = typeof(TStartup).Assembly | |
.GetCustomAttribute<AssemblyInformationalVersionAttribute>() | |
?.InformationalVersion; | |
} | |
public string ApplicationVersion { get; set; } | |
public void Initialize(ITelemetry telemetry) | |
{ | |
telemetry.Context.Component.Version = ApplicationVersion; | |
} | |
} | |
} |
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
using Microsoft.ApplicationInsights.Extensibility; | |
using Microsoft.Azure.Functions.Extensions.DependencyInjection; | |
using Microsoft.Extensions.DependencyInjection; | |
[assembly: FunctionsStartup(typeof(FunctionApp19.Startup))] | |
namespace FunctionApp19 | |
{ | |
public class Startup : FunctionsStartup | |
{ | |
public override void Configure(IFunctionsHostBuilder builder) | |
{ | |
builder.Services.AddSingleton<ITelemetryInitializer, ApplicationVersionInitializer<Startup>>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment