Skip to content

Conversation

@shazron
Copy link
Member

@shazron shazron commented Nov 13, 2025

Closes #101
Closes #99

Related: #102

Description

Currently the log level can be set by setting the env var LOG_LEVEL only which may be less intuitive to set in serverless environments. Also a logRetryAfter setting is added - the number of seconds after which to log a warning if the Retry-After header is greater than the number of seconds. Set to 0 to disable.

Allow dependent callers of this library to set the log level via their respective constructors - for example @adobe/aio-lib-state library.

Related Issue

See #101

How Has This Been Tested?

  • npm test

  • used this code:

const { createFetch, HttpExponentialBackoff } = require('@adobe/aio-lib-core-networking'); // from the branch code
const LOG_LEVEL = 'debug'; // set to 'info' not to see any retries, etc

const proxyFetch = createFetch({ 
    proxyUrl: 'http://localhost:8888',
    logLevel: LOG_LEVEL
})

const httpExponentialBackoff = new HttpExponentialBackoff({
    maxRetries: 3,
    initialDelay: 1000,
    maxDelay: 10000,
    logLevel: LOG_LEVEL,
});

async function main() {
    const response = await proxyFetch('https://www.google.com');
    console.log('ProxyFetch response: ', response.status);
    // this should fail, and retry, and if LOG_LEVEL is debug, it should show debug logs
    const response2 = await httpExponentialBackoff.exponentialBackoff('https://somegibberishurl.com', {});
    console.log('HttpExponentialBackoff response: ', response2.status);
}

main();

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This will log a warning if the Retry-After header is greater than logRetryAfterSeconds. Set to 0 to disable.
@shazron shazron changed the title fix: ACNA-4162 - add constructor options to set log level fix: ACNA-4162 - add constructor options to set log level and logRetryAfterSeconds Nov 13, 2025
* @param {number} [options.logRetryAfterSeconds] the number of seconds after which to log a warning if the Retry-After header is greater than the number of seconds. Set to 0 to disable.
*/
constructor (options = {}) {
this.logLevel = options.logLevel || process.env.LOG_LEVEL || 'info'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why keep this property? looks like its only used to initialize this.logger

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds constructor options to configure log level and retry-after warning thresholds for the networking library components, improving flexibility for dependent libraries in serverless environments.

Key Changes

  • Added logLevel constructor option to both HttpExponentialBackoff and ProxyFetch classes to allow programmatic log level configuration
  • Added logRetryAfterSeconds option to HttpExponentialBackoff to control when retry delays trigger warning vs debug logs
  • Renamed ProxyAuthOptions to ProxyOptions throughout the codebase for better naming clarity

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
types.d.ts Added constructor signatures with logLevel and logRetryAfterSeconds options; renamed ProxyAuthOptions to ProxyOptions
src/HttpExponentialBackoff.js Implemented constructor with logLevel and logRetryAfterSeconds options; refactored internal functions to arrow functions for proper this binding
src/ProxyFetch.js Added logLevel option to constructor and instance logger initialization; renamed parameters from proxyAuthOptions to proxyOptions
src/utils.js Updated parameter naming from proxyAuthOptions to proxyOptions for consistency
test/HttpExponentialBackoff.test.js Added comprehensive tests for Retry-After header handling and logRetryAfterSeconds functionality; added missing spy cleanup
README.md Updated documentation to reflect new constructor options and renamed types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shazron shazron merged commit 8aba62e into master Nov 17, 2025
15 checks passed
@shazron shazron deleted the story/ACNA-4162 branch November 17, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add way to enable debug logging for other libraries that use this as a dependency fix misleading comments

5 participants