Trace4Cats示例Tapir端点
我正在学习不同的Scala图书馆,并进行了追踪。 Trace4Cats声称与Tapir端点集成在一起,我想在我的示例播放路由器中包含它,该路由器将Tapir与OpenAPI文档一起使用。
- 到目前为止,我已经提供了这些依赖性的追踪依赖性:
// Tracing
libraryDependencies += "io.janstenpickle" %% "trace4cats-core" % trace4CatsVersion
libraryDependencies += "io.janstenpickle" %% "trace4cats-inject" % trace4CatsVersion
libraryDependencies += "io.janstenpickle" %% "trace4cats-avro-exporter" % trace4CatsVersion
libraryDependencies += "io.janstenpickle" %% "trace4cats-sttp-tapir" % trace4CatsVersion
libraryDependencies += "io.janstenpickle" %% "trace4cats-datadog-http-exporter" % trace4CatsVersion
- 我有一个带有Play Framework的SIRD路由器的Tapir示例,如Tapir Docs所建议。这是
apirouter
:
@Singleton
class ApiRouter @Inject() (implicit mat: Materializer) extends SimpleRouter {
// Interpreter
private val interpreter = PlayServerInterpreter()
// Controller logic
def countCharacters(s: String): Future[Either[Unit, Int]] =
Future(Right[Unit, Int](s.length))
// Endpoint
val countCharactersEndpoint: PublicEndpoint[String, Unit, Int, Any] =
endpoint
.tag("Example API")
.in("count")
.in(query[String]("string"))
.out(plainBody[Int])
.errorOut(
statusCode(StatusCode.NotFound)
)
// Route
val countCharactersRoutes: Routes =
interpreter.toRoutes(countCharactersEndpoint.serverLogic(countCharacters))
// OpenAPI
private val openApiDocs: OpenAPI = OpenAPIDocsInterpreter().toOpenAPI(
List(countCharactersEndpoint),
"Tapir Play Sample",
"1.0.0"
)
// Doc will be on /docs
private val openApiRoute: Routes = interpreter.toRoutes(SwaggerUI[Future](openApiDocs.toYaml))
// Router
override def routes: Routes =
openApiRoute
.orElse(countCharactersRoutes)
}
我试图搜索有关如何与Tapir集成的Trace4Cats Docs,但我发现的只是其他示例,包括STTP,但我不确定Tapir的语法。我需要具有 trace4cats (或 natchez 或的任何其他解决方案)的人的帮助。非常感谢帮助。
I am learning about different Scala libraries and I got to tracing. Trace4Cats claims integration with Tapir endpoints and I want to include it inside my example Play SIRD router that uses Tapir with OpenAPI documentation.
- So far I've included these dependencies for tracing:
// Tracing
libraryDependencies += "io.janstenpickle" %% "trace4cats-core" % trace4CatsVersion
libraryDependencies += "io.janstenpickle" %% "trace4cats-inject" % trace4CatsVersion
libraryDependencies += "io.janstenpickle" %% "trace4cats-avro-exporter" % trace4CatsVersion
libraryDependencies += "io.janstenpickle" %% "trace4cats-sttp-tapir" % trace4CatsVersion
libraryDependencies += "io.janstenpickle" %% "trace4cats-datadog-http-exporter" % trace4CatsVersion
- I have a working Tapir example with Play Framework's SIRD router, as suggested by Tapir docs. Here is the
ApiRouter
:
@Singleton
class ApiRouter @Inject() (implicit mat: Materializer) extends SimpleRouter {
// Interpreter
private val interpreter = PlayServerInterpreter()
// Controller logic
def countCharacters(s: String): Future[Either[Unit, Int]] =
Future(Right[Unit, Int](s.length))
// Endpoint
val countCharactersEndpoint: PublicEndpoint[String, Unit, Int, Any] =
endpoint
.tag("Example API")
.in("count")
.in(query[String]("string"))
.out(plainBody[Int])
.errorOut(
statusCode(StatusCode.NotFound)
)
// Route
val countCharactersRoutes: Routes =
interpreter.toRoutes(countCharactersEndpoint.serverLogic(countCharacters))
// OpenAPI
private val openApiDocs: OpenAPI = OpenAPIDocsInterpreter().toOpenAPI(
List(countCharactersEndpoint),
"Tapir Play Sample",
"1.0.0"
)
// Doc will be on /docs
private val openApiRoute: Routes = interpreter.toRoutes(SwaggerUI[Future](openApiDocs.toYaml))
// Router
override def routes: Routes =
openApiRoute
.orElse(countCharactersRoutes)
}
I have tried to search Trace4Cats docs on how to integrate it with Tapir, but all I have found is other examples, including STTP, but I'm not sure of the syntax for Tapir. I need help from someone that has experience with Trace4Cats (or Natchez or any other solution that can work here). Help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题太广泛,无法给出一个确切的答案,但我建议您在Trace4Cats的GitHub存储库上查看测试和示例: https://github.com/trace.com/trace4cats/trace4cats/trace4cats4cats4cats4cats4cats4cats-sttp/tree/modaster/modules /sttp-tapir/src/test/scala/io/janstenpickle/trace4cats/sttp/tapir
Your question is too broad to give a precise answer but I would recommend you to look at the tests and examples on the GitHub repository of trace4cats: https://github.com/trace4cats/trace4cats-sttp/tree/master/modules/sttp-tapir/src/test/scala/io/janstenpickle/trace4cats/sttp/tapir