observe
Modules
observe
observe.mockextensionModule observe
API
Declarations
Definitions
ballerina/observe Ballerina library
Functions
addTagToMetrics
Add a key value pair as a tag to system metrics.
Return Type
- error? - An error if an error occurred while attaching tag to System Metrics
addTagToSpan
Add a key value pair as a tag to the span.
Parameters
- tagKey string - Key of the tag
- tagValue string - Value of the tag
- spanId int (default -1) - Id of span to which the tags should be added or -1 to add tags to the current active span
Return Type
- error? - An error if an error occurred while attaching tag to the span
finishSpan
Finish the current span.
Parameters
- spanId int - Id of span to finish
Return Type
- error? - An error if an error occurred while finishing the span
getAllMetrics
function getAllMetrics() returns Metric[]
Retrieve all registered metrics including default metrics from the ballerina runtime, and user defined metrics.
Return Type
- Metric[] - Array of all registered metrics
getMetricsProvider
function getMetricsProvider() returns string
Retrieve metrics provider.
Return Type
- string - metrics provider.
getMetricsReporter
function getMetricsReporter() returns string
Retrieve metrics reporter.
Return Type
- string - metrics reporter.
getSpanContext
Retrieve a map of span context data.
getTracingProvider
function getTracingProvider() returns string
Retrieve tracer provider.
Return Type
- string - Tracing provider.
isMetricsEnabled
function isMetricsEnabled() returns boolean
Check whether metrics is enabled.
Return Type
- boolean - metrics enabled/disabled.
isObservabilityEnabled
function isObservabilityEnabled() returns boolean
Check whether observability is enabled.
Return Type
- boolean - observability enabled/disabled.
isTracingEnabled
function isTracingEnabled() returns boolean
Check whether tracing is enabled.
Return Type
- boolean - tracing enabled/disabled.
lookupMetric
Retrieve the specific metric that is described by the given name and tags.
Parameters
- name string - Name of the metric to lookup
startRootSpan
Start a span with no parent span.
Parameters
- spanName string - Name of the span
Return Type
- int - SpanId of the started span
startSpan
Start a span and create child relationship to current active span or user specified span.
Classes
observe: Counter
This represents the metric type - counter, that can be only increased by an integer number.
Constructor
This instantiates the Counter object. Name field is mandatory, and description and tags fields are optional and have its own default values when no params are passed.
init (string name, string? desc, map<string>? tags)
register
function register() returns error?
Register the counter metric instance with the Metric Registry.
Return Type
- error? - Returns error if there is any metric registered already with the same name but different parameters or in a different kind
unregister
function unregister()
Unregister the counter metric instance with the Metric Registry.
increment
function increment(int amount)
Increment the counter's value by an amount.
Parameters
- amount int (default 1) - The amount by which the value needs to be increased. The amount is defaulted as 1 and will be used if there is no amount passed in
reset
function reset()
Resets the counter's value to zero.
getValue
function getValue() returns int
Retrieves the counter's current value.
Return Type
- int - The current value of the counter
Fields
- name string - Name of the counter metric
- description string - Description of the counter metric
observe: Gauge
This represents the metric type - gauge, that can hold instantaneous, increased or decreased value during the usage.
Constructor
This instantiates the Gauge object. Name field is mandatory, and description, tags, and statitics config fields are optional and have its own default values when no params are passed.
init (string name, string? desc, map<string>? tags, StatisticConfig[]? statisticConfig)
- name string - Name of the Gauge instance
- desc string? "" - Description of the Gauge instance. If no description is provided, the the default empty string will be used
- statisticConfig StatisticConfig[]? () - Statistics configurations array is used for statistics calculation. In case if empty statistics configurations array is passed, then statistics calculation will be disabled. If nil () is passed, then default statistics configs will be used for the statitics calculation
register
function register() returns error?
Register the gauge metric instance with the Metric Registry.
Return Type
- error? - Returns error if there is any metric registered already with the same name but different parameters or in a different kind
unregister
function unregister()
Unregister the counter metric instance with the Metric Registry.
increment
function increment(float amount)
Increment the gauge's value by an amount.
Parameters
- amount float (default 1.0) - The amount by which the value of gauge needs to be increased. The amount is defaulted as 1.0 and will be used if there is no amount passed in
decrement
function decrement(float amount)
Decrement the gauge's value by an amount.
Parameters
- amount float (default 1.0) - The amount by which the value of gauge needs to be decreased. The amount is defaulted as 1.0 and will be used if there is no amount passed in
setValue
function setValue(float amount)
Sets the instantaneous value for gauge.
Parameters
- amount float - The instantaneous value that needs to be set as gauge value
getValue
function getValue() returns float
Retrieves the gauge's current value.
Return Type
- float - The current value of the gauge
getSnapshot
function getSnapshot() returns Snapshot[]?
Retrieves statistics snapshots based on the statistics configs of the gauge.
Return Type
- Snapshot[]? - Array of the statistics snapshots. If there is no statisticsConfigs provided, then it will be nil
Fields
- name string - Name of the counter metric
- description string - Description of the counter metric
- statisticConfigs StatisticConfig[] & readonly - Array of StatisticConfig objects which defines about the statistical calculation of the gauge during its usage
Annotations
observe: Observable
This is used for making a function observable. Can be applied to functions which are not observable by default to make them observable.
Configurables
Records
observe: Metric
This represents the generic metric record that can represent both counter and gauge.
Fields
- name string - Name of the metric
- desc string - Description of the metric
- metricType string - Type of the metric
- summary Snapshot[]? - If the metric is configured with statistics config, then the calculated statistics of the metric
observe: PercentileValue
This represents the percentile value record.
Fields
- percentile float - The percentile of the reported value
- value float - The value of the percentile
observe: Snapshot
This represents the snapshot of the statistics calculation of the gauge.
Fields
- timeWindow int - The time window in which variation of the values are considered
- mean float - The average value within the time window
- max float - The max value within the time window
- min float - The min value within the time window
- stdDev float - The standard deviation value within the time window
- percentileValues PercentileValue[] - The percentiles values calculated wihtin the time window
observe: StatisticConfig
This represents the statistic configuration that can be used to instatiate gauge metric.
Fields
- percentiles float[] - The percentiles that needs to be calculated
- timeWindow int - The time window (in milli seconds) in which variation of the values are considered
- buckets int - The number of buckets used in the sliding time window
Import
import ballerina/observe;
Metadata
Released date: 1 day ago
Version: 1.4.0
Compatibility
Platform: java21
Ballerina version: 2201.11.0
GraalVM compatible: Yes
Pull count
Total: 789077
Current verison: 39
Weekly downloads