Skip to content

Configuration

Garvit Joshi edited this page Apr 2, 2026 · 4 revisions

Configuration

This page covers the client builder, base URL rules, and OkHttpClient ownership model.

Builder

TremorClient is the main public entry point.

Builder call Use case
TremorClient.builder(tremorKey).build() Use local Tremor at http://localhost:8080/tremor
TremorClient.builder(tremorKey).baseUrl(baseUrl).build() Use a specific Tremor server
TremorClient.builder(tremorKey).httpClient(okHttpClient).build() Reuse your own shared OkHttpClient with the default base URL
TremorClient.builder(tremorKey).baseUrl(baseUrl).httpClient(okHttpClient).build() Reuse your own shared OkHttpClient and custom base URL

Base URL Rules

  • Default base URL: http://localhost:8080/tremor
  • Ingest path: /api/v1/ingest
  • Resolved request target: ${baseUrl}/api/v1/ingest
  • baseUrl must be an absolute URL
  • Trailing / is normalized away
  • If baseUrl already ends with /api/v1/ingest, it is used as-is

Examples:

String tremorKey = "...";

TremorClient.builder(tremorKey).build();
TremorClient.builder(tremorKey).baseUrl("http://localhost:8080/tremor").build();
TremorClient.builder(tremorKey).baseUrl("https://tremor.example.com/tremor").build();
TremorClient.builder(tremorKey).baseUrl("https://tremor.example.com/tremor/api/v1/ingest").build();

OkHttp Ownership

Each TremorClient resolves exactly one OkHttpClient.

  • If you pass an OkHttpClient, that single client instance is used
  • If you do not pass one, the library creates one internally
  • close() only shuts down the internally created client
  • A caller-provided OkHttpClient is never shut down by the library

This is the correct setup when your application already has a shared OkHttpClient.

import in.riido.tremor.client.TremorClient;
import okhttp3.OkHttpClient;

String tremorKey = "...";
OkHttpClient okHttpClient = new OkHttpClient();

TremorClient client =
    TremorClient.builder(tremorKey)
        .baseUrl("https://tremor.example.com/tremor")
        .httpClient(okHttpClient)
        .build();

Default Timeouts

When the library creates its own OkHttpClient, it uses:

  • connect timeout: 5 seconds
  • read timeout: 10 seconds
  • write timeout: 10 seconds
  • call timeout: 30 seconds

If you need different transport behavior, provide your own OkHttpClient.

Thread Safety

TremorClient is safe to reuse across threads because:

  • configuration is immutable after construction
  • request-scoped metadata stays in TremorEvent or TremorCaptureOptions
  • the resolved OkHttpClient is shared by the client instance

Closing the Client

Use try-with-resources when the library owns the transport:

String tremorKey = "...";

try (TremorClient client = TremorClient.builder(tremorKey).build()) {
    client.send(new IllegalStateException("boom"));
}

If you pass a shared OkHttpClient, closing TremorClient does not shut down that shared transport.

Clone this wiki locally