Skip to content

Conversation

@404Wolf
Copy link

@404Wolf 404Wolf commented Jul 25, 2025

Add .stream to logs and traces so you can "watch" them

import { ValTown } from '../src';

const sdk = new ValTown();
const thisBranchId = '7e188f6c-67f0-11f0-9cf1-0224a6c84d84';
const fileIdToWatch = '2f05a95e-68d2-11f0-bcb5-0224a6c84d84';

async function streamTraces() {
  for await (const trace of sdk.telemetry.traces.stream({
    branch_ids: [thisBranchId],
    file_id: fileIdToWatch,
  })) {
    console.log(trace);
  }
}

streamTraces();

@404Wolf 404Wolf force-pushed the streaming-telemetry branch 3 times, most recently from cfaef0e to 0129aca Compare July 29, 2025 22:42
@404Wolf 404Wolf force-pushed the streaming-telemetry branch from 0129aca to 056b6b0 Compare July 29, 2025 22:48
Comment on lines +4 to +5
import type * as Core from '../../core';
import type * as Shared from '../shared';
Copy link
Member

Choose a reason for hiding this comment

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

I think we are using verbatimModuleSyntax in the rest of our code but not here, so it seems risky to patch existing code just to make them type-only imports, when that might be part of what stainless needs to auto-resolve in the future when it makes updates


export declare namespace Traces {
export { type TraceListResponse as TraceListResponse, type TraceListParams as TraceListParams };
export type { TraceListResponse, TraceListParams };
Copy link
Member

Choose a reason for hiding this comment

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

Likewise, I don't see why we'd change existing code that doesn't need to be changed here, this is probably going to make automerges harder


export declare namespace Logs {
export { type LogListResponse as LogListResponse, type LogListParams as LogListParams };
export type { LogListResponse, LogListParams };
Copy link
Member

Choose a reason for hiding this comment

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

Probably don't edit this, for the same reason as other comments

Copy link
Author

Choose a reason for hiding this comment

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

Oop, yeah I think the formatter did this :/
Thanks for catching these!

import type * as Core from '../../core';
import type * as Shared from '../shared';

export interface BaseListParams {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could split out this custom code into a separate file so that the only change to stainless's generated files is something like export * from …

const newStartTime = new Date(new URL(newLinks.next).searchParams.get('end')!);
if (newStartTime.getTime() === startTime.getTime()) break; // No new data, stop

for (const item of newData) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we'd use yield* here too because newData is iterable

start: startTime.toISOString(),
end: endTime.toISOString(),
...query,
} as TParams;
Copy link
Member

Choose a reason for hiding this comment

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

Somewhat nervous that this doesn't actually do type checking in the hard way - we can't say satisfies TParams here or const listParams: TParams = here because concrete instances can't have generic types. Probably not a big thing but I don't think TypeScript is protecting us that much here.

query: StreamParams,
options?: Core.RequestOptions,
): AsyncGenerator<TData> {
const { frequency = 1000 } = query;
Copy link
Member

Choose a reason for hiding this comment

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

We should probably use a higher default here, 1/s is a pretty fast ping.

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.

3 participants