client

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package client has client definitions

Package client has client facing factories

Package client //

Package client //

Index

Constants

View Source
const (
	// DefaultTracerName is the name of the tracer used by the Optimizely SDK
	DefaultTracerName = "OptimizelySDK"
	// SpanNameDecide is the name of the span used by the Optimizely SDK for tracing decide call
	SpanNameDecide = "decide"
	// SpanNameDecideForKeys is the name of the span used by the Optimizely SDK for tracing decideForKeys call
	SpanNameDecideForKeys = "decideForKeys"
	// SpanNameDecideAll is the name of the span used by the Optimizely SDK for tracing decideAll call
	SpanNameDecideAll = "decideAll"
	// SpanNameActivate is the name of the span used by the Optimizely SDK for tracing Activate call
	SpanNameActivate = "Activate"
	// SpanNameFetchQualifiedSegments is the name of the span used by the Optimizely SDK for tracing fetchQualifiedSegments call
	SpanNameFetchQualifiedSegments = "fetchQualifiedSegments"
	// SpanNameSendOdpEvent is the name of the span used by the Optimizely SDK for tracing SendOdpEvent call
	SpanNameSendOdpEvent = "SendOdpEvent"
	// SpanNameIsFeatureEnabled is the name of the span used by the Optimizely SDK for tracing IsFeatureEnabled call
	SpanNameIsFeatureEnabled = "IsFeatureEnabled"
	// SpanNameGetEnabledFeatures is the name of the span used by the Optimizely SDK for tracing GetEnabledFeatures call
	SpanNameGetEnabledFeatures = "GetEnabledFeatures"
	// SpanNameGetFeatureVariableBoolean is the name of the span used by the Optimizely SDK for tracing GetFeatureVariableBoolean call
	SpanNameGetFeatureVariableBoolean = "GetFeatureVariableBoolean"
	// SpanNameGetFeatureVariableDouble is the name of the span used by the Optimizely SDK for tracing GetFeatureVariableDouble call
	SpanNameGetFeatureVariableDouble = "GetFeatureVariableDouble"
	// SpanNameGetFeatureVariableInteger is the name of the span used by the Optimizely SDK for tracing GetFeatureVariableInteger call
	SpanNameGetFeatureVariableInteger = "GetFeatureVariableInteger"
	// SpanNameGetFeatureVariableString is the name of the span used by the Optimizely SDK for tracing GetFeatureVariableString call
	SpanNameGetFeatureVariableString = "GetFeatureVariableString"
	// SpanNameGetFeatureVariableJSON is the name of the span used by the Optimizely SDK for tracing GetFeatureVariableJSON call
	SpanNameGetFeatureVariableJSON = "GetFeatureVariableJSON"
	// SpanNameGetFeatureVariablePrivate is the name of the span used by the Optimizely SDK for tracing getFeatureVariable call
	SpanNameGetFeatureVariablePrivate = "getFeatureVariable"
	// SpanNameGetFeatureVariablePublic is the name of the span used by the Optimizely SDK for tracing GetFeatureVariable call
	SpanNameGetFeatureVariablePublic = "GetFeatureVariable"
	// SpanNameGetAllFeatureVariablesWithDecision is the name of the span used by the Optimizely SDK for tracing GetAllFeatureVariablesWithDecision call
	SpanNameGetAllFeatureVariablesWithDecision = "GetAllFeatureVariablesWithDecision"
	// SpanNameGetDetailedFeatureDecisionUnsafe is the name of the span used by the Optimizely SDK for tracing GetDetailedFeatureDecisionUnsafe call
	SpanNameGetDetailedFeatureDecisionUnsafe = "GetDetailedFeatureDecisionUnsafe"
	// SpanNameGetAllFeatureVariables is the name of the span used by the Optimizely SDK for tracing GetAllFeatureVariables call
	SpanNameGetAllFeatureVariables = "GetAllFeatureVariables"
	// SpanNameGetVariation is the name of the span used by the Optimizely SDK for tracing GetVariation call
	SpanNameGetVariation = "GetVariation"
	// SpanNameTrack is the name of the span used by the Optimizely SDK for tracing Track call
	SpanNameTrack = "Track"
	// SpanNameGetFeatureDecision is the name of the span used by the Optimizely SDK for tracing getFeatureDecision call
	SpanNameGetFeatureDecision = "getFeatureDecision"
	// SpanNameGetExperimentDecision is the name of the span used by the Optimizely SDK for tracing getExperimentDecision call
	SpanNameGetExperimentDecision = "getExperimentDecision"
	// SpanNameGetProjectConfig is the name of the span used by the Optimizely SDK for tracing getProjectConfig call
	SpanNameGetProjectConfig = "getProjectConfig"
	// SpanNameGetOptimizelyConfig is the name of the span used by the Optimizely SDK for tracing GetOptimizelyConfig call
	SpanNameGetOptimizelyConfig = "GetOptimizelyConfig"
	// SpanNameGetDecisionVariableMap is the name of the span used by the Optimizely SDK for tracing getDecisionVariableMap call
	SpanNameGetDecisionVariableMap = "getDecisionVariableMap"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type OptimizelyClient

type OptimizelyClient struct {
	ConfigManager   config.ProjectConfigManager
	DecisionService decision.Service
	EventProcessor  event.Processor
	OdpManager      odp.Manager
	// contains filtered or unexported fields
}

OptimizelyClient is the entry point to the Optimizely SDK

func (*OptimizelyClient) Activate

func (o *OptimizelyClient) Activate(experimentKey string, userContext entities.UserContext) (result string, err error)

Activate returns the key of the variation the user is bucketed into and queues up an impression event to be sent to the Optimizely log endpoint for results processing.

func (*OptimizelyClient) Close

func (o *OptimizelyClient) Close()

Close closes the Optimizely instance and stops any ongoing tasks from its children components.

func (*OptimizelyClient) CreateUserContext

func (o *OptimizelyClient) CreateUserContext(userID string, attributes map[string]interface{}) OptimizelyUserContext

CreateUserContext creates a context of the user for which decision APIs will be called. A user context will be created successfully even when the SDK is not fully configured yet.

func (*OptimizelyClient) GetAllFeatureVariables

func (o *OptimizelyClient) GetAllFeatureVariables(featureKey string, userContext entities.UserContext) (optlyJSON *optimizelyjson.OptimizelyJSON, err error)

GetAllFeatureVariables returns all the variables as OptimizelyJSON object for a given feature.

func (*OptimizelyClient) GetAllFeatureVariablesWithDecision

func (o *OptimizelyClient) GetAllFeatureVariablesWithDecision(featureKey string, userContext entities.UserContext) (enabled bool, variableMap map[string]interface{}, err error)

GetAllFeatureVariablesWithDecision returns all the variables for a given feature along with the enabled state.

func (*OptimizelyClient) GetDetailedFeatureDecisionUnsafe

func (o *OptimizelyClient) GetDetailedFeatureDecisionUnsafe(featureKey string, userContext entities.UserContext, disableTracking bool) (decisionInfo decision.UnsafeFeatureDecisionInfo, err error)

GetDetailedFeatureDecisionUnsafe triggers an impression event and returns all the variables for a given feature along with the experiment key, variation key and the enabled state. Usage of this method is unsafe and not recommended since it can be removed in any of the next releases.

func (*OptimizelyClient) GetEnabledFeatures

func (o *OptimizelyClient) GetEnabledFeatures(userContext entities.UserContext) (enabledFeatures []string, err error)

GetEnabledFeatures returns an array containing the keys of all features in the project that are enabled for the given user. For features tests, impression events will be queued up to be sent to the Optimizely log endpoint for results processing.

func (*OptimizelyClient) GetFeatureVariable

func (o *OptimizelyClient) GetFeatureVariable(featureKey, variableKey string, userContext entities.UserContext) (string, entities.VariableType, error)

GetFeatureVariable returns feature variable as a string along with it's associated type.

func (*OptimizelyClient) GetFeatureVariableBoolean

func (o *OptimizelyClient) GetFeatureVariableBoolean(featureKey, variableKey string, userContext entities.UserContext) (convertedValue bool, err error)

GetFeatureVariableBoolean returns the feature variable value of type bool associated with the given feature and variable keys.

func (*OptimizelyClient) GetFeatureVariableDouble

func (o *OptimizelyClient) GetFeatureVariableDouble(featureKey, variableKey string, userContext entities.UserContext) (convertedValue float64, err error)

GetFeatureVariableDouble returns the feature variable value of type double associated with the given feature and variable keys.

func (*OptimizelyClient) GetFeatureVariableInteger

func (o *OptimizelyClient) GetFeatureVariableInteger(featureKey, variableKey string, userContext entities.UserContext) (convertedValue int, err error)

GetFeatureVariableInteger returns the feature variable value of type int associated with the given feature and variable keys.

func (*OptimizelyClient) GetFeatureVariableJSON

func (o *OptimizelyClient) GetFeatureVariableJSON(featureKey, variableKey string, userContext entities.UserContext) (optlyJSON *optimizelyjson.OptimizelyJSON, err error)

GetFeatureVariableJSON returns the feature variable value of type json associated with the given feature and variable keys.

func (*OptimizelyClient) GetFeatureVariableString

func (o *OptimizelyClient) GetFeatureVariableString(featureKey, variableKey string, userContext entities.UserContext) (stringValue string, err error)

GetFeatureVariableString returns the feature variable value of type string associated with the given feature and variable keys.

func (*OptimizelyClient) GetNotificationCenter

func (o *OptimizelyClient) GetNotificationCenter() notification.Center

GetNotificationCenter returns Optimizely Notification Center interface

func (*OptimizelyClient) GetOptimizelyConfig

func (o *OptimizelyClient) GetOptimizelyConfig() (optimizelyConfig *config.OptimizelyConfig)

GetOptimizelyConfig returns OptimizelyConfig object

func (*OptimizelyClient) GetVariation

func (o *OptimizelyClient) GetVariation(experimentKey string, userContext entities.UserContext) (result string, err error)

GetVariation returns the key of the variation the user is bucketed into. Does not generate impression events.

func (*OptimizelyClient) IsFeatureEnabled

func (o *OptimizelyClient) IsFeatureEnabled(featureKey string, userContext entities.UserContext) (result bool, err error)

IsFeatureEnabled returns true if the feature is enabled for the given user. If the user is part of a feature test then an impression event will be queued up to be sent to the Optimizely log endpoint for results processing.

func (*OptimizelyClient) OnTrack

func (o *OptimizelyClient) OnTrack(callback func(eventKey string, userContext entities.UserContext, eventTags map[string]interface{}, conversionEvent event.ConversionEvent)) (int, error)

OnTrack registers a handler for Track notifications

func (*OptimizelyClient) RemoveOnTrack

func (o *OptimizelyClient) RemoveOnTrack(id int) error

RemoveOnTrack removes handler for Track notification with given id

func (*OptimizelyClient) SendOdpEvent

func (o *OptimizelyClient) SendOdpEvent(eventType, action string, identifiers map[string]string, data map[string]interface{}) (err error)

SendOdpEvent sends an event to the ODP server.

func (*OptimizelyClient) Track

func (o *OptimizelyClient) Track(eventKey string, userContext entities.UserContext, eventTags map[string]interface{}) (err error)

Track generates a conversion event with the given event key if it exists and queues it up to be sent to the Optimizely log endpoint for results processing.

func (*OptimizelyClient) WithTraceContext

func (o *OptimizelyClient) WithTraceContext(ctx context.Context) *OptimizelyClient

WithTraceContext sets the context for the OptimizelyClient which can be used to propagate trace information

type OptimizelyDecision

type OptimizelyDecision struct {
	VariationKey string                         `json:"variationKey"`
	Enabled      bool                           `json:"enabled"`
	Variables    *optimizelyjson.OptimizelyJSON `json:"-"`
	RuleKey      string                         `json:"ruleKey"`
	FlagKey      string                         `json:"flagKey"`
	UserContext  OptimizelyUserContext          `json:"userContext"`
	Reasons      []string                       `json:"reasons"`
}

OptimizelyDecision defines the decision returned by decide api.

func NewErrorDecision

func NewErrorDecision(key string, user OptimizelyUserContext, err error) OptimizelyDecision

NewErrorDecision returns a decision with error

func NewOptimizelyDecision

func NewOptimizelyDecision(variationKey, ruleKey, flagKey string, enabled bool, variables *optimizelyjson.OptimizelyJSON, userContext OptimizelyUserContext, reasons []string) OptimizelyDecision

NewOptimizelyDecision creates and returns a new instance of OptimizelyDecision

type OptimizelyFactory

type OptimizelyFactory struct {
	SDKKey              string
	Datafile            []byte
	DatafileAccessToken string
	// contains filtered or unexported fields
}

OptimizelyFactory is used to customize and construct an instance of the OptimizelyClient.

func (*OptimizelyFactory) Client

func (f *OptimizelyFactory) Client(clientOptions ...OptionFunc) (*OptimizelyClient, error)

Client instantiates a new OptimizelyClient with the given options.

func (*OptimizelyFactory) StaticClient

func (f *OptimizelyFactory) StaticClient() (optlyClient *OptimizelyClient, err error)

StaticClient returns a client initialized with a static project config.

type OptimizelyUserContext

type OptimizelyUserContext struct {
	UserID     string                 `json:"userId"`
	Attributes map[string]interface{} `json:"attributes"`
	// contains filtered or unexported fields
}

OptimizelyUserContext defines user contexts that the SDK will use to make decisions for.

func (*OptimizelyUserContext) Decide

Decide returns a decision result for a given flag key and a user context, which contains all data required to deliver the flag or experiment.

func (*OptimizelyUserContext) DecideAll

DecideAll returns a key-map of decision results for all active flag keys with options.

func (*OptimizelyUserContext) DecideForKeys

func (o *OptimizelyUserContext) DecideForKeys(keys []string, options []decide.OptimizelyDecideOptions) map[string]OptimizelyDecision

DecideForKeys returns a key-map of decision results for multiple flag keys and options.

func (*OptimizelyUserContext) FetchQualifiedSegments

func (o *OptimizelyUserContext) FetchQualifiedSegments(options []pkgOdpSegment.OptimizelySegmentOption) (success bool)

FetchQualifiedSegments fetches all qualified segments for the user context.

func (*OptimizelyUserContext) FetchQualifiedSegmentsAsync

func (o *OptimizelyUserContext) FetchQualifiedSegmentsAsync(options []pkgOdpSegment.OptimizelySegmentOption, callback func(success bool))

FetchQualifiedSegmentsAsync fetches all qualified segments aysnchronously for the user context.

func (*OptimizelyUserContext) GetForcedDecision

GetForcedDecision returns the forced decision for a given flag and an optional rule

func (OptimizelyUserContext) GetOptimizely

func (o OptimizelyUserContext) GetOptimizely() *OptimizelyClient

GetOptimizely returns optimizely client instance for Optimizely user context

func (*OptimizelyUserContext) GetQualifiedSegments

func (o *OptimizelyUserContext) GetQualifiedSegments() []string

GetQualifiedSegments returns qualified segments for Optimizely user context

func (OptimizelyUserContext) GetUserAttributes

func (o OptimizelyUserContext) GetUserAttributes() map[string]interface{}

GetUserAttributes returns user attributes for Optimizely user context

func (OptimizelyUserContext) GetUserID

func (o OptimizelyUserContext) GetUserID() string

GetUserID returns userID for Optimizely user context

func (*OptimizelyUserContext) IsQualifiedFor

func (o *OptimizelyUserContext) IsQualifiedFor(segment string) bool

IsQualifiedFor returns true if the user is qualified for the given segment name

func (*OptimizelyUserContext) RemoveAllForcedDecisions

func (o *OptimizelyUserContext) RemoveAllForcedDecisions() bool

RemoveAllForcedDecisions removes all forced decisions bound to this user context.

func (*OptimizelyUserContext) RemoveForcedDecision

func (o *OptimizelyUserContext) RemoveForcedDecision(ctx pkgDecision.OptimizelyDecisionContext) bool

RemoveForcedDecision removes the forced decision for a given flag and an optional rule.

func (*OptimizelyUserContext) SetAttribute

func (o *OptimizelyUserContext) SetAttribute(key string, value interface{})

SetAttribute sets an attribute for a given key.

func (*OptimizelyUserContext) SetForcedDecision

SetForcedDecision sets the forced decision (variation key) for a given decision context (flag key and optional rule key). returns true if the forced decision has been set successfully.

func (*OptimizelyUserContext) SetQualifiedSegments

func (o *OptimizelyUserContext) SetQualifiedSegments(qualifiedSegments []string)

SetQualifiedSegments clears and adds qualified segments for Optimizely user context

func (*OptimizelyUserContext) TrackEvent

func (o *OptimizelyUserContext) TrackEvent(eventKey string, eventTags map[string]interface{}) (err error)

TrackEvent generates a conversion event with the given event key if it exists and queues it up to be sent to the Optimizely log endpoint for results processing.

type OptionFunc

type OptionFunc func(*OptimizelyFactory)

OptionFunc is used to provide custom client configuration to the OptimizelyFactory.

func WithBatchEventProcessor

func WithBatchEventProcessor(batchSize, queueSize int, flushInterval time.Duration) OptionFunc

WithBatchEventProcessor sets event processor on a client.

func WithConfigManager

func WithConfigManager(configManager config.ProjectConfigManager) OptionFunc

WithConfigManager sets polling config manager on a client.

func WithContext

func WithContext(ctx context.Context) OptionFunc

WithContext allows user to pass in their own context to override the default one in the client.

func WithDatafileAccessToken

func WithDatafileAccessToken(datafileAccessToken string) OptionFunc

WithDatafileAccessToken sets authenticated datafile token

func WithDecisionService

func WithDecisionService(decisionService decision.Service) OptionFunc

WithDecisionService sets decision service on a client.

func WithDefaultDecideOptions

func WithDefaultDecideOptions(decideOptions []decide.OptimizelyDecideOptions) OptionFunc

WithDefaultDecideOptions sets default decide options on a client.

func WithEventDispatcher

func WithEventDispatcher(eventDispatcher event.Dispatcher) OptionFunc

WithEventDispatcher sets event dispatcher on the factory.

func WithEventProcessor

func WithEventProcessor(eventProcessor event.Processor) OptionFunc

WithEventProcessor sets event processor on a client

func WithExperimentOverrides

func WithExperimentOverrides(overrideStore decision.ExperimentOverrideStore) OptionFunc

WithExperimentOverrides sets the experiment override store on the decision service.

func WithMetricsRegistry

func WithMetricsRegistry(metricsRegistry metrics.Registry) OptionFunc

WithMetricsRegistry allows user to pass in their own implementation of a metrics collector

func WithNotificationCenter

func WithNotificationCenter(nc notification.Center) OptionFunc

WithNotificationCenter allows user to pass in their own implementation of the notification.Center interface

func WithOdpDisabled

func WithOdpDisabled(disable bool) OptionFunc

WithOdpDisabled disables odp for the client. Default value is false

func WithOdpManager

func WithOdpManager(odpManager odp.Manager) OptionFunc

WithOdpManager sets odp manager on a client.

func WithPollingConfigManager

func WithPollingConfigManager(pollingInterval time.Duration, initDataFile []byte) OptionFunc

WithPollingConfigManager sets polling config manager on a client.

func WithPollingConfigManagerDatafileAccessToken

func WithPollingConfigManagerDatafileAccessToken(pollingInterval time.Duration, initDataFile []byte, datafileAccessToken string) OptionFunc

WithPollingConfigManagerDatafileAccessToken sets polling config manager with auth datafile token on a client

func WithSegmentsCacheSize

func WithSegmentsCacheSize(segmentsCacheSize int) OptionFunc

WithSegmentsCacheSize sets SegmentsCacheSize for odp manager. Default value is 10000

func WithSegmentsCacheTimeout

func WithSegmentsCacheTimeout(segmentsCacheTimeout time.Duration) OptionFunc

WithSegmentsCacheTimeout sets SegmentsCacheTimeoutInSecs for odp manager. Default value is 600s

func WithTracer

func WithTracer(tracer tracing.Tracer) OptionFunc

WithTracer allows user to pass in their own implementation of the Tracer interface

func WithUserProfileService

func WithUserProfileService(userProfileService decision.UserProfileService) OptionFunc

WithUserProfileService sets the user profile service on the decision service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL