All invocations automatically propagate W3C trace context for distributed tracing:
import { getContext } from 'iii-sdk'iii.registerFunction( { id: 'service_a::process' }, async (data: { value: string }) => { const { logger, trace } = getContext() // Add custom span attributes trace?.setAttribute('input.value', data.value) logger.info('Processing in service A') // Call another function - trace context is propagated const result = await iii.call('service_b::transform', data) logger.info('Received result from service B') return result })iii.registerFunction( { id: 'service_b::transform' }, async (data: { value: string }) => { const { logger, trace } = getContext() // This function is part of the same trace logger.info('Transforming in service B') trace?.setAttribute('transform.type', 'uppercase') return { transformed: data.value.toUpperCase() } })
The trace context flows automatically:
Service A starts a span
Service A calls Service B
Service B receives the trace context and creates a child span
Pass channel references in invocation data for streaming:
// Create a channelconst channel = await iii.createChannel()// Pass channel reader to another functionconst resultPromise = iii.call('processor::analyze', { data_source: channel.readerRef})// Write data to the channelchannel.writer.stream.write(Buffer.from('chunk 1'))channel.writer.stream.write(Buffer.from('chunk 2'))channel.writer.stream.end()// Wait for processing to completeconst result = await resultPromise
// Good - type-safeconst result = await iii.call<Input, Output>('fn::id', data)// Avoid - no type safetyconst result = await iii.call('fn::id', data)
Use meaningful function IDs
// Goodawait iii.call('users::create', data)await iii.call('orders::cancel', { id })// Avoidawait iii.call('create', data)await iii.call('fn_42', { id })
Set reasonable timeouts
// Default timeout for normal operationsconst iii = init(url, { invocationTimeoutMs: 30000 })// Override for specific callsawait iii.call('fast::operation', data, 5000)await iii.call('slow::operation', data, 120000)