1

I'm trying to make a CosmosDBTriggered function in my precompiled C# CI/CD deployed project.

enter image description here

Here's the function implementation, which gets deployed with no complaints. I've tried static and instance methods.

enter image description here

There are no errors but also no invocations as reported by the monitoring/Insights tools even though the watched Collection has items and changes while it's deployed.

enter image description here

The function says it's enabled and has a Cosmosdb trigger:

enter image description here

I've tried adding these dependencies individually, but no changes:

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.2.1" />

This function DOES NOT appear in the Triggers of any CosmosDB Collection as I might expect, but I think that's possibly for a different kind of Trigger.

What configuration step am I missing??

UPDATE

When I comment out this [CosmosDB] DocumentClient binding (and anything that relies on it), the function is invoked. So I guess it's a problem with those bindings being used together?

enter image description here

Jason Kleban
  • 20,024
  • 18
  • 75
  • 125
  • 1
    Check your Application Insights logs, that can shed some light on what is going on. Maybe the connection setting you are referring to is not defined in your Function App's Application Settings sections for example (other troubleshooting https://learn.microsoft.com/en-us/azure/cosmos-db/troubleshoot-changefeed-functions). `ConnectionStringSetting` should not have the actual connection string, but rather the name of the setting that holds it. – Matias Quaranta May 02 '21 at 23:49

2 Answers2

1

Are you sure you set the CosmosDbConnection in azure function app on azure?

For example, this is my function app:

Function1.cs

using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp109
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([CosmosDBTrigger(
            databaseName: "testbowman",
            collectionName: "testbowman",
            ConnectionStringSetting = "str",
            CreateLeaseCollectionIfNotExists = true,
            LeaseCollectionName = "lease")]IReadOnlyList<Document> input, ILogger log)
        {
            if (input != null && input.Count > 0)
            {
                log.LogInformation("Documents modified " + input.Count);
                log.LogInformation("First document Id " + input[0].Id);
            }
        }
    }
}

local.settings.json

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "str": "AccountEndpoint=https://testbowman.documents.azure.com:443/;AccountKey=xxxxxx;"
  }
}

But when deploy function app to azure, the local.settings.json will not be used, you need to set the connection string here:

enter image description here

The function app on azure will not tell you this thing, it just doesn't work.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
1

Based on your updated post, the issue is that the Functions runtime is not initializing your Function because of some configuration issue in your bindings.

Normally, the actual error should be in your Application Insights logs.

The Cosmos DB output binding you are using is missing the collection and database properties. Checking the official samples: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-input?tabs=csharp#http-trigger-get-multiple-docs-using-documentclient-c and assuming CosmosDBConnection is a variable that points to the setting name of a setting that contains the connection string:

[CosmosDB(
                databaseName: "<your-db-name>",
                collectionName: "<your-collection-name>",
                ConnectionStringSetting = CosmosDBConnection)] DocumentClient dbClient,
Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47
  • I have yet to try adding those two parameters, but I will. I use with just the connection string name in my other functions (like this), no problem. That overload is not documented as much. I’m confused why I will still have to resupply those parameters when constructing the Uri for the dbClient operation in the implementation - why that redundancy? What would happen if they didn’t match?? – Jason Kleban May 04 '21 at 01:39
  • 1
    In order to see the real error that is preventing your function to be indexed, you'd need to take a look at App Insights logs or attempt to run locally. Based on the fact that you said that removing the binding worked, it means then that the issue might be related to it. When using the DocumentClient type, those parameters really don't add anything, but since the property binding have them, they might be being checked. – Matias Quaranta May 04 '21 at 01:57
  • I cannot find anything relevant in App Insights (though I might not know where to look). Also, the deployment log is nothing but successes. I have now tried adding those extra parameters but this deployment again fails to invoke the triggers. – Jason Kleban May 04 '21 at 11:57
  • Please reach out to Functions support in that case. I don't know the specifics of where those logs would appear. When you run the Function locally, they appear in the Console window, but not sure when running on the cloud. – Matias Quaranta May 04 '21 at 20:57