Rename TraceConfig -> SpanLimits and move to upper package. (#2686)
This commit is contained in:
		
							parent
							
								
									88e760d01c
								
							
						
					
					
						commit
						b8c5acd3ff
					
				| 
						 | 
				
			
			@ -9,8 +9,8 @@ import io.opentelemetry.sdk.autoconfigure.spi.SdkTracerProviderConfigurer;
 | 
			
		|||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SdkTracerProvider;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfigBuilder;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimitsBuilder;
 | 
			
		||||
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
 | 
			
		||||
import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder;
 | 
			
		||||
import io.opentelemetry.sdk.trace.export.SpanExporter;
 | 
			
		||||
| 
						 | 
				
			
			@ -24,7 +24,7 @@ final class TracerProviderConfiguration {
 | 
			
		|||
    SdkTracerProviderBuilder tracerProviderBuilder =
 | 
			
		||||
        SdkTracerProvider.builder()
 | 
			
		||||
            .setResource(resource)
 | 
			
		||||
            .setTraceConfig(configureTraceConfig(config));
 | 
			
		||||
            .setSpanLimits(configureSpanLimits(config));
 | 
			
		||||
 | 
			
		||||
    String sampler = config.getString("otel.traces.sampler");
 | 
			
		||||
    if (sampler != null) {
 | 
			
		||||
| 
						 | 
				
			
			@ -79,8 +79,8 @@ final class TracerProviderConfiguration {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  // Visible for testing
 | 
			
		||||
  static TraceConfig configureTraceConfig(ConfigProperties config) {
 | 
			
		||||
    TraceConfigBuilder builder = TraceConfig.builder();
 | 
			
		||||
  static SpanLimits configureSpanLimits(ConfigProperties config) {
 | 
			
		||||
    SpanLimitsBuilder builder = SpanLimits.builder();
 | 
			
		||||
 | 
			
		||||
    Integer maxAttrs = config.getInt("otel.span.attribute.count.limit");
 | 
			
		||||
    if (maxAttrs != null) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,8 +11,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 | 
			
		|||
import io.opentelemetry.api.common.Attributes;
 | 
			
		||||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SdkTracerProvider;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanProcessor;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
 | 
			
		||||
import io.opentelemetry.sdk.trace.export.SpanExporter;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
| 
						 | 
				
			
			@ -132,8 +132,8 @@ class TracerProviderConfigurationTest {
 | 
			
		|||
 | 
			
		||||
  @Test
 | 
			
		||||
  void configureTraceConfig_empty() {
 | 
			
		||||
    assertThat(TracerProviderConfiguration.configureTraceConfig(EMPTY))
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault());
 | 
			
		||||
    assertThat(TracerProviderConfiguration.configureSpanLimits(EMPTY))
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
| 
						 | 
				
			
			@ -145,9 +145,8 @@ class TracerProviderConfigurationTest {
 | 
			
		|||
    properties.put("otel.span.event.count.limit", "4");
 | 
			
		||||
    properties.put("otel.span.link.count.limit", "3");
 | 
			
		||||
 | 
			
		||||
    TraceConfig config =
 | 
			
		||||
        TracerProviderConfiguration.configureTraceConfig(
 | 
			
		||||
            ConfigProperties.createForTest(properties));
 | 
			
		||||
    SpanLimits config =
 | 
			
		||||
        TracerProviderConfiguration.configureSpanLimits(ConfigProperties.createForTest(properties));
 | 
			
		||||
    assertThat(config.getMaxNumberOfAttributes()).isEqualTo(5);
 | 
			
		||||
    assertThat(config.getMaxNumberOfEvents()).isEqualTo(4);
 | 
			
		||||
    assertThat(config.getMaxNumberOfLinks()).isEqualTo(3);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,8 +5,8 @@
 | 
			
		|||
 | 
			
		||||
package io.opentelemetry.sdk.extension.zpages;
 | 
			
		||||
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfigBuilder;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimitsBuilder;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
import java.io.PrintStream;
 | 
			
		||||
| 
						 | 
				
			
			@ -130,7 +130,7 @@ final class TraceConfigzZPageHandler extends ZPageHandler {
 | 
			
		|||
        /* paramName= */ QUERY_STRING_MAX_NUM_OF_ATTRIBUTES,
 | 
			
		||||
        /* inputPlaceHolder= */ "",
 | 
			
		||||
        /* paramDefaultValue= */ Integer.toString(
 | 
			
		||||
            TraceConfig.getDefault().getMaxNumberOfAttributes()),
 | 
			
		||||
            SpanLimits.getDefault().getMaxNumberOfAttributes()),
 | 
			
		||||
        /* zebraStripeColor= */ ZEBRA_STRIPE_COLOR,
 | 
			
		||||
        /* zebraStripe= */ true);
 | 
			
		||||
    emitChangeTableRow(
 | 
			
		||||
| 
						 | 
				
			
			@ -138,7 +138,7 @@ final class TraceConfigzZPageHandler extends ZPageHandler {
 | 
			
		|||
        /* rowName= */ "MaxNumberOfEvents to",
 | 
			
		||||
        /* paramName= */ QUERY_STRING_MAX_NUM_OF_EVENTS,
 | 
			
		||||
        /* inputPlaceHolder= */ "",
 | 
			
		||||
        /* paramDefaultValue= */ Integer.toString(TraceConfig.getDefault().getMaxNumberOfEvents()),
 | 
			
		||||
        /* paramDefaultValue= */ Integer.toString(SpanLimits.getDefault().getMaxNumberOfEvents()),
 | 
			
		||||
        /* zebraStripeColor= */ ZEBRA_STRIPE_COLOR,
 | 
			
		||||
        /* zebraStripe= */ false);
 | 
			
		||||
    emitChangeTableRow(
 | 
			
		||||
| 
						 | 
				
			
			@ -146,7 +146,7 @@ final class TraceConfigzZPageHandler extends ZPageHandler {
 | 
			
		|||
        /* rowName= */ "MaxNumberOfLinks to",
 | 
			
		||||
        /* paramName= */ QUERY_STRING_MAX_NUM_OF_LINKS,
 | 
			
		||||
        /* inputPlaceHolder= */ "",
 | 
			
		||||
        /* paramDefaultValue= */ Integer.toString(TraceConfig.getDefault().getMaxNumberOfLinks()),
 | 
			
		||||
        /* paramDefaultValue= */ Integer.toString(SpanLimits.getDefault().getMaxNumberOfLinks()),
 | 
			
		||||
        /* zebraStripeColor= */ ZEBRA_STRIPE_COLOR,
 | 
			
		||||
        /* zebraStripe= */ true);
 | 
			
		||||
    emitChangeTableRow(
 | 
			
		||||
| 
						 | 
				
			
			@ -155,7 +155,7 @@ final class TraceConfigzZPageHandler extends ZPageHandler {
 | 
			
		|||
        /* paramName= */ QUERY_STRING_MAX_NUM_OF_ATTRIBUTES_PER_EVENT,
 | 
			
		||||
        /* inputPlaceHolder= */ "",
 | 
			
		||||
        /* paramDefaultValue= */ Integer.toString(
 | 
			
		||||
            TraceConfig.getDefault().getMaxNumberOfAttributesPerEvent()),
 | 
			
		||||
            SpanLimits.getDefault().getMaxNumberOfAttributesPerEvent()),
 | 
			
		||||
        /* zebraStripeColor= */ ZEBRA_STRIPE_COLOR,
 | 
			
		||||
        /* zebraStripe= */ false);
 | 
			
		||||
    emitChangeTableRow(
 | 
			
		||||
| 
						 | 
				
			
			@ -164,7 +164,7 @@ final class TraceConfigzZPageHandler extends ZPageHandler {
 | 
			
		|||
        /* paramName= */ QUERY_STRING_MAX_NUM_OF_ATTRIBUTES_PER_LINK,
 | 
			
		||||
        /* inputPlaceHolder= */ "",
 | 
			
		||||
        /* paramDefaultValue= */ Integer.toString(
 | 
			
		||||
            TraceConfig.getDefault().getMaxNumberOfAttributesPerLink()),
 | 
			
		||||
            SpanLimits.getDefault().getMaxNumberOfAttributesPerLink()),
 | 
			
		||||
        /* zebraStripeColor= */ ZEBRA_STRIPE_COLOR,
 | 
			
		||||
        /* zebraStripe= */ true);
 | 
			
		||||
    out.print("</table>");
 | 
			
		||||
| 
						 | 
				
			
			@ -360,7 +360,7 @@ final class TraceConfigzZPageHandler extends ZPageHandler {
 | 
			
		|||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    if (action.equals(QUERY_STRING_ACTION_CHANGE)) {
 | 
			
		||||
      TraceConfigBuilder newConfigBuilder = configSupplier.get().toBuilder();
 | 
			
		||||
      SpanLimitsBuilder newConfigBuilder = configSupplier.get().toBuilder();
 | 
			
		||||
      String samplingProbabilityStr = queryMap.get(QUERY_STRING_SAMPLING_PROBABILITY);
 | 
			
		||||
      if (samplingProbabilityStr != null) {
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			@ -421,7 +421,7 @@ final class TraceConfigzZPageHandler extends ZPageHandler {
 | 
			
		|||
      }
 | 
			
		||||
      configSupplier.setActiveTraceConfig(newConfigBuilder.build());
 | 
			
		||||
    } else if (action.equals(QUERY_STRING_ACTION_DEFAULT)) {
 | 
			
		||||
      TraceConfig defaultConfig = TraceConfig.builder().build();
 | 
			
		||||
      SpanLimits defaultConfig = SpanLimits.builder().build();
 | 
			
		||||
      configSupplier.setActiveTraceConfig(defaultConfig);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,26 +8,26 @@ package io.opentelemetry.sdk.extension.zpages;
 | 
			
		|||
import io.opentelemetry.api.common.Attributes;
 | 
			
		||||
import io.opentelemetry.api.trace.SpanKind;
 | 
			
		||||
import io.opentelemetry.context.Context;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.LinkData;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
 | 
			
		||||
final class TracezTraceConfigSupplier implements Supplier<TraceConfig>, Sampler {
 | 
			
		||||
final class TracezTraceConfigSupplier implements Supplier<SpanLimits>, Sampler {
 | 
			
		||||
 | 
			
		||||
  private volatile Sampler sampler;
 | 
			
		||||
  private volatile TraceConfig activeTraceConfig;
 | 
			
		||||
  private volatile SpanLimits activeSpanLimits;
 | 
			
		||||
 | 
			
		||||
  TracezTraceConfigSupplier() {
 | 
			
		||||
    sampler = Sampler.traceIdRatioBased(1.0);
 | 
			
		||||
    activeTraceConfig = TraceConfig.getDefault();
 | 
			
		||||
    activeSpanLimits = SpanLimits.getDefault();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public TraceConfig get() {
 | 
			
		||||
    return activeTraceConfig;
 | 
			
		||||
  public SpanLimits get() {
 | 
			
		||||
    return activeSpanLimits;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Sampler getSampler() {
 | 
			
		||||
| 
						 | 
				
			
			@ -38,8 +38,8 @@ final class TracezTraceConfigSupplier implements Supplier<TraceConfig>, Sampler
 | 
			
		|||
    this.sampler = sampler;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void setActiveTraceConfig(TraceConfig traceConfig) {
 | 
			
		||||
    activeTraceConfig = traceConfig;
 | 
			
		||||
  void setActiveTraceConfig(SpanLimits spanLimits) {
 | 
			
		||||
    activeSpanLimits = spanLimits;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,8 +6,8 @@
 | 
			
		|||
package io.opentelemetry.sdk.extension.zpages;
 | 
			
		||||
 | 
			
		||||
import com.sun.net.httpserver.HttpServer;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanProcessor;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.net.InetSocketAddress;
 | 
			
		||||
| 
						 | 
				
			
			@ -94,8 +94,8 @@ public final class ZPageServer {
 | 
			
		|||
  @Nullable
 | 
			
		||||
  private static HttpServer server;
 | 
			
		||||
 | 
			
		||||
  /** Returns a supplier of {@link TraceConfig} which can be reconfigured using zpages. */
 | 
			
		||||
  public static Supplier<TraceConfig> getTracezTraceConfigSupplier() {
 | 
			
		||||
  /** Returns a supplier of {@link SpanLimits} which can be reconfigured using zpages. */
 | 
			
		||||
  public static Supplier<SpanLimits> getTracezTraceConfigSupplier() {
 | 
			
		||||
    return tracezTraceConfigSupplier;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ package io.opentelemetry.sdk.extension.zpages;
 | 
			
		|||
import static org.assertj.core.api.Assertions.assertThat;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableMap;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
import java.io.ByteArrayOutputStream;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
| 
						 | 
				
			
			@ -46,29 +46,28 @@ class TraceConfigzZPageHandlerTest {
 | 
			
		|||
    assertThat(output.toString()).contains("MaxNumberOfAttributes to");
 | 
			
		||||
    assertThat(output.toString()).contains("name=" + queryMaxNumOfAttributes);
 | 
			
		||||
    assertThat(output.toString())
 | 
			
		||||
        .contains(
 | 
			
		||||
            "(" + Integer.toString(TraceConfig.getDefault().getMaxNumberOfAttributes()) + ")");
 | 
			
		||||
        .contains("(" + Integer.toString(SpanLimits.getDefault().getMaxNumberOfAttributes()) + ")");
 | 
			
		||||
    assertThat(output.toString()).contains("MaxNumberOfEvents to");
 | 
			
		||||
    assertThat(output.toString()).contains("name=" + queryMaxNumOfEvents);
 | 
			
		||||
    assertThat(output.toString())
 | 
			
		||||
        .contains("(" + Integer.toString(TraceConfig.getDefault().getMaxNumberOfEvents()) + ")");
 | 
			
		||||
        .contains("(" + Integer.toString(SpanLimits.getDefault().getMaxNumberOfEvents()) + ")");
 | 
			
		||||
    assertThat(output.toString()).contains("MaxNumberOfLinks to");
 | 
			
		||||
    assertThat(output.toString()).contains("name=" + queryMaxNumOfLinks);
 | 
			
		||||
    assertThat(output.toString())
 | 
			
		||||
        .contains("(" + Integer.toString(TraceConfig.getDefault().getMaxNumberOfLinks()) + ")");
 | 
			
		||||
        .contains("(" + Integer.toString(SpanLimits.getDefault().getMaxNumberOfLinks()) + ")");
 | 
			
		||||
    assertThat(output.toString()).contains("MaxNumberOfAttributesPerEvent to");
 | 
			
		||||
    assertThat(output.toString()).contains("name=" + queryMaxNumOfAttributesPerEvent);
 | 
			
		||||
    assertThat(output.toString())
 | 
			
		||||
        .contains(
 | 
			
		||||
            "("
 | 
			
		||||
                + Integer.toString(TraceConfig.getDefault().getMaxNumberOfAttributesPerEvent())
 | 
			
		||||
                + Integer.toString(SpanLimits.getDefault().getMaxNumberOfAttributesPerEvent())
 | 
			
		||||
                + ")");
 | 
			
		||||
    assertThat(output.toString()).contains("MaxNumberOfAttributesPerLink to");
 | 
			
		||||
    assertThat(output.toString()).contains("name=" + queryMaxNumOfAttributesPerLink);
 | 
			
		||||
    assertThat(output.toString())
 | 
			
		||||
        .contains(
 | 
			
		||||
            "("
 | 
			
		||||
                + Integer.toString(TraceConfig.getDefault().getMaxNumberOfAttributesPerLink())
 | 
			
		||||
                + Integer.toString(SpanLimits.getDefault().getMaxNumberOfAttributesPerLink())
 | 
			
		||||
                + ")");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -163,15 +162,15 @@ class TraceConfigzZPageHandlerTest {
 | 
			
		|||
    assertThat(configSupplier.getSampler().getDescription())
 | 
			
		||||
        .isEqualTo(Sampler.traceIdRatioBased(1.0).getDescription());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfAttributes())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfAttributes());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfAttributes());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfEvents())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfEvents());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfEvents());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfLinks())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfLinks());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfLinks());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfAttributesPerEvent())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfAttributesPerEvent());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfAttributesPerEvent());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfAttributesPerLink())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfAttributesPerLink());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfAttributesPerLink());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
| 
						 | 
				
			
			@ -188,15 +187,15 @@ class TraceConfigzZPageHandlerTest {
 | 
			
		|||
    assertThat(configSupplier.getSampler().getDescription())
 | 
			
		||||
        .isEqualTo(Sampler.traceIdRatioBased(1.0).getDescription());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfAttributes())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfAttributes());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfAttributes());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfEvents())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfEvents());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfEvents());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfLinks())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfLinks());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfLinks());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfAttributesPerEvent())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfAttributesPerEvent());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfAttributesPerEvent());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfAttributesPerLink())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfAttributesPerLink());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfAttributesPerLink());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
| 
						 | 
				
			
			@ -322,15 +321,15 @@ class TraceConfigzZPageHandlerTest {
 | 
			
		|||
    assertThat(configSupplier.getSampler().getDescription())
 | 
			
		||||
        .isEqualTo(Sampler.traceIdRatioBased(1.0).getDescription());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfAttributes())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfAttributes());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfAttributes());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfEvents())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfEvents());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfEvents());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfLinks())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfLinks());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfLinks());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfAttributesPerEvent())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfAttributesPerEvent());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfAttributesPerEvent());
 | 
			
		||||
    assertThat(configSupplier.get().getMaxNumberOfAttributesPerLink())
 | 
			
		||||
        .isEqualTo(TraceConfig.getDefault().getMaxNumberOfAttributesPerLink());
 | 
			
		||||
        .isEqualTo(SpanLimits.getDefault().getMaxNumberOfAttributesPerLink());
 | 
			
		||||
 | 
			
		||||
    // POST request, Should apply changes
 | 
			
		||||
    traceConfigzZPageHandler.processRequest("POST", queryMap, output);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,7 +19,7 @@ import io.opentelemetry.sdk.common.Clock;
 | 
			
		|||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.IdGenerator;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SdkTracerProvider;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
 | 
			
		||||
import io.opentelemetry.sdk.trace.export.SpanExporter;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
| 
						 | 
				
			
			@ -86,7 +86,7 @@ class OpenTelemetrySdkTest {
 | 
			
		|||
  void testConfiguration_tracerSettings() {
 | 
			
		||||
    Resource resource = Resource.create(Attributes.builder().put("cat", "meow").build());
 | 
			
		||||
    IdGenerator idGenerator = mock(IdGenerator.class);
 | 
			
		||||
    TraceConfig traceConfig = TraceConfig.getDefault();
 | 
			
		||||
    SpanLimits spanLimits = SpanLimits.getDefault();
 | 
			
		||||
    OpenTelemetrySdk openTelemetry =
 | 
			
		||||
        OpenTelemetrySdk.builder()
 | 
			
		||||
            .setTracerProvider(
 | 
			
		||||
| 
						 | 
				
			
			@ -94,7 +94,7 @@ class OpenTelemetrySdkTest {
 | 
			
		|||
                    .setClock(clock)
 | 
			
		||||
                    .setResource(resource)
 | 
			
		||||
                    .setIdGenerator(idGenerator)
 | 
			
		||||
                    .setTraceConfig(traceConfig)
 | 
			
		||||
                    .setSpanLimits(spanLimits)
 | 
			
		||||
                    .build())
 | 
			
		||||
            .build();
 | 
			
		||||
    TracerProvider unobfuscatedTracerProvider =
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +104,7 @@ class OpenTelemetrySdkTest {
 | 
			
		|||
        .isInstanceOfSatisfying(
 | 
			
		||||
            SdkTracerProvider.class,
 | 
			
		||||
            sdkTracerProvider ->
 | 
			
		||||
                assertThat(sdkTracerProvider.getActiveTraceConfig()).isEqualTo(traceConfig));
 | 
			
		||||
                assertThat(sdkTracerProvider.getSpanLimits()).isEqualTo(spanLimits));
 | 
			
		||||
    // Since TracerProvider is in a different package, the only alternative to this reflective
 | 
			
		||||
    // approach would be to make the fields public for testing which is worse than this.
 | 
			
		||||
    assertThat(unobfuscatedTracerProvider)
 | 
			
		||||
| 
						 | 
				
			
			@ -129,7 +129,7 @@ class OpenTelemetrySdkTest {
 | 
			
		|||
  // Demonstrates how clear or confusing is SDK configuration
 | 
			
		||||
  @Test
 | 
			
		||||
  void fullOpenTelemetrySdkConfigurationDemo() {
 | 
			
		||||
    TraceConfig newConfig = TraceConfig.builder().setMaxLengthOfAttributeValues(128).build();
 | 
			
		||||
    SpanLimits newConfig = SpanLimits.builder().setMaxLengthOfAttributeValues(128).build();
 | 
			
		||||
 | 
			
		||||
    OpenTelemetrySdkBuilder sdkBuilder =
 | 
			
		||||
        OpenTelemetrySdk.builder()
 | 
			
		||||
| 
						 | 
				
			
			@ -141,7 +141,7 @@ class OpenTelemetrySdkTest {
 | 
			
		|||
                    .setClock(mock(Clock.class))
 | 
			
		||||
                    .setIdGenerator(mock(IdGenerator.class))
 | 
			
		||||
                    .setResource(Resource.getEmpty())
 | 
			
		||||
                    .setTraceConfig(newConfig)
 | 
			
		||||
                    .setSpanLimits(newConfig)
 | 
			
		||||
                    .build());
 | 
			
		||||
 | 
			
		||||
    sdkBuilder.build();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,6 @@ package io.opentelemetry.sdk.trace;
 | 
			
		|||
 | 
			
		||||
import io.opentelemetry.api.trace.SpanKind;
 | 
			
		||||
import io.opentelemetry.api.trace.Tracer;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
import org.openjdk.jmh.annotations.Benchmark;
 | 
			
		||||
import org.openjdk.jmh.annotations.Fork;
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +36,7 @@ public class SpanAttributeTruncateBenchmark {
 | 
			
		|||
  public final void setup() {
 | 
			
		||||
    Tracer tracer =
 | 
			
		||||
        SdkTracerProvider.builder()
 | 
			
		||||
            .setTraceConfig(TraceConfig.builder().setMaxLengthOfAttributeValues(maxLength).build())
 | 
			
		||||
            .setSpanLimits(SpanLimits.builder().setMaxLengthOfAttributeValues(maxLength).build())
 | 
			
		||||
            .build()
 | 
			
		||||
            .get("benchmarkTracer");
 | 
			
		||||
    sdkSpanBuilder =
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,7 +16,6 @@ import io.opentelemetry.context.Context;
 | 
			
		|||
import io.opentelemetry.sdk.common.Clock;
 | 
			
		||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
 | 
			
		||||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.EventData;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.LinkData;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.SpanData;
 | 
			
		||||
| 
						 | 
				
			
			@ -43,7 +42,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
  private static final Logger logger = Logger.getLogger(RecordEventsReadableSpan.class.getName());
 | 
			
		||||
 | 
			
		||||
  // The config used when constructing this Span.
 | 
			
		||||
  private final TraceConfig traceConfig;
 | 
			
		||||
  private final SpanLimits spanLimits;
 | 
			
		||||
  // Contains the identifiers associated with this Span.
 | 
			
		||||
  private final SpanContext context;
 | 
			
		||||
  // The parent SpanContext of this span. Invalid if this is a root span.
 | 
			
		||||
| 
						 | 
				
			
			@ -97,7 +96,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
      InstrumentationLibraryInfo instrumentationLibraryInfo,
 | 
			
		||||
      SpanKind kind,
 | 
			
		||||
      SpanContext parentSpanContext,
 | 
			
		||||
      TraceConfig traceConfig,
 | 
			
		||||
      SpanLimits spanLimits,
 | 
			
		||||
      SpanProcessor spanProcessor,
 | 
			
		||||
      Clock clock,
 | 
			
		||||
      Resource resource,
 | 
			
		||||
| 
						 | 
				
			
			@ -119,7 +118,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
    this.startEpochNanos = startEpochNanos;
 | 
			
		||||
    this.attributes = attributes;
 | 
			
		||||
    this.events = new ArrayList<>();
 | 
			
		||||
    this.traceConfig = traceConfig;
 | 
			
		||||
    this.spanLimits = spanLimits;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			@ -130,7 +129,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
   * @param kind the span kind.
 | 
			
		||||
   * @param parentSpanContext the parent span context, or {@link SpanContext#getInvalid()} if this
 | 
			
		||||
   *     span is a root span.
 | 
			
		||||
   * @param traceConfig trace parameters like sampler and probability.
 | 
			
		||||
   * @param spanLimits trace parameters like sampler and probability.
 | 
			
		||||
   * @param spanProcessor handler called when the span starts and ends.
 | 
			
		||||
   * @param clock the clock used to get the time.
 | 
			
		||||
   * @param resource the resource associated with this span.
 | 
			
		||||
| 
						 | 
				
			
			@ -145,7 +144,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
      SpanKind kind,
 | 
			
		||||
      @Nullable SpanContext parentSpanContext,
 | 
			
		||||
      @Nonnull Context parentContext,
 | 
			
		||||
      TraceConfig traceConfig,
 | 
			
		||||
      SpanLimits spanLimits,
 | 
			
		||||
      SpanProcessor spanProcessor,
 | 
			
		||||
      Clock clock,
 | 
			
		||||
      Resource resource,
 | 
			
		||||
| 
						 | 
				
			
			@ -160,7 +159,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
            instrumentationLibraryInfo,
 | 
			
		||||
            kind,
 | 
			
		||||
            parentSpanContext,
 | 
			
		||||
            traceConfig,
 | 
			
		||||
            spanLimits,
 | 
			
		||||
            spanProcessor,
 | 
			
		||||
            clock,
 | 
			
		||||
            resource,
 | 
			
		||||
| 
						 | 
				
			
			@ -261,11 +260,11 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
        return this;
 | 
			
		||||
      }
 | 
			
		||||
      if (attributes == null) {
 | 
			
		||||
        attributes = new AttributesMap(traceConfig.getMaxNumberOfAttributes());
 | 
			
		||||
        attributes = new AttributesMap(spanLimits.getMaxNumberOfAttributes());
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (traceConfig.shouldTruncateStringAttributeValues()) {
 | 
			
		||||
        value = StringUtils.truncateToSize(key, value, traceConfig.getMaxLengthOfAttributeValues());
 | 
			
		||||
      if (spanLimits.shouldTruncateStringAttributeValues()) {
 | 
			
		||||
        value = StringUtils.truncateToSize(key, value, spanLimits.getMaxLengthOfAttributeValues());
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      attributes.put(key, value);
 | 
			
		||||
| 
						 | 
				
			
			@ -301,7 +300,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
        EventData.create(
 | 
			
		||||
            clock.now(),
 | 
			
		||||
            name,
 | 
			
		||||
            copyAndLimitAttributes(attributes, traceConfig.getMaxNumberOfAttributesPerEvent()),
 | 
			
		||||
            copyAndLimitAttributes(attributes, spanLimits.getMaxNumberOfAttributesPerEvent()),
 | 
			
		||||
            totalAttributeCount));
 | 
			
		||||
    return this;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -316,7 +315,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
        EventData.create(
 | 
			
		||||
            unit.toNanos(timestamp),
 | 
			
		||||
            name,
 | 
			
		||||
            copyAndLimitAttributes(attributes, traceConfig.getMaxNumberOfAttributesPerEvent()),
 | 
			
		||||
            copyAndLimitAttributes(attributes, spanLimits.getMaxNumberOfAttributesPerEvent()),
 | 
			
		||||
            totalAttributeCount));
 | 
			
		||||
    return this;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -345,7 +344,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
 | 
			
		|||
        logger.log(Level.FINE, "Calling addEvent() on an ended Span.");
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      if (events.size() < traceConfig.getMaxNumberOfEvents()) {
 | 
			
		||||
      if (events.size() < spanLimits.getMaxNumberOfEvents()) {
 | 
			
		||||
        events.add(timedEvent);
 | 
			
		||||
      }
 | 
			
		||||
      totalRecordedEvents++;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,6 @@ import io.opentelemetry.context.Context;
 | 
			
		|||
import io.opentelemetry.sdk.common.Clock;
 | 
			
		||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
 | 
			
		||||
import io.opentelemetry.sdk.internal.MonotonicClock;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.LinkData;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +39,7 @@ final class SdkSpanBuilder implements SpanBuilder {
 | 
			
		|||
  private final String spanName;
 | 
			
		||||
  private final InstrumentationLibraryInfo instrumentationLibraryInfo;
 | 
			
		||||
  private final TracerSharedState tracerSharedState;
 | 
			
		||||
  private final TraceConfig traceConfig;
 | 
			
		||||
  private final SpanLimits spanLimits;
 | 
			
		||||
 | 
			
		||||
  @Nullable private Context parent;
 | 
			
		||||
  private SpanKind spanKind = SpanKind.INTERNAL;
 | 
			
		||||
| 
						 | 
				
			
			@ -54,11 +53,11 @@ final class SdkSpanBuilder implements SpanBuilder {
 | 
			
		|||
      String spanName,
 | 
			
		||||
      InstrumentationLibraryInfo instrumentationLibraryInfo,
 | 
			
		||||
      TracerSharedState tracerSharedState,
 | 
			
		||||
      TraceConfig traceConfig) {
 | 
			
		||||
      SpanLimits spanLimits) {
 | 
			
		||||
    this.spanName = spanName;
 | 
			
		||||
    this.instrumentationLibraryInfo = instrumentationLibraryInfo;
 | 
			
		||||
    this.tracerSharedState = tracerSharedState;
 | 
			
		||||
    this.traceConfig = traceConfig;
 | 
			
		||||
    this.spanLimits = spanLimits;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
| 
						 | 
				
			
			@ -95,7 +94,7 @@ final class SdkSpanBuilder implements SpanBuilder {
 | 
			
		|||
        LinkData.create(
 | 
			
		||||
            spanContext,
 | 
			
		||||
            RecordEventsReadableSpan.copyAndLimitAttributes(
 | 
			
		||||
                attributes, traceConfig.getMaxNumberOfAttributesPerLink()),
 | 
			
		||||
                attributes, spanLimits.getMaxNumberOfAttributesPerLink()),
 | 
			
		||||
            totalAttributeCount));
 | 
			
		||||
    return this;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -104,11 +103,11 @@ final class SdkSpanBuilder implements SpanBuilder {
 | 
			
		|||
    Objects.requireNonNull(link, "link");
 | 
			
		||||
    totalNumberOfLinksAdded++;
 | 
			
		||||
    if (links == null) {
 | 
			
		||||
      links = new ArrayList<>(traceConfig.getMaxNumberOfLinks());
 | 
			
		||||
      links = new ArrayList<>(spanLimits.getMaxNumberOfLinks());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // don't bother doing anything with any links beyond the max.
 | 
			
		||||
    if (links.size() == traceConfig.getMaxNumberOfLinks()) {
 | 
			
		||||
    if (links.size() == spanLimits.getMaxNumberOfLinks()) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -142,11 +141,11 @@ final class SdkSpanBuilder implements SpanBuilder {
 | 
			
		|||
      return this;
 | 
			
		||||
    }
 | 
			
		||||
    if (attributes == null) {
 | 
			
		||||
      attributes = new AttributesMap(traceConfig.getMaxNumberOfAttributes());
 | 
			
		||||
      attributes = new AttributesMap(spanLimits.getMaxNumberOfAttributes());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (traceConfig.shouldTruncateStringAttributeValues()) {
 | 
			
		||||
      value = StringUtils.truncateToSize(key, value, traceConfig.getMaxLengthOfAttributeValues());
 | 
			
		||||
    if (spanLimits.shouldTruncateStringAttributeValues()) {
 | 
			
		||||
      value = StringUtils.truncateToSize(key, value, spanLimits.getMaxLengthOfAttributeValues());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    attributes.put(key, value);
 | 
			
		||||
| 
						 | 
				
			
			@ -201,7 +200,7 @@ final class SdkSpanBuilder implements SpanBuilder {
 | 
			
		|||
    Attributes samplingAttributes = samplingResult.getAttributes();
 | 
			
		||||
    if (!samplingAttributes.isEmpty()) {
 | 
			
		||||
      if (attributes == null) {
 | 
			
		||||
        attributes = new AttributesMap(traceConfig.getMaxNumberOfAttributes());
 | 
			
		||||
        attributes = new AttributesMap(spanLimits.getMaxNumberOfAttributes());
 | 
			
		||||
      }
 | 
			
		||||
      samplingAttributes.forEach((key, value) -> attributes.put((AttributeKey) key, value));
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -218,7 +217,7 @@ final class SdkSpanBuilder implements SpanBuilder {
 | 
			
		|||
        spanKind,
 | 
			
		||||
        parentSpanContext,
 | 
			
		||||
        parentContext,
 | 
			
		||||
        traceConfig,
 | 
			
		||||
        spanLimits,
 | 
			
		||||
        tracerSharedState.getActiveSpanProcessor(),
 | 
			
		||||
        getClock(parentSpan, tracerSharedState.getClock()),
 | 
			
		||||
        tracerSharedState.getResource(),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,7 +30,7 @@ final class SdkTracer implements Tracer {
 | 
			
		|||
      return Tracer.getDefault().spanBuilder(spanName);
 | 
			
		||||
    }
 | 
			
		||||
    return new SdkSpanBuilder(
 | 
			
		||||
        spanName, instrumentationLibraryInfo, sharedState, sharedState.getActiveTraceConfig());
 | 
			
		||||
        spanName, instrumentationLibraryInfo, sharedState, sharedState.getSpanLimits());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,6 @@ import io.opentelemetry.sdk.common.Clock;
 | 
			
		|||
import io.opentelemetry.sdk.common.CompletableResultCode;
 | 
			
		||||
import io.opentelemetry.sdk.internal.ComponentRegistry;
 | 
			
		||||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
import java.io.Closeable;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +47,7 @@ public final class SdkTracerProvider implements TracerProvider, Closeable {
 | 
			
		|||
      Clock clock,
 | 
			
		||||
      IdGenerator idsGenerator,
 | 
			
		||||
      Resource resource,
 | 
			
		||||
      Supplier<TraceConfig> traceConfigSupplier,
 | 
			
		||||
      Supplier<SpanLimits> traceConfigSupplier,
 | 
			
		||||
      Sampler sampler,
 | 
			
		||||
      List<SpanProcessor> spanProcessors) {
 | 
			
		||||
    this.sharedState =
 | 
			
		||||
| 
						 | 
				
			
			@ -74,9 +73,9 @@ public final class SdkTracerProvider implements TracerProvider, Closeable {
 | 
			
		|||
    return tracerSdkComponentRegistry.get(instrumentationName, instrumentationVersion);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Returns the active {@link TraceConfig}. */
 | 
			
		||||
  public TraceConfig getActiveTraceConfig() {
 | 
			
		||||
    return sharedState.getActiveTraceConfig();
 | 
			
		||||
  /** Returns the {@link SpanLimits} that are currently applied to created spans. */
 | 
			
		||||
  public SpanLimits getSpanLimits() {
 | 
			
		||||
    return sharedState.getSpanLimits();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Returns the configured {@link Sampler}. */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,7 +10,6 @@ import static java.util.Objects.requireNonNull;
 | 
			
		|||
import io.opentelemetry.sdk.common.Clock;
 | 
			
		||||
import io.opentelemetry.sdk.internal.SystemClock;
 | 
			
		||||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,7 +24,7 @@ public final class SdkTracerProviderBuilder {
 | 
			
		|||
  private Clock clock = SystemClock.getInstance();
 | 
			
		||||
  private IdGenerator idsGenerator = IdGenerator.random();
 | 
			
		||||
  private Resource resource = Resource.getDefault();
 | 
			
		||||
  private Supplier<TraceConfig> traceConfigSupplier = TraceConfig::getDefault;
 | 
			
		||||
  private Supplier<SpanLimits> traceConfigSupplier = SpanLimits::getDefault;
 | 
			
		||||
  private Sampler sampler = DEFAULT_SAMPLER;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			@ -66,23 +65,23 @@ public final class SdkTracerProviderBuilder {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Assign an initial {@link TraceConfig} that should be used with this SDK.
 | 
			
		||||
   * Assign an initial {@link SpanLimits} that should be used with this SDK.
 | 
			
		||||
   *
 | 
			
		||||
   * @return this
 | 
			
		||||
   */
 | 
			
		||||
  public SdkTracerProviderBuilder setTraceConfig(TraceConfig traceConfig) {
 | 
			
		||||
    requireNonNull(traceConfig, "traceConfig");
 | 
			
		||||
    this.traceConfigSupplier = () -> traceConfig;
 | 
			
		||||
  public SdkTracerProviderBuilder setSpanLimits(SpanLimits spanLimits) {
 | 
			
		||||
    requireNonNull(spanLimits, "traceConfig");
 | 
			
		||||
    this.traceConfigSupplier = () -> spanLimits;
 | 
			
		||||
    return this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Assign a {@link Supplier} of {@link TraceConfig}. {@link TraceConfig} will be retrieved each
 | 
			
		||||
   * time a {@link io.opentelemetry.api.trace.Span} is started.
 | 
			
		||||
   * Assign a {@link Supplier} of {@link SpanLimits}. {@link SpanLimits} will be retrieved each time
 | 
			
		||||
   * a {@link io.opentelemetry.api.trace.Span} is started.
 | 
			
		||||
   *
 | 
			
		||||
   * @return this
 | 
			
		||||
   */
 | 
			
		||||
  public SdkTracerProviderBuilder setTraceConfig(Supplier<TraceConfig> traceConfigSupplier) {
 | 
			
		||||
  public SdkTracerProviderBuilder setSpanLimits(Supplier<SpanLimits> traceConfigSupplier) {
 | 
			
		||||
    requireNonNull(traceConfigSupplier, "traceConfig");
 | 
			
		||||
    this.traceConfigSupplier = traceConfigSupplier;
 | 
			
		||||
    return this;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,125 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright The OpenTelemetry Authors
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package io.opentelemetry.sdk.trace;
 | 
			
		||||
 | 
			
		||||
import com.google.auto.value.AutoValue;
 | 
			
		||||
import io.opentelemetry.api.trace.Span;
 | 
			
		||||
import javax.annotation.concurrent.Immutable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Class that holds limits enforced during span recording.
 | 
			
		||||
 *
 | 
			
		||||
 * <p>Note: To allow dynamic updates of {@link SpanLimits} you should register a {@link
 | 
			
		||||
 * java.util.function.Supplier} with {@link
 | 
			
		||||
 * io.opentelemetry.sdk.trace.SdkTracerProviderBuilder#setSpanLimits(java.util.function.Supplier)}
 | 
			
		||||
 * which supplies dynamic configs when queried.
 | 
			
		||||
 */
 | 
			
		||||
@AutoValue
 | 
			
		||||
@Immutable
 | 
			
		||||
public abstract class SpanLimits {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Value for attribute length which indicates attributes should not be truncated.
 | 
			
		||||
   *
 | 
			
		||||
   * @see SpanLimitsBuilder#setMaxLengthOfAttributeValues(int)
 | 
			
		||||
   */
 | 
			
		||||
  public static final int UNLIMITED_ATTRIBUTE_LENGTH = -1;
 | 
			
		||||
 | 
			
		||||
  // These values are the default values for all the global parameters.
 | 
			
		||||
  // TODO: decide which default sampler to use
 | 
			
		||||
 | 
			
		||||
  private static final SpanLimits DEFAULT = new SpanLimitsBuilder().build();
 | 
			
		||||
 | 
			
		||||
  /** Returns the default {@link SpanLimits}. */
 | 
			
		||||
  public static SpanLimits getDefault() {
 | 
			
		||||
    return DEFAULT;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Returns a new {@link SpanLimitsBuilder} to construct a {@link SpanLimits}. */
 | 
			
		||||
  public static SpanLimitsBuilder builder() {
 | 
			
		||||
    return new SpanLimitsBuilder();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static SpanLimits create(
 | 
			
		||||
      int maxNumAttributes,
 | 
			
		||||
      int maxNumEvents,
 | 
			
		||||
      int maxNumLinks,
 | 
			
		||||
      int maxNumAttributesPerEvent,
 | 
			
		||||
      int maxNumAttributesPerLink,
 | 
			
		||||
      int maxAttributeLength) {
 | 
			
		||||
    return new AutoValue_SpanLimits(
 | 
			
		||||
        maxNumAttributes,
 | 
			
		||||
        maxNumEvents,
 | 
			
		||||
        maxNumLinks,
 | 
			
		||||
        maxNumAttributesPerEvent,
 | 
			
		||||
        maxNumAttributesPerLink,
 | 
			
		||||
        maxAttributeLength);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of attributes per {@link Span}.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of attributes per {@link Span}.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfAttributes();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of events per {@link Span}.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of events per {@code Span}.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfEvents();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of links per {@link Span}.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of links per {@code Span}.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfLinks();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of attributes per event.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of attributes per event.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfAttributesPerEvent();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of attributes per link.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of attributes per link.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfAttributesPerLink();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max length of string attribute value in characters.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max length of string attribute value in characters.
 | 
			
		||||
   * @see #shouldTruncateStringAttributeValues()
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxLengthOfAttributeValues();
 | 
			
		||||
 | 
			
		||||
  public boolean shouldTruncateStringAttributeValues() {
 | 
			
		||||
    return getMaxLengthOfAttributeValues() != UNLIMITED_ATTRIBUTE_LENGTH;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns a {@link SpanLimitsBuilder} initialized to the same property values as the current
 | 
			
		||||
   * instance.
 | 
			
		||||
   *
 | 
			
		||||
   * @return a {@link SpanLimitsBuilder} initialized to the same property values as the current
 | 
			
		||||
   *     instance.
 | 
			
		||||
   */
 | 
			
		||||
  public SpanLimitsBuilder toBuilder() {
 | 
			
		||||
    return new SpanLimitsBuilder()
 | 
			
		||||
        .setMaxNumberOfAttributes(getMaxNumberOfAttributes())
 | 
			
		||||
        .setMaxNumberOfEvents(getMaxNumberOfEvents())
 | 
			
		||||
        .setMaxNumberOfLinks(getMaxNumberOfLinks())
 | 
			
		||||
        .setMaxNumberOfAttributesPerEvent(getMaxNumberOfAttributesPerEvent())
 | 
			
		||||
        .setMaxNumberOfAttributesPerLink(getMaxNumberOfAttributesPerLink())
 | 
			
		||||
        .setMaxLengthOfAttributeValues(getMaxLengthOfAttributeValues());
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -3,19 +3,19 @@
 | 
			
		|||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package io.opentelemetry.sdk.trace.config;
 | 
			
		||||
package io.opentelemetry.sdk.trace;
 | 
			
		||||
 | 
			
		||||
import io.opentelemetry.api.internal.Utils;
 | 
			
		||||
import io.opentelemetry.api.trace.Span;
 | 
			
		||||
 | 
			
		||||
/** Builder for {@link TraceConfig}. */
 | 
			
		||||
public final class TraceConfigBuilder {
 | 
			
		||||
/** Builder for {@link SpanLimits}. */
 | 
			
		||||
public final class SpanLimitsBuilder {
 | 
			
		||||
  private static final int DEFAULT_SPAN_MAX_NUM_ATTRIBUTES = 1000;
 | 
			
		||||
  private static final int DEFAULT_SPAN_MAX_NUM_EVENTS = 1000;
 | 
			
		||||
  private static final int DEFAULT_SPAN_MAX_NUM_LINKS = 1000;
 | 
			
		||||
  private static final int DEFAULT_SPAN_MAX_NUM_ATTRIBUTES_PER_EVENT = 32;
 | 
			
		||||
  private static final int DEFAULT_SPAN_MAX_NUM_ATTRIBUTES_PER_LINK = 32;
 | 
			
		||||
  private static final int DEFAULT_MAX_ATTRIBUTE_LENGTH = TraceConfig.UNLIMITED_ATTRIBUTE_LENGTH;
 | 
			
		||||
  private static final int DEFAULT_MAX_ATTRIBUTE_LENGTH = SpanLimits.UNLIMITED_ATTRIBUTE_LENGTH;
 | 
			
		||||
 | 
			
		||||
  private int maxNumAttributes = DEFAULT_SPAN_MAX_NUM_ATTRIBUTES;
 | 
			
		||||
  private int maxNumEvents = DEFAULT_SPAN_MAX_NUM_EVENTS;
 | 
			
		||||
| 
						 | 
				
			
			@ -24,7 +24,7 @@ public final class TraceConfigBuilder {
 | 
			
		|||
  private int maxNumAttributesPerLink = DEFAULT_SPAN_MAX_NUM_ATTRIBUTES_PER_LINK;
 | 
			
		||||
  private int maxAttributeLength = DEFAULT_MAX_ATTRIBUTE_LENGTH;
 | 
			
		||||
 | 
			
		||||
  TraceConfigBuilder() {}
 | 
			
		||||
  SpanLimitsBuilder() {}
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Sets the global default max number of attributes per {@link Span}.
 | 
			
		||||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ public final class TraceConfigBuilder {
 | 
			
		|||
   *     must be positive otherwise {@link #build()} will throw an exception.
 | 
			
		||||
   * @return this.
 | 
			
		||||
   */
 | 
			
		||||
  public TraceConfigBuilder setMaxNumberOfAttributes(int maxNumberOfAttributes) {
 | 
			
		||||
  public SpanLimitsBuilder setMaxNumberOfAttributes(int maxNumberOfAttributes) {
 | 
			
		||||
    Utils.checkArgument(maxNumberOfAttributes > 0, "maxNumberOfAttributes must be greater than 0");
 | 
			
		||||
    this.maxNumAttributes = maxNumberOfAttributes;
 | 
			
		||||
    return this;
 | 
			
		||||
| 
						 | 
				
			
			@ -46,7 +46,7 @@ public final class TraceConfigBuilder {
 | 
			
		|||
   *     positive otherwise {@link #build()} will throw an exception.
 | 
			
		||||
   * @return this.
 | 
			
		||||
   */
 | 
			
		||||
  public TraceConfigBuilder setMaxNumberOfEvents(int maxNumberOfEvents) {
 | 
			
		||||
  public SpanLimitsBuilder setMaxNumberOfEvents(int maxNumberOfEvents) {
 | 
			
		||||
    Utils.checkArgument(maxNumberOfEvents > 0, "maxNumberOfEvents must be greater than 0");
 | 
			
		||||
    this.maxNumEvents = maxNumberOfEvents;
 | 
			
		||||
    return this;
 | 
			
		||||
| 
						 | 
				
			
			@ -59,7 +59,7 @@ public final class TraceConfigBuilder {
 | 
			
		|||
   *     positive otherwise {@link #build()} will throw an exception.
 | 
			
		||||
   * @return this.
 | 
			
		||||
   */
 | 
			
		||||
  public TraceConfigBuilder setMaxNumberOfLinks(int maxNumberOfLinks) {
 | 
			
		||||
  public SpanLimitsBuilder setMaxNumberOfLinks(int maxNumberOfLinks) {
 | 
			
		||||
    Utils.checkArgument(maxNumberOfLinks > 0, "maxNumberOfLinks must be greater than 0");
 | 
			
		||||
    this.maxNumLinks = maxNumberOfLinks;
 | 
			
		||||
    return this;
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +72,7 @@ public final class TraceConfigBuilder {
 | 
			
		|||
   *     must be positive otherwise {@link #build()} will throw an exception.
 | 
			
		||||
   * @return this.
 | 
			
		||||
   */
 | 
			
		||||
  public TraceConfigBuilder setMaxNumberOfAttributesPerEvent(int maxNumberOfAttributesPerEvent) {
 | 
			
		||||
  public SpanLimitsBuilder setMaxNumberOfAttributesPerEvent(int maxNumberOfAttributesPerEvent) {
 | 
			
		||||
    Utils.checkArgument(
 | 
			
		||||
        maxNumberOfAttributesPerEvent > 0, "maxNumberOfAttributesPerEvent must be greater than 0");
 | 
			
		||||
    this.maxNumAttributesPerEvent = maxNumberOfAttributesPerEvent;
 | 
			
		||||
| 
						 | 
				
			
			@ -86,7 +86,7 @@ public final class TraceConfigBuilder {
 | 
			
		|||
   *     must be positive otherwise {@link #build()} will throw an exception.
 | 
			
		||||
   * @return this.
 | 
			
		||||
   */
 | 
			
		||||
  public TraceConfigBuilder setMaxNumberOfAttributesPerLink(int maxNumberOfAttributesPerLink) {
 | 
			
		||||
  public SpanLimitsBuilder setMaxNumberOfAttributesPerLink(int maxNumberOfAttributesPerLink) {
 | 
			
		||||
    Utils.checkArgument(
 | 
			
		||||
        maxNumberOfAttributesPerLink > 0, "maxNumberOfAttributesPerLink must be greater than 0");
 | 
			
		||||
    this.maxNumAttributesPerLink = maxNumberOfAttributesPerLink;
 | 
			
		||||
| 
						 | 
				
			
			@ -97,11 +97,11 @@ public final class TraceConfigBuilder {
 | 
			
		|||
   * Sets the global default max length of string attribute value in characters.
 | 
			
		||||
   *
 | 
			
		||||
   * @param maxLengthOfAttributeValues the global default max length of string attribute value in
 | 
			
		||||
   *     characters. It must be non-negative (or {@link TraceConfig#UNLIMITED_ATTRIBUTE_LENGTH})
 | 
			
		||||
   *     characters. It must be non-negative (or {@link SpanLimits#UNLIMITED_ATTRIBUTE_LENGTH})
 | 
			
		||||
   *     otherwise {@link #build()} will throw an exception.
 | 
			
		||||
   * @return this.
 | 
			
		||||
   */
 | 
			
		||||
  public TraceConfigBuilder setMaxLengthOfAttributeValues(int maxLengthOfAttributeValues) {
 | 
			
		||||
  public SpanLimitsBuilder setMaxLengthOfAttributeValues(int maxLengthOfAttributeValues) {
 | 
			
		||||
    Utils.checkArgument(
 | 
			
		||||
        maxLengthOfAttributeValues == -1 || maxLengthOfAttributeValues > 0,
 | 
			
		||||
        "maxLengthOfAttributeValues must be -1 to "
 | 
			
		||||
| 
						 | 
				
			
			@ -110,14 +110,9 @@ public final class TraceConfigBuilder {
 | 
			
		|||
    return this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Builds and returns a {@code TraceConfig} with the desired values.
 | 
			
		||||
   *
 | 
			
		||||
   * @return a {@code TraceConfig} with the desired values.
 | 
			
		||||
   * @throws IllegalArgumentException if any of the max numbers are not positive.
 | 
			
		||||
   */
 | 
			
		||||
  public TraceConfig build() {
 | 
			
		||||
    return TraceConfig.create(
 | 
			
		||||
  /** Builds and returns a {@link SpanLimits} with the values of this builder. */
 | 
			
		||||
  public SpanLimits build() {
 | 
			
		||||
    return SpanLimits.create(
 | 
			
		||||
        maxNumAttributes,
 | 
			
		||||
        maxNumEvents,
 | 
			
		||||
        maxNumLinks,
 | 
			
		||||
| 
						 | 
				
			
			@ -8,7 +8,6 @@ package io.opentelemetry.sdk.trace;
 | 
			
		|||
import io.opentelemetry.sdk.common.Clock;
 | 
			
		||||
import io.opentelemetry.sdk.common.CompletableResultCode;
 | 
			
		||||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
| 
						 | 
				
			
			@ -21,7 +20,7 @@ final class TracerSharedState {
 | 
			
		|||
  private final IdGenerator idGenerator;
 | 
			
		||||
  private final Resource resource;
 | 
			
		||||
 | 
			
		||||
  private final Supplier<TraceConfig> traceConfigSupplier;
 | 
			
		||||
  private final Supplier<SpanLimits> traceConfigSupplier;
 | 
			
		||||
  private final Sampler sampler;
 | 
			
		||||
  private final SpanProcessor activeSpanProcessor;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +30,7 @@ final class TracerSharedState {
 | 
			
		|||
      Clock clock,
 | 
			
		||||
      IdGenerator idGenerator,
 | 
			
		||||
      Resource resource,
 | 
			
		||||
      Supplier<TraceConfig> traceConfigSupplier,
 | 
			
		||||
      Supplier<SpanLimits> traceConfigSupplier,
 | 
			
		||||
      Sampler sampler,
 | 
			
		||||
      List<SpanProcessor> spanProcessors) {
 | 
			
		||||
    this.clock = clock;
 | 
			
		||||
| 
						 | 
				
			
			@ -54,12 +53,8 @@ final class TracerSharedState {
 | 
			
		|||
    return resource;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the active {@code TraceConfig}.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the active {@code TraceConfig}.
 | 
			
		||||
   */
 | 
			
		||||
  TraceConfig getActiveTraceConfig() {
 | 
			
		||||
  /** Returns the current {@link SpanLimits}. */
 | 
			
		||||
  SpanLimits getSpanLimits() {
 | 
			
		||||
    return traceConfigSupplier.get();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,171 +0,0 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright The OpenTelemetry Authors
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package io.opentelemetry.sdk.trace.config;
 | 
			
		||||
 | 
			
		||||
import com.google.auto.value.AutoValue;
 | 
			
		||||
import io.opentelemetry.api.trace.Span;
 | 
			
		||||
import javax.annotation.concurrent.Immutable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Class that holds global trace parameters.
 | 
			
		||||
 *
 | 
			
		||||
 * <p>Note: To allow dynamic updates of {@link TraceConfig} you should register a {@link
 | 
			
		||||
 * java.util.function.Supplier} with {@link
 | 
			
		||||
 * io.opentelemetry.sdk.trace.SdkTracerProviderBuilder#setTraceConfig(java.util.function.Supplier)}
 | 
			
		||||
 * which supplies dynamic configs when queried.
 | 
			
		||||
 *
 | 
			
		||||
 * <p>Configuration options for {@link TraceConfig} can be read from system properties, environment
 | 
			
		||||
 * variables, or {@link java.util.Properties} objects.
 | 
			
		||||
 *
 | 
			
		||||
 * <p>For system properties and {@link java.util.Properties} objects, {@link TraceConfig} will look
 | 
			
		||||
 * for the following names:
 | 
			
		||||
 *
 | 
			
		||||
 * <ul>
 | 
			
		||||
 *   <li>{@code otel.config.sampler.probability}: to set the global default sampler which is used
 | 
			
		||||
 *       when constructing a new {@code Span}.
 | 
			
		||||
 *   <li>{@code otel.span.attribute.count.limit}: to set the global default max number of attributes
 | 
			
		||||
 *       per {@link Span}.
 | 
			
		||||
 *   <li>{@code otel.span.event.count.limit}: to set the global default max number of events per
 | 
			
		||||
 *       {@link Span}.
 | 
			
		||||
 *   <li>{@code otel.span.link.count.limit}: to set the global default max number of links per
 | 
			
		||||
 *       {@link Span}.
 | 
			
		||||
 *   <li>{@code otel.config.max.event.attrs}: to set the global default max number of attributes per
 | 
			
		||||
 *       event.
 | 
			
		||||
 *   <li>{@code otel.config.max.link.attrs}: to set the global default max number of attributes per
 | 
			
		||||
 *       link.
 | 
			
		||||
 *   <li>{@code otel.config.max.attr.length}: to set the global default max length of string
 | 
			
		||||
 *       attribute value in characters.
 | 
			
		||||
 * </ul>
 | 
			
		||||
 *
 | 
			
		||||
 * <p>For environment variables, {@link TraceConfig} will look for the following names:
 | 
			
		||||
 *
 | 
			
		||||
 * <ul>
 | 
			
		||||
 *   <li>{@code OTEL_CONFIG_SAMPLER_PROBABILITY}: to set the global default sampler which is used
 | 
			
		||||
 *       when constructing a new {@code Span}.
 | 
			
		||||
 *   <li>{@code OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT}: to set the global default max number of attributes
 | 
			
		||||
 *       per {@link Span}.
 | 
			
		||||
 *   <li>{@code OTEL_SPAN_EVENT_COUNT_LIMIT}: to set the global default max number of events per
 | 
			
		||||
 *       {@link Span}.
 | 
			
		||||
 *   <li>{@code OTEL_SPAN_LINK_COUNT_LIMIT}: to set the global default max number of links per
 | 
			
		||||
 *       {@link Span}.
 | 
			
		||||
 *   <li>{@code OTEL_CONFIG_MAX_EVENT_ATTRS}: to set the global default max number of attributes per
 | 
			
		||||
 *       event.
 | 
			
		||||
 *   <li>{@code OTEL_CONFIG_MAX_LINK_ATTRS}: to set the global default max number of attributes per
 | 
			
		||||
 *       link.
 | 
			
		||||
 *   <li>{@code OTEL_CONFIG_MAX_ATTR_LENGTH}: to set the global default max length of string
 | 
			
		||||
 *       attribute value in characters.
 | 
			
		||||
 * </ul>
 | 
			
		||||
 */
 | 
			
		||||
@AutoValue
 | 
			
		||||
@Immutable
 | 
			
		||||
public abstract class TraceConfig {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Value for attribute length which indicates attributes should not be truncated.
 | 
			
		||||
   *
 | 
			
		||||
   * @see TraceConfigBuilder#setMaxLengthOfAttributeValues(int)
 | 
			
		||||
   */
 | 
			
		||||
  public static final int UNLIMITED_ATTRIBUTE_LENGTH = -1;
 | 
			
		||||
 | 
			
		||||
  // These values are the default values for all the global parameters.
 | 
			
		||||
  // TODO: decide which default sampler to use
 | 
			
		||||
 | 
			
		||||
  private static final TraceConfig DEFAULT = new TraceConfigBuilder().build();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the default {@code TraceConfig}.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the default {@code TraceConfig}.
 | 
			
		||||
   */
 | 
			
		||||
  public static TraceConfig getDefault() {
 | 
			
		||||
    return DEFAULT;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Returns a new {@link TraceConfigBuilder} to construct a {@link TraceConfig}. */
 | 
			
		||||
  public static TraceConfigBuilder builder() {
 | 
			
		||||
    return new TraceConfigBuilder();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static TraceConfig create(
 | 
			
		||||
      int maxNumAttributes,
 | 
			
		||||
      int maxNumEvents,
 | 
			
		||||
      int maxNumLinks,
 | 
			
		||||
      int maxNumAttributesPerEvent,
 | 
			
		||||
      int maxNumAttributesPerLink,
 | 
			
		||||
      int maxAttributeLength) {
 | 
			
		||||
    return new AutoValue_TraceConfig(
 | 
			
		||||
        maxNumAttributes,
 | 
			
		||||
        maxNumEvents,
 | 
			
		||||
        maxNumLinks,
 | 
			
		||||
        maxNumAttributesPerEvent,
 | 
			
		||||
        maxNumAttributesPerLink,
 | 
			
		||||
        maxAttributeLength);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of attributes per {@link Span}.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of attributes per {@link Span}.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfAttributes();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of events per {@link Span}.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of events per {@code Span}.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfEvents();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of links per {@link Span}.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of links per {@code Span}.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfLinks();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of attributes per event.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of attributes per event.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfAttributesPerEvent();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max number of attributes per link.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max number of attributes per link.
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxNumberOfAttributesPerLink();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns the global default max length of string attribute value in characters.
 | 
			
		||||
   *
 | 
			
		||||
   * @return the global default max length of string attribute value in characters.
 | 
			
		||||
   * @see #shouldTruncateStringAttributeValues()
 | 
			
		||||
   */
 | 
			
		||||
  public abstract int getMaxLengthOfAttributeValues();
 | 
			
		||||
 | 
			
		||||
  public boolean shouldTruncateStringAttributeValues() {
 | 
			
		||||
    return getMaxLengthOfAttributeValues() != UNLIMITED_ATTRIBUTE_LENGTH;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns a {@link TraceConfigBuilder} initialized to the same property values as the current
 | 
			
		||||
   * instance.
 | 
			
		||||
   *
 | 
			
		||||
   * @return a {@link TraceConfigBuilder} initialized to the same property values as the current
 | 
			
		||||
   *     instance.
 | 
			
		||||
   */
 | 
			
		||||
  public TraceConfigBuilder toBuilder() {
 | 
			
		||||
    return new TraceConfigBuilder()
 | 
			
		||||
        .setMaxNumberOfAttributes(getMaxNumberOfAttributes())
 | 
			
		||||
        .setMaxNumberOfEvents(getMaxNumberOfEvents())
 | 
			
		||||
        .setMaxNumberOfLinks(getMaxNumberOfLinks())
 | 
			
		||||
        .setMaxNumberOfAttributesPerEvent(getMaxNumberOfAttributesPerEvent())
 | 
			
		||||
        .setMaxNumberOfAttributesPerLink(getMaxNumberOfAttributesPerLink())
 | 
			
		||||
        .setMaxLengthOfAttributeValues(getMaxLengthOfAttributeValues());
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,68 +0,0 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright The OpenTelemetry Authors
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Classes that holds global trace parameters
 | 
			
		||||
 *
 | 
			
		||||
 * <h2>Contents</h2>
 | 
			
		||||
 *
 | 
			
		||||
 * <ul>
 | 
			
		||||
 *   <li>{@link io.opentelemetry.sdk.trace.config.TraceConfig}
 | 
			
		||||
 * </ul>
 | 
			
		||||
 *
 | 
			
		||||
 * <h2>Default values for {@link io.opentelemetry.sdk.trace.config.TraceConfig}</h2>
 | 
			
		||||
 *
 | 
			
		||||
 * <ul>
 | 
			
		||||
 *   <li>{@code SAMPLER: Samplers.alwaysOn()}
 | 
			
		||||
 *   <li>{@code SPAN_MAX_NUM_ATTRIBUTES: 32}
 | 
			
		||||
 *   <li>{@code SPAN_MAX_NUM_EVENTS: 128}
 | 
			
		||||
 *   <li>{@code SPAN_MAX_NUM_LINKS: 32}
 | 
			
		||||
 *   <li>{@code SPAN_MAX_NUM_ATTRIBUTES_PER_EVENT: 32}
 | 
			
		||||
 *   <li>{@code SPAN_MAX_NUM_ATTRIBUTES_PER_LINK: 32}
 | 
			
		||||
 * </ul>
 | 
			
		||||
 *
 | 
			
		||||
 * <p>Configuration options for {@link io.opentelemetry.sdk.trace.config.TraceConfig} can be read
 | 
			
		||||
 * from system properties, environment variables, or {@link java.util.Properties} objects.
 | 
			
		||||
 *
 | 
			
		||||
 * <p>For system Properties and {@link java.util.Properties} objects, {@link
 | 
			
		||||
 * io.opentelemetry.sdk.trace.config.TraceConfig} will look for the following names:
 | 
			
		||||
 *
 | 
			
		||||
 * <ul>
 | 
			
		||||
 *   <li>{@code otel.config.sampler.probability}: to set the global default sampler which is used
 | 
			
		||||
 *       when constructing a new {@code Span}.
 | 
			
		||||
 *   <li>{@code otel.span.attribute.count.limit}: to set the global default max number of attributes
 | 
			
		||||
 *       per {@code Span}.
 | 
			
		||||
 *   <li>{@code otel.span.event.count.limit}: to set the global default max number of events per
 | 
			
		||||
 *       {@code Span}.
 | 
			
		||||
 *   <li>{@code otel.span.link.count.limit}: to set the global default max number of links per
 | 
			
		||||
 *       {@code Span}.
 | 
			
		||||
 *   <li>{@code otel.config.max.event.attrs}: to set the global default max number of attributes per
 | 
			
		||||
 *       event.
 | 
			
		||||
 *   <li>{@code otel.config.max.link.attrs}: to set the global default max number of attributes per
 | 
			
		||||
 *       link.
 | 
			
		||||
 * </ul>
 | 
			
		||||
 *
 | 
			
		||||
 * <p>For environment variable, {@link io.opentelemetry.sdk.trace.config.TraceConfig} will look for
 | 
			
		||||
 * the following names:
 | 
			
		||||
 *
 | 
			
		||||
 * <ul>
 | 
			
		||||
 *   <li>{@code OTEL_CONFIG_SAMPLER_PROBABILITY}: to set the global default sampler which is used
 | 
			
		||||
 *       when constructing a new {@code Span}.
 | 
			
		||||
 *   <li>{@code OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT}: to set the global default max number of attributes
 | 
			
		||||
 *       per {@code Span}.
 | 
			
		||||
 *   <li>{@code OTEL_SPAN_EVENT_COUNT_LIMIT}: to set the global default max number of events per
 | 
			
		||||
 *       {@code Span}.
 | 
			
		||||
 *   <li>{@code OTEL_SPAN_LINK_COUNT_LIMIT}: to set the global default max number of links entries
 | 
			
		||||
 *       per {@code Span}.
 | 
			
		||||
 *   <li>{@code OTEL_CONFIG_MAX_EVENT_ATTRS}: to set the global default max number of attributes per
 | 
			
		||||
 *       event.
 | 
			
		||||
 *   <li>{@code OTEL_CONFIG_MAX_LINK_ATTRS}: to set the global default max number of attributes per
 | 
			
		||||
 *       link.
 | 
			
		||||
 * </ul>
 | 
			
		||||
 */
 | 
			
		||||
@ParametersAreNonnullByDefault
 | 
			
		||||
package io.opentelemetry.sdk.trace.config;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.ParametersAreNonnullByDefault;
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +6,7 @@
 | 
			
		|||
package io.opentelemetry.sdk.trace.data;
 | 
			
		||||
 | 
			
		||||
import io.opentelemetry.api.common.Attributes;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
 | 
			
		||||
public interface EventData {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -61,7 +61,7 @@ public interface EventData {
 | 
			
		|||
   * The total number of attributes that were recorded on this Event. This number may be larger than
 | 
			
		||||
   * the number of attributes that are attached to this span, if the total number recorded was
 | 
			
		||||
   * greater than the configured maximum value. See: {@link
 | 
			
		||||
   * TraceConfig#getMaxNumberOfAttributesPerEvent()}
 | 
			
		||||
   * SpanLimits#getMaxNumberOfAttributesPerEvent()}
 | 
			
		||||
   *
 | 
			
		||||
   * @return The total number of attributes on this event.
 | 
			
		||||
   */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ package io.opentelemetry.sdk.trace.data;
 | 
			
		|||
 | 
			
		||||
import io.opentelemetry.api.common.Attributes;
 | 
			
		||||
import io.opentelemetry.api.trace.SpanContext;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Data representation of a Link.
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +64,7 @@ public interface LinkData {
 | 
			
		|||
   * The total number of attributes that were recorded on this Link. This number may be larger than
 | 
			
		||||
   * the number of attributes that are attached to this span, if the total number recorded was
 | 
			
		||||
   * greater than the configured maximum value. See: {@link
 | 
			
		||||
   * TraceConfig#getMaxNumberOfAttributesPerLink()}
 | 
			
		||||
   * SpanLimits#getMaxNumberOfAttributesPerLink()}
 | 
			
		||||
   *
 | 
			
		||||
   * @return The number of attributes on this link.
 | 
			
		||||
   */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,7 @@ import io.opentelemetry.api.trace.SpanKind;
 | 
			
		|||
import io.opentelemetry.api.trace.TraceState;
 | 
			
		||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
 | 
			
		||||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import javax.annotation.concurrent.Immutable;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -155,7 +155,7 @@ public interface SpanData {
 | 
			
		|||
   * The total number of {@link EventData} events that were recorded on this span. This number may
 | 
			
		||||
   * be larger than the number of events that are attached to this span, if the total number
 | 
			
		||||
   * recorded was greater than the configured maximum value. See: {@link
 | 
			
		||||
   * TraceConfig#getMaxNumberOfEvents()}
 | 
			
		||||
   * SpanLimits#getMaxNumberOfEvents()}
 | 
			
		||||
   *
 | 
			
		||||
   * @return The total number of events recorded on this span.
 | 
			
		||||
   */
 | 
			
		||||
| 
						 | 
				
			
			@ -164,7 +164,7 @@ public interface SpanData {
 | 
			
		|||
  /**
 | 
			
		||||
   * The total number of {@link LinkData} links that were recorded on this span. This number may be
 | 
			
		||||
   * larger than the number of links that are attached to this span, if the total number recorded
 | 
			
		||||
   * was greater than the configured maximum value. See: {@link TraceConfig#getMaxNumberOfLinks()}
 | 
			
		||||
   * was greater than the configured maximum value. See: {@link SpanLimits#getMaxNumberOfLinks()}
 | 
			
		||||
   *
 | 
			
		||||
   * @return The total number of links recorded on this span.
 | 
			
		||||
   */
 | 
			
		||||
| 
						 | 
				
			
			@ -173,7 +173,7 @@ public interface SpanData {
 | 
			
		|||
  /**
 | 
			
		||||
   * The total number of attributes that were recorded on this span. This number may be larger than
 | 
			
		||||
   * the number of attributes that are attached to this span, if the total number recorded was
 | 
			
		||||
   * greater than the configured maximum value. See: {@link TraceConfig#getMaxNumberOfAttributes()}
 | 
			
		||||
   * greater than the configured maximum value. See: {@link SpanLimits#getMaxNumberOfAttributes()}
 | 
			
		||||
   *
 | 
			
		||||
   * @return The total number of attributes on this span.
 | 
			
		||||
   */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,7 +29,6 @@ import io.opentelemetry.context.Context;
 | 
			
		|||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
 | 
			
		||||
import io.opentelemetry.sdk.internal.TestClock;
 | 
			
		||||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.EventData;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.LinkData;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.SpanData;
 | 
			
		||||
| 
						 | 
				
			
			@ -531,9 +530,9 @@ class RecordEventsReadableSpanTest {
 | 
			
		|||
  @Test
 | 
			
		||||
  void droppingAttributes() {
 | 
			
		||||
    final int maxNumberOfAttributes = 8;
 | 
			
		||||
    TraceConfig traceConfig =
 | 
			
		||||
        TraceConfig.builder().setMaxNumberOfAttributes(maxNumberOfAttributes).build();
 | 
			
		||||
    RecordEventsReadableSpan span = createTestSpan(traceConfig);
 | 
			
		||||
    SpanLimits spanLimits =
 | 
			
		||||
        SpanLimits.builder().setMaxNumberOfAttributes(maxNumberOfAttributes).build();
 | 
			
		||||
    RecordEventsReadableSpan span = createTestSpan(spanLimits);
 | 
			
		||||
    try {
 | 
			
		||||
      for (int i = 0; i < 2 * maxNumberOfAttributes; i++) {
 | 
			
		||||
        span.setAttribute(longKey("MyStringAttributeKey" + i), (long) i);
 | 
			
		||||
| 
						 | 
				
			
			@ -566,9 +565,9 @@ class RecordEventsReadableSpanTest {
 | 
			
		|||
  @Test
 | 
			
		||||
  void droppingAndAddingAttributes() {
 | 
			
		||||
    final int maxNumberOfAttributes = 8;
 | 
			
		||||
    TraceConfig traceConfig =
 | 
			
		||||
        TraceConfig.builder().setMaxNumberOfAttributes(maxNumberOfAttributes).build();
 | 
			
		||||
    RecordEventsReadableSpan span = createTestSpan(traceConfig);
 | 
			
		||||
    SpanLimits spanLimits =
 | 
			
		||||
        SpanLimits.builder().setMaxNumberOfAttributes(maxNumberOfAttributes).build();
 | 
			
		||||
    RecordEventsReadableSpan span = createTestSpan(spanLimits);
 | 
			
		||||
    try {
 | 
			
		||||
      for (int i = 0; i < 2 * maxNumberOfAttributes; i++) {
 | 
			
		||||
        span.setAttribute(longKey("MyStringAttributeKey" + i), (long) i);
 | 
			
		||||
| 
						 | 
				
			
			@ -601,8 +600,8 @@ class RecordEventsReadableSpanTest {
 | 
			
		|||
  @Test
 | 
			
		||||
  void droppingEvents() {
 | 
			
		||||
    final int maxNumberOfEvents = 8;
 | 
			
		||||
    TraceConfig traceConfig = TraceConfig.builder().setMaxNumberOfEvents(maxNumberOfEvents).build();
 | 
			
		||||
    RecordEventsReadableSpan span = createTestSpan(traceConfig);
 | 
			
		||||
    SpanLimits spanLimits = SpanLimits.builder().setMaxNumberOfEvents(maxNumberOfEvents).build();
 | 
			
		||||
    RecordEventsReadableSpan span = createTestSpan(spanLimits);
 | 
			
		||||
    try {
 | 
			
		||||
      for (int i = 0; i < 2 * maxNumberOfEvents; i++) {
 | 
			
		||||
        span.addEvent("event2", Attributes.empty());
 | 
			
		||||
| 
						 | 
				
			
			@ -753,11 +752,11 @@ class RecordEventsReadableSpanTest {
 | 
			
		|||
  private RecordEventsReadableSpan createTestSpanWithAttributes(
 | 
			
		||||
      Map<AttributeKey, Object> attributes) {
 | 
			
		||||
    AttributesMap attributesMap =
 | 
			
		||||
        new AttributesMap(TraceConfig.getDefault().getMaxNumberOfAttributes());
 | 
			
		||||
        new AttributesMap(SpanLimits.getDefault().getMaxNumberOfAttributes());
 | 
			
		||||
    attributes.forEach(attributesMap::put);
 | 
			
		||||
    return createTestSpan(
 | 
			
		||||
        SpanKind.INTERNAL,
 | 
			
		||||
        TraceConfig.getDefault(),
 | 
			
		||||
        SpanLimits.getDefault(),
 | 
			
		||||
        null,
 | 
			
		||||
        attributesMap,
 | 
			
		||||
        Collections.singletonList(link));
 | 
			
		||||
| 
						 | 
				
			
			@ -766,7 +765,7 @@ class RecordEventsReadableSpanTest {
 | 
			
		|||
  private RecordEventsReadableSpan createTestRootSpan() {
 | 
			
		||||
    return createTestSpan(
 | 
			
		||||
        SpanKind.INTERNAL,
 | 
			
		||||
        TraceConfig.getDefault(),
 | 
			
		||||
        SpanLimits.getDefault(),
 | 
			
		||||
        SpanId.getInvalid(),
 | 
			
		||||
        null,
 | 
			
		||||
        Collections.singletonList(link));
 | 
			
		||||
| 
						 | 
				
			
			@ -774,17 +773,17 @@ class RecordEventsReadableSpanTest {
 | 
			
		|||
 | 
			
		||||
  private RecordEventsReadableSpan createTestSpan(SpanKind kind) {
 | 
			
		||||
    return createTestSpan(
 | 
			
		||||
        kind, TraceConfig.getDefault(), parentSpanId, null, Collections.singletonList(link));
 | 
			
		||||
        kind, SpanLimits.getDefault(), parentSpanId, null, Collections.singletonList(link));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private RecordEventsReadableSpan createTestSpan(TraceConfig config) {
 | 
			
		||||
  private RecordEventsReadableSpan createTestSpan(SpanLimits config) {
 | 
			
		||||
    return createTestSpan(
 | 
			
		||||
        SpanKind.INTERNAL, config, parentSpanId, null, Collections.singletonList(link));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private RecordEventsReadableSpan createTestSpan(
 | 
			
		||||
      SpanKind kind,
 | 
			
		||||
      TraceConfig config,
 | 
			
		||||
      SpanLimits config,
 | 
			
		||||
      @Nullable String parentSpanId,
 | 
			
		||||
      @Nullable AttributesMap attributes,
 | 
			
		||||
      List<LinkData> links) {
 | 
			
		||||
| 
						 | 
				
			
			@ -864,7 +863,7 @@ class RecordEventsReadableSpanTest {
 | 
			
		|||
    String traceId = this.traceId;
 | 
			
		||||
    String spanId = this.spanId;
 | 
			
		||||
    String parentSpanId = this.parentSpanId;
 | 
			
		||||
    TraceConfig traceConfig = TraceConfig.getDefault();
 | 
			
		||||
    SpanLimits spanLimits = SpanLimits.getDefault();
 | 
			
		||||
    SpanProcessor spanProcessor = NoopSpanProcessor.getInstance();
 | 
			
		||||
    TestClock clock = TestClock.create();
 | 
			
		||||
    Resource resource = this.resource;
 | 
			
		||||
| 
						 | 
				
			
			@ -888,7 +887,7 @@ class RecordEventsReadableSpanTest {
 | 
			
		|||
                    traceId, parentSpanId, TraceFlags.getDefault(), TraceState.getDefault())
 | 
			
		||||
                : SpanContext.getInvalid(),
 | 
			
		||||
            Context.root(),
 | 
			
		||||
            traceConfig,
 | 
			
		||||
            spanLimits,
 | 
			
		||||
            spanProcessor,
 | 
			
		||||
            clock,
 | 
			
		||||
            resource,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,7 +31,6 @@ import io.opentelemetry.api.trace.TraceState;
 | 
			
		|||
import io.opentelemetry.api.trace.TracerProvider;
 | 
			
		||||
import io.opentelemetry.context.Context;
 | 
			
		||||
import io.opentelemetry.context.Scope;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.LinkData;
 | 
			
		||||
import io.opentelemetry.sdk.trace.data.SpanData;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
| 
						 | 
				
			
			@ -108,8 +107,8 @@ class SdkSpanBuilderTest {
 | 
			
		|||
  @Test
 | 
			
		||||
  void truncateLink() {
 | 
			
		||||
    final int maxNumberOfLinks = 8;
 | 
			
		||||
    TraceConfig traceConfig = TraceConfig.builder().setMaxNumberOfLinks(maxNumberOfLinks).build();
 | 
			
		||||
    TracerProvider tracerProvider = SdkTracerProvider.builder().setTraceConfig(traceConfig).build();
 | 
			
		||||
    SpanLimits spanLimits = SpanLimits.builder().setMaxNumberOfLinks(maxNumberOfLinks).build();
 | 
			
		||||
    TracerProvider tracerProvider = SdkTracerProvider.builder().setSpanLimits(spanLimits).build();
 | 
			
		||||
    // Verify methods do not crash.
 | 
			
		||||
    SpanBuilder spanBuilder = tracerProvider.get("test").spanBuilder(SPAN_NAME);
 | 
			
		||||
    for (int i = 0; i < 2 * maxNumberOfLinks; i++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -131,8 +130,8 @@ class SdkSpanBuilderTest {
 | 
			
		|||
 | 
			
		||||
  @Test
 | 
			
		||||
  void truncateLinkAttributes() {
 | 
			
		||||
    TraceConfig traceConfig = TraceConfig.builder().setMaxNumberOfAttributesPerLink(1).build();
 | 
			
		||||
    TracerProvider tracerProvider = SdkTracerProvider.builder().setTraceConfig(traceConfig).build();
 | 
			
		||||
    SpanLimits spanLimits = SpanLimits.builder().setMaxNumberOfAttributesPerLink(1).build();
 | 
			
		||||
    TracerProvider tracerProvider = SdkTracerProvider.builder().setSpanLimits(spanLimits).build();
 | 
			
		||||
    // Verify methods do not crash.
 | 
			
		||||
    SpanBuilder spanBuilder = tracerProvider.get("test").spanBuilder(SPAN_NAME);
 | 
			
		||||
    Attributes attributes =
 | 
			
		||||
| 
						 | 
				
			
			@ -356,9 +355,8 @@ class SdkSpanBuilderTest {
 | 
			
		|||
  @Test
 | 
			
		||||
  void droppingAttributes() {
 | 
			
		||||
    final int maxNumberOfAttrs = 8;
 | 
			
		||||
    TraceConfig traceConfig =
 | 
			
		||||
        TraceConfig.builder().setMaxNumberOfAttributes(maxNumberOfAttrs).build();
 | 
			
		||||
    TracerProvider tracerProvider = SdkTracerProvider.builder().setTraceConfig(traceConfig).build();
 | 
			
		||||
    SpanLimits spanLimits = SpanLimits.builder().setMaxNumberOfAttributes(maxNumberOfAttrs).build();
 | 
			
		||||
    TracerProvider tracerProvider = SdkTracerProvider.builder().setSpanLimits(spanLimits).build();
 | 
			
		||||
    // Verify methods do not crash.
 | 
			
		||||
    SpanBuilder spanBuilder = tracerProvider.get("test").spanBuilder(SPAN_NAME);
 | 
			
		||||
    for (int i = 0; i < 2 * maxNumberOfAttrs; i++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -378,8 +376,8 @@ class SdkSpanBuilderTest {
 | 
			
		|||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void tooLargeAttributeValuesAreTruncated() {
 | 
			
		||||
    TraceConfig traceConfig = TraceConfig.builder().setMaxLengthOfAttributeValues(10).build();
 | 
			
		||||
    TracerProvider tracerProvider = SdkTracerProvider.builder().setTraceConfig(traceConfig).build();
 | 
			
		||||
    SpanLimits spanLimits = SpanLimits.builder().setMaxLengthOfAttributeValues(10).build();
 | 
			
		||||
    TracerProvider tracerProvider = SdkTracerProvider.builder().setSpanLimits(spanLimits).build();
 | 
			
		||||
    // Verify methods do not crash.
 | 
			
		||||
    SpanBuilder spanBuilder = tracerProvider.get("test").spanBuilder(SPAN_NAME);
 | 
			
		||||
    spanBuilder.setAttribute("builderStringNull", null);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,6 @@ import io.opentelemetry.sdk.common.Clock;
 | 
			
		|||
import io.opentelemetry.sdk.common.CompletableResultCode;
 | 
			
		||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
 | 
			
		||||
import io.opentelemetry.sdk.resources.Resource;
 | 
			
		||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
 | 
			
		||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
 | 
			
		||||
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
| 
						 | 
				
			
			@ -98,16 +97,15 @@ class SdkTracerProviderTest {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  void builder_NullTraceConfig() {
 | 
			
		||||
    assertThatThrownBy(() -> SdkTracerProvider.builder().setTraceConfig((TraceConfig) null))
 | 
			
		||||
  void builder_NullSpanLimits() {
 | 
			
		||||
    assertThatThrownBy(() -> SdkTracerProvider.builder().setSpanLimits((SpanLimits) null))
 | 
			
		||||
        .isInstanceOf(NullPointerException.class)
 | 
			
		||||
        .hasMessage("traceConfig");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  void builder_NullTraceConfigSupplier() {
 | 
			
		||||
    assertThatThrownBy(
 | 
			
		||||
            () -> SdkTracerProvider.builder().setTraceConfig((Supplier<TraceConfig>) null))
 | 
			
		||||
  void builder_NullSpanLimitsSupplier() {
 | 
			
		||||
    assertThatThrownBy(() -> SdkTracerProvider.builder().setSpanLimits((Supplier<SpanLimits>) null))
 | 
			
		||||
        .isInstanceOf(NullPointerException.class)
 | 
			
		||||
        .hasMessage("traceConfig");
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -159,11 +157,11 @@ class SdkTracerProviderTest {
 | 
			
		|||
 | 
			
		||||
  @Test
 | 
			
		||||
  void build_traceConfig() {
 | 
			
		||||
    TraceConfig initialTraceConfig = TraceConfig.builder().build();
 | 
			
		||||
    SpanLimits initialSpanLimits = SpanLimits.builder().build();
 | 
			
		||||
    SdkTracerProvider sdkTracerProvider =
 | 
			
		||||
        SdkTracerProvider.builder().setTraceConfig(initialTraceConfig).build();
 | 
			
		||||
        SdkTracerProvider.builder().setSpanLimits(initialSpanLimits).build();
 | 
			
		||||
 | 
			
		||||
    assertThat(sdkTracerProvider.getActiveTraceConfig()).isSameAs(initialTraceConfig);
 | 
			
		||||
    assertThat(sdkTracerProvider.getSpanLimits()).isSameAs(initialSpanLimits);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,45 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright The OpenTelemetry Authors
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package io.opentelemetry.sdk.trace.config;
 | 
			
		||||
 | 
			
		||||
import static org.assertj.core.api.Assertions.assertThat;
 | 
			
		||||
 | 
			
		||||
import io.opentelemetry.sdk.trace.SpanLimits;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
class SpanLimitsTest {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  void defaultSpanLimits() {
 | 
			
		||||
    assertThat(SpanLimits.getDefault().getMaxNumberOfAttributes()).isEqualTo(1000);
 | 
			
		||||
    assertThat(SpanLimits.getDefault().getMaxNumberOfEvents()).isEqualTo(1000);
 | 
			
		||||
    assertThat(SpanLimits.getDefault().getMaxNumberOfLinks()).isEqualTo(1000);
 | 
			
		||||
    assertThat(SpanLimits.getDefault().getMaxNumberOfAttributesPerEvent()).isEqualTo(32);
 | 
			
		||||
    assertThat(SpanLimits.getDefault().getMaxNumberOfAttributesPerLink()).isEqualTo(32);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  void updateSpanLimits_All() {
 | 
			
		||||
    SpanLimits spanLimits =
 | 
			
		||||
        SpanLimits.builder()
 | 
			
		||||
            .setMaxNumberOfAttributes(8)
 | 
			
		||||
            .setMaxNumberOfEvents(10)
 | 
			
		||||
            .setMaxNumberOfLinks(11)
 | 
			
		||||
            .setMaxNumberOfAttributesPerEvent(1)
 | 
			
		||||
            .setMaxNumberOfAttributesPerLink(2)
 | 
			
		||||
            .build();
 | 
			
		||||
    assertThat(spanLimits.getMaxNumberOfAttributes()).isEqualTo(8);
 | 
			
		||||
    assertThat(spanLimits.getMaxNumberOfEvents()).isEqualTo(10);
 | 
			
		||||
    assertThat(spanLimits.getMaxNumberOfLinks()).isEqualTo(11);
 | 
			
		||||
    assertThat(spanLimits.getMaxNumberOfAttributesPerEvent()).isEqualTo(1);
 | 
			
		||||
    assertThat(spanLimits.getMaxNumberOfAttributesPerLink()).isEqualTo(2);
 | 
			
		||||
 | 
			
		||||
    // Preserves values
 | 
			
		||||
    SpanLimits spanLimitsDupe = spanLimits.toBuilder().build();
 | 
			
		||||
    // Use reflective comparison to catch when new fields are added.
 | 
			
		||||
    assertThat(spanLimitsDupe).usingRecursiveComparison().isEqualTo(spanLimits);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,44 +0,0 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright The OpenTelemetry Authors
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package io.opentelemetry.sdk.trace.config;
 | 
			
		||||
 | 
			
		||||
import static org.assertj.core.api.Assertions.assertThat;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
class TraceConfigTest {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  void defaultTraceConfig() {
 | 
			
		||||
    assertThat(TraceConfig.getDefault().getMaxNumberOfAttributes()).isEqualTo(1000);
 | 
			
		||||
    assertThat(TraceConfig.getDefault().getMaxNumberOfEvents()).isEqualTo(1000);
 | 
			
		||||
    assertThat(TraceConfig.getDefault().getMaxNumberOfLinks()).isEqualTo(1000);
 | 
			
		||||
    assertThat(TraceConfig.getDefault().getMaxNumberOfAttributesPerEvent()).isEqualTo(32);
 | 
			
		||||
    assertThat(TraceConfig.getDefault().getMaxNumberOfAttributesPerLink()).isEqualTo(32);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  void updateTraceConfig_All() {
 | 
			
		||||
    TraceConfig traceConfig =
 | 
			
		||||
        TraceConfig.builder()
 | 
			
		||||
            .setMaxNumberOfAttributes(8)
 | 
			
		||||
            .setMaxNumberOfEvents(10)
 | 
			
		||||
            .setMaxNumberOfLinks(11)
 | 
			
		||||
            .setMaxNumberOfAttributesPerEvent(1)
 | 
			
		||||
            .setMaxNumberOfAttributesPerLink(2)
 | 
			
		||||
            .build();
 | 
			
		||||
    assertThat(traceConfig.getMaxNumberOfAttributes()).isEqualTo(8);
 | 
			
		||||
    assertThat(traceConfig.getMaxNumberOfEvents()).isEqualTo(10);
 | 
			
		||||
    assertThat(traceConfig.getMaxNumberOfLinks()).isEqualTo(11);
 | 
			
		||||
    assertThat(traceConfig.getMaxNumberOfAttributesPerEvent()).isEqualTo(1);
 | 
			
		||||
    assertThat(traceConfig.getMaxNumberOfAttributesPerLink()).isEqualTo(2);
 | 
			
		||||
 | 
			
		||||
    // Preserves values
 | 
			
		||||
    TraceConfig traceConfigDupe = traceConfig.toBuilder().build();
 | 
			
		||||
    // Use reflective comparison to catch when new fields are added.
 | 
			
		||||
    assertThat(traceConfigDupe).usingRecursiveComparison().isEqualTo(traceConfig);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue