Skip to content

Conversation

jonathannorris
Copy link
Member

@jonathannorris jonathannorris commented Jun 26, 2025

This PR

This PR adds support for the track method to the Multi-Provider and Multi-Provider-Web, allowing tracking events to be sent across multiple underlying providers with customizable behaviour through evaluation strategies.

Features Added

🎯 Core Functionality

  • Track Method: MultiProvider now implements the track method from the OpenFeature specification
  • Strategy Integration: New shouldTrackWithThisProvider method allows strategies to control which providers receive tracking calls
  • Error Resilience: Individual provider tracking failures don't break the flow - errors are logged and other providers continue

🛡️ Robust Error Handling

  • Gracefully handles providers without track method implementation
  • Logs errors but never throws - tracking failures won't break application flow
  • Respects provider status (automatically skips NOT_READY/FATAL providers)

⚙️ Customizable Behavior

  • Default: Tracks with all ready providers
  • Custom Strategies: Override shouldTrackWithThisProvider for selective tracking
  • Use Cases: Primary/backup provider scenarios, event-type filtering, etc.

Multi-Provider Usage Example

import { OpenFeature } from '@openfeature/server-sdk'
import { MultiProvider } from '@openfeature/multi-provider'

const multiProvider = new MultiProvider([
  { provider: new ProviderA() },
  { provider: new ProviderB() }
])

await OpenFeature.setProviderAndWait(multiProvider)
const client = OpenFeature.getClient()

// Tracked events will be sent to all providers by default
client.track('purchase', { targetingKey: 'user123' }, { value: 99.99, currency: 'USD' })
// Custom strategy for selective tracking
class CustomStrategy extends BaseEvaluationStrategy {
  shouldTrackWithThisProvider(strategyContext, context, eventName, details) {
    // Only track purchases with primary provider
    return eventName === 'purchase' && strategyContext.providerName === 'primary'
  }
}

Multi-Provider-Web Usage Example

import { WebMultiProvider } from '@openfeature/multi-provider-web'
import { OpenFeature } from '@openfeature/web-sdk'

const multiProvider = new WebMultiProvider([
  { provider: new ProviderA() },
  { provider: new ProviderB() }
])

await OpenFeature.setProviderAndWait(multiProvider)
const client = OpenFeature.getClient()

// Tracked events will be sent to all providers by default
client.track('user-conversion', { 
  value: 99.99, 
  currency: 'USD',
  conversionType: 'purchase' 
})

client.track('page-view', {
  page: '/checkout',
  source: 'direct'
})

@jonathannorris jonathannorris changed the title Add Track Method Support to Multi-Provider feat(multi-provider): Add Track Method Support to Multi-Provider Jun 26, 2025
Copy link

@weyert weyert left a comment

Choose a reason for hiding this comment

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

Awesome, looks good :))

…ation

Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
@jonathannorris jonathannorris force-pushed the feat-add-muli-provider-track-support branch from 3c06587 to c19428b Compare June 27, 2025 03:27
@jonathannorris jonathannorris requested a review from beeme1mr June 27, 2025 03:29
Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
@jonathannorris jonathannorris merged commit 91ba360 into open-feature:main Jul 11, 2025
7 checks passed
jonathannorris added a commit to open-feature/spec that referenced this pull request Jul 11, 2025
…#320)

## This PR

This PR updates the Multi-Provider documentation in the OpenFeature
specification to document the new `track` method support that was added
in [PR #1323](open-feature/js-sdk-contrib#1323).

### 📚 New Documentation Sections

- **Track Method Support**: Added a section explaining how the
Multi-Provider implements tracking functionality
- **Introduction Section**: Updated use case examples to highlight
tracking capabilities
- **BaseEvaluationStrategy**: Added `shouldTrackWithThisProvider` method
to the abstract class

## Code Examples Added

```typescript
// Basic tracking usage
const multiProvider = new MultiProvider([
  { provider: new ProviderA() },
  { provider: new ProviderB() }
])

await OpenFeature.setProviderAndWait(multiProvider)
const client = OpenFeature.getClient()

// Track events across all ready providers
client.track('purchase', { targetingKey: 'user123' }, { value: 99.99, currency: 'USD' })
```

---------

Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants