Skip to content

Commit 10380f3

Browse files
authored
Merge pull request #355 from DataDog/agent/optional-application-id
fix(browser): make applicationId optional at runtime
2 parents 6bbed48 + f18f28e commit 10380f3

3 files changed

Lines changed: 59 additions & 8 deletions

File tree

packages/browser/src/domain/configuration.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Configuration, EndpointBuilder, InitConfiguration } from '@datadog/browser-core'
2-
import { display, validateAndBuildConfiguration } from '@datadog/browser-core'
2+
import { validateAndBuildConfiguration } from '@datadog/browser-core'
33
import type { FlagsConfiguration } from '@datadog/flagging-core'
44
import type { EvaluationContext } from '@openfeature/web-sdk'
55
import type { DDRum } from '../openfeature/rumIntegration'
@@ -90,11 +90,6 @@ export interface FlaggingConfiguration extends Configuration {
9090
export function validateAndBuildFlaggingConfiguration(
9191
initConfiguration: FlaggingInitConfiguration
9292
): FlaggingConfiguration | undefined {
93-
if (!initConfiguration.applicationId) {
94-
display.error('Application ID is not configured, no flagging data will be collected.')
95-
return
96-
}
97-
9893
const baseConfiguration = validateAndBuildConfiguration(initConfiguration)
9994
if (!baseConfiguration) {
10095
return

packages/browser/test/openfeature/exposures.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,39 @@ describe('Exposures End-to-End', () => {
298298
})
299299
})
300300

301+
it('should send exposure events without RUM application attribution when applicationId is not provided', async () => {
302+
fetchMock.mockImplementation((url: string) => {
303+
if (url.includes('exposures')) {
304+
return Promise.resolve({ ok: true, status: 200 })
305+
}
306+
if (url.includes('precompute-assignments')) {
307+
return Promise.resolve({
308+
ok: true,
309+
json: () => Promise.resolve(precomputedServerResponse),
310+
})
311+
}
312+
return Promise.resolve({ ok: true, json: () => Promise.resolve({}) })
313+
})
314+
315+
await OpenFeature.setContext({ targetingKey: 'test-user-123' })
316+
const provider = new DatadogProvider({
317+
clientToken: 'test-client-token',
318+
env: 'test',
319+
site: INTAKE_SITE_STAGING,
320+
enableExposureLogging: true,
321+
})
322+
await OpenFeature.setProviderAndWait(provider)
323+
324+
OpenFeature.getClient().getStringValue('string-flag', 'default')
325+
triggerBatch()
326+
327+
const exposuresCalls = getExposuresCalls()
328+
expect(exposuresCalls).toHaveLength(1)
329+
330+
const [event] = parseExposureEvents(exposuresCalls[0][1].body)
331+
expect(event.rum).toEqual({ view: { url: 'http://localhost/' } })
332+
})
333+
301334
it('should not send exposure events when exposure logging is disabled', async () => {
302335
// Mock server response
303336
fetchMock.mockImplementation((url: string) => {

packages/browser/test/openfeature/provider.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ describe('DatadogProvider', () => {
3333
describe('configuration validation', () => {
3434
beforeEach(() => {
3535
setupProvider()
36-
OpenFeature.setProvider(provider)
3736
})
3837

3938
it('should throw error when ddog-gov.com site is provided', () => {
@@ -139,7 +138,6 @@ describe('DatadogProvider', () => {
139138
describe('metadata', () => {
140139
beforeEach(() => {
141140
setupProvider()
142-
OpenFeature.setProvider(provider)
143141
})
144142

145143
it('should have correct metadata', () => {
@@ -520,6 +518,31 @@ describe('DatadogProvider', () => {
520518
})
521519
})
522520

521+
describe('initialization without applicationId', () => {
522+
it('should initialize successfully', async () => {
523+
const originalFetch = global.fetch
524+
global.fetch = jest.fn().mockResolvedValue({
525+
ok: true,
526+
json: async () => precomputedResponse,
527+
})
528+
const testProvider = new DatadogProvider({
529+
clientToken: 'xxx',
530+
env: 'test',
531+
site: INTAKE_SITE_STAGING,
532+
enableExposureLogging: false,
533+
enableFlagEvaluationTracking: false,
534+
enableRumFeatureFlagTracking: false,
535+
})
536+
537+
try {
538+
await expect(testProvider.initialize()).resolves.toBeUndefined()
539+
expect(testProvider.status).toBe(ProviderStatus.READY)
540+
} finally {
541+
global.fetch = originalFetch
542+
}
543+
})
544+
})
545+
523546
describe('error handling integration', () => {
524547
let originalFetch: (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>
525548
let isolatedFetchMock: jest.Mock

0 commit comments

Comments
 (0)