Skip to content

Conversation

jviau
Copy link
Contributor

@jviau jviau commented Jul 11, 2025

Issue describing the changes in this PR

Part of #11010
Resolves #11170

Pull request checklist

IMPORTANT: Currently, changes must be backported to the in-proc branch to be included in Core Tools and non-Flex deployments.

  • Backporting to the in-proc branch is not required
    • Otherwise: Link to backporting PR
  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • My changes do not require diagnostic events changes
    • Otherwise: I have added/updated all related diagnostic events and their documentation (Documentation issue linked to PR)
  • I have added all required tests (Unit tests, E2E tests)

Additional information

Adds an IHealthCheckPublisher which publishes health checks as telemetry.

  • Writes log statements for the health checks. Currently will only log when unhealthy.
  • Adds 2 metrics for health
Name Instrument Type Unit (UCUM) Description
azure.functions.health_check.reports Histogram {health}{0, 0.5, 1}[1] Represents the overall health state of the instance

[1]: Represents the health as a double, ranging from 0 to 1. 1 = healthy, 0.5 = degraded, 0 = unhealthy. By keeping this between 0 and 1, we open the door to a percentage based health calculation.

Attribute Type Description Examples
azure.functions.health_check.tag String The health check tag the metric is for <empty_string> [1], azure.functions.liveness, azure.functions.readiness

[1]: Empty string represents all health checks being included for this metric

Name Instrument Type Unit (UCUM) Description
azure.functions.health_check.unhealthy_checks Histogram {health}{0, 0.5, 1}[1] Represents the individual health state of the health check components. Only emitted when not healthy.

[1]: Represents the health as a double, ranging from 0 to 1. 1 = healthy, 0.5 = degraded, 0 = unhealthy. By keeping this between 0 and 1, we open the door to a percentage based health calculation.

Attribute Type Description Examples
azure.functions.health_check.tag String The health check tag the metric is for <empty_string> [1], azure.functions.liveness, azure.functions.readiness
azure.functions.health_check.name String The name of the health check [2] azure.functions.script_host.lifecycle, azure.functions.web_host.lifecycle, azure.functions.deployment

[1]: Empty string represents this was part of the all health checks publish. The goal is to have this tag match with azure.functions.health_check.reports so they can be joined into a single view/query in dashboards.
[2]: The name of a health check should follow OTel attribute naming conventions itself.

Other Changes

  • Introduces ObjectPool<T> usage, with helpers for getting shared pools. First shared pool introduced is for StringBuilder. This allows for efficient re-usage of string builders when possible.
    • Will make a PR later to shift to using the shared string builder pool throughout the repo.

Notes

We intend to use health checks to back liveness & readiness probes. As such, having metrics scoped to specific health check tags will be important to highlight directly the history of those probes. This is why TelemetryHealthCheckPublisher has the additionalTags parameter. This approach will lead to redundant metrics, as publishing metrics for the "default" (no tag) health check plus a tag-filtered health check will overlap.

@jviau jviau requested a review from a team as a code owner July 11, 2025 22:17
@jviau jviau changed the title Add TelemetryHealthCheckPublisher [HealthChecks] Add TelemetryHealthCheckPublisher Jul 11, 2025
@Copilot Copilot AI review requested due to automatic review settings August 29, 2025 16:30
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new TelemetryHealthCheckPublisher that publishes health check results as telemetry data (logs and metrics), along with supporting infrastructure for object pooling. The implementation enables health check monitoring through structured telemetry with configurable filtering by tags.

  • Introduces TelemetryHealthCheckPublisher with telemetry output for health checks (logs for unhealthy states, metrics for all states)
  • Adds object pooling infrastructure with PoolFactory, PoolRental<T>, and extensions for efficient memory management
  • Updates test dependencies from FluentAssertions to AwesomeAssertions across multiple test files

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/WebJobs.Script/Diagnostics/HealthChecks/TelemetryHealthCheckPublisher.cs Core publisher implementation with logging and metrics recording
src/WebJobs.Script/Diagnostics/HealthChecks/HealthCheckMetrics.cs Metrics infrastructure for health check telemetry
src/WebJobs.Script/Diagnostics/HealthChecks/HealthCheckExtensions.cs Extension methods for registering publishers and filtering reports
src/WebJobs.Script/Pools/*.cs Object pooling infrastructure for performance optimization
test/WebJobs.Script.Tests/Diagnostics/HealthChecks/TelemetryHealthCheckPublisherTests.cs Comprehensive unit tests for the publisher
eng/build/Engineering.props Language version update to preview
Multiple test files Dependency updates and test assertion library migration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -49,6 +49,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.3.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Telemetry.Abstractions" Version="8.10.0" />
Copy link
Member

Choose a reason for hiding this comment

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

Did you run into any issues with the 9.8.0?

public static Action Act(Action act) => act;

/// <summary>
/// Helper method to inline an action delegate.
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean func delegate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HealthChecks] Add health check telemetry publisher
2 participants