override def handleRequest()

in utils/src/main/scala/com/google/example/o11y/cask/TraceWrappedHandler.scala [33:58]


  override def handleRequest(exchange: HttpServerExchange): Unit =
    Using.Manager { use =>
      use(GlobalOpenTelemetry.getPropagators.getTextMapPropagator.extract(Context.current(), exchange, UndertowTextMapGetter).makeCurrent())
      val spanBuilder =
        tracer.spanBuilder(spanName(exchange))
          .setSpanKind(SpanKind.SERVER)
          .setAttribute(HttpSemconv.clientAddress, exchange.getConnection.getPeerAddress.toString)
          .setAttribute(HttpSemconv.serverAddress, exchange.getHostName)
          .setAttribute(HttpSemconv.serverPort, exchange.getHostPort.toLong)
          .setAttribute(HttpSemconv.urlPath, exchange.getRequestPath)
          .setAttribute(HttpSemconv.urlQuery, exchange.getQueryString)
          .setAttribute(HttpSemconv.urlScheme, exchange.getRequestScheme)
      val span: Span = spanBuilder.startSpan()
      use(span.makeCurrent())
      try underlying.handleRequest(exchange)
      catch
        case e: Exception =>
          span.recordException(e)
          throw e
      finally
        try
          span.setAttribute(HttpSemconv.httpStatusCode, exchange.getStatusCode)
          // TODO - set error appropriately
          // TODO - check response sizes
        finally span.end()
    }