diff --git a/packages/stream-metadata/src/node.ts b/packages/stream-metadata/src/node.ts index 27c61c984..c38979286 100644 --- a/packages/stream-metadata/src/node.ts +++ b/packages/stream-metadata/src/node.ts @@ -16,13 +16,16 @@ process.title = 'stream-metadata' const logger = getLogger('server') -logger.info({ - riverEnv: config.riverEnv, - chainId: config.web3Config.river.chainId, - port: config.port, - riverRegistry: config.web3Config.river.addresses.riverRegistry, - riverChainRpcUrl: config.riverChainRpcUrl, -}) +logger.info( + { + riverEnv: config.riverEnv, + chainId: config.web3Config.river.chainId, + port: config.port, + riverRegistry: config.web3Config.river.addresses.riverRegistry, + riverChainRpcUrl: config.riverChainRpcUrl, + }, + 'config', +) /* * Server setup @@ -57,16 +60,15 @@ export function setupRoutes(srv: Server) { srv.get('/space/:spaceAddress', async (request, reply) => { const { spaceAddress } = request.params as { spaceAddress?: string } - logger.info(`GET /space`, { spaceAddress }) + logger.info({ spaceAddress }, 'GET /space/../metadata') + const { protocol, serverAddress } = getServerInfo() return fetchSpaceMetadata(request, reply, `${protocol}://${serverAddress}`) }) srv.get('/space/:spaceAddress/image', async (request, reply) => { const { spaceAddress } = request.params as { spaceAddress?: string } - logger.info(`GET /space/../image`, { - spaceAddress, - }) + logger.info({ spaceAddress }, 'GET /space/../image') return fetchSpaceImage(request, reply) }) @@ -95,8 +97,8 @@ process.on('SIGTERM', async () => { await server.close() logger.info('Server closed gracefully') process.exit(0) - } catch (err) { - logger.error('Error during server shutdown', err) + } catch (error) { + logger.error(error, 'Error during server shutdown') process.exit(1) } }) @@ -107,8 +109,8 @@ async function main() { setupRoutes(server) await server.listen({ port: config.port }) logger.info('Server started') - } catch (err) { - logger.error('Error starting server', err) + } catch (error) { + logger.error(error, 'Error starting server') process.exit(1) } } diff --git a/packages/stream-metadata/src/riverStreamRpcClient.ts b/packages/stream-metadata/src/riverStreamRpcClient.ts index 3d1554b77..880eb1eb2 100644 --- a/packages/stream-metadata/src/riverStreamRpcClient.ts +++ b/packages/stream-metadata/src/riverStreamRpcClient.ts @@ -25,9 +25,7 @@ const contentCache: Record = {} export type StreamRpcClient = PromiseClient & { url?: string } function makeStreamRpcClient(url: string): StreamRpcClient { - logger.info(`makeStreamRpcClient: Connecting`, { - url, - }) + logger.info({ url }, 'makeStreamRpcClient: Connecting') const options: ConnectTransportOptions = { baseUrl: url, @@ -47,7 +45,7 @@ async function getStreamClient(streamId: `0x${string}`) { clients.set(client.url!, client) url = client.url! } - logger.info('getStreamClient: client url', url) + logger.info({ url }, 'getStreamClient: client url') const client = clients.get(url) if (!client) { @@ -83,9 +81,12 @@ async function mediaContentFromStreamView( ): Promise { const mediaInfo = streamView.mediaContent.info if (mediaInfo) { - logger.info(`mediaContentFromStreamView`, { - spaceId: mediaInfo.spaceId, - }) + logger.info( + { + spaceId: mediaInfo.spaceId, + }, + 'mediaContentFromStreamView', + ) // Aggregate data chunks into a single Uint8Array const data = new Uint8Array( @@ -103,9 +104,7 @@ async function mediaContentFromStreamView( // Determine the MIME type const mimeType = filetypemime(decrypted) if (mimeType?.length > 0) { - logger.info(`mediaContentFromStreamView`, { - mimeType, - }) + logger.info({ mimeType }, 'mediaContentFromStreamView') // Return decrypted data and MIME type return { @@ -133,24 +132,30 @@ export async function getStream(streamId: string): Promise { - logger.info('getNodeForStream', streamId) + logger.info({ streamId }, 'getNodeForStream') const now = Date.now() const cachedData = cache[streamId] @@ -31,13 +31,16 @@ export async function getNodeForStream( const streamData = await riverRegistry.streamRegistry.read.getStream(streamId) if (streamData.nodes.length === 0) { - const err = new Error(`No nodes found for stream ${streamId}`) - logger.error(`No nodes found for stream`, { - streamId, - err, - }) + const error = new Error(`No nodes found for stream ${streamId}`) + logger.error( + { + streamId, + err: error, + }, + 'No nodes found for stream', + ) - throw err + throw error } const lastMiniblockNum = streamData.lastMiniblockNum @@ -45,11 +48,14 @@ export async function getNodeForStream( const randomIndex = Math.floor(Math.random() * streamData.nodes.length) const node = await riverRegistry.nodeRegistry.read.getNode(streamData.nodes[randomIndex]) - logger.info(`connected to node`, { - streamId, - nodeUrl: node.url, - lastMiniblockNum, - }) + logger.info( + { + streamId, + nodeUrl: node.url, + lastMiniblockNum, + }, + 'connected to node', + ) // Cache the result with a 15-minute expiration cache[streamId] = {