Skip to content

Commit

Permalink
Merge pull request #42404 from geoand/otel-polish
Browse files Browse the repository at this point in the history
Apply minor polish to OpenTelemetry code
  • Loading branch information
geoand authored Aug 8, 2024
2 parents 1703ccb + cc6c210 commit bd14127
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ public Scope attach(Context toAttach) {

Scope scope = DEFAULT_CONTEXT_STORAGE.attach(toAttach);

return () -> {
if (beforeAttach == null) {
OpenTelemetryUtil.clearMDCData(null);
} else {
OpenTelemetryUtil.setMDCData(beforeAttach, null);
return new Scope() {
@Override
public void close() {
if (beforeAttach == null) {
OpenTelemetryUtil.clearMDCData(null);
} else {
OpenTelemetryUtil.setMDCData(beforeAttach, null);
}
scope.close();
}
scope.close();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ public OpenTelemetry apply(SyntheticCreationalContext<OpenTelemetry> context) {
});

final Map<String, String> oTelConfigs = getOtelConfigs();

OtelConfigsSupplier propertiesSupplier = new OtelConfigsSupplier(oTelConfigs);
if (oTelRuntimeConfig.sdkDisabled()) {
return AutoConfiguredOpenTelemetrySdk.builder()
.setResultAsGlobal()
.disableShutdownHook()
.addPropertiesSupplier(() -> oTelConfigs)
.addPropertiesSupplier(propertiesSupplier)
.build()
.getOpenTelemetrySdk();
}

var builder = AutoConfiguredOpenTelemetrySdk.builder()
.setResultAsGlobal()
.disableShutdownHook()
.addPropertiesSupplier(() -> oTelConfigs)
.addPropertiesSupplier(propertiesSupplier)
.setServiceClassLoader(Thread.currentThread().getContextClassLoader());
for (var customizer : builderCustomizers) {
customizer.customize(builder);
Expand Down Expand Up @@ -156,4 +156,17 @@ public String convert(final String value) throws IllegalArgumentException, NullP
}
}
}

private static class OtelConfigsSupplier implements Supplier<Map<String, String>> {
private final Map<String, String> oTelConfigs;

public OtelConfigsSupplier(Map<String, String> oTelConfigs) {
this.oTelConfigs = oTelConfigs;
}

@Override
public Map<String, String> get() {
return oTelConfigs;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ThreadContextSnapshot currentContext(Map<String, String> props) {

io.opentelemetry.context.Context context = QuarkusContextStorage.INSTANCE.current();

// Use anonymous classes instad of lambdas for the native image
// Use anonymous classes instead of lambdas for the native image
return new ThreadContextSnapshot() {

@Override
Expand Down Expand Up @@ -47,14 +47,14 @@ public void endContext() throws IllegalStateException {

@Override
public ThreadContextSnapshot clearedContext(Map<String, String> props) {
// Use anonymous classes instad of lambdas for the native image
// Use anonymous classes instead of lambdas for the native image
return new ThreadContextSnapshot() {
@Override
public ThreadContextController begin() {
return new ThreadContextController() {
@Override
public void endContext() throws IllegalStateException {
// nothring to do
// nothing to do
}
};
}
Expand Down

0 comments on commit bd14127

Please sign in to comment.