Skip to content

Commit

Permalink
Merge pull request #1428 from softwaremill/opentelemetry-metrics-backend
Browse files Browse the repository at this point in the history
Opentelemetry metrics backend
  • Loading branch information
Pask423 authored May 6, 2022
2 parents 639172d + d65e1e3 commit e76a46e
Show file tree
Hide file tree
Showing 12 changed files with 440 additions and 455 deletions.
26 changes: 6 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ lazy val allAggregates = projectsWithOptionalNative ++
jsoniter.projectRefs ++
sprayJson.projectRefs ++
playJson.projectRefs ++
openTracingBackend.projectRefs ++
prometheusBackend.projectRefs ++
openTelemetryBackend.projectRefs ++
openTelemetry.projectRefs ++
finagleBackend.projectRefs ++
armeriaBackend.projectRefs ++
armeriaScalazBackend.projectRefs ++
Expand Down Expand Up @@ -891,26 +890,14 @@ lazy val prometheusBackend = (projectMatrix in file("metrics/prometheus-backend"
.jvmPlatform(scalaVersions = scala2 ++ scala3)
.dependsOn(core)

lazy val openTracingBackend = (projectMatrix in file("metrics/open-tracing-backend"))
lazy val openTelemetry = (projectMatrix in file("metrics/open-telemetry"))
.settings(commonJvmSettings)
.settings(
name := "opentracing-backend",
libraryDependencies ++= Seq(
"io.opentracing" % "opentracing-api" % "0.33.0",
"io.opentracing" % "opentracing-mock" % "0.33.0" % Test
),
scalaTest
)
.jvmPlatform(scalaVersions = scala2 ++ scala3)
.dependsOn(core)

lazy val openTelemetryBackend = (projectMatrix in file("metrics/open-telemetry-backend"))
.settings(commonJvmSettings)
.settings(
name := "opentelemetry-backend",
name := "opentelemetry",
libraryDependencies ++= Seq(
"io.opentelemetry" % "opentelemetry-api" % "1.13.0",
"io.opentelemetry" % "opentelemetry-sdk-testing" % "1.13.0" % Test
"io.opentelemetry" % "opentelemetry-sdk-testing" % "1.13.0" % Test,
"io.opentelemetry" % "opentelemetry-sdk-metrics-testing" % "1.13.0-alpha" % Test
),
scalaTest
)
Expand Down Expand Up @@ -1043,9 +1030,8 @@ lazy val docs: ProjectMatrix = (projectMatrix in file("generated-docs")) // impo
okhttpBackend,
// okhttpMonixBackend,
http4sBackend,
openTracingBackend,
prometheusBackend,
openTelemetryBackend,
openTelemetry,
slf4jBackend
)
.jvmPlatform(scalaVersions = List(scala2_13))
3 changes: 2 additions & 1 deletion docs/backends/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ All backends that support asynchronous/non-blocking streams, also support server
There are also backends which wrap other backends to provide additional functionality. These include:

* `TryBackend`, which safely wraps any exceptions thrown by a synchronous backend in `scala.util.Try`
* `OpenTracingBackend`, for OpenTracing-compatible distributed tracing. See the [dedicated section](wrappers/opentracing.md).
* `OpenTelemetryTracingBackend`, for OpenTelemetry-compatible distributed tracing. See the [dedicated section](wrappers/opentelemetry.md).
* `OpenTelemetryMetricsBackend`, for OpenTelemetry-compatible metrics. See the [dedicated section](wrappers/opentelemetry.md).
* `PrometheusBackend`, for gathering Prometheus-format metrics. See the [dedicated section](wrappers/prometheus.md).
* extendable logging backends (with an slf4j implementation) backends. See the [dedicated section](wrappers/logging.md).
* `ResolveRelativeUrisBackend` to resolve relative URIs given a base URI, or an arbitrary effectful function
Expand Down
54 changes: 47 additions & 7 deletions docs/backends/wrappers/opentelemetry.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Opentelemetry backend
# Opentelemetry

To use, add the following dependency to your project:
Both backends from below depend only on [opentelemetry](https://github.com/open-telemetry/opentelemetry-java).
The opentelemetry are type of wrapper backends, so they wrap any other backend. They require an instance of opentelemetry.

To use, any of below backends, add the following dependency to your project:

```
"com.softwaremill.sttp.client3" %% "opentelemetry-backend" % "@VERSION@"
"com.softwaremill.sttp.client3" %% "opentelemetry" % "@VERSION@"
```

This backend depends only on [opentelemetry](https://github.com/open-telemetry/opentelemetry-java).
### Opentelemetry tracing backend

The opentelemetry backend wraps any other backend, but it's useless without an instance of opentelemetry. To obtain instance of OpenTelemetryBackend:
To obtain instance of OpenTelemetryTracingBackend:

```scala
OpenTelemetryBackend(
OpenTelemetryTracingBackend(
sttpBackend,
openTelemetry
)
Expand All @@ -21,9 +23,47 @@ OpenTelemetryBackend(
By default, the span is named after the HTTP method (e.g "HTTP POST") as [recommended by OpenTelemetry](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#name) for HTTP clients.
It can be customized by setting the third argument in constructor:
```scala
OpenTelemetryBackend(
OpenTelemetryTracingBackend(
sttpBackend,
openTelemetry,
request => s"HTTP ${request.method.method}"
)
```

There is also the possibility to customize tracer name and version by using constructor parameter:
```scala
OpenTelemetryTracingBackend(
sttpBackend,
openTelemetry,
tracerConfig = Some(TracerConfig("my_custom_tracer_name", "1.0.0"))
)
```

### Opentelemetry metrics backend

To obtain instance of OpenTelemetryMetricsBackend:

```scala
OpenTelemetryMetricsBackend(
sttpBackend,
openTelemetry
)
```

All counters have provided default names, but the names can be customized by setting correct parameters in constructor:
```scala
OpenTelemetryMetricsBackend(
sttpBackend,
openTelemetry,
responseToSuccessCounterMapper = _ => Some(CollectorConfig("my_custom_counter_name"))
)
```

There is also the possibility to customize meter name and version by using constructor parameter:
```scala
OpenTelemetryMetricsBackend(
sttpBackend,
openTelemetry,
meterConfig = Some(MeterConfig("my_custom_meter_name", "1.0.0"))
)
```
121 changes: 0 additions & 121 deletions docs/backends/wrappers/opentracing.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ Development and maintenance of sttp client is sponsored by [SoftwareMill](https:
:maxdepth: 2
:caption: Backend wrappers
backends/wrappers/opentracing
backends/wrappers/opentelemetry
backends/wrappers/prometheus
backends/wrappers/logging
Expand Down
Loading

0 comments on commit e76a46e

Please sign in to comment.