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

Use Scott as an instrumentation backend #1

Open
dodie opened this issue Mar 22, 2019 · 0 comments
Open

Use Scott as an instrumentation backend #1

dodie opened this issue Mar 22, 2019 · 0 comments

Comments

@dodie
Copy link
Collaborator

dodie commented Mar 22, 2019

Code for the configuration:

public static Configuration getTracingConfiguration() {
		return new Configuration.Builder()
				.setTrackerClass("io.ghostwriter.GhostWriter")
				.setInclude(getPropertyConfig("GHOSTWRITER_INCLUDE", new String[] {}))
				.setExclude(getPropertyConfig("GHOSTWRITER_EXCLUDE", new String[] {}))
				.setIncludeByAnnotation(setIfPropertyExists("GHOSTWRITER_ANNOTATED_ONLY", new String[] {"io.ghostwriter.annotation.Include"}))
				.setExcludeByAnnotation(Arrays.asList("io.ghostwriter.annotation.Exclude"))
				.setExcludeMethodsByName(getPropertyConfig("GHOSTWRITER_EXCLUDE_METHODS", new String[] {"toString", "equals", "hashCode", "compareTo"}))
				.setIncludeLambdas(false)
				.setTrackReturn(getPropertyConfig("GHOSTWRITER_TRACE_RETURNING", true))
				.setTrackUnhandledException(getPropertyConfig("GHOSTWRITER_TRACE_ON_ERROR", true))
				.setTrackLocalVariableStateChange(getPropertyConfig("GHOSTWRITER_TRACE_VALUE_CHANGE", true))
				.setTrackFieldStateChanges(false)
				.setMinimumMethodLoc(getPropertyConfig("GHOSTWRITER_SHORT_METHOD_LIMIT", 0))
				.build();
	}

	private static List<String> getPropertyConfig(String propertyKey, final String[] defaultValues) {
		final String property = System.getProperty(propertyKey);

		final String[] params;
		if (property != null) {
			params = property.split(",");
		} else {
			params = defaultValues;
		}

		return Arrays.asList(params);
	}

	private static List<String> setIfPropertyExists(String propertyKey, final String[] values) {
		if (System.getProperty(propertyKey) != null) {
			return Arrays.asList(values);
		} else {
			return new ArrayList<String>();
		}
	}

	private static boolean getPropertyConfig(String propertyKey, final boolean defaultValue) {
		String propertyValue = System.getProperty(propertyKey);
		if (propertyValue != null) {
			return Boolean.parseBoolean(propertyValue);
		} else {
			return defaultValue;
		}
	}

	private static int getPropertyConfig(String propertyKey, final int defaultValue) {
		String propertyValue = System.getProperty(propertyKey);
		if (propertyValue != null) {
			return Integer.parseInt(propertyValue);
		} else {
			return defaultValue;
		}
	}
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

No branches or pull requests

1 participant