Skip to content

Commit

Permalink
added reporting config installer (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
shashank11p authored Apr 27, 2023
1 parent 6bb2be2 commit c66faa5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ final class ConfigProvider {

private static volatile ReportingConfig reportingConfig;

private static ReportingConfig load() {
ServiceLoader<ReportingConfig> configs = ServiceLoader.load(ReportingConfig.class);
private static ReportingConfig load(ClassLoader cl) {
ServiceLoader<ReportingConfig> configs = ServiceLoader.load(ReportingConfig.class, cl);
Iterator<ReportingConfig> iterator = configs.iterator();
if (!iterator.hasNext()) {
logger.error("Failed to load reporting config");
Expand All @@ -43,11 +43,22 @@ private static ReportingConfig load() {
return iterator.next();
}

public static ReportingConfig get(ClassLoader cl) {
if (reportingConfig == null) {
synchronized (ConfigProvider.class) {
if (reportingConfig == null) {
reportingConfig = load(cl);
}
}
}
return reportingConfig;
}

public static ReportingConfig get() {
if (reportingConfig == null) {
synchronized (ConfigProvider.class) {
if (reportingConfig == null) {
reportingConfig = load();
reportingConfig = load(Thread.currentThread().getContextClassLoader());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright The Hypertrace Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.hypertrace.agent.otel.extensions.config;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.tooling.BeforeAgentListener;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import org.hypertrace.agent.core.config.ReportingConfig.ConfigProvider;

@AutoService(BeforeAgentListener.class)
public class ReportingConfigInstaller implements BeforeAgentListener {

@Override
public void beforeAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
ConfigProvider.get(getClass().getClassLoader());
}
}

0 comments on commit c66faa5

Please sign in to comment.