Skip to content

Commit

Permalink
Deprecated registerObserver methods that were using the GlobalOpenTel…
Browse files Browse the repository at this point in the history
…emetry instance.
  • Loading branch information
jenarros committed Mar 30, 2022
1 parent c1d75a6 commit 013921a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.oshi;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.oshi.ProcessMetrics;
import io.opentelemetry.instrumentation.oshi.SystemMetrics;
Expand All @@ -16,15 +17,15 @@ public final class MetricsRegistration {

public static void register() {
if (registered.compareAndSet(false, true)) {
SystemMetrics.registerObservers();
SystemMetrics.registerObservers(GlobalOpenTelemetry.get());

// ProcessMetrics don't follow the spec
if (Config.get()
.getBoolean("otel.instrumentation.oshi.experimental-metrics.enabled", false)) {
ProcessMetrics.registerObservers();
ProcessMetrics.registerObservers(GlobalOpenTelemetry.get());
}
}
}

private MetricsRegistration() {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ public class ProcessMetrics {

private ProcessMetrics() {}

/** Register observers for java runtime metrics. */
/**
* Register observers for java runtime metrics.
* @deprecated use {@link #registerObservers(OpenTelemetry openTelemetry)}
*/
@Deprecated
public static void registerObservers() {
registerObservers(GlobalOpenTelemetry.get());
}

public static void registerObservers(OpenTelemetry openTelemetry) {
Meter meter = openTelemetry.getMeterProvider().get("io.opentelemetry.oshi");
SystemInfo systemInfo = new SystemInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ public class SystemMetrics {

private SystemMetrics() {}

/** Register observers for system metrics. */
/**
* Register observers for system metrics.
* @deprecated use {@link #registerObservers(OpenTelemetry openTelemetry)}
*/
@Deprecated
public static void registerObservers() {
registerObservers(GlobalOpenTelemetry.get());
}

public static void registerObservers(OpenTelemetry openTelemetry) {
Meter meter = openTelemetry.getMeterProvider().get("io.opentelemetry.oshi");
SystemInfo systemInfo = new SystemInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.instrumentation.oshi;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -16,11 +17,11 @@ class ProcessMetricsTest extends AbstractProcessMetricsTest {

@Override
protected void registerMetrics() {
ProcessMetrics.registerObservers();
ProcessMetrics.registerObservers(GlobalOpenTelemetry.get());
}

@Override
protected InstrumentationExtension testing() {
return testing;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.instrumentation.oshi;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -16,11 +17,11 @@ class SystemMetricsTest extends AbstractSystemMetricsTest {

@Override
protected void registerMetrics() {
SystemMetrics.registerObservers();
SystemMetrics.registerObservers(GlobalOpenTelemetry.get());
}

@Override
protected InstrumentationExtension testing() {
return testing;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.javaagent.runtimemetrics;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.runtimemetrics.GarbageCollector;
import io.opentelemetry.instrumentation.runtimemetrics.MemoryPools;
Expand All @@ -20,8 +21,8 @@ public class RuntimeMetricsInstaller implements AgentListener {
public void afterAgent(Config config, AutoConfiguredOpenTelemetrySdk unused) {
if (config.isInstrumentationEnabled(
Collections.singleton("runtime-metrics"), /* defaultEnabled= */ true)) {
GarbageCollector.registerObservers();
MemoryPools.registerObservers();
GarbageCollector.registerObservers(GlobalOpenTelemetry.get());
MemoryPools.registerObservers(GlobalOpenTelemetry.get());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* <p>Example usage:
*
* <pre>{@code
* GarbageCollector.registerObservers();
* GarbageCollector.registerObservers(GlobalOpenTelemetry.get());
* }</pre>
*
* <p>Example metrics being exported:
Expand All @@ -34,7 +34,11 @@
public final class GarbageCollector {
private static final AttributeKey<String> GC_KEY = AttributeKey.stringKey("gc");

/** Register all observers provided by this module. */
/**
* Register all observers provided by this module.
* @deprecated use {@link #registerObservers(OpenTelemetry openTelemetry)}
*/
@Deprecated
public static void registerObservers() {
registerObservers(GlobalOpenTelemetry.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* <p>Example usage:
*
* <pre>{@code
* MemoryPools.registerObservers();
* MemoryPools.registerObservers(GlobalOpenTelemetry.get());
* }</pre>
*
* <p>Example metrics being exported: Component
Expand Down Expand Up @@ -59,6 +59,7 @@ public final class MemoryPools {
private static final Attributes MAX_NON_HEAP = Attributes.of(TYPE_KEY, MAX, AREA_KEY, NON_HEAP);

/** Register only the "area" measurements. */
@Deprecated
public static void registerMemoryAreaObservers() {
registerMemoryPoolObservers(GlobalOpenTelemetry.get());
}
Expand All @@ -78,6 +79,7 @@ public static void registerMemoryAreaObservers(OpenTelemetry openTelemetry) {
}

/** Register only the "pool" measurements. */
@Deprecated
public static void registerMemoryPoolObservers() {
registerMemoryPoolObservers(GlobalOpenTelemetry.get());
}
Expand Down Expand Up @@ -113,7 +115,11 @@ public static void registerMemoryPoolObservers(OpenTelemetry openTelemetry) {
});
}

/** Register all measurements provided by this module. */
/**
* Register all measurements provided by this module.
* @deprecated use {@link #registerObservers(OpenTelemetry openTelemetry)}
*/
@Deprecated
public static void registerObservers() {
registerMemoryAreaObservers();
registerMemoryPoolObservers();
Expand Down

0 comments on commit 013921a

Please sign in to comment.