Documentation Index

Fetch the complete documentation index at: https://kb.vastdata.com/llms.txt

Use this file to discover all available pages before exploring further.

Class Reference

Prev Next

ctx Class

The ctx class passes execution context metadata, telemetry interfaces, secrets, and metrics instruments to your function handler.

The ctx object is passed as an argument to both the event initializer function (init(ctx)) and the event handler function (handler()).

It provides access to the following capabilities:

Property / Method

Type / Return Type

Description

logger

logging.Logger

The function logger instance with OpenTelemetry logging integration.

tracer

opentelemetry.trace.Tracer

The OpenTelemetry tracer used to generate trace spans.

meter

Optional[opentelemetry.metrics.Meter]

The OpenTelemetry meter instance used to generate custom metrics.

secrets

dict

Access to Kubernetes secrets mounted to the function runtime. Returns an empty dictionary if secrets are not mounted.

function_name

str

The deployed service name of the function.

pipeline_triggers_map

dict

The pipeline triggers map structure containing function trigger linkages and conditional trigger labels.

get_pipeline_triggers_map()

dict

Getter method returning the pipeline triggers map dictionary.

counter(name, unit="", description="")

Optional[Counter]

Creates or retrieves a monotonic counter metric instrument.

histogram(name, unit="", description="", boundaries=None)

Optional[Histogram]

Creates or retrieves a histogram metric instrument with optional custom bucket boundaries.

updowncounter(name, unit="", description="")

Optional[UpDownCounter]

Creates or retrieves a metric instrument for values that can increase or decrease (e.g., queue size).

gauge(name, callback, unit="", description="")

Optional[ObservableGauge]

Creates or retrieves an observable gauge metric instrument measured via a callback function.

start_as_current_span(*args, **kwargs)

ContextManager[Span]

Starts a new OpenTelemetry span set as the active span in the current context.

start_as_current_event_span(event, *args, **kwargs)

ContextManager[Span]

Starts a new OpenTelemetry span explicitly attached to the specified VastEvent trace context.

Tracer and Spans

The embedded tracer is a standard OpenTelemetry tracer. You can use ctx.tracer or the helper methods ctx.start_as_current_span() and ctx.start_as_current_event_span() to generate telemetry spans visualizable in DataEngine.

Logger

The embedded logger (ctx.logger) is an OpenTelemetry-integrated Python logger. Use standard severity levels (info, warning, error, etc.) to produce trace-correlated execution logs.

Note

By default, the runtime also captures stdout (such as print() statements) and logs from standard Python loggers, automatically transmitting them via OpenTelemetry to VAST DataEngine.

Access to Custom Attributes

You can use the ctx object to create custom attributes. Custom attributes must be initialized by the init() function and then they can be accessed in the event handler path.

For example:

def init(ctx):
    # One-time initialization
    ctx.logger.info("Initialized...")

    # Initialize custom attributes on the context object
    ctx.myvalue = "some_value"
    ctx.counter = 1


def handler(ctx, event):
    # Event processing path
    ctx.logger.info(f"Handler processing event: {event}")

    # Access and update custom attributes set during init
    ctx.counter += 1

    return f"myvalue={ctx.myvalue}, counter={ctx.counter}"

Custom Metrics

Functions can register and emit custom OpenTelemetry metrics using helper methods on the ctx object:

  • counter: Track cumulative counts (e.g., total items processed).

  • histogram: Measure value distributions (e.g., request latency in milliseconds). Custom bucket boundaries can be provided using the boundaries argument.

  • updowncounter: Track fluctuating quantities (e.g., active concurrent tasks).

  • gauge: Observe instantaneous values measured via an asynchronous callback function (e.g., memory utilization).

Access to Secrets

Secrets mounted to your pipeline or function deployment are accessible via the ctx.secrets dictionary. If no secrets directory is mounted, ctx.secrets returns an empty dictionary.

Pipeline Triggers Map

The ctx.pipeline_triggers_map property provides access to the pipeline configuration map, detailing downstream function trigger relationships and conditional trigger labels.

VastEvent Class

Base class for all event types. It provides access to CloudEvent attributes, OpenTelemetry trace context, conditional trigger labeling, and type-casting methods (as_element_event(), as_schedule_event(), as_function_event(), as_manual_event()).

Base class for all event types. Returns the following properties:

Property

Type

Description

version

str

The version of the CloudEvents specification which the event uses. This is hardcoded as 1.0.

id

str

A unique identifier for the event.

timestamp

str

The timestamp of the event.

trigger

str

The name of the source trigger for the event.

trigger_id

str

The identifier of the source trigger of the event.

broker

str

The event broker that handled the event.

topic

str

The topic that handled the event.

type

str

Returns one of the following event types:

  • Element. An event produced by an element type trigger. See also subtype.

  • Schedule. An event produced by a schedule type trigger, which produces events on a configured schedule.

  • Function. An event sent by a function to another function in a deployed pipeline.

  • Manual: An event triggered manually by a user.

subtype

str

For element type events, returns one of the following:

  • ObjectCreated. An event produced when an element was uploaded to the source view (bucket) of the trigger.

  • ObjectDeleted. An event produced when an element was deleted from the source view (bucket) of the trigger.

  • ObjectTagCreated. An event produced when an S3 object tag was added to an element in the source view (bucket) of the trigger.

  • ObjectTagDeleted. An event produced when an S3 object tag was removed from an element in the source view (bucket) of the trigger.

For schedule type events, returns TimerElapsed in the format:

"ce_time": datetime.now(timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z"),

For function type events, returns "subtype is not available for function event type."

extensions

dict

A dictionary of custom CloudEvent extension attributes attached to the event.

partition_key

str

The topic partition that handled the event. Maps to the raw CloudEvent JSON attribute partitionkey.

inherited_trace_id

Optional[int]

The trace ID extracted from the traceparent header if present; otherwise None.

get_trace_id(pipeline_revision_id)

int

Returns the integer trace ID for the event, using inherited headers or generating one from the event ID and pipeline revision ID.

get_hex_trace_id(pipeline_revision_id)

str

Returns the 32-character hexadecimal string representation of the trace ID.

set_trigger_labels(labels)

None

Sets a dictionary of key-value conditional trigger labels on the event context.

start_as_current_span(*args, **kwargs)

ContextManager[Span]

Starts an OpenTelemetry span attached to the event's trace context.

ElementTriggerVastEvent Class

Represents element type events. This type of event is produced by an element type trigger that watches for the creation or removal of an element (S3 object) or tag (s3 object tag) in a source view (bucket).

Includes all VastEvent properties plus:

Property

Type

Description

object_key

str

The object key of the object that was involved in the event. Depending on the subtype, the object may have been uploaded to the bucket, deleted from the bucket, a tag added to the object, or a tag removed from the object.

bucket

str

The bucket where the event was produced.

partition_key

str

The path to the element that involved in the event, formed as bucket/object_key. Maps to the raw CloudEvent JSON attribute partitionkey.

FunctionVastEvent Class

Represents function type events. This type of event is sent by a function to another function if the first function triggers the second function in a deployed pipeline.

Includes all VastEvent properties plus:

Property

Type

Description

function_trigger

str

The name/identifier of the function that triggered this event.

Note

For FunctionVastEvent, subtype is not available and returns None. Accessing trigger or trigger_id will log a warning directing you to use function_trigger instead.

ScheduleVastEvent Class

Represents schedule type events. This type of event is produced by a schedule type trigger that produces events on a configured schedule.

Includes all VastEvent properties plus:

Property

Type

Description

cron_schedule

str

The schedule of the trigger that produced the event, in cron schedule format.

timer_elapsed_timestamp

str

The time at which the schedule fired the trigger to produce the event, as a timestamp in the format: scheduled_time.isoformat().replace("+00:00", "Z")

ManualVastEvent Class

Represents manual type events triggered directly by a user.

This class inherits all base properties and methods from VastEvent without adding additional specialized properties. It provides the as_manual_event() casting method.

VastEventList Class

A wrapper class around a list of VastEvent objects designed for batch event processing.

Method

Return Type

Description

set_trigger_labels(labels)

None

Sets conditional trigger labels for all events contained within the batch.