Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

feat(datadog): Add DD RUM to flipt-node client #19

Merged
merged 7 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ README.md
CHANGELOG.md
.github
src/constants.ts
src/metrics.ts
LICENSE
.gitignore
.release-please-manifest.json
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,51 @@ const response = await client.evaluation.variant({
console.log("Received response from Flipt!", response);
```

### Metrics

There is support for [Datadog RUM](https://docs.datadoghq.com/real_user_monitoring/) through this client. This allows you to track the values of feature flag evaluation and how it relates to active browser sessions.

To start tracking feature flags on Datadog:

```typescript
import { datadogRum } from '@datadog/browser-rum';
import { FliptMetrics } from '@flipt-io/flipt/metrics';

datadogRum.init({
applicationId: '<APPLICATION_ID>',
clientToken: '<CLIENT_TOKEN>',
site: 'datadoghq.com',
service:'<SERVICE_NAME>',
env:'<ENV_NAME>',
enableExperimentalFeatures: ["feature_flags"],
sessionSampleRate:100,
sessionReplaySampleRate: 20,
trackUserInteractions: true,
trackResources: true,
trackLongTasks: true,
defaultPrivacyLevel:'mask-user-input'
});

datadogRum.startSessionReplayRecording();

const metricsClient = new FliptMetrics(new FliptApiClient({
environment: "http://localhost:8080",
auth: {
credentials: {
username: "YOUR_USERNAME",
password: "YOUR_PASSWORD",
},
},
}).evaluation, datadogRum);

const response = await metricsClient.variant({
namespaceKey: "default",
flagKey: "hello-this",
entityId: uuidv4(),
context: {},
});
```

## Beta status

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version in your package.json file. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Expand Down
30 changes: 30 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { FliptApi } from "@flipt-io/flipt";
import { Evaluation } from "api/resources/evaluation/client/Client";

export class FliptMetrics {
evaluationClient: Evaluation;
datadogRum: any;

constructor(evaluationClient: Evaluation, datadogRum: any) {
this.evaluationClient = evaluationClient;
this.datadogRum = datadogRum;
}

public async boolean(
request: FliptApi.evaluation.EvaluationRequest
): Promise<FliptApi.evaluation.BooleanEvaluationResponse> {
const response = await this.evaluationClient.boolean(request);

this.datadogRum.addFeatureFlagEvaluation(`${request.namespaceKey}/${request.flagKey}`, response.enabled);
return response;
}

public async variant(
request: FliptApi.evaluation.EvaluationRequest
): Promise<FliptApi.evaluation.VariantEvaluationResponse> {
const response = await this.evaluationClient.variant(request);

this.datadogRum.addFeatureFlagEvaluation(`${request.namespaceKey}/${request.flagKey}`, response.variantKey);
return response;
}
}