Azure-sdk-for-js: [Service Bus] Improve debug logs for ATOM API

Created on 27 Oct 2020  路  4Comments  路  Source: Azure/azure-sdk-for-js

Logs corresponding to the methods under ServiceBusAdministrationClient are shown as below.
Example: The initial log inside the createQueue method.
azure:service-bus:administration:verbose Performing management operation - createQueue() for "partitioned-queue" with options: [object Object]

Update the log statement to show better info for the options instead of [object Object].(Maybe use JSON.stringify)

Client Service Bus help wanted

All 4 comments

PRs are welcome to add this feature.
Code Pointers:

  • Set up environment and run rush build
  • Open the sdk/servicebus/service-bus folder in your editor/IDE, find the ServiceBusAdministrationClient class and get started
  • To change the log levels, you can tweak the AZURE_LOG_LEVEL env variable to one of these values

    • verbose

    • info

    • warning

    • error

@HarshaNalluru and @ramya-rao-a I think one option is to use '%j' format specifier as logger is using nodejs util.format method. Should we use this approach?

logger.verbose(
        `Performing management operation - createQueue() for "${queueName}" with options: %j`,
        options
      );

Also, is there a way to verify these logging statement output on my local?

@mohsin-mehmood, it should be fine if it works.

Setup

  • A well-formed connection string should be enough since this specific log happens before the request is made.
  • Add a .env file in the servicebus/service-bus folder with a connection string such as SERVICEBUS_CONNECTION_STRING=Endpoint=endpoint/;SharedAccessKeyName=key;SharedAccessKey=key - sample.env
    (The request would fail since the connection string is bad, but the log that you're testing should appear before the failure, so all good.)
    (Or create a service-bus account in the azure portal and populate the actual connection string)

To run a test

Once you have the SERVICEBUS_CONNECTION_STRING in the .env file and you do the changes to the src folder, you can run a test

  • Go to atomManagement.spec.ts
  • Set it.only for any test that would invoke the createQueue method for example or add your own
  • Set the environment variable DEBUG=azure* in the cmd line or terminal - Reference
  • Run the test by rushx test:node or rushx test:browser (Assuming you have the rush setup)

If you want to verify through a sample instead, follow below.

To verify through a sample

  • Once you're done with the changes to the src folder, run rushx pack to generate the package (Assuming you have the rush setup)
  • Above command would generate the package azure-service-bus-7.0.0-preview.8.tgz
  • In a fresh npm project(npm init), do npm install azure-service-bus-7.0.0-preview.8.tgz(make sure the path is valid)
  • Set the environment variable DEBUG=azure* in the cmd line or terminal - Reference
  • Copy/write a sample such as administrationClient.ts and run it with ts-node.

This might seem like a lot of setup, let me know if you have questions or if you're stuck at any point 馃檪

Done with #12187

Thanks @mohsin-mehmood!

Was this page helpful?
0 / 5 - 0 ratings