Skip to content

Commit

Permalink
Event processor should use the default headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion committed Sep 12, 2024
1 parent 745e994 commit 7ec9310
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ describe('given an event processor', () => {
}),
);
contextDeduplicator = new ContextDeduplicator();
eventProcessor = new EventProcessor(eventProcessorConfig, clientContext, contextDeduplicator);
eventProcessor = new EventProcessor(
eventProcessorConfig,
clientContext,
{},
contextDeduplicator,
);
});

afterEach(() => {
Expand Down Expand Up @@ -788,6 +793,7 @@ describe('given an event processor', () => {
eventProcessor = new EventProcessor(
eventProcessorConfig,
clientContextWithDebug,
{},
contextDeduplicator,
);

Expand Down
4 changes: 3 additions & 1 deletion packages/shared/common/src/internal/events/EventProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import LDEventProcessor from '../../api/subsystem/LDEventProcessor';
import AttributeReference from '../../AttributeReference';
import ContextFilter from '../../ContextFilter';
import { ClientContext } from '../../options';
import { LDHeaders } from '../../utils';
import { DiagnosticsManager } from '../diagnostics';
import EventSender from './EventSender';
import EventSummarizer, { SummarizedFlagsEvent } from './EventSummarizer';
Expand Down Expand Up @@ -106,13 +107,14 @@ export default class EventProcessor implements LDEventProcessor {
constructor(
private readonly config: EventProcessorOptions,
clientContext: ClientContext,
baseHeaders: LDHeaders,
private readonly contextDeduplicator?: LDContextDeduplicator,
private readonly diagnosticsManager?: DiagnosticsManager,
start: boolean = true,
) {
this.capacity = config.eventsCapacity;
this.logger = clientContext.basicConfiguration.logger;
this.eventSender = new EventSender(clientContext);
this.eventSender = new EventSender(clientContext, baseHeaders);

this.contextFilter = new ContextFilter(
config.allAttributesPrivate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ describe('given an event sender', () => {

eventSender = new EventSender(
new ClientContext('sdk-key', basicConfig, { ...mockPlatform, info }),
{
authorization: 'sdk-key',
'user-agent': 'TestUserAgent/2.0.2',
'x-launchdarkly-tags': 'application-id/testApplication1 application-version/1.0.0',
'x-launchdarkly-wrapper': 'Rapper/1.2.3',
},
);

eventSenderResult = await eventSender.sendEventData(
Expand Down
12 changes: 5 additions & 7 deletions packages/shared/common/src/internal/events/EventSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
LDUnexpectedResponseError,
} from '../../errors';
import { ClientContext, getEventsUri } from '../../options';
import { defaultHeaders, httpErrorMessage, sleep } from '../../utils';
import { httpErrorMessage, LDHeaders, sleep } from '../../utils';

export default class EventSender implements LDEventSender {
private crypto: Crypto;
Expand All @@ -22,16 +22,14 @@ export default class EventSender implements LDEventSender {
private eventsUri: string;
private requests: Requests;

constructor(clientContext: ClientContext) {
constructor(clientContext: ClientContext, baseHeaders: LDHeaders) {
const { basicConfiguration, platform } = clientContext;
const {
sdkKey,
serviceEndpoints: { analyticsEventPath, diagnosticEventPath, includeAuthorizationHeader },
tags,
serviceEndpoints: { analyticsEventPath, diagnosticEventPath },
} = basicConfiguration;
const { crypto, info, requests } = platform;
const { crypto, requests } = platform;

this.defaultHeaders = defaultHeaders(sdkKey, info, tags, includeAuthorizationHeader);
this.defaultHeaders = { ...baseHeaders };
this.eventsUri = getEventsUri(basicConfiguration.serviceEndpoints, analyticsEventPath, []);
this.diagnosticEventsUri = getEventsUri(
basicConfiguration.serviceEndpoints,
Expand Down
17 changes: 10 additions & 7 deletions packages/shared/sdk-client/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ export default class LDClientImpl implements LDClient {
this.connectionMode = this.config.initialConnectionMode;
this.clientContext = new ClientContext(sdkKey, this.config, platform);
this.logger = this.config.logger;

this.baseHeaders = defaultHeaders(
this.sdkKey,
this.platform.info,
this.config.tags,
this.config.serviceEndpoints.includeAuthorizationHeader,
this.config.userAgentHeaderName,
);

this.flagManager = new FlagManager(
this.platform,
sdkKey,
Expand All @@ -97,6 +106,7 @@ export default class LDClientImpl implements LDClient {
sdkKey,
this.config,
platform,
this.baseHeaders,
this.diagnosticsManager,
!this.isOffline(),
);
Expand All @@ -113,13 +123,6 @@ export default class LDClientImpl implements LDClient {
this.emitter.emit('change', ldContext, flagKeys);
});

Check failure on line 125 in packages/shared/sdk-client/src/LDClientImpl.ts

View workflow job for this annotation

GitHub Actions / build-test-sdk-client

Delete `⏎`
this.baseHeaders = defaultHeaders(
this.sdkKey,
this.platform.info,
this.config.tags,
true,
'x-launchdarkly-user-agent',
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { ClientContext, internal, Platform } from '@launchdarkly/js-sdk-common';
import { ClientContext, internal, LDHeaders, Platform } from '@launchdarkly/js-sdk-common';

import Configuration from '../configuration';

const createEventProcessor = (
clientSideID: string,
config: Configuration,
platform: Platform,
baseHeaders: LDHeaders,
diagnosticsManager?: internal.DiagnosticsManager,
start: boolean = false,
): internal.EventProcessor | undefined => {
if (config.sendEvents) {
return new internal.EventProcessor(
{ ...config, eventsCapacity: config.capacity },
new ClientContext(clientSideID, config, platform),
baseHeaders,
undefined,
diagnosticsManager,
start,
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/sdk-server/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default class LDClientImpl implements LDClient {
}
this.config = config;
this.logger = config.logger;
const baseHeaders = defaultHeaders(sdkKey, platform.info, config.tags);

const clientContext = new ClientContext(sdkKey, config, platform);
const featureStore = config.featureStoreFactory(clientContext);
Expand All @@ -178,6 +179,7 @@ export default class LDClientImpl implements LDClient {
this.eventProcessor = new internal.EventProcessor(
config,
clientContext,
baseHeaders,
new ContextDeduplicator(config),
this.diagnosticsManager,
);
Expand Down Expand Up @@ -208,7 +210,6 @@ export default class LDClientImpl implements LDClient {
},
};
this.evaluator = new Evaluator(this.platform, queries);
const baseHeaders = defaultHeaders(sdkKey, platform.info, config.tags);

const listeners = createStreamListeners(dataSourceUpdates, this.logger, {
put: () => this.initSuccess(),
Expand Down

0 comments on commit 7ec9310

Please sign in to comment.