Effect CommunityEC
Effect Community3w ago
2 replies
danielo515

Issues with Spans Detaching from Main Trace in Effect Functions

I am having issues with certain spans becoming detached from the main trace when third party code is calling my effect functions.
I have the following Service, that yields its required runtime and then passes that runtime to some builder functions that make the functions the third party code will call. It looks something like this:

export class AiPlanningService extends Effect.Service<AiPlanningService>()(
  "AiPlanningService",
  {
    dependencies: [
        DepA,
        DepB,
    ],
    accessors: true,
    effect: Effect.gen(function* () {
      const runtime = yield* Effect.runtime<
        | DepA
        | DepB
      >();

      const buildToolset = Effect.fn("buildToolset")(function* (
        annualPlanningId: string,
        planningYear: number,
      ) {
        const planningProvider = yield* DepA;
        return {
          getHistoricalConceptAnalysis: createGetHistoricalConceptAnalysisTool(
            runtime,
            annualPlanningId,
            planningYear,
          ),
          
        };
      });
      
      const methodA = ({
        args1,
      }: {
        arg1: string;
      }) =>
        Effect.gen(function* () {
          const toolset = yield* buildToolset(args1, 2025);
          // Use the in the AI generation from Vercel AI SDK
          yield* generateText("Bla bla bla", { toolset });
    }),
  },
);


The way the tool generators are using the runtime is something like this (thread):
Was this page helpful?