Skip to content

Commit

Permalink
Remove lambdas from OTel code
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Aug 8, 2024
1 parent 53f837b commit bbd821a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 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;
}
}
}

0 comments on commit bbd821a

Please sign in to comment.