-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add open-telemetry sync tracing backend wrapper; rename otel artifact (…
- Loading branch information
Showing
12 changed files
with
389 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...entelemetry-backend/src/main/scala/sttp/client4/opentelemetry/OpenTelemetryDefaults.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package sttp.client4.opentelemetry | ||
|
||
import sttp.client4.GenericRequest | ||
import io.opentelemetry.api.common.Attributes | ||
import io.opentelemetry.semconv.HttpAttributes | ||
import sttp.client4.Response | ||
import io.opentelemetry.semconv.UrlAttributes | ||
import io.opentelemetry.semconv.ErrorAttributes | ||
import io.opentelemetry.semconv.ServerAttributes | ||
import io.opentelemetry.api.common.AttributesBuilder | ||
|
||
object OpenTelemetryDefaults { | ||
|
||
/** @see https://opentelemetry.io/docs/specs/semconv/http/http-spans/#name */ | ||
def spanName(request: GenericRequest[_, _]): String = s"${request.method.method}" | ||
|
||
/** @see https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#http-client */ | ||
def requestAttributes(request: GenericRequest[_, _]): Attributes = requestAttributesBuilder(request).build() | ||
|
||
/** @see | ||
* https://opentelemetry.io/docs/specs/semconv/http/http-spans/#http-client (full url is required for tracing, but | ||
* not for metrics) | ||
*/ | ||
def requestAttributesWithFullUrl(request: GenericRequest[_, _]): Attributes = | ||
requestAttributesBuilder(request).put(UrlAttributes.URL_FULL, request.uri.toString()).build() | ||
|
||
private def requestAttributesBuilder(request: GenericRequest[_, _]): AttributesBuilder = | ||
Attributes.builder | ||
.put(HttpAttributes.HTTP_REQUEST_METHOD, request.method.method) | ||
.put(UrlAttributes.URL_FULL, request.uri.toString()) | ||
.put(ServerAttributes.SERVER_ADDRESS, request.uri.host.getOrElse("unknown")) | ||
.put(ServerAttributes.SERVER_PORT, request.uri.port.getOrElse(80)) | ||
|
||
/** @see https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#http-client */ | ||
def responseAttributes(request: GenericRequest[_, _], response: Response[_]): Attributes = | ||
Attributes.builder | ||
.put(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, response.code.code.toLong: java.lang.Long) | ||
.build() | ||
|
||
def errorAttributes(e: Throwable): Attributes = { | ||
val errorType = e match { | ||
case _: java.net.UnknownHostException => "unknown_host" | ||
case _ => e.getClass.getSimpleName | ||
} | ||
Attributes.builder().put(ErrorAttributes.ERROR_TYPE, errorType).build() | ||
} | ||
|
||
val instrumentationScopeName = "sttp-client4" | ||
|
||
val instrumentationScopeVersion = "1.0.0" | ||
} |
Oops, something went wrong.