Skip to content

Export data

If you want to export data about how your flag are used, you can use the DataExporter.
It collects all the variations events and can save these events on several locations:

  • File - create local files with the variation usages.
  • Log - use your logger to write the variation usages.
  • S3 - export your variation usages to S3.
  • Webhook - export your variation usages by calling a webhook.
  • Google Cloud Storage - export your variation usages by calling a webhook.

If the existing exporter does not work with your system you can extend the system and use a custom exporter.

Data format

Currently, we are supporting only feature events.
It represents individual flag evaluations and are considered "full fidelity" events.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
    "kind": "feature",
    "contextKind": "anonymousUser",
    "userKey": "ABCD",
    "creationDate": 1618228297,
    "key": "test-flag",
    "variation": "Default",
    "value": false,
    "default": false
}

Configuration fields

Field Description
kind The kind for a feature event is feature. A feature event will only be generated if the trackEvents attribute of the flag is set to true.
contextKind The kind of context which generated an event. This will only be "anonymousUser" for events generated on behalf of an anonymous user or the reserved word "user" for events generated on behalf of a non-anonymous user
userKey The key of the user object used in a feature flag evaluation.
creationDate When the feature flag was requested at Unix epoch time in milliseconds.
key The key of the feature flag requested.
variation The variation of the flag requested. Available values are:
True: if the flag was evaluated to True
False: if the flag was evaluated to False
Dafault: if the flag was evaluated to Default
SdkDefault: if something wrong happened and the SDK default value was used.
value The value of the feature flag returned by feature flag evaluation.
default (Optional) This value is set to true if feature flag evaluation failed, in which case the value returned was the default value passed to variation.

Events are collected and send in bulk to avoid spamming your exporter (see details in how to configure data export)

How to configure data export?

In your ffclient.Config add the DataExporter field and configure your export location.

To avoid spamming your location everytime you have a variation called, go-feature-flag is storing in memory all the events and send them in bulk to the exporter. You can decide the threshold on when to send the data with the properties FlushInterval and MaxEventInMemory. The first threshold hit will export the data.

If there are some flags you don't want to export, you can use trackEvents fields on these specific flags to disable the data export (see flag file format).

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ffclient.Config{ 
    // ...
   DataExporter: ffclient.DataExporter{
        FlushInterval:   10 * time.Second,
        MaxEventInMemory: 1000,
        Exporter: &fileexporter.Exporter{
            OutputDir: "/output-data/",
        },
    },
    // ...
}

Configuration fields

Field Description
Exporter The configuration of the exporter you want to use. All the exporters are available in the exporter package.
FlushInterval (optional)
Time to wait before exporting the data.
Default: 60 seconds.
MaxEventInMemory (optional)
If MaxEventInMemory is reach before the FlushInterval a intermediary export will be done
Default: 100000.

Don't track a flag

By default, all flags are trackable, and their data are exported.

If you want to exclude a specific flag from the data export, you can set the property trackEvents to false on your flag, and you will have no export for it.

1
2
3
4
5
6
test-flag:
  percentage: 50
  true: "B"
  false: "A"
  default: "Default"
  trackEvents: false
1
2
3
4
5
6
7
8
9
{
  "test-flag": {
    "percentage": 50,
    "true": "B",
    "false": "A",
    "default": "Default",
    "trackEvents": false
  }
}
1
2
3
4
5
6
[test-flag]
percentage = 50.0
true = "B"
false = "A"
default = "Default"
trackEvents = false