← All Exercises

Deterministic Log Sampling

basicjavascript~10min

Background

Hash-based sampling keeps the same lines across restarts and replicas, so a scattered trace still reconstructs completely for whatever traffic survives the filter.

Problem

Implement deterministic log sampling: for each log identifier, compute the FNV-1a 32-bit hash, take the value modulo 100, and keep the line when the result is strictly below keepPercent. Output the kept identifiers in input order.

Input

A JSON object {"keepPercent": number, "logs": string[]} of unique identifiers.

Output

A JSON object {"kept": string[]} in input order.

Sample tests

Sample 1

Input: {"keepPercent":30,"logs":["a","b","c","d","e","f","g","h","i","j"]}
Expected: {"kept":["a","f","j"]}

Sample 2

Input: {"keepPercent":100,"logs":["x","y"]}
Expected: {"kept":["x","y"]}

Your solution

Learning objective

Apply deterministic hashing for reproducible sampling decisions.