Skip to content

[CosmosDb] Replacing scaling logs to WebJobs extension methods#975

Merged
alrod merged 1 commit into
devfrom
alrod/replace-logs-cosmosdb
Mar 20, 2026
Merged

[CosmosDb] Replacing scaling logs to WebJobs extension methods#975
alrod merged 1 commit into
devfrom
alrod/replace-logs-cosmosdb

Conversation

@alrod

@alrod alrod commented Nov 18, 2025

Copy link
Copy Markdown
Member

Summary

Replace direct LogWarning calls in the CosmosDB scaling extensions with standardized LogFunctionScaleWarning WebJobs extension method.

This enables the Scale Controller's OpenTelemetry logger to intercept scaling warning events (EventId 8003) and forward them to the customer's Application Insights, providing visibility into connectivity errors during scaling.

Changes

  • CosmosDBMetricsProvider.cs: Added functionId constructor parameter; replaced LogWarning with LogFunctionScaleWarning; improved 'Unable to handle' message; renamed errormsg to errorMessage; fixed TryHandleCosmosException to pass _functionId instead of string.Empty
  • CosmosDBTargetScaler.cs: Replaced LogWarning with LogFunctionScaleWarning for concurrency validation warning
  • CosmosDBScaleMonitor.cs: Updated constructor call to pass functionId to CosmosDBMetricsProvider
  • CosmosDBMetricsProviderTests.cs: Updated constructor call and test assertions to match new warning log format
  • WebJobs.Extensions.CosmosDB.csproj: Updated Microsoft.Azure.WebJobs from 3.0.42 to 3.0.44
  • Directory.Version.props: Version bump to 4.15.0
  • release_notes.md: Added release notes for 4.15.0

Phase 2 (follow-up)

Migrating the LogInformation scale vote detail logs to LogFunctionScaleVote will follow once azure-webjobs-sdk #3189 ships (changes vote log level from Debug to Information).

Context

Part of the Scale Controller App Insights logging feature (AAPT-Antares-ScaleController PR #14140160).

Related PRs in azure-sdk-for-net:

  • #53923 - Storage Queue extension
  • #53925 - EventHubs extension
  • #53926 - ServiceBus extension

if (!TryHandleCosmosException(e))
{
_logger.LogWarning(Events.OnScaling, "Unable to handle {0}: {1}", e.GetType().ToString(), e.Message);
_logger.LogFunctionScaleWarning("Unable to handle.", _functionId, e);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given the format change here, I suggest to reword to "Unable to handle exception.", or perhaps keep the wording as it was for this?

Thinking the formatted end result "Function 'Foo' warning: Unable to handle." showing up in log summaries is too vague.

}

_logger.LogWarning(Events.OnScaling, errormsg);
_logger.LogFunctionScaleWarning(errormsg, _functionId, e);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: while you're in here, let's fix errormsg -> errorMsg or errorMessage

@fabiocav

Copy link
Copy Markdown
Member

@alrod closing this stale PR. This is no longer applicable here.

@fabiocav fabiocav closed this Feb 14, 2026
@alrod

alrod commented Mar 19, 2026

Copy link
Copy Markdown
Member Author

/reopen

@alrod alrod reopened this Mar 19, 2026
@alrod alrod force-pushed the alrod/replace-logs-cosmosdb branch from 041ecde to ae60e18 Compare March 19, 2026 18:06
@alrod alrod force-pushed the alrod/replace-logs-cosmosdb branch 3 times, most recently from 76ebcb7 to 625e00b Compare March 19, 2026 18:37
@@ -79,7 +79,7 @@ internal TargetScalerResult GetScaleResultInternal(TargetScalerContext context,
targetWorkerCount = partitionCount;
}

_logger.LogInformation(targetScaleMessage);
_logger.LogFunctionScaleVote(_functionId, targetWorkerCount, (int)remainingWork, concurrency, targetScaleMessage);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question here as in the other PR - these go from Information to Debug now. Will customers be confused they're no longer seeing these logs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reverted - keeping LogInformation for the vote detail log as-is. See my reply on the SB PR for the full plan (phase 1: warnings/errors only, phase 2: vote logs after WebJobs SDK log level fix).

@alrod alrod force-pushed the alrod/replace-logs-cosmosdb branch from 29edc5a to a8b14a3 Compare March 19, 2026 22:00
@alrod alrod merged commit fd9ad82 into dev Mar 20, 2026
6 checks passed
@alrod alrod deleted the alrod/replace-logs-cosmosdb branch March 20, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants