Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ class SttpBackendTracer[F[_], G[_], +P, Ctx](
_ <- childSpan.putAll(reqHeaderAttrs ++ reqExtraAttrs: _*)
resp <- lower(ctxBackend.send(req))
_ <- childSpan.setStatus(SttpStatusMapping.statusToSpanStatus(resp.statusText, resp.code))
respHttpAttrs = SttpResponse.toAttributes(resp)
respHeaderAttrs = SttpHeaders.responseFields(Headers(resp.headers), dropHeadersWhen)
// responseAttributesGetter could be expensive, so only call if the span is sampled
respExtraAttrs = if (isSampled) responseAttributesGetter.get(resp) else Map.empty
_ <- childSpan.putAll(respHeaderAttrs ++ respExtraAttrs: _*)
_ <- childSpan.putAll(respHttpAttrs ++ respHeaderAttrs ++ respExtraAttrs: _*)
} yield resp
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ object SttpRequest {
private final val ipv6Regex =
"^(?:(?:(?:[A-F0-9]{1,4}:){6}|(?=(?:[A-F0-9]{0,4}:){0,6}(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$)(([0-9A-F]{1,4}:){0,5}|:)((:[0-9A-F]{1,4}){1,5}:|:))(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}|(?=(?:[A-F0-9]{0,4}:){0,7}[A-F0-9]{0,4}$)(([0-9A-F]{1,4}:){1,7}|:)((:[0-9A-F]{1,4}){1,7}|:))$".r

def toAttributes[T, R](req: Request[T, R]): Map[String, AttributeValue] =
req.uri.host.map { host =>
val key = host.toUpperCase match {
case ipv4Regex(_*) => SemanticAttributeKeys.remoteServiceIpv4
case ipv6Regex(_*) => SemanticAttributeKeys.remoteServiceIpv6
case _ => SemanticAttributeKeys.remoteServiceHostname
}
def toAttributes[T, R](req: Request[T, R]): Map[String, AttributeValue] = {
Map(
SemanticAttributeKeys.httpUrl -> StringValue(req.uri.toString()),
SemanticAttributeKeys.httpMethod -> StringValue(req.method.method)
) ++
req.uri.host.map { host =>
val key = host.toUpperCase match {
case ipv4Regex(_*) => SemanticAttributeKeys.remoteServiceIpv4
case ipv6Regex(_*) => SemanticAttributeKeys.remoteServiceIpv6
case _ => SemanticAttributeKeys.remoteServiceHostname
}

key -> StringValue(host)
}.toMap ++ req.uri.port.map(port => SemanticAttributeKeys.remoteServicePort -> LongValue(port.toLong))
key -> StringValue(host)
}.toMap ++ req.uri.port.map(port => SemanticAttributeKeys.remoteServicePort -> LongValue(port.toLong))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package trace4cats.sttp.client3

import sttp.client3.Response
import trace4cats.model.{AttributeValue, SemanticAttributeKeys}

object SttpResponse {
def toAttributes[T](res: Response[T]): List[(String, AttributeValue)] =
List(
SemanticAttributeKeys.httpStatusCode -> res.code.code,
SemanticAttributeKeys.httpStatusMessage -> res.statusText
)
}