-
Non-Product Related Assistance
Request for existing cases, user IDs, Portal navigation support and more
Request for existing cases, user IDs, Portal navigation support and more
The following declarations are essential for setting up custom instrumentation with the OTEL Java agent:
private static final OpenTelemetry openTelemetry = GlobalOpenTelemetry.get();
private static final Meter meter = openTelemetry.getMeter("your package");
This first line initializes the OpenTelemetry object using the globally accessible GlobalOpenTelemetry instance. This object serves as the entry point to the OpenTelemetry API, allowing you to create and manage various telemetry components, such as metrics and traces.
This second line creates a meter object using the OpenTelemetry instance. The getMeter method initializes the meter with the specified name, "com.sap.crun.landscape.aspect.ReportOtelCustomAspect". This meter is used to collect and report custom metrics specific to the application, in this case, every minute.
These declarations ensure that your Java microservice can use OpenTelemetry to capture and export custom metrics effectively.
private final ObservableLongMeasurement successfulJobCounter;
private final ObservableLongMeasurement failedJobCounter;
successfulJobCounter = meter.gaugeBuilder("custom.total.success")
.setDescription("successful jobs")
.setUnit("1")
.ofLongs()
.buildObserver();
failedJobCounter = meter.gaugeBuilder("custom.total.failure")
.setDescription("failed Jobs")
.setUnit("1")
.ofLongs()
.buildObserver();
meter.batchCallback(
() -> {
recordMeasurement();
},
successfulJobCounter,
failedJobCounter);
private void recordMeasurement() {
Attributes attributes =
Attributes.builder()
.put(stringKey("space"),"cfSpace")
.build();
successfulJobCounter.record(totalSlisImportSuccess, attributes);
failedJobCounter.record(totalSlisImportFailure, attributes);
}
The meter.batchCallback() method sets up a function (callback) to execute a batch of operations when triggered.
It calls recordMeasurement() to record metrics using successfulJobCounter and failedJobCounter and it allows for efficient and controlled batch processing of metrics in applications using OpenTelemetry.