in src/instrumentation.ts [30:70]
private _patch(azFunc: typeof AzFunc): typeof AzFunc {
const disposables: AzFunc.Disposable[] = [];
// Tell the Azure Functions Host that we will send logs directly from Node.js
// (so that the host doesn't duplicate)
azFunc.app.setup({
capabilities: {
WorkerOpenTelemetryEnabled: true,
},
});
// Send logs directly from Node.js
disposables.push(
azFunc.app.hook.log((context) => {
this.logger.emit({
body: context.message,
severityNumber: toOtelSeverityNumber(context.level),
severityText: context.level,
});
})
);
// Ensure Azure Functions Host trace context is propagated onto the user's Node.js function handler
disposables.push(
azFunc.app.hook.preInvocation((context) => {
const traceContext = context.invocationContext.traceContext;
if (traceContext) {
context.functionHandler = otelContext.bind(
propagation.extract(otelContext.active(), {
traceparent: traceContext.traceParent,
tracestate: traceContext.traceState,
}),
context.functionHandler
);
}
})
);
this._azFuncDisposable = azFunc.Disposable.from(...disposables);
return azFunc;
}