content: /*
   * Copyright The OpenTelemetry Authors
   * SPDX-License-Identifier: Apache-2.0
   */
  
  package io.opentelemetry.instrumentation.restlet.v1_1;
  
  import com.google.errorprone.annotations.CanIgnoreReturnValue;
  import io.opentelemetry.api.OpenTelemetry;
  import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder;
  import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
  import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
  import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder;
  import io.opentelemetry.instrumentation.restlet.v1_1.internal.Experimental;
  import io.opentelemetry.instrumentation.restlet.v1_1.internal.RestletTelemetryBuilderFactory;
  import java.util.Collection;
  import java.util.function.Function;
  import org.restlet.data.Request;
  import org.restlet.data.Response;
  
  /** A builder of {@link RestletTelemetry}. */
  public final class RestletTelemetryBuilder {
  
    private final DefaultHttpServerInstrumenterBuilder<Request, Response> builder;
  
    static {
      Experimental.internalSetEmitExperimentalTelemetry(
          (builder, emit) -> builder.builder.setEmitExperimentalHttpServerTelemetry(emit));
    }
  
    RestletTelemetryBuilder(OpenTelemetry openTelemetry) {
      builder = RestletTelemetryBuilderFactory.create(openTelemetry);
    }
  
    /**
     * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented
     * items.
     */
    @CanIgnoreReturnValue
    public RestletTelemetryBuilder addAttributesExtractor(
        AttributesExtractor<Request, Response> attributesExtractor) {
      builder.addAttributesExtractor(attributesExtractor);
      return this;
    }
  
    /**
     * Configures the HTTP request headers that will be captured as span attributes.
     *
     * @param requestHeaders A list of HTTP header names.
     */
    @CanIgnoreReturnValue
    public RestletTelemetryBuilder setCapturedRequestHeaders(Collection<String> requestHeaders) {
      builder.setCapturedRequestHeaders(requestHeaders);
      return this;
    }
  
    /**
     * Configures the HTTP response headers that will be captured as span attributes.
     *
     * @param responseHeaders A list of HTTP header names.
     */
    @CanIgnoreReturnValue
    public RestletTelemetryBuilder setCapturedResponseHeaders(Collection<String> responseHeaders) {
      builder.setCapturedResponseHeaders(responseHeaders);
      return this;
    }
  
    /**
     * Configures the instrumentation to recognize an alternative set of HTTP request methods.
     *
     * <p>By default, this instrumentation defines "known" methods as the ones listed in <a
     * href="https://www.rfc-editor.org/rfc/rfc9110.html#name-methods">RFC9110</a> and the PATCH
     * method defined in <a href="https://www.rfc-editor.org/rfc/rfc5789.html">RFC5789</a>.
     *
     * <p>Note: calling this method <b>overrides</b> the default known method sets completely; it does
     * not supplement it.
     *
     * @param knownMethods A set of recognized HTTP request methods.
     * @see HttpServerAttributesExtractorBuilder#setKnownMethods(Collection)
     */
    @CanIgnoreReturnValue
    public RestletTelemetryBuilder setKnownMethods(Collection<String> knownMethods) {
      builder.setKnownMethods(knownMethods);
      return this;
    }
  
    /** Sets custom {@link SpanNameExtractor} via transform function. */
    @CanIgnoreReturnValue
    public RestletTelemetryBuilder setSpanNameExtractor(
        Function<SpanNameExtractor<Request>, SpanNameExtractor<Request>>
            spanNameExtractorTransformer) {
      builder.setSpanNameExtractor(spanNameExtractorTransformer);
      return this;
    }
  
    /**
     * Returns a new {@link RestletTelemetry} with the settings of this {@link
     * RestletTelemetryBuilder}.
     */
    public RestletTelemetry build() {
      return new RestletTelemetry(builder.build());
    }
  }
  