Why does my Azure Function disobey env var logging settings but respect host.json?

42 views Asked by At

I added logging through opentelemetry and now I am getting duplicated entries of logs as they are sent through both Function's handler and opentelemetry handler.

I want to disable Function logging as opentelemetry adds tracer span awareness through OperationID/ParentID, thus making opentelemetry logs more functional with correlation. It is necessary to disable Function's logging in an individual function at this point, as the rest functions are not instrumented yet.

According to this document, I must be able to set environment variables like

AzureFunctionsJobHost__logging__logLevel__Function__MyFunction__User

to control logging while overriding other settings. I found that host-level setting like

AzureFunctionsJobHost__logging__logLevel__Function=None

does work, essentially disabling all logging, but on individual function level (with __MyFunction__User suffix) this setting is ignored.

I also noticed that settings through host.json work, too:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
      "Function": "Information",
      "Function.MyFunction.User": "None"
    }
  }
}

The above achieves the goal, but configuring through env vars is preferred for me. What am I missing?

1

There are 1 answers

0
SiddheshDesai On

I tried using both the settings below and the Logging was disabled only when I added the Log level to None for the individual Function in host.json and after adding the setting in Environment variables it did not work.

Environment Settings: -

"name": "AzureFunctionsJobHost__logging__logLevel__Function__http_trigger__User",
"value": "None",
"name": "AzureFunctionsJobHost__logging__logLevel__Function__http_trigger",
"value": "None",

host.json:-

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
     "Function.http_trigger"  : "Information",
     "Function.timer_trigger" : "Information"
    }  
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

The Function Logs were still visible: -

enter image description here

But when I added loglevel setting at host.json to None, The Function trigger Logs were disabled: -

host.json:-

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
     "Function.http_trigger"  : "None",
     "Function.timer_trigger" : "None"
    }  
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

Output: -

enter image description here

This looks like a Bug. I have raised a Github Issue on the same to make this Setting work, Follow this issue for the further updates.