Skip to content

Commit

Permalink
Add required traces to the package zio.http.netty (zio#2322)
Browse files Browse the repository at this point in the history
* Add required traces to the package zio.http.netty

* remove import zio.stacktracer.TracingImplicits.disableAutoTrace
from NettyDriver.scala
  • Loading branch information
gregor-rayman authored and 987Nabil committed Jul 28, 2023
1 parent 62b2ea0 commit 21d3ccd
Show file tree
Hide file tree
Showing 31 changed files with 43 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package zio.http.netty

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Chunk, ChunkBuilder, Trace, Unsafe}

import zio.http.netty.AsyncBodyReader.State
Expand All @@ -24,7 +25,6 @@ import zio.http.netty.NettyBody.UnsafeAsync
import io.netty.buffer.ByteBufUtil
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
import io.netty.handler.codec.http.{HttpContent, LastHttpContent}

abstract class AsyncBodyReader(implicit trace: Trace) extends SimpleChannelInboundHandler[HttpContent](true) {

protected val unsafeClass: Unsafe = Unsafe.unsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
package zio.http.netty

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

import io.netty.channel._
import io.netty.channel.embedded.EmbeddedChannel
import io.netty.channel.epoll._
import io.netty.channel.kqueue._
import io.netty.channel.socket.nio._
import io.netty.incubator.channel.uring._

object ChannelFactories {

private[zio] def make[A <: Channel](channel: => A)(implicit trace: Trace): UIO[ChannelFactory[A]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package zio.http.netty
import java.util.concurrent.Executor

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

import io.netty.channel._
import io.netty.channel.epoll.{Epoll, EpollEventLoopGroup}
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/netty/NettyBody.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package zio.http.netty

import java.nio.charset.Charset

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Chunk, Task, Trace, Unsafe, ZIO}

import zio.stream.ZStream
Expand All @@ -29,7 +30,6 @@ import zio.http.{Body, Boundary, Header, Headers, MediaType}
import io.netty.buffer.{ByteBuf, ByteBufUtil}
import io.netty.channel.{Channel => JChannel}
import io.netty.util.AsciiString

object NettyBody extends BodyEncoding {

/**
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/main/scala/zio/http/netty/NettyBodyWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package zio.http.netty

import zio.Chunk.ByteArray
import zio._
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.Body
import zio.http.Body._
Expand All @@ -26,10 +27,9 @@ import zio.http.netty.NettyBody.{AsciiStringBody, AsyncBody, ByteBufBody, Unsafe
import io.netty.buffer.Unpooled
import io.netty.channel._
import io.netty.handler.codec.http.{DefaultHttpContent, LastHttpContent}

object NettyBodyWriter {

def write(body: Body, ctx: ChannelHandlerContext): ZIO[Any, Throwable, Boolean] =
def write(body: Body, ctx: ChannelHandlerContext)(implicit trace: Trace): ZIO[Any, Throwable, Boolean] =
body match {
case body: ByteBufBody =>
ZIO.succeed {
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/netty/NettyChannel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package zio.http.netty

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Task, Trace, UIO, ZIO}

import zio.http.Channel

import io.netty.channel.{Channel => JChannel, ChannelFuture => JChannelFuture}

final case class NettyChannel[-A](
private val channel: JChannel,
private val convert: A => Any,
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/netty/NettyConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package zio.http.netty

import zio.Config
import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.netty.NettyConfig.LeakDetectionLevel

import io.netty.util.ResourceLeakDetector

final case class NettyConfig(
leakDetectionLevel: LeakDetectionLevel,
channelType: ChannelType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package zio.http.netty
import java.time.Duration

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

import zio.http.Cookie.SameSite
import zio.http.internal.CookieEncoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package zio.http.netty
import java.util.concurrent.CancellationException

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

import io.netty.util.concurrent.{Future, GenericFutureListener}

Expand Down
2 changes: 2 additions & 0 deletions zio-http/src/main/scala/zio/http/netty/NettyResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package zio.http.netty

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Promise, Trace, Unsafe, ZIO}

import zio.http.Response.NativeResponse
Expand All @@ -31,6 +32,7 @@ object NettyResponse {

final def make(ctx: ChannelHandlerContext, jRes: FullHttpResponse)(implicit
unsafe: Unsafe,
trace: Trace,
): NativeResponse = {
val status = Conversions.statusFromNetty(jRes.status())
val headers = Conversions.headersFromNetty(jRes.headers())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package zio.http.netty
import java.util.concurrent.ConcurrentHashMap

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

import zio.http._
import zio.http.netty.model.Conversions
Expand All @@ -31,7 +32,7 @@ private[zio] object NettyResponseEncoder {
private val frozenCache = new ConcurrentHashMap[Response, FullHttpResponse]()
private val frozenZioCache = new ConcurrentHashMap[Response, UIO[HttpResponse]]()

def encode(response: Response): ZIO[Any, Throwable, HttpResponse] = {
def encode(response: Response)(implicit trace: Trace): ZIO[Any, Throwable, HttpResponse] = {
val body = response.body
if (body.isComplete) {
val cachedValue = frozenZioCache.get(response)
Expand All @@ -47,7 +48,7 @@ private[zio] object NettyResponseEncoder {
}
}

def fastEncode(response: Response, bytes: Array[Byte])(implicit unsafe: Unsafe): FullHttpResponse =
def fastEncode(response: Response, bytes: Array[Byte])(implicit unsafe: Unsafe, trace: Trace): FullHttpResponse =
if (response.frozen) {
val encodedResponse = frozenCache.get(response)

Expand Down
5 changes: 4 additions & 1 deletion zio-http/src/main/scala/zio/http/netty/NettyRuntime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package zio.http.netty

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

import io.netty.channel._
import io.netty.util.concurrent.{Future, GenericFutureListener}
Expand Down Expand Up @@ -78,7 +79,9 @@ private[zio] trait NettyRuntime { self =>
)(implicit unsafe: Unsafe, trace: Trace): Unit =
run(ctx, ensured, interruptOnClose = false)(program)

private def closeListener(rtm: Runtime[Any], fiber: Fiber.Runtime[_, _]): GenericFutureListener[Future[_ >: Void]] =
private def closeListener(rtm: Runtime[Any], fiber: Fiber.Runtime[_, _])(implicit
trace: Trace,
): GenericFutureListener[Future[_ >: Void]] =
(_: Future[_ >: Void]) => {
val _ = rtm.unsafe.fork {
fiber.interrupt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package zio.http.netty

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

import zio.http.ChannelEvent.UserEvent
import zio.http.netty.client.ChannelState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package zio.http.netty.client

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.Status

sealed trait ChannelState { self =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package zio.http.netty.client

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

import zio.http.netty.{NettyBodyWriter, NettyResponse, NettyRuntime}
import zio.http.{Request, Response}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package zio.http.netty.client

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Promise, Trace}

import zio.http.Status
import zio.http.netty.{AsyncBodyReader, NettyFutureExecutor, NettyRuntime}

import io.netty.channel._
import io.netty.handler.codec.http.{HttpContent, LastHttpContent}

final class ClientResponseStreamHandler(
rtm: NettyRuntime,
onComplete: Promise[Throwable, ChannelState],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import java.io.{FileInputStream, InputStream}
import java.security.KeyStore
import javax.net.ssl.TrustManagerFactory

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.ClientSSLConfig

import io.netty.handler.ssl.util.InsecureTrustManagerFactory
import io.netty.handler.ssl.{SslContext, SslContextBuilder}

object ClientSSLConverter {
private def trustStoreToSslContext(trustStoreStream: InputStream, trustStorePassword: String): SslContext = {
val trustStore = KeyStore.getInstance("JKS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit
import scala.collection.mutable

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

import zio.http.ClientDriver.ChannelInterface
import zio.http._
Expand All @@ -32,7 +33,6 @@ import io.netty.channel.{Channel, ChannelFactory, ChannelHandler, EventLoopGroup
import io.netty.handler.codec.http.websocketx.{WebSocketClientProtocolHandler, WebSocketFrame => JWebSocketFrame}
import io.netty.handler.codec.http.{FullHttpRequest, HttpObjectAggregator}
import io.netty.handler.timeout.ReadTimeoutHandler

final case class NettyClientDriver private (
channelFactory: ChannelFactory[Channel],
eventLoopGroup: EventLoopGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.net.InetSocketAddress
import java.util.concurrent.TimeUnit

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

import zio.http.URL.Location
import zio.http._
Expand All @@ -36,7 +37,6 @@ import io.netty.channel.{
import io.netty.handler.codec.http.{HttpClientCodec, HttpContentDecompressor}
import io.netty.handler.proxy.HttpProxyHandler
import io.netty.handler.timeout.ReadTimeoutHandler

trait NettyConnectionPool extends ConnectionPool[JChannel]

object NettyConnectionPool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package zio.http.netty.client

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Task, Trace, ZIO}

import zio.http.Request
Expand All @@ -24,7 +25,6 @@ import zio.http.netty.model.Conversions

import io.netty.buffer.Unpooled
import io.netty.handler.codec.http.{DefaultFullHttpRequest, DefaultHttpRequest, HttpHeaderNames, HttpRequest}

private[zio] object NettyRequestEncoder {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package zio.http.netty.client

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Promise, Trace, Unsafe}

import zio.http.Response
import zio.http.netty.{NettyResponse, NettyRuntime}

import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
import io.netty.handler.codec.http.FullHttpResponse

final class WebSocketClientInboundHandler(
rtm: NettyRuntime,
onResponse: Promise[Throwable, Response],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package zio.http.netty.model

import scala.collection.AbstractIterator

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.Server.Config.CompressionOptions
import zio.http._
import zio.http.internal.{CaseMode, CharSequenceExtensions}
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/netty/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package zio.http

import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Trace, ZIO}

import io.netty.util.AsciiString

package object netty {

private[zio] object Names {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import zio.http.{ClientDriver, Driver, HttpApp, Server}
import io.netty.bootstrap.ServerBootstrap
import io.netty.channel._
import io.netty.util.ResourceLeakDetector

private[zio] final case class NettyDriver(
appRef: AppRef,
channelFactory: ChannelFactory[ServerChannel],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package zio.http.netty.server
import java.util.concurrent.TimeUnit

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

import zio.http.Server
import zio.http.Server.RequestStreaming
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

package zio.http.netty.server

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.SSLConfig.HttpBehaviour

import io.netty.channel.{ChannelFutureListener, ChannelHandlerContext, SimpleChannelInboundHandler}
import io.netty.handler.codec.http.{DefaultHttpResponse, HttpMessage, HttpResponseStatus, HttpVersion}

private[zio] class ServerHttpsHandler(httpBehaviour: HttpBehaviour) extends SimpleChannelInboundHandler[HttpMessage] {
override def channelRead0(ctx: ChannelHandlerContext, msg: HttpMessage): Unit = {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import scala.annotation.tailrec
import scala.util.control.NonFatal

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

import zio.http._
import zio.http.netty._
Expand All @@ -35,7 +36,6 @@ import io.netty.channel._
import io.netty.handler.codec.http._
import io.netty.handler.codec.http.websocketx.{WebSocketFrame => JWebSocketFrame, WebSocketServerProtocolHandler}
import io.netty.handler.timeout.ReadTimeoutException

@Sharable
private[zio] final case class ServerInboundHandler(
appRef: AppRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package zio.http.netty.server
import java.io.FileInputStream
import java.util

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.SSLConfig.{HttpBehaviour, Provider}
import zio.http.netty.Names
import zio.http.{SSLConfig, Server}
Expand All @@ -33,7 +35,6 @@ import io.netty.handler.ssl.ApplicationProtocolConfig.{
}
import io.netty.handler.ssl.util.SelfSignedCertificate
import io.netty.handler.ssl.{SslContext, SslHandler, _}

object SSLUtil {

implicit class SslContextBuilderOps(self: SslContextBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import io.netty.util.AsciiString

import java.text.SimpleDateFormat
import java.util.Date // scalafix:ok;

import zio.stacktracer.TracingImplicits.disableAutoTrace
private[zio] final class ServerTime(minDuration: Long) {

private var last: Long = System.currentTimeMillis()
Expand Down
Loading

0 comments on commit 21d3ccd

Please sign in to comment.