Skip to content

spotify/confidence-sdk-java

Java Confidence SDK

Java library for Confidence. This library is designed to work in a java backend environment. For Android, please visit Confidence-SDK-Android.

Install

Maven

<dependency>
    <groupId>com.spotify.confidence</groupId>
    <artifactId>sdk-java</artifactId>
    <version>0.1.4-SNAPSHOT</version>
</dependency>

Note: we strongly recommend to adopt the latest non-SNAPSHOT release available here.

Depending on a development snapshot

We deploy snapshots from the main branch to Sonatype OSSRH. To use a snapshot, add the following repository to your pom.xml:

<distributionManagement>
    <snapshotRepository>
        <id>oss.snapshots</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

Usage

The SDK is instantiated using a client secret that is configured in the Confidence UI or via the management console.

Resolving flags

Flag values are evaluated remotely and returned to the application:

final Confidence confidence = Confidence.builder("<CLIENT_TOKEN>").build();
confidence.setContext(Map.of("country", ConfidenceValue.of("SE")));
final String propertyValue =
    confidence
        .withContext(
            Map.of(
                "user_id", ConfidenceValue.of("<some-user-id>"),
                "country", ConfidenceValue.of("SE")))
        .getValue("flag-name.property-name", "defaultValue");

Tracking events

Events are emitted to the Confidence backend:

confidence.track("my-event", ConfidenceValue.of(Map.of("field", ConfidenceValue.of("data"))));

OpenFeature

The library includes a Provider for the OpenFeature Java SDK, that can be used to resolve feature flag values from the Confidence platform.

The constructor for creating an OpenFeature ConfidenceProvider takes a Confidence instance as a parameter. We kindly ask you to use the Confidence.Builder.buildForProvider() function when creating a Confidence instance that will be used with OpenFeature.

To learn more about the basic concepts (flags, targeting key, evaluation contexts), the OpenFeature reference documentation can be useful.

Telemetry

In order to improve the services provided by Confidence, the SDK collects a very limited amount of telemetry data. This data is sent in the form of an additional gRPC header with each resolve request. The data does not contain any information that can be used to link the data to a specific end user.

Please refer to the Telemetry class to understand the data that is collected.

To opt out of this behavior, you can disable telemetry by setting the disableTelemetry flag to true when building the Confidence instance.

final Confidence confidence = Confidence.Builder("<CLIENT_SECRET>")
        .disableTelemetry(true)
        .build();

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages