Skip to content

ref: Properly type tracing channels#1517

Merged
Luca Forstner (lforst) merged 7 commits intomainfrom
lforst/type-tracing-channels
Mar 11, 2026
Merged

ref: Properly type tracing channels#1517
Luca Forstner (lforst) merged 7 commits intomainfrom
lforst/type-tracing-channels

Conversation

@lforst
Copy link
Member

@lforst Luca Forstner (lforst) commented Mar 7, 2026

This PR adds a type system to the plugins so that we have e2e typed tracing channels. This should allow us to hopefully migrate the rest of the wrappers to diagnostics channels more easily and safely.

  • Adds a defineChannels helper that allows for configuring a list of channels that can be passed directly as a generic type to the base plugin
  • The return value of the defineChannels function exposes the channels as fields which in return expose tracingChannel() and tracePromise() as helper functions to emit tracing events. These functions are fully typed and compatible with the plugins if the type is passed in properly.

Closes #1502

Comment on lines +20 to +21
name: string;
fullName: string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have both name and fullName? Can't we derive one from the other?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very valid you bring this up cause this I was the most hesitant with.

It's either:

  • You provide the short form, ie chat.completions.create and we prefix it with orchestrion:openai:, which is a bit tricky because orchestrion decides by itself what the {pkg} in orchestrion:{pkg}: would be.
  • We provide the long form, ie orchestrion:openai:chat.completions.create, but then we have to dynamically strip away the orchestion:openai: prefix which I found a bit nasty too

So my through process was: Screw it, providing both is not too hard and also leaves very little room for (runtime) error.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can have a defineChannels API that looks like so?

export function defineChannels<T extends Record<string, { channelName: string; kind: ChannelKind }>>(
  pkg: string,
  specs: T,
): { [K in keyof T]: TypedChannel<...> } {
  return Object.fromEntries(
    Object.entries(specs).map(([key, spec]) =>
      [key, channel({
        ...spec,
        fullChannelName: `orchestrion:${pkg}:${spec.channelName}`,
      })]
    )
  );
}
export const openAIChannels = defineChannels("openai", {
  chatCompletionsCreate: { channelName: "chat.completions.create", kind: "async" },
});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented

@lforst Luca Forstner (lforst) force-pushed the lforst/type-tracing-channels branch 2 times, most recently from 9566be5 to 2300966 Compare March 10, 2026 11:59
@lforst Luca Forstner (lforst) force-pushed the lforst/type-tracing-channels branch from 88a83a1 to 22cd406 Compare March 10, 2026 16:00
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! the type safety feels way better

@lforst Luca Forstner (lforst) merged commit 496297e into main Mar 11, 2026
45 of 46 checks passed
@lforst Luca Forstner (lforst) deleted the lforst/type-tracing-channels branch March 11, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make SDK more typesafe

2 participants