Skip to content

Commit ecfd93b

Browse files
authored
feat: impact metrics docs (#356)
1 parent d7ea9b0 commit ecfd93b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,65 @@ UnleashConfig config = UnleashConfig.builder()
320320
321321
This will then start using OkHttp instead of HttpURLConnection to send metrics.
322322
323+
## Impact metrics
324+
325+
Impact metrics are lightweight, application-level time-series metrics stored and visualized directly inside Unleash. They allow you to connect specific application data, such as request counts, error rates, or memory usage, to your feature flags and release plans.
326+
327+
Use impact metrics to validate feature impact and automate your release process. For example, you can monitor usage patterns or performance to see if a feature is meeting its goals. By combining impact metrics with release templates, you can reduce manual release operations and automate milestone progression based on metric thresholds.
328+
329+
The SDK automatically attaches the following context labels to your metrics: `appName`, `environment`, and `origin` (for example, `origin=sdk` or `origin=Edge`).
330+
331+
### Counters
332+
333+
Use counters for cumulative values that only increase, such as the total number of requests or errors.
334+
335+
```java
336+
UnleashConfig config =
337+
UnleashConfig.builder()
338+
.appName("my-java-app")
339+
.instanceId("instance-1")
340+
.unleashAPI("https://YOUR-API-URL")
341+
.apiKey("<YOUR_API_TOKEN>")
342+
.build();
343+
344+
Unleash unleash = new DefaultUnleash(config);
345+
346+
unleash.getImpactMetrics()
347+
.defineCounter("request_count", "Total number of HTTP requests processed");
348+
349+
unleash.getImpactMetrics().incrementCounter("request_count");
350+
```
351+
352+
### Gauges
353+
354+
Use gauges for values that can go up and down, such as current memory usage or active thread count.
355+
356+
```java
357+
unleash.getImpactMetrics()
358+
.defineGauge("heap_memory_total", "Current heap memory usage in bytes");
359+
360+
long currentHeap = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
361+
362+
unleash.getImpactMetrics().updateGauge("heap_memory_total", currentHeap);
363+
```
364+
365+
### Histograms
366+
367+
Use histograms to measure the distribution of values, such as request duration or response size. Unleash automatically calculates percentiles (p50, p95, p99).
368+
369+
```java
370+
unleash.getImpactMetrics()
371+
.defineHistogram("request_time_ms", "Time taken to process a request in milliseconds");
372+
373+
long start = System.currentTimeMillis();
374+
// handleRequest();
375+
long duration = System.currentTimeMillis() - start;
376+
377+
unleash.getImpactMetrics().observeHistogram("request_time_ms", duration);
378+
```
379+
380+
Impact metrics are batched and sent on the same interval as regular SDK metrics. They are ingested via the regular metrics endpoint.
381+
323382
## Local backup
324383
By default unleash-client fetches the feature toggles from unleash-server every 10s, and stores the
325384
result in `unleash-repo.json` which is located in the `java.io.tmpdir` directory. This means that if

0 commit comments

Comments
 (0)