Search in sources :

Example 1 with SpanLimitsBuilder

use of io.opentelemetry.sdk.trace.SpanLimitsBuilder in project opentelemetry-java by open-telemetry.

the class TraceConfigzZPageHandler method applyTraceConfig.

/**
 * Apply updated trace configuration through the tracerProvider based on query parameters.
 *
 * @param queryMap the map containing URL query parameters.
 * @throws NumberFormatException if one of the {@code double}/{@code integer} valued query string
 *     does not contain a parsable {@code double}/{@code integer}.
 */
private void applyTraceConfig(Map<String, String> queryMap) {
    String action = queryMap.get(QUERY_STRING_ACTION);
    if (action == null) {
        return;
    }
    if (action.equals(QUERY_STRING_ACTION_CHANGE)) {
        SpanLimitsBuilder newConfigBuilder = configSupplier.get().toBuilder();
        String samplingProbabilityStr = queryMap.get(QUERY_STRING_SAMPLING_PROBABILITY);
        if (samplingProbabilityStr != null) {
            try {
                double samplingProbability = Double.parseDouble(samplingProbabilityStr);
                configSupplier.setSampler(Sampler.traceIdRatioBased(samplingProbability));
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("SamplingProbability must be of the type double", e);
            }
        }
        String maxNumOfAttributesStr = queryMap.get(QUERY_STRING_MAX_NUM_OF_ATTRIBUTES);
        if (maxNumOfAttributesStr != null) {
            try {
                int maxNumOfAttributes = Integer.parseInt(maxNumOfAttributesStr);
                newConfigBuilder.setMaxNumberOfAttributes(maxNumOfAttributes);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("MaxNumOfAttributes must be of the type integer", e);
            }
        }
        String maxNumOfEventsStr = queryMap.get(QUERY_STRING_MAX_NUM_OF_EVENTS);
        if (maxNumOfEventsStr != null) {
            try {
                int maxNumOfEvents = Integer.parseInt(maxNumOfEventsStr);
                newConfigBuilder.setMaxNumberOfEvents(maxNumOfEvents);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("MaxNumOfEvents must be of the type integer", e);
            }
        }
        String maxNumOfLinksStr = queryMap.get(QUERY_STRING_MAX_NUM_OF_LINKS);
        if (maxNumOfLinksStr != null) {
            try {
                int maxNumOfLinks = Integer.parseInt(maxNumOfLinksStr);
                newConfigBuilder.setMaxNumberOfLinks(maxNumOfLinks);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("MaxNumOfLinks must be of the type integer", e);
            }
        }
        String maxNumOfAttributesPerEventStr = queryMap.get(QUERY_STRING_MAX_NUM_OF_ATTRIBUTES_PER_EVENT);
        if (maxNumOfAttributesPerEventStr != null) {
            try {
                int maxNumOfAttributesPerEvent = Integer.parseInt(maxNumOfAttributesPerEventStr);
                newConfigBuilder.setMaxNumberOfAttributesPerEvent(maxNumOfAttributesPerEvent);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("MaxNumOfAttributesPerEvent must be of the type integer", e);
            }
        }
        String maxNumOfAttributesPerLinkStr = queryMap.get(QUERY_STRING_MAX_NUM_OF_ATTRIBUTES_PER_LINK);
        if (maxNumOfAttributesPerLinkStr != null) {
            try {
                int maxNumOfAttributesPerLink = Integer.parseInt(maxNumOfAttributesPerLinkStr);
                newConfigBuilder.setMaxNumberOfAttributesPerLink(maxNumOfAttributesPerLink);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("MaxNumOfAttributesPerLink must be of the type integer", e);
            }
        }
        configSupplier.setActiveTraceConfig(newConfigBuilder.build());
    } else if (action.equals(QUERY_STRING_ACTION_DEFAULT)) {
        SpanLimits defaultConfig = SpanLimits.builder().build();
        configSupplier.setActiveTraceConfig(defaultConfig);
    }
}
Also used : SpanLimitsBuilder(io.opentelemetry.sdk.trace.SpanLimitsBuilder) SpanLimits(io.opentelemetry.sdk.trace.SpanLimits)

Example 2 with SpanLimitsBuilder

use of io.opentelemetry.sdk.trace.SpanLimitsBuilder in project opentelemetry-java by open-telemetry.

the class TracerProviderConfiguration method configureSpanLimits.

// Visible for testing
static SpanLimits configureSpanLimits(ConfigProperties config) {
    SpanLimitsBuilder builder = SpanLimits.builder();
    Integer maxLength = config.getInt("otel.span.attribute.value.length.limit");
    if (maxLength != null) {
        builder.setMaxAttributeValueLength(maxLength);
    }
    Integer maxAttrs = config.getInt("otel.span.attribute.count.limit");
    if (maxAttrs != null) {
        builder.setMaxNumberOfAttributes(maxAttrs);
    }
    Integer maxEvents = config.getInt("otel.span.event.count.limit");
    if (maxEvents != null) {
        builder.setMaxNumberOfEvents(maxEvents);
    }
    Integer maxLinks = config.getInt("otel.span.link.count.limit");
    if (maxLinks != null) {
        builder.setMaxNumberOfLinks(maxLinks);
    }
    return builder.build();
}
Also used : SpanLimitsBuilder(io.opentelemetry.sdk.trace.SpanLimitsBuilder)

Aggregations

SpanLimitsBuilder (io.opentelemetry.sdk.trace.SpanLimitsBuilder)2 SpanLimits (io.opentelemetry.sdk.trace.SpanLimits)1