Skip to content

Commit

Permalink
feat: streamline service name propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseRFelix committed Aug 13, 2024
1 parent b483989 commit da6ef1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/trpc/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export const createTRPCRouter = t.router;
* are logged in.
*/
export const publicProcedure = t.procedure
/**
* Opentelemetry tRPC middleware that names the handling transaction after the called procedure.
*/
.use(async ({ path, rawInput, type, next, ctx }) => {
const serviceName =
ctx.opentelemetryServiceName ?? "fallback-osmosis-frontend-service-name";
Expand Down Expand Up @@ -138,10 +141,12 @@ export function localLink<TRouter extends AnyRouter>({
router,
assetLists,
chainList,
opentelemetryServiceName,
}: {
router: TRouter;
assetLists: AssetList[];
chainList: Chain[];
opentelemetryServiceName: string | undefined;
}): TRPCLink<TRouter> {
return () =>
({ op }) =>
Expand All @@ -152,6 +157,7 @@ export function localLink<TRouter extends AnyRouter>({
const caller = createCaller({
assetLists,
chainList,
opentelemetryServiceName,
});
try {
// Attempt to execute the operation using the router's caller.
Expand Down
2 changes: 2 additions & 0 deletions packages/web/utils/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
import { AssetLists } from "~/config/generated/asset-lists";
import { ChainList } from "~/config/generated/chain-list";
import { type AppRouter, appRouter } from "~/server/api/root-router";
import { getOpentelemetryServiceName } from "~/utils/service-name";
import {
constructEdgeRouterKey,
constructEdgeUrlPathname,
Expand Down Expand Up @@ -122,6 +123,7 @@ export const api = createTRPCNext<AppRouter>({
router: appRouter,
assetLists: AssetLists,
chainList: ChainList,
opentelemetryServiceName: getOpentelemetryServiceName(),
})(runtime),

/**
Expand Down

0 comments on commit da6ef1c

Please sign in to comment.