GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - spotify/confidence-sdk-java

BranchesTags
Open more actions menu

Latest commit

 

History

260 Commits
260 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
confidence-proto
confidence-proto
 
 
openfeature-provider-shared
openfeature-provider-shared
 
 
openfeature-provider
openfeature-provider
 
 
sdk-java
sdk-java
 
 
.gitignore
.gitignore
 
 
.release-please-manifest.json
.release-please-manifest.json
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
OWNERS.md
OWNERS.md
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
catalog-info.yaml
catalog-info.yaml
 
 
checkstyle.xml
checkstyle.xml
 
 
pom.xml
pom.xml
 
 
release-please-config.json
release-please-config.json
 
 
version.properties
version.properties
 
 

Repository files navigation

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.

💡 Looking for better performance? Check out the Confidence Local Resolver Provider for Java, which evaluates flags locally via WebAssembly for increased resilience and lower latency.

We suggest you to use the OpenFeature SDK to consume the Confidence feature flags.

Install

OpenFeature provider (Maven)

Add the OpenFeature provider dependency if you want to use Confidence via the OpenFeature Java SDK:

<dependency>
    <groupId>com.spotify.confidence</groupId>
    <artifactId>openfeature-provider</artifactId>
    <version>0.6.1-SNAPSHOT</version>
</dependency>

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

Usage

OpenFeature providers connect the OpenFeature SDK to your flag system. Use the Confidence OpenFeature provider to evaluate flags with the Confidence platform.

Quickstart: OpenFeature provider (Java)

Tip

For better resilience and lower latency, see the Confidence Local Resolver Provider which resolves flags locally without per-evaluation network calls.

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

import com.spotify.confidence.Confidence;
import com.spotify.confidence.ConfidenceFeatureProvider;
import dev.openfeature.sdk.Client;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.OpenFeatureAPI;

// 1) Configure and register the provider
ConfidenceFeatureProvider provider = new ConfidenceFeatureProvider(
    Confidence.builder("<CLIENT_SECRET>")
);
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProvider(provider);

// 2) Get an OpenFeature client
Client client = api.getClient();

// 3) Provide an evaluation context (targeting key + attributes)
Map<String, Value> requestAttrs = new HashMap<>();
requestAttrs.put("email", new Value(session.getAttribute("email")));
requestAttrs.put("product", new Value("productId"));
String targetingKey = session.getId();
EvaluationContext reqCtx = new ImmutableContext(targetingKey, requestAttrs);

// 4) Evaluate flags
boolean enabled = client.getBooleanValue("my-flag.enabled", false, reqCtx);
String group = client.getStringValue("my-flag.group", "group1", reqCtx);

Advanced configuration (optional)

ConfidenceFeatureProvider provider = new ConfidenceFeatureProvider(
    Confidence.builder("<CLIENT_SECRET>")
        .resolveDeadlineMs(250) // timeout for flag resolution
        .flagResolverManagedChannel("localhost", 8080) // e.g., local sidecar
);

To learn more about providers and evaluation contexts, see the OpenFeature reference docs.

Direct SDK usage (optional)

Use the Confidence SDK directly if you are not using OpenFeature.

Vanilla SDK (Maven)

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

Resolving flags

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

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

Testing with ConfidenceStub

// Create a ConfidenceStub instance
ConfidenceStub stub = ConfidenceStub.createStub();

// Configure a predefined value for a flag
stub.configureValue("flag-name.property-name", "predefinedValue");

// Retrieve the value using the stub
String value = stub.getValue("flag-name.property-name", "defaultValue");
System.out.println("Retrieved value: " + value);

// Verify the call history
List<String> callHistory = stub.getCallHistory();
System.out.println("Call history: " + callHistory);

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

Readme
Apache-2.0 license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

7 stars

Watchers

9 watching

Forks

5 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.