Skip to content

Commit

Permalink
Add traces to all effectful methods for zio.http.codec package (#2317)
Browse files Browse the repository at this point in the history
  • Loading branch information
zarinfam authored Jul 28, 2023
1 parent dd07127 commit 500cbb7
Show file tree
Hide file tree
Showing 28 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions zio-http/src/main/scala/zio/http/codec/Alternator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package zio.http.codec

import zio.ZNothing
import zio.stacktracer.TracingImplicits.disableAutoTrace

/**
* A alternator is a type class responsible for combining invariant type
Expand Down
2 changes: 2 additions & 0 deletions zio-http/src/main/scala/zio/http/codec/Combiner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace

/**
* A combiner is a type class responsible for combining invariant type
* parameters using a tuple. It is used to compose the parameters of the
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/codec/ContentCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace
object ContentCodec extends ContentCodecs
2 changes: 2 additions & 0 deletions zio-http/src/main/scala/zio/http/codec/ContentCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.stream.ZStream

import zio.schema.Schema
Expand Down
2 changes: 2 additions & 0 deletions zio-http/src/main/scala/zio/http/codec/Doc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.html

/**
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/codec/HeaderCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace
object HeaderCodec extends HeaderCodecs
2 changes: 2 additions & 0 deletions zio-http/src/main/scala/zio/http/codec/HeaderCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package zio.http.codec

import scala.util.Try

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.Header
import zio.http.Header.HeaderType

Expand Down
1 change: 1 addition & 0 deletions zio-http/src/main/scala/zio/http/codec/HttpCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import scala.language.implicitConversions
import scala.reflect.ClassTag

import zio._
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.stream.ZStream

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package zio.http.codec
import scala.util.control.NoStackTrace

import zio.Cause
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.{Path, Status}

Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/codec/HttpCodecType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace
sealed trait HttpCodecType

object HttpCodecType {
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/codec/MethodCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace
object MethodCodec extends MethodCodecs
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/codec/MethodCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace
private[codec] trait MethodCodecs {
import HttpCodecType.Method

Expand Down
1 change: 1 addition & 0 deletions zio-http/src/main/scala/zio/http/codec/PathCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import scala.annotation.tailrec
import scala.collection.immutable.ListMap
import scala.language.implicitConversions

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Chunk, NonEmptyChunk}

import zio.http.Path
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/codec/QueryCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace
object QueryCodec extends QueryCodecs
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/codec/QueryCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace
private[codec] trait QueryCodecs {
def query(name: String): QueryCodec[String] =
HttpCodec.Query(name, TextCodec.string)
Expand Down
1 change: 1 addition & 0 deletions zio-http/src/main/scala/zio/http/codec/RichTextCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.lang.Integer.parseInt
import scala.annotation.tailrec
import scala.collection.immutable.BitSet

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Chunk, NonEmptyChunk}

/**
Expand Down
1 change: 1 addition & 0 deletions zio-http/src/main/scala/zio/http/codec/SegmentCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package zio.http.codec
import scala.language.implicitConversions

import zio.Chunk
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.Path

Expand Down
1 change: 1 addition & 0 deletions zio-http/src/main/scala/zio/http/codec/SimpleCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package zio.http.codec
import zio.stacktracer.TracingImplicits.disableAutoTrace

/**
* A simple codec is either equal to a given value, or unconstrained within a
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/codec/StatusCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/

package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace
object StatusCodec extends StatusCodecs
3 changes: 2 additions & 1 deletion zio-http/src/main/scala/zio/http/codec/StatusCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package zio.http.codec

import zio.http.Status
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.Status
private[codec] trait StatusCodecs {
def status(status: Status): StatusCodec[Unit] = HttpCodec.Status(SimpleCodec.Specified(status))

Expand Down
2 changes: 2 additions & 0 deletions zio-http/src/main/scala/zio/http/codec/TextCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package zio.http.codec

import java.util.UUID

import zio.stacktracer.TracingImplicits.disableAutoTrace

/**
* A [[zio.http.codec.TextCodec]] defines a codec for a text fragment. The text
* fragment can be decoded into a value, or the value can be encoded into a text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package zio.http.codec.internal

import zio.http.codec.HttpCodec
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.codec.HttpCodec
private[http] final case class Atomized[A](
method: A,
status: A,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package zio.http.codec.internal

import zio.Chunk
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.codec.HttpCodec._
import zio.http.codec._
Expand Down
19 changes: 11 additions & 8 deletions zio-http/src/main/scala/zio/http/codec/internal/BodyCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package zio.http.codec.internal

import zio._
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.stream.ZStream

Expand All @@ -41,12 +42,12 @@ private[internal] sealed trait BodyCodec[A] { self =>
/**
* Attempts to decode the `A` from a body using the given codec.
*/
def decodeFromBody(body: Body, codec: BinaryCodec[Element]): IO[Throwable, A]
def decodeFromBody(body: Body, codec: BinaryCodec[Element])(implicit trace: Trace): IO[Throwable, A]

/**
* Encodes the `A` to a body in the given codec.
*/
def encodeToBody(value: A, codec: BinaryCodec[Element]): Body
def encodeToBody(value: A, codec: BinaryCodec[Element])(implicit trace: Trace): Body

/**
* Erases the type for easier use in the internal implementation.
Expand Down Expand Up @@ -78,9 +79,9 @@ private[internal] object BodyCodec {
case object Empty extends BodyCodec[Unit] {
type Element = Unit

def decodeFromBody(body: Body, codec: BinaryCodec[Unit]): IO[Nothing, Unit] = ZIO.unit
def decodeFromBody(body: Body, codec: BinaryCodec[Unit])(implicit trace: Trace): IO[Nothing, Unit] = ZIO.unit

def encodeToBody(value: Unit, codec: BinaryCodec[Unit]): Body = Body.empty
def encodeToBody(value: Unit, codec: BinaryCodec[Unit])(implicit trace: Trace): Body = Body.empty

def schema: Schema[Unit] = Schema[Unit]

Expand All @@ -91,26 +92,28 @@ private[internal] object BodyCodec {

final case class Single[A](schema: Schema[A], mediaType: Option[MediaType], name: Option[String])
extends BodyCodec[A] {
def decodeFromBody(body: Body, codec: BinaryCodec[A]): IO[Throwable, A] = {
def decodeFromBody(body: Body, codec: BinaryCodec[A])(implicit trace: Trace): IO[Throwable, A] = {
if (schema == Schema[Unit]) ZIO.unit.asInstanceOf[IO[Throwable, A]]
else
body.asChunk.flatMap { chunk =>
ZIO.fromEither(codec.decode(chunk))
}
}

def encodeToBody(value: A, codec: BinaryCodec[A]): Body =
def encodeToBody(value: A, codec: BinaryCodec[A])(implicit trace: Trace): Body =
Body.fromChunk(codec.encode(value))

type Element = A
}

final case class Multiple[E](schema: Schema[E], mediaType: Option[MediaType], name: Option[String])
extends BodyCodec[ZStream[Any, Nothing, E]] {
def decodeFromBody(body: Body, codec: BinaryCodec[E]): IO[Throwable, ZStream[Any, Nothing, E]] =
def decodeFromBody(body: Body, codec: BinaryCodec[E])(implicit
trace: Trace,
): IO[Throwable, ZStream[Any, Nothing, E]] =
ZIO.succeed((body.asStream >>> codec.streamDecoder).orDie)

def encodeToBody(value: ZStream[Any, Nothing, E], codec: BinaryCodec[E]): Body =
def encodeToBody(value: ZStream[Any, Nothing, E], codec: BinaryCodec[E])(implicit trace: Trace): Body =
Body.fromStream(value >>> codec.streamEncoder)

type Element = E
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.time._
import java.util.UUID

import zio._
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.stream.ZStream

Expand Down Expand Up @@ -145,7 +146,7 @@ private[codec] object EncoderDecoder {
erased.encodeToBody(_, jsonCodec)
}

private val formFieldEncoders: Chunk[(String, Any) => FormField] =
private val formFieldEncoders: Chunk[(String, Any) => FormField] =
flattened.content.map { bodyCodec => (name: String, value: Any) =>
{
val erased = bodyCodec.erase
Expand All @@ -162,6 +163,9 @@ private[codec] object EncoderDecoder {
}
}
}

implicit val trace: Trace = Trace.empty

private val jsonDecoders: Chunk[Body => IO[Throwable, _]] =
flattened.content.map { bodyCodec =>
val jsonCodec = JsonCodec.schemaBasedBinaryCodec(bodyCodec.schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package zio.http.codec.internal

import scala.util.control.NoStackTrace

import zio.stacktracer.TracingImplicits.disableAutoTrace
case object HaltException
extends RuntimeException("This exception is used only for control flow purposes")
with NoStackTrace
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package zio.http.codec.internal

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.codec.HttpCodec._
import zio.http.codec.{HttpCodec, HttpCodecError}

Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/codec/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

package zio.http

import zio.stacktracer.TracingImplicits.disableAutoTrace
package object codec {
type ContentCodec[A] = HttpCodec[HttpCodecType.Content, A]
type HeaderCodec[A] = HttpCodec[HttpCodecType.Header, A]
Expand Down

0 comments on commit 500cbb7

Please sign in to comment.