Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to extract span parent from request headers in caliban-tracing #1673

Open
jeejeeone opened this issue Apr 3, 2023 · 0 comments
Labels
enhancement New feature or request server Issue related to caliban server

Comments

@jeejeeone
Copy link
Contributor

Provide a way to extract span parent from request headers in caliban-tracing. This will enable (easy) tracing across different microservices etc using caliban-tracing. I'm unsure what request headers should be injected into tracing context. Possibly it would be user defined? Maybe some default implementation can be provided for some specification like B3?

Some quick poc of a RequestInterceptor:

  case class TracingContextInterceptor(spanName: String, includeHeaders: Set[String])
      extends RequestInterceptor[Tracing] {
    override def apply[R <: Tracing, A](request: ServerRequest)(e: ZIO[R, TapirResponse, A]): ZIO[R, TapirResponse, A] =
      ZIO.serviceWithZIO[Tracing] { tracing =>
        val headers = request.headers
          .map(header => header.name -> header.value)
          .toMap
          .collect {
            case (k, v) if includeHeaders.contains(k) => (k, v)
          }
          .toSeq

        val carrier: mutable.Map[String, String] = mutable.Map(headers: _*)

        tracing.extractSpan(
          TraceContextPropagator.default,
          IncomingContextCarrier.default(carrier),
          spanName
        )(e)
      }
  }
@ghostdogpr ghostdogpr added enhancement New feature or request server Issue related to caliban server labels Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server Issue related to caliban server
Projects
None yet
Development

No branches or pull requests

2 participants