Skip to content

lightfoot-team/lightfoot-server-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lightfoot Server SDK

A comprehensive server SDK for Lightfoot with integrated OpenTelemetry instrumentation and feature flag management.

Installation

npm install lightfoot-server-sdk

Quick Start

const { LightFootSDK } = require('lightfoot-server-sdk');

// Initialize the SDK
const lightFoot = new LightFootSDK({
  flagEvaluationURL: "http://localhost:3001",
  OTLPExporterBaseUrl: "http://localhost:4318"
});

// Initialize telemetry and feature flags
lightFoot.init();

// Get the OpenFeature client for feature flag evaluation
const featureFlagsClient = lightFoot.getClient();

Features

  • OpenTelemetry Integration - Automatic instrumentation for traces, metrics, and logs
  • Feature Flag Management - Built-in OpenFeature support for feature flags
  • Easy Configuration - Simple setup

Configuration

Local Configuration

const { LightFootSDK } = require('lightfoot-server-sdk');

const lightFoot = new LightFootSDK({
  flagEvaluationURL: "http://localhost:3001",   // Your Lightfoot flag evaluation API endpoint
  OTLPExporterBaseUrl: "http://localhost:4318"  // OpenTelemetry collector endpoint
});

Deployment Configuration

const lightFoot = new LightFootSDK({
  flagEvaluationURL: "https://api.your-lightfoot-instance.com",
  OTLPExporterBaseUrl: "https://otel-collector.your-domain.com"
});

Usage Example

const { LightFootSDK } = require('lightfoot-server-sdk');

const lightFoot = new LightFootSDK({
  flagEvaluationURL: "http://localhost:3001",
  OTLPExporterBaseUrl: "http://localhost:4318"
});

lightFoot.init();
const featureFlagsClient = lightFoot.getClient();

function getUserContext(req) {
  const userId = req.get('x-user-id');
  return {
    targetingKey: userId,
    kind: 'user',
    user: {
      id: userId,
      role: req.get('x-user-role') || '',
      group: req.get('x-user-group') || '',
    }
  };
}

router.get("/", (async(req, _)) => {
  const context = getUserContext(req);
  const newFeature = featureFlagsClient.getBooleanValue("new-feature", false, context);

  if (newFeature) {
    // execute code with new feature
  } else {
    // execute code without new feature
  }
});

Methods Available on Feature Flag Client

  • getBooleanValue(flagKey: string, defaultValue: boolean, context?: EvaluationContext): boolean
  • getStringValue(flagKey: string, defaultValue: string, context?: EvaluationContext): string
  • getNumberValue(flagKey: string, defaultValue: number, context?: EvaluationContext): number
  • getObjectValue(flagKey: string, defaultValue: object, context?: EvaluationContext): object

Requirements

  • Node.js 16.0.0 or higher
  • TypeScript 4.5+ (if using TypeScript)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors