Actions
The ballerinax/amp package exposes the following clients:
| Client | Purpose |
|---|---|
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. |
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
| Field | Type | Default | Description |
|---|---|---|---|
otelEndpoint | string | "http://localhost:22893/otel" | Base URL of the AMP OpenTelemetry OTLP HTTP endpoint. The connector appends /v1/traces automatically. |
apiKey | string | "" | API key sent as the x-amp-api-key header on every export request. Leave empty if authentication is not required. |
serviceName | string | "" | Overrides the service.name OpenTelemetry resource attribute. Defaults to the Ballerina service name when empty. |
orgUid | string | "" | OpenChoreo organization UID, attached as the openchoreo.dev/org-uid resource attribute on every span. |
projectUid | string | "" | OpenChoreo project UID, attached as the openchoreo.dev/project-uid resource attribute. |
componentUid | string | "" | OpenChoreo component UID, attached as the openchoreo.dev/component-uid resource attribute. |
environmentUid | string | "" | OpenChoreo environment UID, attached as the openchoreo.dev/environment-uid resource attribute. |
samplerType | string | "const" | Sampling strategy: "const" (always/never sample), "probabilistic" (ratio-based), or "ratelimiting" (leaky-bucket rate cap). |
samplerParam | decimal | 1 | Sampler parameter: 1 = always sample for const; a ratio between 0 and 1 for probabilistic; maximum requests per second for ratelimiting. |
reporterFlushInterval | int | 1000 | Exporter flush timeout in milliseconds: the maximum time before a partial batch is sent. |
reporterBufferSize | int | 10000 | Maximum 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:
| Name | Type | Required | Description |
|---|---|---|---|
tracingEnabled | boolean (Config.toml [ballerina.observe]) | Yes | Must be true to activate tracing in the Ballerina runtime. |
tracingProvider | string (Config.toml [ballerina.observe]) | Yes | Must be set to "amp" to select this provider. |
otelEndpoint | string (Config.toml [ballerinax.amp]) | No | Base OTLP HTTP endpoint URL. Defaults to http://localhost:22893/otel. |
apiKey | string (Config.toml [ballerinax.amp]) | No | API key for authenticating with the AMP endpoint. |
orgUid / projectUid / componentUid / environmentUid | string (Config.toml [ballerinax.amp]) | No | OpenChoreo 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.
}