Skip to content

Latest commit

 

History

History
280 lines (199 loc) · 10.3 KB

examples.md

File metadata and controls

280 lines (199 loc) · 10.3 KB

Code Examples

This example shows a simple example of how to use Trace4Cats without the need to inject a root span via a Kleisli (see the Inject example below).

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

This example shows a simple example of how to use Trace4Cats with ZIO without the need to inject a root span via the environment (see the Inject example below).

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how spans may be used in a for comprehension along side other Resources. Also shows how multiple completers may be combined using a monoid in the AllCompleters object.

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"
"io.janstenpickle" %% "trace4cats-jaeger-thrift-exporter" % "0.10.1"
"io.janstenpickle" %% "trace4cats-log-exporter" % "0.10.1"
"io.janstenpickle" %% "trace4cats-opentelemetry-otlp-grpc-exporter" % "0.10.1"
"io.janstenpickle" %% "trace4cats-opentelemetry-otlp-http-exporter" % "0.10.1"
"io.janstenpickle" %% "trace4cats-opentelemetry-jaeger-exporter" % "0.10.1"
"io.janstenpickle" %% "trace4cats-stackdriver-grpc-exporter" % "0.10.1"
"io.janstenpickle" %% "trace4cats-stackdriver-http-exporter" % "0.10.1"
"io.janstenpickle" %% "trace4cats-datadog-http-exporter" % "0.10.1"
"io.janstenpickle" %% "trace4cats-newrelic-http-exporter" % "0.10.1"

Demonstrates how the callstack may be traced using the Trace typeclass. This functionality has been slightly adapted from Natchez, but gives you the ability to set the span's kind on creation and status during execution.

It also shows how via the io.janstenpickle.trace4cats.natchez.conversions._ import you can implicitly convert to and from Natchez's Trace typeclass so if you have imported some library that makes use of Natchez you can interoperate with Trace4Cats.

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-inject" % "0.10.1"
"io.janstenpickle" %% "trace4cats-natchez" % "0.10.1" // required only for interop
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how to use the Trace typeclass with ZIO environment instead of a Kleisli. A Trace instance is provided with the following import:

io.janstenpickle.trace4cats.inject.zio._

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-inject-zio" % "0.10.1"
"io.janstenpickle" %% "trace4cats-natchez" % "0.10.1" // required only for interop
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how the callstack may be traced with Trace4Cats using the Natchez Trace typeclass.

It also shows how via the io.janstenpickle.trace4cats.natchez.conversions._ import you can implicitly convert to and from Trace4Cats' Trace typeclass for interopability.

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-inject" % "0.10.1" // required only for interop
"io.janstenpickle" %% "trace4cats-natchez" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how a span can be propagated through an FS2 stream. Uses the Writer monad to include an [Span] along side each element. Implicit methods are provided with the import io.janstenpickle.trace4cats.fs2.syntax.all._ to lift an [EntryPoint] into the stream and use it to perform traced operations within the stream, propagating a span between closures.

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-fs2" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Very similar to the FS2 example above, however the effect type on the stream is lifted to the traced effect type allowing for traced operations with the same effect type to be performed within the stream. This avoids the need for having to use two type parameters when passing around a TracedStream.

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-fs2" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how to use Trace4Cats with Http4s routes and clients. Span contexts are propagated via HTTP headers, and span status is derived from HTTP status codes. Implicit methods on HttpRoutes and Client are provided with the imports:

io.janstenpickle.trace4cats.http4s.server.syntax._
io.janstenpickle.trace4cats.http4s.client.syntax._

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-inject" % "0.10.1"
"io.janstenpickle" %% "trace4cats-http4s-client" % "0.10.1"
"io.janstenpickle" %% "trace4cats-http4s-server" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how to use Trace4Cats with Http4s routes and clients. Span contexts are propagated via HTTP headers, and span status is derived from HTTP status codes. Implicit methods on HttpRoutes and Client are provided with the imports:

io.janstenpickle.trace4cats.http4s.server.syntax._
io.janstenpickle.trace4cats.http4s.client.syntax._
io.janstenpickle.trace4cats.inject.zio._

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-inject-zio" % "0.10.1"
"io.janstenpickle" %% "trace4cats-http4s-client" % "0.10.1"
"io.janstenpickle" %% "trace4cats-http4s-server" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how to use Trace4Cats with an Sttp backend. Span contexts are propagated via HTTP headers, and span status is derived from HTTP status codes.

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-inject" % "0.10.1"
"io.janstenpickle" %% "trace4cats-sttp-client" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how to use Trace4Cats with an Sttp backend and ZIO. Span contexts are propagated via HTTP headers, and span status is derived from HTTP status codes.

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-inject-zio" % "0.10.1"
"io.janstenpickle" %% "trace4cats-sttp-client" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how to use the attribute filter with an exporter in order to remove sensitive attributes from spans. Note that this would more commonly be configured on the collector.

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-filtering" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"

Demonstrates how to use tail samplers with an exporter in order to sample spans after they have been created. Note that this would more commonly be configured on the collector.

Requires:

"io.janstenpickle" %% "trace4cats-core" % "0.10.1"
"io.janstenpickle" %% "trace4cats-filtering" % "0.10.1"
"io.janstenpickle" %% "trace4cats-avro-exporter" % "0.10.1"