Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoggingOptions.getDefaultInstance() always returns a new object #908

Open
alamothe opened this issue Mar 17, 2022 · 4 comments
Open

LoggingOptions.getDefaultInstance() always returns a new object #908

alamothe opened this issue Mar 17, 2022 · 4 comments
Assignees
Labels
api: logging Issues related to the googleapis/java-logging API. next major: breaking change this is a change that we should wait to bundle into the next major version priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@alamothe
Copy link

LoggingOptions.getDefaultInstance() always returns a new object:

  public static LoggingOptions getDefaultInstance() {
    return newBuilder().build();
  }

This is very misleading, because the method name suggests it will return the same instance.

Consequences are that Logging instance is not shared among handlers etc. if we use LoggingOptions.getDefaultInstance() to pass the options, without saving them to a variable.

In fact, our codebase had LoggingOptions.getDefaultInstance().service in a few places, and a new client was always created as a result.

@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/java-logging API. label Mar 17, 2022
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Mar 17, 2022
@minherz minherz added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. next major: breaking change this is a change that we should wait to bundle into the next major version and removed triage me I really want to be triaged. 🚨 This issue needs some love. labels Mar 23, 2022
@minherz
Copy link
Contributor

minherz commented Mar 23, 2022

Thank you for raising this problem. The method returns a new instance of the LoggingOptions instance with default setup.
I understand the source of the confusion. The consecutive calls to the loggingOptions.getService() will return the same service instance which, in our case will be Logging instance. However, consecutive calls to the LoggingOptions.getDefaultInstance().getService() will indeed return each time a new instance of the Logging implementation.
Unfortunately, we do not have information how many our customers use the fact that the call to the LoggingOptions.getDefaultInstance() returns a new instance of the LoggingOptions. In result, we cannot modify this behavior without introducing a breaking change.
We will certainly make this change in the next major version.

@losalex
Copy link
Contributor

losalex commented Mar 30, 2022

Lowering the priority to consider it in next release

@losalex losalex added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Mar 30, 2022
@losalex losalex removed their assignment Jul 3, 2023
@ejstembler
Copy link

What is the work-around for this? The main example code show's using LoggingOptions.getDefaultInstance().getService()

@cindy-peng cindy-peng self-assigned this Jan 29, 2024
@cindy-peng
Copy link
Contributor

Hi @ejstembler, sorry for the late reply!
As a work-around, we suggest to save LoggingOptions instance as a variable first and call loggingOptions.getService() to retrieve the same service instance:

LoggingOptions loggingOptions = LoggingOptions.getDefaultInstance();
try(Logging logging = loggingOptions.getService()) {
  // use logging here
}

Any consecutive calls to the loggingOptions.getService() will return the same service instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/java-logging API. next major: breaking change this is a change that we should wait to bundle into the next major version priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

6 participants