Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

WIP: load SentryOptions from external sources. #536

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maciejwalkowiak
Copy link
Contributor

馃摙 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

馃摐 Description

The point of this PR at this stage is to discuss and think if this is the direction we want to go, or are there better ideas.

Adds the ability to load SentryOptions from external sources:

  • environment variables
  • system properties
  • sentry.properties file

This is still WIP with missing:

  • tests
  • passing logger everywhere
  • polishing the code (adding @NotNull etc)
  • proper package structure
  • using this code in integrations

馃挕 Motivation and Context

This feature is being brought in for the sake of compatibility with 1.x branch. Most of the code is either copied or inspired by the same functionality from 1.x branch with certain changes:

  • we do not support anymore resolving properties from the DSN url
  • we do not use SLF4J for logging but rather pass an instance of ILogger.

What is supported:

  • loading from JNDI registry
  • loading from environment properties
  • loading from system properties
  • loading from properties file
    • properties file name can be:
      • sentry.properties
      • or file name can be obtained from env variable SENTRY_PROPERTIES_FILE
      • or file name can be obtained from system property sentry.properties.file
    • file can be located:
      • in the classpath
      • file system

SentryOptionsProvider is an entry-point to resolve SentryOptions. We can either use it inside no-arg Sentry#init() method, or resolve options and pass it to Sentry#init(options).

馃挌 How did you test it?

TODO

馃摑 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • All tests passing
  • No breaking changes

馃敭 Next steps

if (shutdownTimeout != null) {
options.setShutdownTimeout(shutdownTimeout);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we will need to set all the non-null properties from external config

*/
public static boolean isAvailable() {
try {
Class.forName("javax.naming.InitialContext", false, JndiSupport.class.getClassLoader());
Copy link
Member

Choose a reason for hiding this comment

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

This isnt' very Android friendly.
We'd need a clear way to init without going through all these Java ways

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say that none of the providers should be "executed" on Android, but just its own AndroidProvider.

it doesnt make sense to try to read system envs, locate the file etc if the only thing that makes sense for android is its own provider.
ideally, the options have a list of providers, and its empty by default, so depending on the integration, they add their own providers that make sense, something like that.
eg sentry-spring would have a system env, file system provider etc...
sentry-android would have only its own provider, that reads from the manifest

we'll also need a new module/package like io.sentry.config that has non android related things, I dont want customers needing to add extra rules to not fail their build because of unknown classes, this happened with the older version of the SDK and a lot of people complained.

Comment on lines +7 to +10
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NoInitialContextException;
Copy link
Contributor

Choose a reason for hiding this comment

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

this cant live in the sentry-core package.
Android SDK has a subset of the Java SDK, javax is not one of them

return null;
}

try (InputStreamReader rdr = new InputStreamReader(is, charset)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make sense to use a BufferedReader as well?

@maciejwalkowiak maciejwalkowiak mentioned this pull request Sep 8, 2020
8 tasks
Base automatically changed from feat/sentry-java to master September 10, 2020 22:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants