Skip to main content

Actions

The ballerinax/amp package exposes the following clients:

ClientPurpose
AMP Tracer ProviderRegisters as Ballerina's active tracing provider on module initialization, intercepting all OpenTelemetry spans generated by the runtime and exporting them to the configured AMP endpoint over OTLP HTTP.

AMP tracer provider

Registers as Ballerina's active tracing provider on module initialization, intercepting all OpenTelemetry spans generated by the runtime and exporting them to the configured AMP endpoint over OTLP HTTP.

Configuration

FieldTypeDefaultDescription
otelEndpointstring"http://localhost:22893/otel"Base URL of the AMP OpenTelemetry OTLP HTTP endpoint. The connector appends /v1/traces automatically.
apiKeystring""API key sent as the x-amp-api-key header on every export request. Leave empty if authentication is not required.
serviceNamestring""Overrides the service.name OpenTelemetry resource attribute. Defaults to the Ballerina service name when empty.
orgUidstring""OpenChoreo organization UID, attached as the openchoreo.dev/org-uid resource attribute on every span.
projectUidstring""OpenChoreo project UID, attached as the openchoreo.dev/project-uid resource attribute.
componentUidstring""OpenChoreo component UID, attached as the openchoreo.dev/component-uid resource attribute.
environmentUidstring""OpenChoreo environment UID, attached as the openchoreo.dev/environment-uid resource attribute.
samplerTypestring"const"Sampling strategy: "const" (always/never sample), "probabilistic" (ratio-based), or "ratelimiting" (leaky-bucket rate cap).
samplerParamdecimal1Sampler parameter: 1 = always sample for const; a ratio between 0 and 1 for probabilistic; maximum requests per second for ratelimiting.
reporterFlushIntervalint1000Exporter flush timeout in milliseconds: the maximum time before a partial batch is sent.
reporterBufferSizeint10000Maximum number of spans held in the export buffer at any time before older spans are dropped.

Initializing the client

// The AMP module is activated via a side-effect import, and no client object is created.
import ballerinax/amp as _;

// Ballerina.toml: enable observability at build time:
// [build-options]
// observabilityIncluded = true

// Config.toml; select AMP as the tracing provider and supply credentials:
// [ballerina.observe]
// tracingEnabled = true
// tracingProvider = "amp"
//
// [ballerinax.amp]
// otelEndpoint = "https://your-amp-endpoint/otel"
// apiKey = "<your-api-key>"
// orgUid = "<your-org-uid>"
// projectUid = "<your-project-uid>"
// componentUid = "<your-component-uid>"
// environmentUid = "<your-environment-uid>"

Operations

Tracing activation

initializeTracing

Activates the AMP tracing provider by importing the module as a side-effect. On initialization the module reads all [ballerinax.amp] values from Config.toml, builds an OtlpHttpSpanExporter targeting the configured endpoint, sets up a BatchSpanProcessor, and registers the resulting SdkTracerProvider with the Ballerina runtime. All subsequent spans generated by the program are automatically captured and exported, with no explicit function calls needed after setup.

Parameters:

NameTypeRequiredDescription
tracingEnabledboolean (Config.toml [ballerina.observe])YesMust be true to activate tracing in the Ballerina runtime.
tracingProviderstring (Config.toml [ballerina.observe])YesMust be set to "amp" to select this provider.
otelEndpointstring (Config.toml [ballerinax.amp])NoBase OTLP HTTP endpoint URL. Defaults to http://localhost:22893/otel.
apiKeystring (Config.toml [ballerinax.amp])NoAPI key for authenticating with the AMP endpoint.
orgUid / projectUid / componentUid / environmentUidstring (Config.toml [ballerinax.amp])NoOpenChoreo resource identifiers attached as attributes on every exported span.

Returns: ()

Sample code:

import ballerinax/amp as _;

public function main() returns error? {
// Tracing is active automatically after the import.
// All spans generated within this program are exported
// to the AMP endpoint configured in Config.toml.
}