In Ktor client, `Attributes` can be used to pass ...
# ktor
a
In Ktor client,
Attributes
can be used to pass custom data throughout the request lifecycle. When using the
OkHttpEngine
, I'm looking for a way to map these Ktor
Attributes
to OkHttp
Tags
. As the current
OkHttpEngine
implementation within KTOR doesn't seem to bridge this , how can I achieve this mapping?
a
Can you give an example of an attribute/tag pair that needs to be mapped? When should the mapping occur?
a
Suppose we want to attach a
Map<String, Any>
as a custom analytics container to a Ktor request. This map might store: • DNS lookup time • TLS handshake duration • Connection establishment time • Or even application-level metadata At any point, whether inside a Ktor plugin or OkHttp interceptor or in the okhttp event listener callbacks , we should be able to: 1. Add or update values like
"dnsLatency" -> 1.2s"
2. Access this map through
request.tag()
in OkHttp This bridge between Ktor
Attributes
and OkHttp
Tags
allows developers to attach analytics or other contextual metadata to a request and access it across different layers (Ktor and OkHttp). This is especially useful for observability, debugging, and fine-grained request monitoring. Also in current okhttp engine implementation , HttpRequestData have attributes only mapping this to okhttp tag is missing
Untitled
a
Unfortunately, I cannot see how the attributes and tags could be mapped without fixing the OkHttp engine implementation. Can you please file a feature request to address this limitation?
a
Sure
@Aleksei Tirman [JB] I believe this should be the case for Darwin Engine also , it must be providing us some way to move our custom data type from request to response cycle