API Requests
Initialise Coryn and start recording before reporting. These operations accept calls from any thread. Reports become built-in Events; no State Provider registration is needed. Requests outside an active recording are not buffered for a future session.
addApiRequest
fun addApiRequest(
endpoint: String,
method: String,
durationMs: Long,
headers: Map<String, List<String>> = emptyMap(),
body: String? = null,
urlParams: Map<String, List<String>> = emptyMap(),
responseCode: Int? = null,
responseHeaders: Map<String, List<String>> = emptyMap(),
responseBody: String? = null,
error: String? = null,
startedAtUnixMs: Long? = null,
requestBodySizeBytes: Long? = null,
responseBodySizeBytes: Long? = null,
truncation: CorynApiRequestTruncation? = CorynApiRequestTruncation.UNKNOWN
)
Report a completed HTTP request or transport failure. Java static overloads allow omission of trailing optional arguments, down to the three required parameters.
| Parameter | Meaning |
|---|---|
endpoint | Endpoint identifier. Supply a safe value without sensitive path or query data. |
method | HTTP method, normalised to uppercase. |
durationMs | Execution duration in milliseconds; negative values become zero. |
headers, urlParams, responseHeaders | Names mapped to lists of values, preserving repetitions. |
body, responseBody | Optional text payloads. |
responseCode | HTTP status, including HTTP errors. Omit for a failure without a response. |
error | Optional transport failure description. |
startedAtUnixMs | Wall-clock request start in Unix milliseconds; when omitted, inferred from call time minus duration. |
requestBodySizeBytes, responseBodySizeBytes | Optional body sizes; -1 can indicate unknown length. |
truncation | TRUNCATED when data was shortened, UNKNOWN when completeness is uncertain, or null when verified complete. |
The Event timestamp is the time of reporting; start and duration are metadata. Collection snapshots are copied before queueing. Do not modify collections during the call; later changes do not affect the report.
Retained diagnostics are limited to 16,384 total text characters, 8,192 per string, 64 entries per map, and 16 values per entry. Trimming sets TRUNCATED, even if the caller supplied null or UNKNOWN. Reports share the 256 pending State/Event operation limit.
The manual API does not automatically redact supplied data. UI masks do not protect network Events. Omit or sanitise sensitive data before reporting.
createApiRequestStateProviderOkHttpInterceptor
fun createApiRequestStateProviderOkHttpInterceptor(
captureRequestBody: Boolean = false,
captureResponseBody: Boolean = false,
transformRequest: (Request) -> Request? = { it },
transformResponse: (Response) -> Response? = { it },
redactedHeaders: Set<String> = emptySet(),
skippedHeaders: Set<String> = emptySet(),
redactedUrlParameters: Set<String> = emptySet(),
skippedUrlParameters: Set<String> = emptySet()
): Interceptor
Request, Response, and Interceptor are OkHttp types. Apps using this integration must declare OkHttp in their compile dependencies. Manual reporting does not require that app dependency.
Create after Coryn.init(), then install as an application interceptor using OkHttpClient.Builder.addInterceptor. Java static overloads can omit trailing options, including every option.
val client = OkHttpClient.Builder()
.addInterceptor(Coryn.createApiRequestStateProviderOkHttpInterceptor())
.build()
| Option | Behaviour |
|---|---|
captureRequestBody | Opt into previews of repeatable, non-duplex, textual bodies of known length up to 8,192 bytes. |
captureResponseBody | Opt into textual previews up to 8,192 bytes. Peeking can read ahead and wait for bytes; keep disabled for streaming clients. |
transformRequest, transformResponse | Return sanitised diagnostic copies, or null to skip the Event. Do not consume or close the supplied bodies. |
redactedHeaders | Replace matching request/response header values with <redacted>, keeping their names. |
skippedHeaders | Omit matching request/response headers. |
redactedUrlParameters | Replace matching query parameter values, keeping their names. |
skippedUrlParameters | Omit matching query parameters. |
Names match case-insensitively. Skipping takes precedence over redaction. Rule sets are copied at interceptor creation. Built-in redaction covers standard authentication/cookie/API-key headers and common secret query names; it does not identify every app-specific secret. URL credentials and fragments are omitted, and query values are reported separately.
Transforms, body previews and API request reporting run synchronously on the caller's interceptor thread before the response is returned. Diagnostic copies do not replace the request sent by OkHttp or the response returned to the app. Reporting and transform failures do not replace the host call's response or original transport exception.
Only requests starting during active recording are eligible, and reports submitted after recording stops are ignored. One application-interceptor invocation reports one logical call, including retries and redirects. Duration ends when response headers arrive or transport fails; it excludes response-body consumption. Unsupported bodies are omitted. Event streams, NDJSON, and JSON-sequence response previews are skipped; filter other streaming formats in your app.
See the API Requests guide for the full redaction list, filtering examples, body restrictions, and Java usage.
Intentional redaction, omission, or disabled body capture does not itself imply truncation.