-
Notifications
You must be signed in to change notification settings - Fork 129
Open telemetry update #617
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
Merged
Yuan Qu (yuanqu72)
merged 15 commits into
microsoft:main
from
yuanqu72:open-telemetry-update
Sep 21, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a4fdc98
Add Microsoft.FeatureManagement.Telemetry.OpenTelemetry package with …
yuanqu72 5fa02de
Clarify OpenTelemetryDemo README wording and recommend OpenTelemetry …
yuanqu72 4b9439f
Merge branch 'main' into open-telemetry-update
yuanqu72 1aa1bb8
Add TargetingLogProcessor and migrate OpenTelemetryDemo to the Azure …
yuanqu72 8b8454a
Fix README OpenTelemetryDemo sample description to ASP.NET Core Web App.
yuanqu72 1c339a0
Make install-dotnet.ps1 fail loudly on a silent .NET install failure …
yuanqu72 b0a5b18
Merge upstream/main into open-telemetry-update, resolving install-dot…
yuanqu72 441bd57
Update OpenTelemetryDemo README description to mention Variants.
yuanqu72 4b3bae3
Reuse OpenTelemetry histogram instruments, await sign-in, avoid overw…
yuanqu72 7f66f1d
Fix feature evaluation log sampling
yuanqu72 71026b0
Remove sampling note from README
yuanqu72 040a5b2
Simplify OpenTelemetry integration and rename the feature evaluation …
yuanqu72 84731d8
Refactor OpenTelemetry registration and shared constants while clarif…
yuanqu72 1dd498f
Rename OpenTelemetry integration to AddFeatureManagementProcessors
yuanqu72 097256f
Merge branch 'main' into open-telemetry-update
yuanqu72 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,28 @@ | ||
| # Installs .NET 8 and .NET 10 for CI/CD environment | ||
| # see: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script#examples | ||
|
|
||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; | ||
|
|
||
| &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Channel 8.0 | ||
| $installScript = [scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1')) | ||
|
|
||
| $channels = @("8.0", "10.0") | ||
|
|
||
| foreach ($channel in $channels) | ||
| { | ||
| & $installScript -Channel $channel | ||
| } | ||
|
|
||
| # Fail fast with a clear error instead of letting a silent install failure surface later as a | ||
| # confusing "You must install or update .NET to run this application" error during test/build. | ||
| $dotnet = & "$PSScriptRoot/resolve-dotnet.ps1" | ||
| $installedSdks = & $dotnet --list-sdks | ||
|
|
||
| &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Channel 10.0 | ||
| foreach ($channel in $channels) | ||
| { | ||
| if (-not ($installedSdks | Select-String -Pattern "^$([regex]::Escape($channel))\.")) | ||
| { | ||
| throw "Verification failed: .NET SDK for channel $channel was not found after installation. Installed SDKs:`n$installedSdks" | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace OpenTelemetryDemo | ||
| { | ||
| /// <summary> | ||
| /// High-performance, source-generator-style logging (<see cref="LoggerMessage.Define"/>) for | ||
| /// this app's custom events. Each event's message template includes the | ||
| /// "microsoft.custom_event.name" placeholder, which becomes a `LogRecord` attribute that the | ||
| /// Azure Monitor OpenTelemetry Exporter (if configured) uses to classify the log as a custom | ||
| /// event in Application Insights, rather than a plain trace. | ||
| /// </summary> | ||
| public static class LoggerExtensions | ||
| { | ||
| private const string AzureMonitorCustomEventNameKey = "microsoft.custom_event.name"; | ||
|
|
||
| private static readonly Action<ILogger, string, int, Exception> _vote = LoggerMessage.Define<string, int>( | ||
| LogLevel.Information, | ||
| new EventId(1, AzureMonitorCustomEventNameKey), | ||
| "{" + AzureMonitorCustomEventNameKey + "} {ImageRating}"); | ||
|
|
||
| private static readonly Action<ILogger, string, string, long, Exception> _checkout = LoggerMessage.Define<string, string, long>( | ||
| LogLevel.Information, | ||
| new EventId(2, AzureMonitorCustomEventNameKey), | ||
| "{" + AzureMonitorCustomEventNameKey + "} {success} {checkoutAmount}"); | ||
|
|
||
| public static void LogVote(this ILogger logger, int rating) | ||
| { | ||
| _vote(logger, "Vote", rating, null); | ||
| } | ||
|
|
||
| public static void LogCheckout(this ILogger logger, long amount) | ||
| { | ||
| _checkout(logger, "checkout", "yes", amount, null); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.6.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Microsoft.FeatureManagement.AspNetCore\Microsoft.FeatureManagement.AspNetCore.csproj" /> | ||
| <ProjectReference Include="..\..\src\Microsoft.FeatureManagement.Telemetry.OpenTelemetry\Microsoft.FeatureManagement.Telemetry.OpenTelemetry.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| @page | ||
| @model CheckoutModel | ||
| @{ | ||
| ViewData["Title"] = "Checkout"; | ||
| } | ||
| <h1>@ViewData["Title"]</h1> | ||
|
|
||
| <p>Click Below To Check Out!</p> | ||
|
|
||
| <form method="post"> | ||
| @Html.AntiForgeryToken() | ||
| <button id="checkout" name="checkout" type="submit" class="btn btn-primary btn-sm"> | ||
| Check Out | ||
| </button> | ||
| </form> | ||
|
|
||
| @if (Model.CheckedOut) | ||
| { | ||
| <p class="mt-3">Checked Out! Amount: @Model.CheckoutAmount</p> | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| using System.Diagnostics.Metrics; | ||
| using Microsoft.AspNetCore.Mvc.RazorPages; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace OpenTelemetryDemo.Pages | ||
| { | ||
| public class CheckoutModel : PageModel | ||
| { | ||
| private readonly Meter _meter; | ||
| private readonly Histogram<long> _checkoutAmountHistogram; | ||
| private readonly ILogger<CheckoutModel> _logger; | ||
|
|
||
| public CheckoutModel(IMeterFactory meterFactory, ILogger<CheckoutModel> logger) | ||
| { | ||
| _meter = meterFactory?.Create("OpenTelemetryDemo") ?? throw new ArgumentNullException(nameof(meterFactory)); | ||
| _checkoutAmountHistogram = _meter.CreateHistogram<long>("checkoutAmount"); | ||
| _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
| } | ||
|
|
||
| public bool CheckedOut { get; set; } | ||
|
|
||
| public int CheckoutAmount { get; set; } | ||
|
|
||
| public void OnPost() | ||
| { | ||
| CheckoutAmount = Random.Shared.Next(1, 100); | ||
|
|
||
| // | ||
| // Track the checkout amount metric using the OpenTelemetry metrics API | ||
| // (System.Diagnostics.Metrics), exported via WithMetrics/AddMeter. | ||
| _checkoutAmountHistogram.Record(CheckoutAmount); | ||
|
|
||
| // | ||
| // Emits a log-based custom event, the OpenTelemetry equivalent of | ||
| // TelemetryClient.TrackEvent. | ||
| _logger.LogCheckout(CheckoutAmount); | ||
|
|
||
| CheckedOut = true; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| @page | ||
| @model ErrorModel | ||
| @{ | ||
| ViewData["Title"] = "Error"; | ||
| } | ||
|
|
||
| <h1 class="text-danger">Error.</h1> | ||
| <h2 class="text-danger">An error occurred while processing your request.</h2> | ||
|
|
||
| @if (Model.ShowRequestId) | ||
| { | ||
| <p> | ||
| <strong>Request ID:</strong> <code>@Model.RequestId</code> | ||
| </p> | ||
| } | ||
|
|
||
| <h3>Development Mode</h3> | ||
| <p> | ||
| Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred. | ||
| </p> | ||
| <p> | ||
| <strong>The Development environment shouldn't be enabled for deployed applications.</strong> | ||
| It can result in displaying sensitive information from exceptions to end users. | ||
| For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong> | ||
| and restarting the app. | ||
| </p> |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.AspNetCore.Mvc.RazorPages; | ||
| using System.Diagnostics; | ||
|
|
||
| namespace OpenTelemetryDemo.Pages | ||
| { | ||
| [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
| [IgnoreAntiforgeryToken] | ||
| public class ErrorModel : PageModel | ||
| { | ||
| public string RequestId { get; set; } | ||
|
|
||
| public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
|
|
||
| private readonly ILogger<ErrorModel> _logger; | ||
|
|
||
| public ErrorModel(ILogger<ErrorModel> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| public void OnGet() | ||
| { | ||
| RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| @page | ||
| @model IndexModel | ||
| @{ | ||
| ViewData["Title"] = "Home page"; | ||
| } | ||
|
|
||
| <div class="text-center mb-40"> | ||
| <h1 class="display-4">Welcome, @Model.Username !</h1> | ||
| </div> | ||
|
|
||
| <div class="text-center"> | ||
| <div style="display:inline-block;width:500px;"> | ||
| <img class="mb-40" src="@ViewData["ImageUri"]" alt="Dinosaur selected by the ImageRating feature" /> | ||
| <div class="panel panel-primary"> | ||
| <div class="panel-heading"> | ||
| <h3 class="panel-title"> | ||
| <span class="glyphicon glyphicon-arrow-right"></span>Rate the image on a scale of 1 - 5 !<span class="glyphicon glyphicon-new-window"></span> | ||
| </h3> | ||
| </div> | ||
| <form action="/" method="post"> | ||
| <div class="panel-body mb-5"> | ||
| <ul class="list-group"> | ||
| <li class="list-group-item"> | ||
| <div class="radio"> | ||
| <label> | ||
| <input type="radio" name="imageScore" value="5"> | ||
| 5 | ||
| </label> | ||
| </div> | ||
| </li> | ||
| <li class="list-group-item"> | ||
| <div class="radio"> | ||
| <label> | ||
| <input type="radio" name="imageScore" value="4"> | ||
| 4 | ||
| </label> | ||
| </div> | ||
| </li> | ||
| <li class="list-group-item"> | ||
| <div class="radio"> | ||
| <label> | ||
| <input type="radio" name="imageScore" value="3"> | ||
| 3 | ||
| </label> | ||
| </div> | ||
| </li> | ||
| <li class="list-group-item"> | ||
| <div class="radio"> | ||
| <label> | ||
| <input type="radio" name="imageScore" value="2"> | ||
| 2 | ||
| </label> | ||
| </div> | ||
| </li> | ||
| <li class="list-group-item"> | ||
| <div class="radio"> | ||
| <label> | ||
| <input type="radio" name="imageScore" value="1"> | ||
| 1 | ||
| </label> | ||
| </div> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| @Html.AntiForgeryToken() | ||
| <div class="panel-footer"> | ||
| <input type="submit" class="btn btn-primary btn-sm" value="Vote" /> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| </div> |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
| using System.Diagnostics.Metrics; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.AspNetCore.Mvc.RazorPages; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.FeatureManagement; | ||
|
|
||
| namespace OpenTelemetryDemo.Pages | ||
| { | ||
| public class IndexModel : PageModel | ||
| { | ||
| private readonly IVariantFeatureManager _featureManager; | ||
| private readonly Meter _meter; | ||
| private readonly Histogram<long> _imageRatingHistogram; | ||
| private readonly ILogger<IndexModel> _logger; | ||
|
|
||
| public IndexModel(IVariantFeatureManager featureManager, IMeterFactory meterFactory, ILogger<IndexModel> logger) | ||
| { | ||
| _featureManager = featureManager ?? throw new ArgumentNullException(nameof(featureManager)); | ||
| _meter = meterFactory?.Create("OpenTelemetryDemo") ?? throw new ArgumentNullException(nameof(meterFactory)); | ||
| _imageRatingHistogram = _meter.CreateHistogram<long>("ImageRating"); | ||
| _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
| } | ||
|
|
||
| public string Username { get; set; } | ||
|
|
||
| public async Task<IActionResult> OnGet() | ||
| { | ||
| Username = HttpContext.User.Identity.Name; | ||
|
|
||
| if (string.IsNullOrEmpty(Username)) | ||
| { | ||
| return Redirect("/RandomizeUser"); | ||
| } | ||
|
|
||
| // | ||
| // Use application's feature manager to get assigned variant for current user | ||
| Variant variant = await _featureManager | ||
| .GetVariantAsync("ImageRating", HttpContext.RequestAborted); | ||
|
|
||
| // | ||
| // Set the page's display image based on the assigned variant. | ||
| ViewData["ImageUri"] = variant.Configuration.Value; | ||
|
|
||
| return Page(); | ||
| } | ||
|
|
||
| public IActionResult OnPost() | ||
| { | ||
| if (Request.Form != null) | ||
| { | ||
| string val = Request.Form["imageScore"]; | ||
|
|
||
| if (val != null && | ||
| int.TryParse(val, out int rating)) | ||
| { | ||
| // | ||
| // Track the image rating metric using the OpenTelemetry metrics API | ||
| // (System.Diagnostics.Metrics), exported via WithMetrics/AddMeter. | ||
| _imageRatingHistogram.Record(rating); | ||
|
|
||
| // | ||
| // Emits a log-based custom event, the OpenTelemetry equivalent of | ||
| // TelemetryClient.TrackEvent. | ||
| _logger.LogVote(rating); | ||
| } | ||
| } | ||
|
|
||
| return Redirect("/RandomizeUser"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| @page | ||
| @model OpenTelemetryDemo.Pages.RandomizeUserModel | ||
| @{ | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.