Skip to content

Commit 6fbdc41

Browse files
authored
Avoid contention in otel emission (#372)
1 parent 2b2fbe2 commit 6fbdc41

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

apps/spark/src/main/java/com/linkedin/openhouse/jobs/util/AppsOtelEmitter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public AppsOtelEmitter(List<OpenTelemetry> otels) {
2222
}
2323

2424
@Override
25-
public <T> T executeWithStats(
25+
public synchronized <T> T executeWithStats(
2626
Callable<T> callable, String scope, String metricPrefix, Attributes attributes)
2727
throws Exception {
2828
long startTime = System.currentTimeMillis();

services/common/src/main/java/com/linkedin/openhouse/common/metrics/OpenHouseOtelEmitter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public <T> T executeWithStats(
3131
}
3232

3333
@Override
34-
public void count(String scope, String metric, long count, Attributes attributes) {
34+
public synchronized void count(String scope, String metric, long count, Attributes attributes) {
3535
for (OpenTelemetry otel : otels) {
3636
Meter meter = otel.getMeter(scope);
3737
LongCounter counter = meter.counterBuilder(metric).build();
@@ -44,7 +44,7 @@ public void count(String scope, String metric, long count, Attributes attributes
4444
}
4545

4646
@Override
47-
public void time(String scope, String metric, long amount, Attributes attributes) {
47+
public synchronized void time(String scope, String metric, long amount, Attributes attributes) {
4848
for (OpenTelemetry otel : otels) {
4949
Meter meter = otel.getMeter(scope);
5050
LongHistogram histogram =
@@ -58,7 +58,7 @@ public void time(String scope, String metric, long amount, Attributes attributes
5858
}
5959

6060
@Override
61-
public void gauge(String scope, String metric, long value, Attributes attributes) {
61+
public synchronized void gauge(String scope, String metric, long value, Attributes attributes) {
6262
for (OpenTelemetry otel : otels) {
6363
Meter meter = otel.getMeter(scope);
6464
LongGaugeBuilder gaugeBuilder =

0 commit comments

Comments
 (0)