diff --git a/openfeature-provider/src/test/java/com/spotify/confidence/ConfidenceFeatureProviderTest.java b/openfeature-provider/src/test/java/com/spotify/confidence/ConfidenceFeatureProviderTest.java index 0b3a959..26a12ba 100644 --- a/openfeature-provider/src/test/java/com/spotify/confidence/ConfidenceFeatureProviderTest.java +++ b/openfeature-provider/src/test/java/com/spotify/confidence/ConfidenceFeatureProviderTest.java @@ -24,7 +24,7 @@ class ConfidenceFeatureProviderTest { public void setup() { fakeEngine = new FakeEventSenderEngine(new FakeClock()); fakeFlagResolverClient = new ResolverClientTestUtils.FakeFlagResolverClient(); - root = Confidence.create(fakeEngine, fakeFlagResolverClient); + root = Confidence.create(fakeEngine, fakeFlagResolverClient, "clientKey"); } @Test diff --git a/openfeature-provider/src/test/java/com/spotify/confidence/FeatureProviderTest.java b/openfeature-provider/src/test/java/com/spotify/confidence/FeatureProviderTest.java index d5fafcd..3fb846d 100644 --- a/openfeature-provider/src/test/java/com/spotify/confidence/FeatureProviderTest.java +++ b/openfeature-provider/src/test/java/com/spotify/confidence/FeatureProviderTest.java @@ -77,7 +77,7 @@ void beforeEach() { final FlagResolverClientImpl flagResolver = new FlagResolverClientImpl( new GrpcFlagResolver("fake-secret", channel, telemetryInterceptor), telemetry); - final Confidence confidence = Confidence.create(fakeEventSender, flagResolver); + final Confidence confidence = Confidence.create(fakeEventSender, flagResolver, "clientKey"); final FeatureProvider featureProvider = new ConfidenceFeatureProvider(confidence); openFeatureAPI = OpenFeatureAPI.getInstance(); diff --git a/openfeature-provider/src/test/java/com/spotify/confidence/FlagResolverContextTest.java b/openfeature-provider/src/test/java/com/spotify/confidence/FlagResolverContextTest.java index 5cf2267..277bff4 100644 --- a/openfeature-provider/src/test/java/com/spotify/confidence/FlagResolverContextTest.java +++ b/openfeature-provider/src/test/java/com/spotify/confidence/FlagResolverContextTest.java @@ -20,7 +20,7 @@ void beforeEach() { final FakeEventSenderEngine fakeEventSender = new FakeEventSenderEngine(new FakeClock()); this.fakeFlagResolver = new FakeFlagResolver(); final FlagResolverClientImpl flagResolver = new FlagResolverClientImpl(fakeFlagResolver); - this.confidence = Confidence.create(fakeEventSender, flagResolver); + this.confidence = Confidence.create(fakeEventSender, flagResolver, "clientKey"); final FeatureProvider featureProvider = new ConfidenceFeatureProvider(confidence); final OpenFeatureAPI openFeatureAPI = OpenFeatureAPI.getInstance(); diff --git a/sdk-java/src/main/java/com/spotify/confidence/Confidence.java b/sdk-java/src/main/java/com/spotify/confidence/Confidence.java index 1533a53..bb88de7 100644 --- a/sdk-java/src/main/java/com/spotify/confidence/Confidence.java +++ b/sdk-java/src/main/java/com/spotify/confidence/Confidence.java @@ -21,6 +21,8 @@ import io.grpc.StatusRuntimeException; import java.io.Closeable; import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Instant; import java.util.Map; @@ -131,6 +133,15 @@ public FlagEvaluation getEvaluation(String key, T defaultValue) { } final ResolvedFlag resolvedFlag = response.getResolvedFlags(0); + final String clientKey = client().clientSecret; + final String flag = resolvedFlag.getFlag(); + final String context = URLEncoder.encode(getContext().toString(), StandardCharsets.UTF_8); + final String logMessage = + String.format( + "See resolves for '%s' in Confidence: " + + "https://app.confidence.spotify.com/flags/resolver-test?client-key=%s&flag=flags/%s&context=%s", + flag, clientKey, flag, context); + log.debug(logMessage); if (!requestFlagName.equals(resolvedFlag.getFlag())) { final String errorMessage = String.format( @@ -192,11 +203,14 @@ CompletableFuture resolveFlags(String flagName) { @VisibleForTesting static Confidence create( - EventSenderEngine eventSenderEngine, FlagResolverClient flagResolverClient) { + EventSenderEngine eventSenderEngine, + FlagResolverClient flagResolverClient, + String clientSecret) { final Closer closer = Closer.create(); closer.register(eventSenderEngine); closer.register(flagResolverClient); - return new RootInstance(new ClientDelegate(closer, flagResolverClient, eventSenderEngine)); + return new RootInstance( + new ClientDelegate(closer, flagResolverClient, eventSenderEngine, clientSecret)); } public static Confidence.Builder builder(String clientSecret) { @@ -207,14 +221,17 @@ private static class ClientDelegate implements FlagResolverClient, EventSenderEn private final Closeable closeable; private final FlagResolverClient flagResolverClient; private final EventSenderEngine eventSenderEngine; + private String clientSecret; private ClientDelegate( Closeable closeable, FlagResolverClient flagResolverClient, - EventSenderEngine eventSenderEngine) { + EventSenderEngine eventSenderEngine, + String clientSecret) { this.closeable = closeable; this.flagResolverClient = flagResolverClient; this.eventSenderEngine = eventSenderEngine; + this.clientSecret = clientSecret; } @Override @@ -355,7 +372,8 @@ public Confidence build() { new EventSenderEngineImpl(clientSecret, DEFAULT_CHANNEL, Instant::now); closer.register(flagResolverClient); closer.register(eventSenderEngine); - return new RootInstance(new ClientDelegate(closer, flagResolverClient, eventSenderEngine)); + return new RootInstance( + new ClientDelegate(closer, flagResolverClient, eventSenderEngine, clientSecret)); } private void registerChannelForShutdown(ManagedChannel channel) { diff --git a/sdk-java/src/test/java/com/spotify/confidence/ConfidenceContextTest.java b/sdk-java/src/test/java/com/spotify/confidence/ConfidenceContextTest.java index e36447b..af94f6f 100644 --- a/sdk-java/src/test/java/com/spotify/confidence/ConfidenceContextTest.java +++ b/sdk-java/src/test/java/com/spotify/confidence/ConfidenceContextTest.java @@ -15,7 +15,7 @@ public class ConfidenceContextTest { @Test public void testThrowInvalidContextInMessage() { - final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient); + final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient, "clientKey"); assertThrows( Exceptions.InvalidContextInMessaageError.class, () -> @@ -24,7 +24,7 @@ public void testThrowInvalidContextInMessage() { @Test public void getContextContainsParentContextValues() { - final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient); + final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient, "clientKey"); root.updateContextEntry("page", ConfidenceValue.of("http://..")); final EventSender confidence = root.withContext(ImmutableMap.of("pants", ConfidenceValue.of("yellow"))); @@ -41,7 +41,7 @@ public void getContextContainsParentContextValues() { @Test public void setContextOverwritesContext() { - final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient); + final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient, "clientKey"); root.updateContextEntry("page", ConfidenceValue.of("http://..")); final EventSender confidence = root.withContext(ImmutableMap.of("pants", ConfidenceValue.of("yellow"))); @@ -65,7 +65,7 @@ public void setContextOverwritesContext() { @Test public void parentContextFieldCanBeOverridden() { - final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient); + final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient, "clientKey"); root.updateContextEntry("pants-color", ConfidenceValue.of("yellow")); final EventSender confidence = root.withContext(ImmutableMap.of("pants-color", ConfidenceValue.of("blue"))); @@ -83,7 +83,7 @@ public void parentContextFieldCanBeOverridden() { @Test public void parentContextFieldCanBeOverriddenOrRemoved() { - final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient); + final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient, "clientKey"); root.updateContextEntry("pants-color", ConfidenceValue.of("yellow")); final EventSender confidence = root.withContext(ImmutableMap.of("shirt-color", ConfidenceValue.of("blue"))); @@ -98,7 +98,7 @@ public void parentContextFieldCanBeOverriddenOrRemoved() { @Test public void multiLevelContexts() { - final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient); + final Confidence root = Confidence.create(fakeEngine, fakeFlagResolverClient, "clientKey"); final int numberOfLevels = 9; Confidence last = root; for (int i = 0; i < numberOfLevels; i++) { diff --git a/sdk-java/src/test/java/com/spotify/confidence/ConfidenceIntegrationTest.java b/sdk-java/src/test/java/com/spotify/confidence/ConfidenceIntegrationTest.java index 6324073..70e8867 100644 --- a/sdk-java/src/test/java/com/spotify/confidence/ConfidenceIntegrationTest.java +++ b/sdk-java/src/test/java/com/spotify/confidence/ConfidenceIntegrationTest.java @@ -79,7 +79,7 @@ void beforeEach() { final FlagResolverClientImpl flagResolver = new FlagResolverClientImpl( new GrpcFlagResolver("fake-secret", channel, telemetryInterceptor), telemetry); - confidence = Confidence.create(fakeEventSender, flagResolver); + confidence = Confidence.create(fakeEventSender, flagResolver, ""); } @AfterAll @@ -478,7 +478,7 @@ public void resolveDoesNotContainHeaderWithTelemetryDataWhenDisabled() { final FlagResolverClientImpl flagResolver = new FlagResolverClientImpl( new GrpcFlagResolver("fake-secret", channel, nullTelemetryInterceptor)); - confidence = Confidence.create(fakeEventSender, flagResolver); + confidence = Confidence.create(fakeEventSender, flagResolver, "clientKey"); mockSampleResponse(); diff --git a/sdk-java/src/test/java/com/spotify/confidence/ConfidenceResourceManagementTest.java b/sdk-java/src/test/java/com/spotify/confidence/ConfidenceResourceManagementTest.java index b55c1fb..618eea5 100644 --- a/sdk-java/src/test/java/com/spotify/confidence/ConfidenceResourceManagementTest.java +++ b/sdk-java/src/test/java/com/spotify/confidence/ConfidenceResourceManagementTest.java @@ -18,7 +18,7 @@ public class ConfidenceResourceManagementTest { public void setup() { fakeEngine = new FakeEventSenderEngine(new FakeClock()); fakeFlagResolverClient = new ResolverClientTestUtils.FakeFlagResolverClient(); - root = Confidence.create(fakeEngine, fakeFlagResolverClient); + root = Confidence.create(fakeEngine, fakeFlagResolverClient, "clientKey"); } @Test diff --git a/sdk-java/src/test/java/com/spotify/confidence/ConfidenceTest.java b/sdk-java/src/test/java/com/spotify/confidence/ConfidenceTest.java index cb1245f..608c630 100644 --- a/sdk-java/src/test/java/com/spotify/confidence/ConfidenceTest.java +++ b/sdk-java/src/test/java/com/spotify/confidence/ConfidenceTest.java @@ -26,7 +26,7 @@ final class ConfidenceTest { @BeforeEach void beforeEach() { - confidence = Confidence.create(fakeEngine, fakeFlagResolverClient); + confidence = Confidence.create(fakeEngine, fakeFlagResolverClient, "clientKey"); } @Test @@ -244,7 +244,8 @@ void flagWithErroneousSchema() { @Test void internalError() { - final Confidence confidence = Confidence.create(fakeEngine, new FailingFlagResolverClient()); + final Confidence confidence = + Confidence.create(fakeEngine, new FailingFlagResolverClient(), "clientKey"); final Integer value = confidence.getValue("no-match-flag", 20); assertEquals(20, value);