forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 2
/
OpenTelemetryMeterRegistryBuilder.java
47 lines (38 loc) · 1.41 KB
/
OpenTelemetryMeterRegistryBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.micrometer1shim;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.opentelemetry.api.OpenTelemetry;
import java.util.concurrent.TimeUnit;
/** A builder of {@link OpenTelemetryMeterRegistry}. */
public final class OpenTelemetryMeterRegistryBuilder {
// Visible for testing
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
private final OpenTelemetry openTelemetry;
private Clock clock = Clock.SYSTEM;
private TimeUnit baseTimeUnit = TimeUnit.MILLISECONDS;
OpenTelemetryMeterRegistryBuilder(OpenTelemetry openTelemetry) {
this.openTelemetry = openTelemetry;
}
/** Sets a custom {@link Clock}. Useful for testing. */
public OpenTelemetryMeterRegistryBuilder setClock(Clock clock) {
this.clock = clock;
return this;
}
/** Sets the base time unit. */
public OpenTelemetryMeterRegistryBuilder setBaseTimeUnit(TimeUnit baseTimeUnit) {
this.baseTimeUnit = baseTimeUnit;
return this;
}
/**
* Returns a new {@link OpenTelemetryMeterRegistry} with the settings of this {@link
* OpenTelemetryMeterRegistryBuilder}.
*/
public MeterRegistry build() {
return new OpenTelemetryMeterRegistry(
clock, baseTimeUnit, openTelemetry.getMeterProvider().get(INSTRUMENTATION_NAME));
}
}