Instrumentation and telemetry in functions

It is possible to emit certain types of telemetry from your functions to allow for monitoring and debugging of production workflows.

To learn how to view telemetry emitted by your functions, see our AIP Observability documentation.

Supported telemetry types

The following table provides an overview of the types of telemetry supported by each function language. Note that a single span over the total execution duration of the function, along with a single request log, is automatically created for all function types.

LanguageLogsSpansMetrics
TypeScript v1YesOnly product-defined spans[1]Only product-defined metrics[2]
TypeScript v2YesYes[3]Only product-defined metrics[2]
PythonNoNoOnly product-defined metrics[2]

[1] Product-defined spans in TypeScript v1 functions include operations like object loads and query executions.

[2] Foundry records the total execution duration for all types of functions.

[3] TypeScript v2 functions automatically instrument all outbound network requests, but custom spans can also be added.

Logs

You can emit custom logs from functions and view them retroactively. The following examples demonstrate how to emit logs from both TypeScript v1 and v2 functions.

In TypeScript v2 functions, Foundry will set up the OpenTelemetry SDK's global logger provider, and you will be able to retrieve a logger from it. If you want to use third-party libraries for logging, you must configure them to emit logs through a logger obtained from the global logger provider.

Copied!
1 2 3 4 5 6 7 export class MyFunctions { @Function() public myFunction(name: string): string { console.log(`This is a custom log line ${name}.`); return `Hello, ${name}!`; } }
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 import { logs } from "@opentelemetry/api-logs"; const logger = logs.getLogger("my-function"); export default function myFunction(): string { logger.emit({ attributes: { LOG_MESSAGE: "This is a custom log line." }, body: { name } }); return `Hello, ${name}!`; }

Spans

You can also create custom spans in TypeScript v2 functions to track the duration of specific operations. The following example demonstrates how to create a custom span.

In TypeScript v2 functions, Foundry will set up the OpenTelemetry SDK's global tracer provider, and you will be able to retrieve a tracer from it. If you want to use third-party libraries for tracing, you must configure them to emit traces through a tracer obtained from the global tracer provider.

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import { trace } from "@opentelemetry/api"; import { Integer } from "@osdk/functions"; const tracer = trace.getTracer("my-function"); export default function sqrt(n: Integer): Integer { const sqrt = tracer.startActiveSpan("my-custom-span", () => { try { return Math.sqrt(n); } finally { span.end(); } }); return sqrt; }