Skip to main content
Every III function handler has access to a context object that provides logging, tracing, and request metadata.

getContext()

Get the current context within a function handler.
Context
Current execution context

Example: Basic Usage

Logger

The Logger provides structured logging with automatic trace correlation.

Methods

info()

Log an informational message.
string
required
Log message
unknown
Optional structured data to include in the log

warn()

Log a warning message.
string
required
Warning message
unknown
Optional structured data

error()

Log an error message.
string
required
Error message
unknown
Optional error details or structured data

debug()

Log a debug message.
string
required
Debug message
unknown
Optional debug data

Example: Structured Logging

Automatic Trace Correlation

Logs are automatically correlated with traces:
All logs from both services share the same trace_id, making it easy to trace requests across services.

Trace Span

The trace span allows adding custom attributes, events, and status to the current trace.

setAttribute()

Add a custom attribute to the span.
string
required
Attribute key
string | number | boolean
required
Attribute value

addEvent()

Add a timestamped event to the span.
string
required
Event name
Record<string, any>
Optional event attributes

setStatus()

Set the span status.

recordException()

Record an exception in the span.

Example: Rich Tracing

withContext()

Manually set context for async operations (advanced use case).
(context: Context) => Promise<T>
required
Async function to execute with the context
Context
required
Context object to use
T
The function’s return value
You typically don’t need to use withContext() directly. The III SDK manages context automatically for function handlers.

Example: Custom Context

Logger Constructor

Create a standalone logger instance outside of function handlers.
string
Optional trace ID for correlation
string
Optional service name
string
Optional span ID

Example: Standalone Logger

Best Practices

Context Outside Handlers

If you call getContext() outside a function handler, you get a default context with a basic logger: