Azure / Azure/azure-functions-dotnet-worker

Enhancement: Make FunctionContext.RetryContext useful/populated in more scenarios

Open
#2,005 5 comments 0 reactions 0 assignees View on GitHub
needs-discussion
Dominant language
C#
Stars
466
Forks
215
Avg merge
3d 10h
Merged PRs (30d)
7

Description

FunctionContext.RetryContext is null in quite a number of scenarios, even though the properties it exposes are known to the runtime for some (many?) of those scenarios. It would be a very valuable enhancement to have this property more widely supported.

This has been identified as a potentially breaking change in other issues in the repo, so this would be a change for a new major version - .NET 9 perhaps. This is an enhancement - a feature request, not a bugfix.

I have a function app with an Azure Queue Storage trigger. Entries in the log indicate that the runtime knows how many times the queue entry has been dequeued, and indeed it looks like it is possible to access this metadata by adding a parameter to my function, as detailed in this document https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns#trigger-metadata. I can add a parameter to my function to determine the number of times it has been dequeued. However, I cannot immediately see a way to access the maximum number of dequeues for this queue.

As a user of functions, my feedback is that the way the retry data is made available seems to be quite fragmented/inconsistent, with different methods of getting access to that data needed for different trigger types. It would be much more useful if FunctionContext.RetryContext were used to expose as much data as can be made available in more trigger types/scenarios. The consistency of getting this information from the same place in different scenarios would make people's code much more portable, enabling easier migration from one trigger type to another, as the needs of the system change. It should also reduce the number of times you get issues raised asking why FunctionContext.RetryContext is null, so it might also offer a way to reduce the maintenance burden for you, somewhat.

This would be particularly useful for code that needs to make decisions based upon the number of times an attempt has been made to complete an operation. One such example is changing the logging level of a message written to the log, which is part of what I want to do. However, there will be other types of behaviour that vary when it is determined that a failure happened on the last retry and will result in the message being moved to the poison queue, such as informing someone of this permanent failure.

I integrate with a number of APIs and it is not unusual for there to be a single failure of a processing operation in my function because one of those remote APIs is down for maintenance, or because of a failover event. However, I want to identify when all attempts to process the queued message have failed, as this represents a more serious type of failure that needs investigation/intervention. This is more difficult than it should be, because FunctionContext.RetryContext is null, so I cannot use the properties it is intended to expose to trigger my custom behaviours.

This request is related to other, closed issues, where other people have been interested in the same or similar behaviours:
#720
#1438
#1443

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing FunctionContext.RetryContext and the trigger-metadata documentation linked in the issue, then compare the related discussions in issues #720, #1438, and #1443. Done means retry information is exposed consistently across the supported trigger scenarios, with the available properties defined clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.