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

feat: Expose set sdk metadata #166

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ object ConfidenceFactory {
fun create(
context: Context,
clientSecret: String,
sdk: SdkMetadata = SdkMetadata(SDK_ID, BuildConfig.SDK_VERSION),
initialContext: Map<String, ConfidenceValue> = mapOf(),
region: ConfidenceRegion = ConfidenceRegion.GLOBAL,
dispatcher: CoroutineDispatcher = Dispatchers.IO
Expand All @@ -243,12 +244,12 @@ object ConfidenceFactory {
context,
clientSecret,
flushPolicies = listOf(minBatchSizeFlushPolicy),
sdkMetadata = SdkMetadata(SDK_ID, BuildConfig.SDK_VERSION),
sdkMetadata = sdk,
dispatcher = dispatcher
)
val flagApplierClient = FlagApplierClientImpl(
clientSecret,
SdkMetadata(SDK_ID, BuildConfig.SDK_VERSION),
sdk,
region,
dispatcher
)
Expand All @@ -258,7 +259,7 @@ object ConfidenceFactory {
region = region,
httpClient = OkHttpClient(),
dispatcher = dispatcher,
sdkMetadata = SdkMetadata(SDK_ID, BuildConfig.SDK_VERSION)
sdkMetadata = sdk
)
val visitorId = ConfidenceValue.String(VisitorUtil.getId(context))
val initContext = initialContext.toMutableMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ConfidenceIntegrationTests {
map["user"] =
ConfidenceValue.Struct(mapOf("country" to ConfidenceValue.String("SE")))

val oldConfidence = ConfidenceFactory.create(mockContext, clientSecret, map)
val oldConfidence = ConfidenceFactory.create(mockContext, clientSecret, initialContext = map)
val context = oldConfidence.getContext()

val storage = FileDiskStorage.create(mockContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MainVm(app: Application) : AndroidViewModel(app) {
app.applicationContext,
clientSecret,
initialContext = mapOf("targeting_key" to ConfidenceValue.String("a98a4291-53b0-49d9-bae8-73d3f5da2070")),
ConfidenceRegion.EUROPE
region = ConfidenceRegion.EUROPE
)
confidence.track(AndroidLifecycleEventProducer(getApplication(), false))
eventSender = confidence.withContext(mutableMap)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@

package com.spotify.confidence.openfeature

import android.content.Context
import com.spotify.confidence.BuildConfig
import com.spotify.confidence.Confidence
import com.spotify.confidence.ConfidenceError.ErrorCode
import com.spotify.confidence.ConfidenceError.FlagNotFoundError
import com.spotify.confidence.ConfidenceError.ParseError
import com.spotify.confidence.ConfidenceFactory
import com.spotify.confidence.ConfidenceRegion
import com.spotify.confidence.ConfidenceValue
import com.spotify.confidence.Evaluation
import com.spotify.confidence.ResolveReason
import com.spotify.confidence.client.SdkMetadata
import dev.openfeature.sdk.EvaluationContext
import dev.openfeature.sdk.FeatureProvider
import dev.openfeature.sdk.Hook
Expand Down Expand Up @@ -143,6 +148,23 @@ class ConfidenceFeatureProvider private constructor(
companion object {
private class ConfidenceMetadata(override var name: String? = "confidence") : ProviderMetadata

fun createConfidence(
context: Context,
clientSecret: String,
initialContext: Map<String, ConfidenceValue> = mapOf(),
region: ConfidenceRegion = ConfidenceRegion.GLOBAL,
dispatcher: CoroutineDispatcher = Dispatchers.IO
): Confidence {
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if we could introduce a new interface ConfidenceForOpenFeature or something, and make the create function below accept that, as a way to force users to use this createConfidence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in this case ConfidenceForOpenFeature should inherit both from event sender and from Contextual

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and all other functions are from confidence object itself, we don't have a confidence interface currently.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps worth exploring, but I am also not strongly convinced these extra interfaces will actually help the user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you agree taking this in another PR and moving forward with this PR?

return ConfidenceFactory.create(
context,
clientSecret,
sdk = SdkMetadata("SDK_ID_KOTLIN_PROVIDER", BuildConfig.SDK_VERSION),
initialContext = initialContext,
region = region,
dispatcher = dispatcher
)
}

@Suppress("LongParameterList")
fun create(
confidence: Confidence,
Expand Down
Loading