0

Subscribe to new logs

by
Published Oct 17, 2025

Open a websocket connection to subscribe to logs matching the provided filters. Logs are streamed in real-time as they are generated. You can query for logs across multiple resources, but all resources must be in the same region and belong to the same owner.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Subscribe to new logs
7
 * Open a websocket connection to subscribe to logs matching the provided filters. Logs are streamed in real-time as they are generated.
8

9
You can query for logs across multiple resources, but all resources must be in the same region and belong to the same owner.
10

11
 */
12
export async function main(
13
	auth: Render,
14
	ownerId: string | undefined,
15
	startTime: string | undefined,
16
	endTime: string | undefined,
17
	direction: 'forward' | 'backward' | undefined,
18
	resource: string | undefined,
19
	instance: string | undefined,
20
	host: string | undefined,
21
	statusCode: string | undefined,
22
	method: string | undefined,
23
	level: string | undefined,
24
	_type: string | undefined,
25
	text: string | undefined,
26
	path: string | undefined,
27
	limit: string | undefined
28
) {
29
	const url = new URL(`https://api.render.com/v1/logs/subscribe`)
30
	for (const [k, v] of [
31
		['ownerId', ownerId],
32
		['startTime', startTime],
33
		['endTime', endTime],
34
		['direction', direction],
35
		['resource', resource],
36
		['instance', instance],
37
		['host', host],
38
		['statusCode', statusCode],
39
		['method', method],
40
		['level', level],
41
		['type', _type],
42
		['text', text],
43
		['path', path],
44
		['limit', limit]
45
	]) {
46
		if (v !== undefined && v !== '' && k !== undefined) {
47
			url.searchParams.append(k, v)
48
		}
49
	}
50
	const response = await fetch(url, {
51
		method: 'GET',
52
		headers: {
53
			Authorization: 'Bearer ' + auth.apiKey
54
		},
55
		body: undefined
56
	})
57
	if (!response.ok) {
58
		const text = await response.text()
59
		throw new Error(`${response.status} ${text}`)
60
	}
61
	return await response.text()
62
}
63