All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.opentelemetry.javaagent.bootstrap.internal.ConfiguredResourceAttributesHolder Maven / Gradle / Ivy

There is a newer version: 2.11.0-alpha
Show newest version
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.javaagent.bootstrap.internal;

import static io.opentelemetry.api.common.AttributeKey.stringKey;

import io.opentelemetry.api.common.Attributes;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;

/**
 * This class is internal and is hence not for public use. Its APIs are unstable and can change at
 * any time.
 */
public final class ConfiguredResourceAttributesHolder {

  private static final Map resourceAttributes = new HashMap<>();

  public static Map getResourceAttributes() {
    return resourceAttributes;
  }

  public static void initialize(Attributes resourceAttribute) {
    List mdcResourceAttributes =
        AgentInstrumentationConfig.get()
            .getList(
                "otel.instrumentation.common.mdc.resource-attributes", Collections.emptyList());
    for (String key : mdcResourceAttributes) {
      String value = resourceAttribute.get(stringKey(key));
      if (value != null) {
        ConfiguredResourceAttributesHolder.resourceAttributes.put(key, value);
      }
    }
  }

  @Nullable
  public static String getAttributeValue(String key) {
    return resourceAttributes.get(key);
  }

  private ConfiguredResourceAttributesHolder() {}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy