Skip to content

Instantly share code, notes, and snippets.

@shibayan
Created October 12, 2020 11:08
Show Gist options
  • Save shibayan/b16a693cb3b6032b6920b0e7019197ef to your computer and use it in GitHub Desktop.
Save shibayan/b16a693cb3b6032b6920b0e7019197ef to your computer and use it in GitHub Desktop.
Azure Functions App Version Initializer
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;
}
}
}
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