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

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

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

package io.opentelemetry.javaagent.bootstrap.internal;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter;
import java.util.function.Consumer;

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

  private JavaagentHttpClientInstrumenters() {}

  public static  Instrumenter create(
      String instrumentationName,
      HttpClientAttributesGetter httpAttributesGetter) {
    return create(
        DefaultHttpClientInstrumenterBuilder.create(
            instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter),
        b -> {});
  }

  public static  Instrumenter create(
      String instrumentationName,
      HttpClientAttributesGetter httpAttributesGetter,
      TextMapSetter headerSetter) {
    return create(instrumentationName, httpAttributesGetter, headerSetter, b -> {});
  }

  public static  Instrumenter create(
      DefaultHttpClientInstrumenterBuilder builder) {
    return create(builder, customizer -> {});
  }

  public static  Instrumenter create(
      String instrumentationName,
      HttpClientAttributesGetter httpAttributesGetter,
      TextMapSetter headerSetter,
      Consumer> instrumenterBuilderConsumer) {
    return create(
        DefaultHttpClientInstrumenterBuilder.create(
            instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter, headerSetter),
        instrumenterBuilderConsumer);
  }

  private static  Instrumenter create(
      DefaultHttpClientInstrumenterBuilder builder,
      Consumer> builderCustomizer) {
    return builder
        .configure(AgentCommonConfig.get())
        .setBuilderCustomizer(builderCustomizer)
        .build();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy