• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""
    EXPAND ALL

    EDIT ON GITHUB

    Flushing events

    Read time: 6 minutes
    Last edited: May 17, 2023

    Overview

    This topic explains how to use the flush feature. The flush feature is available on both server-side and client-side SDKs.

    Server-side, client-side, and mobile LaunchDarkly SDKs automatically flush pending analytics events to LaunchDarkly at regular intervals. This prevents the SDK from having to send constant network requests. The time between intervals varies by SDK, and is configurable. To learn how to configure your SDK's flush interval, read Configuration.

    You can manually call flush to send events immediately without waiting for the next interval. Most customers do not need to use the flush feature because SDKs automatically flush their pending analytics events on a periodic frequency. However, it can be useful if you are using the SDK in a short-lived serverless process or a test application, rather than in a long-running application. To learn more, read Analytics events.

    Using the flush feature

    The flush feature tells the client to send all of an SDK's pending analytics events to LaunchDarkly as soon as possible.

    All SDKs support asynchronous flushing, which tells the SDK to start delivering events, but returns control to the application before delivery is complete. Some SDKs also support synchronous flushing, which tells the SDK to deliver the events and not return control until delivery is complete.

    Details about each SDK's configuration are available in the SDK-specific sections below.

    • Client-side SDKs
    • Server-side SDKs

    Client-side SDKs

    This feature is available in the following client-side SDKs:

    .NET (client-side)

    Expand .NET (client-side) code sample

    Internally, the client-side .NET SDK keeps an event buffer for Track and Identify calls. These are flushed periodically in a background thread. If you test the SDK in a REPL, you may want to manually call Flush to process events immediately.

    The flush interval is configurable. If you need to change the interval, you can do so with the Configuration class.

    To call flush:

    client.Flush();

    Android

    Expand Android code sample

    The Android SDK keeps an internal event buffer for analytics calls. These are flushed periodically in a background thread. You can configure the flush interval if needed.

    In some situations, such as when you're testing the SDK in a simulator, you may want to manually call flush to request any queued events to be sent immediately. This call is non-blocking, so it returns before the events are sent.

    Here's how:

    client.flush();

    The flush interval is configurable.

    C/C++ (client-side)

    Expand C/C++ (server-side) code sample

    The LaunchDarkly SDK keeps an internal event buffer for analytics events. These are flushed periodically in a background thread. In some situations, for example, if you're testing the SDK in a simulator, you may want to manually call flush to process events immediately.

    LDClientFlush(client);

    The flush interval is configurable. If you need to change the interval, you can do so via the configuration.

    Flutter

    Expand Flutter code sample

    Internally, the Flutter SDK keeps an event buffer for track calls. These are flushed periodically in a background thread. You can configure the flush interval if needed.

    In some situations, such as when you're testing the SDK in a simulator, you may want to manually call flush to request any queued events to be sent immediately. This call is non-blocking, so it returns before the events are sent.

    To call flush:

    await LDClient.flush();

    iOS

    Expand iOS code sample

    Internally, the iOS SDK keeps an event buffer for track calls. These are flushed periodically in a background thread. You can configure the flush interval if needed.

    In some situations, such as when you're testing the SDK in a simulator, you may want to manually call flush to request any queued events to be sent immediately. This call is non-blocking, so it returns before the events are sent.

    To call flush:

    LDClient.get()!.flush()

    JavaScript

    Expand JavaScript code sample

    Internally, the JavaScript SDK keeps an event buffer for track calls. These are flushed periodically in a background thread. You can configure the flush interval if needed.

    In some situations, such as when you're testing the SDK in a simulator, you may want to manually call flush to request any queued events to be sent immediately. This call is non-blocking, so it returns before the events are sent.

    This method is asynchronous. You can pass a callback or wait for the returned Promise to determine when all events have been flushed.

    To call flush:

    client.flush();

    Node.js (client-side)

    Expand Node.js (client-side) code sample

    Internally, the LaunchDarkly SDK keeps an analytics event buffer. These events are flushed periodically. In some situations, you may want to manually call flush to process events immediately.

    This method is asynchronous. You can pass a callback or wait for the returned Promise to determine when all events have been flushed.

    To call flush:

    client.flush();
    // or, with a callback:
    client.flush(() => {
    console.log('flush complete');
    });
    // or, with a Promise:
    client.flush().then(() => {
    console.log('flush complete');
    });

    React Native

    Expand React Native code sample

    Internally, the React Native SDK keeps an event buffer for track calls. These are flushed periodically in a background thread. You can configure the flush interval if needed.

    In some situations, such as when you're testing the SDK in a simulator, you may want to manually call flush to request any queued events to be sent immediately. This call is non-blocking, so it returns before the events are sent.

    To call flush:

    client.flush();

    Roku

    Expand Roku code sample

    Internally, the Roku SDK keeps an event buffer for track calls. These are flushed periodically in a background thread. You can configure the flush interval if needed.

    In some situations, such as when you're testing the SDK in a simulator, you may want to manually call flush to request any queued events to be sent immediately. This call is non-blocking, so it returns before the events are sent.

    To call flush:

    launchDarkly.flush()

    Server-side SDKs

    This feature is available in the following server-side SDKs:

    .NET (server-side)

    Expand .NET (server-side) code sample

    The .NET (server-side) SDK supports asynchronous flushing with the Flush method.

    To call flush:

    client.Flush();

    Starting in version 7.0.0, the SDK also supports synchronous flushing with the FlushAndWait method. In this example, the TimeSpan.FromSeconds(2) value means that the application is willing to wait no more than two seconds for event delivery.

    client.FlushAndWait(TimeSpan.FromSeconds(2));

    The flush interval is configurable. If you need to change the interval, you can do so with the Configuration class.

    Here's how:

    var config = Configuration.Builder("sdk-key-123abc")
    .Events(
    Components.SendEvents().FlushInterval(TimeSpan.FromSeconds(10))
    )
    .Build();
    var client = new LdClient(config);

    C/C++ (server-side)

    Expand C/C++ (server-side) code sample

    The LaunchDarkly SDK keeps an internal event buffer for analytics events. These are flushed periodically in a background thread. If you test the SDK in a simulator, you may want to manually call flush to process events immediately.

    This function will not block, but instead initiate a flush operation in the background. The flush interval is configurable. If you need to change the interval, you can do so with the configuration.

    Here's how:

    LDClientFlush(client);

    Go

    Expand Go code sample

    The Go SDK supports asynchronous flushing with the Flush method.

    client.Flush();

    Starting in version 6.0.0, the SDK also supports synchronous flushing with the FlushAndWait method. In this example, the time.Second*2 value means that the application is willing to wait no more than two seconds for event delivery.

    client.FlushAndWait(time.Second*2);

    The interval for automatic event flushing is configurable. If you need to change the interval, you can do so by making a custom client configuration. Here's how:

    config := ld.Config{
    Events: ldcomponents.SendEvents().FlushInterval(time.Second*10),
    }

    Haskell

    Expand Haskell code sample

    The LaunchDarkly SDK keeps an internal event buffer for analytics events. These events are flushed periodically in a background thread. If you test the SDK in a simulator, you may want to manually call flush to process events immediately.

    This function will not block, but instead initiate a flush operation in the background. The flush interval is configurable. If you need to change the interval, you can do so with the configuration.

    Here's how:

    flushEvents client

    Java

    Expand Java code sample

    Internally, the LaunchDarkly SDK keeps an event buffer for track and identify calls. These are flushed periodically in a background thread. If you test the SDK in a REPL, you may want to manually call flush to process events immediately.

    Here's how:

    client.flush();

    The flush interval is configurable. If you need to change the interval, you can do so with LDConfig.Builder and Components.sendEvents().

    Lua

    Expand Lua code sample

    The LaunchDarkly SDK keeps an internal event buffer for analytics events. These are flushed periodically in a background thread. If you test the SDK in a simulator, you may want to manually call flush to process events immediately.

    This function will not block, but instead initiate a flush operation in the background. The flush interval is configurable. If you need to change the interval, you can do so via the configuration.

    Here's how:

    client:flush()

    Node.js (server-side)

    Expand Node.js (server-side) code sample

    Internally, the LaunchDarkly SDK keeps an event buffer for track and identify calls. These are flushed periodically in a background thread. If you test the SDK in a REPL, you may want to manually call flush to process events immediately.

    The flush interval is configurable. If you need to change the interval, you can do so when configuring your client instance.

    Here's how:

    client.flush();

    PHP

    Expand PHP code sample

    Internally, the LaunchDarkly SDK keeps an event buffer for variation, track, and identify calls. These are automatically flushed when the LDClient is destroyed. PHP's shared-nothing architecture means manual invocation of this method is typically not needed. Developers may do so if they wish to flush events prior to teardown.

    Here's how:

    ldclient->flush();

    Python

    Expand Python code sample

    Internally, the LaunchDarkly SDK keeps an event buffer for variation, track, and identify calls. These are flushed periodically in a background thread. If you test the SDK in a REPL, you may want to manually call flush to process events immediately. Otherwise, Python may close before flushing the event buffer and your user changes and tracks will be lost.

    The flush interval is configurable. If you need to change the interval, you can do so when you configure your client instance.

    Here's how:

    ldclient.get().flush()

    Ruby

    Expand Ruby code sample

    Internally, the LaunchDarkly SDK keeps an event buffer for track and identify calls. These are flushed periodically in a background thread. If you test the SDK in a REPL, you may want to manually call flush to process events immediately.

    The flush interval is configurable. If you need to change the interval, you can do so when you configure your client instance.

    Here's how:

    client.flush

    Rust

    Expand Rust code sample

    Internally, the LaunchDarkly SDK keeps an event buffer for the analytics events that are produced by calling the variation or variation_detail methods, the track methods, or identify. These are flushed periodically in a background thread. In some situations, you may want to manually call flush to process events immediately.

    The flush interval is configurable. If you need to change the interval, you can do so by making a custom client configuration.

    Here's how:

    let result = client.flush();