Skip to content

Commit

Permalink
improve client span
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Nov 16, 2023
1 parent 5b39a51 commit ef62669
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-eggs-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-app/prelude": patch
---

improve client span
21 changes: 12 additions & 9 deletions packages/prelude/_src/client/clientFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import type { GetResponse, Methods, QueryRequest, RequestSchemed } from "@effect-app/prelude/schema"
import { condemnCustom } from "@effect-app/prelude/schema"
import { condemnCustom, SchemaNamed } from "@effect-app/prelude/schema"
import * as utils from "@effect-app/prelude/utils"
import { Path } from "path-parser"
import type { ApiConfig } from "./config.js"
Expand Down Expand Up @@ -73,6 +73,9 @@ function clientFor_<M extends Requests>(models: M) {

// @ts-expect-error doc
const actionName = utils.uncapitalize(cur)
const requestName = ReasonableString(
Request.Model instanceof SchemaNamed ? Request.Model.name : Request.name
)

// if we don't need props, then also dont require an argument.
const props = [Request.Body, Request.Query, Request.Path]
Expand All @@ -87,7 +90,7 @@ function clientFor_<M extends Requests>(models: M) {
.flatMap(
mapResponseM(parseResponse)
)
.withSpan("client.request", { attributes: { actionName } }),
.withSpan("client.request", { attributes: { requestName } }),
meta
)
: Object.assign(
Expand All @@ -96,16 +99,16 @@ function clientFor_<M extends Requests>(models: M) {
.flatMap(
mapResponseM(parseResponse)
)
.withSpan("client.request", { attributes: { actionName } }),
.withSpan("client.request", { attributes: { requestName } }),
{
...meta,
mapPath: (req: any) => req ? makePathWithQuery(path, req) : Request.path
}
)
: props.length === 0
? Object.assign(fetchApi3S(b)({}).withSpan("client.request", { attributes: { actionName } }), meta)
? Object.assign(fetchApi3S(b)({}).withSpan("client.request", { attributes: { requestName } }), meta)
: Object.assign(
(req: any) => fetchApi3S(b)(req).withSpan("client.request", { attributes: { actionName } }),
(req: any) => fetchApi3S(b)(req).withSpan("client.request", { attributes: { requestName } }),
{
...meta,
mapPath: (req: any) =>
Expand All @@ -126,7 +129,7 @@ function clientFor_<M extends Requests>(models: M) {
.flatMap(
mapResponseM(parseResponseE)
)
.withSpan("client.request", { attributes: { actionName } }),
.withSpan("client.request", { attributes: { requestName } }),
meta
)
: Object.assign(
Expand All @@ -135,16 +138,16 @@ function clientFor_<M extends Requests>(models: M) {
.flatMap(
mapResponseM(parseResponseE)
)
.withSpan("client.request", { attributes: { actionName } }),
.withSpan("client.request", { attributes: { requestName } }),
{
...meta,
mapPath: (req: any) => req ? makePathWithQuery(path, req) : Request.path
}
)
: props.length === 0
? Object.assign(fetchApi3SE(b)({}).withSpan("client.request", { attributes: { actionName } }), meta)
? Object.assign(fetchApi3SE(b)({}).withSpan("client.request", { attributes: { requestName } }), meta)
: Object.assign(
(req: any) => fetchApi3SE(b)(req).withSpan("client.request", { attributes: { actionName } }),
(req: any) => fetchApi3SE(b)(req).withSpan("client.request", { attributes: { requestName } }),
{
...meta,
mapPath: (req: any) =>
Expand Down

0 comments on commit ef62669

Please sign in to comment.