Azure / azure-sdk-for-go

This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
https://docs.microsoft.com/azure/developer/go/
MIT License
1.62k stars 823 forks source link

Allow passing in an interface to control logging output #23257

Open justinrush opened 2 months ago

justinrush commented 2 months ago

Feature Request

The azsecrets.Client logs verbose, unstructured, and redacted information to stdout on each request. We'd like to be able to log this structured (e.g. json) and control the log level... for example, this is being logged to stdout and isn't something I want to see unless I'm troubleshooting low level details (e.g. set it to log level trace).

[Jul 29 16:43:53.498374] Response: ==> REQUEST/RESPONSE (Try=1/80.273952ms, OpTime=80.390415ms) -- RESPONSE RECEIVED
   POST https://login.microsoftonline.com/guid/oauth2/v2.0/token
   Accept-Encoding: REDACTED
   Client-Request-Id: REDACTED
   Content-Length: 1685
   Content-Type: application/x-www-form-urlencoded; charset=utf-8
   Return-Client-Request-Id: REDACTED
   User-Agent: azsdk-go-azidentity/v1.7.0 (go1.21.10; linux)
   X-Client-Cpu: REDACTED
   X-Client-Os: REDACTED
   X-Client-Sku: REDACTED
   X-Client-Ver: REDACTED
   --------------------------------------------------------------------------------
   RESPONSE Status: 200 OK
   Cache-Control: no-store, no-cache
   Client-Request-Id: REDACTED
   Content-Length: 1675
   Content-Type: application/json; charset=utf-8
   Date: Mon, 29 Jul 2024 16:43:52 GMT
   Expires: -1
   P3p: REDACTED
   Pragma: no-cache
   Set-Cookie: REDACTED
   Strict-Transport-Security: REDACTED
   X-Content-Type-Options: REDACTED
   X-Ms-Clitelem: REDACTED
   X-Ms-Ests-Server: REDACTED
   X-Ms-Request-Id: guid
   X-Ms-Srs: REDACTED
   X-Xss-Protection: REDACTED

[Jul 29 16:43:53.498405] Retry: response 200
[Jul 29 16:43:53.498418] Retry: exit due to non-retriable status code
[Jul 29 16:43:53.498554] Authentication: WorkloadIdentityCredential.GetToken() acquired a token for scope "https://vault.azure.net/.default"
[Jul 29 16:43:53.498629] Authentication: DefaultAzureCredential authenticated with WorkloadIdentityCredential
[Jul 29 16:43:53.498722] Request: ==> OUTGOING REQUEST (Try=1)
   GET https://my-account.vault.azure.net/secrets/my-key/?api-version=7.5
   Accept: application/json
   Authorization: REDACTED
   User-Agent: azsdk-go-azsecrets/v1.1.0 (go1.21.10; linux)

[Jul 29 16:43:53.507432] Response: ==> REQUEST/RESPONSE (Try=1/8.601882ms, OpTime=8.695666ms) -- RESPONSE RECEIVED
   GET https://my-account.vault.azure.net/secrets/my-key/?api-version=7.5
   Accept: application/json
   Authorization: REDACTED
   User-Agent: azsdk-go-azsecrets/v1.1.0 (go1.21.10; linux)
   --------------------------------------------------------------------------------
   RESPONSE Status: 200 OK
   Cache-Control: no-cache
   Content-Length: 349
   Content-Type: application/json; charset=utf-8
   Date: Mon, 29 Jul 2024 16:43:53 GMT
   Expires: -1
   Pragma: no-cache
   Strict-Transport-Security: REDACTED
   X-Content-Type-Options: REDACTED
   X-Ms-Keyvault-Network-Info: REDACTED
   X-Ms-Keyvault-Rbac-Assignment-Id: REDACTED
   X-Ms-Keyvault-Region: REDACTED
   X-Ms-Keyvault-Service-Version: REDACTED
   X-Ms-Request-Id: guid

[Jul 29 16:43:53.507458] Retry: response 200
[Jul 29 16:43:53.507468] Retry: exit due to non-retriable status code
tanyasethi-msft commented 1 month ago

Additionally, All other SDK's have a way to enable logging into a file in a no code change way. References below - .NET SDK - Client-side logging with the Azure Storage client library for .NET (REST API) | Microsoft Learn Java SDK - https://learn.microsoft.com/en-us/rest/api/storageservices/client-side-logging-with-the-microsoft-azure-storage-sdk-for-java Python SDK- https://learn.microsoft.com/en-us/azure/developer/python/sdk/azure-sdk-logging Can we have a similar functionality for Go sdk as well?