Runtime information provider for application-level ambient metadata.
$ dotnet add package Microsoft.Extensions.AmbientMetadata.ApplicationThis flows runtime information for application-level ambient metadata such as the version, deployment ring, environment, and name. This information can be useful to enrich telemetry.
From the command-line:
dotnet add package Microsoft.Extensions.AmbientMetadata.Application
Or directly in the C# project file:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AmbientMetadata.Application" Version="[CURRENTVERSION]" />
</ItemGroup>
The services can be registered using any of the following methods:
public static IHostBuilder UseApplicationMetadata(this IHostBuilder builder, string sectionName = DefaultSectionName)
public static TBuilder UseApplicationMetadata<TBuilder>(this TBuilder builder, string sectionName = DefaultSectionName) where TBuilder : IHostApplicationBuilder
public static IServiceCollection AddApplicationMetadata(this IServiceCollection services, Action<ApplicationMetadata> configure)
When loading from configuration, the version and deployment ring metadata are read from the ambientmetadata:application section. The environment and application names are read from the IHostEnvironment.
{
"AmbientMetadata" {
"Application" {
"BuildVersion": "1.0-alpha1.2346",
"DeploymentRing": "InnerRing"
}
}
}
The ApplicationMetadata can be injected wherever needed. For example:
public class MyClass
{
public MyClass(IOptions<ApplicationMetadata> options) { Application = options.Value; }
private ApplicationMetadata Application { get; }
public void DoWork()
{
Log.LogEnvironment(Application.Version, Application.DeploymentRing, Application.Environment, Application.Name);
}
}
We welcome feedback and contributions in .