← Back to changelog
January 30, 2025

JS/TS SDK supports trace sampling

Picture Hassieb PakzadHassieb Pakzad

Trace sampling is now supported in the JS SDK and integrations.

Trace sampling enables you to specify the proportion of traces that the SDK should collect and send to Langfuse. By adjusting the sampleRate, you can balance between comprehensive tracing and resource efficiency.

You can configure the sample rate using the constructor parameter or the environment variable.

Using Constructor Parameters

You can set the sampleRate when initializing the Langfuse client. The sampleRate should be a value between 0 and 1, representing the share of traces to be sent to Langfuse.

import { Langfuse } from "langfuse";
 
const langfuse = new Langfuse({
  secretKey: "sk-lf-...",
  publicKey: "pk-lf-...",
  sampleRate: 0.2, // Samples 20% of the traces
});

Using Environment Variables

Alternatively, you can configure the sample rate via the LANGFUSE_SAMPLE_RATE environment variable. This method is useful for dynamic configurations without changing the codebase.

.env
LANGFUSE_SAMPLE_RATE="0.2"

Learn More

For detailed information on configuring and using trace sampling, please refer to the Sampling Documentation and the Sampling Section in the Guide.

Was this page useful?

Questions? We're here to help

Subscribe to updates