Class OtlpGrpcMetricExporterBuilder

java.lang.Object
io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder

public final class OtlpGrpcMetricExporterBuilder extends Object
Builder utility for this exporter.
Since:
1.14.0
  • Method Details

    • setChannel

      @Deprecated public OtlpGrpcMetricExporterBuilder setChannel(io.grpc.ManagedChannel channel)
      Deprecated.
      Use setEndpoint(String). If you have a use case not satisfied by the methods on this builder, please file an issue to let us know what it is.
      Sets the managed chanel to use when communicating with the backend. Takes precedence over setEndpoint(String) if both are called.

      Note: calling this overrides the spec compliant User-Agent header. To ensure spec compliance, set ManagedChannelBuilder.userAgent(String) to OtlpUserAgent.getUserAgent() when building the channel.

      Parameters:
      channel - the channel to use
      Returns:
      this builder's instance
    • setTimeout

      public OtlpGrpcMetricExporterBuilder setTimeout(long timeout, TimeUnit unit)
      Sets the maximum time to wait for the collector to process an exported batch of metrics. If unset, defaults to 10Ls.
    • setTimeout

      public OtlpGrpcMetricExporterBuilder setTimeout(Duration timeout)
      Sets the maximum time to wait for the collector to process an exported batch of metrics. If unset, defaults to 10Ls.
    • setConnectTimeout

      public OtlpGrpcMetricExporterBuilder setConnectTimeout(long timeout, TimeUnit unit)
      Sets the maximum time to wait for new connections to be established. If unset, defaults to 10Ls.
      Since:
      1.36.0
    • setConnectTimeout

      public OtlpGrpcMetricExporterBuilder setConnectTimeout(Duration timeout)
      Sets the maximum time to wait for new connections to be established. If unset, defaults to 10Ls.
      Since:
      1.36.0
    • setEndpoint

      public OtlpGrpcMetricExporterBuilder setEndpoint(String endpoint)
      Sets the OTLP endpoint to connect to. If unset, defaults to "http://localhost:4317". The endpoint must start with either http:// or https://.
    • setCompression

      public OtlpGrpcMetricExporterBuilder setCompression(String compressionMethod)
      Sets the method used to compress payloads. If unset, compression is disabled. Compression method "gzip" and "none" are supported out of the box. Additional compression methods can be supported by providing custom Compressor implementations via the service loader.
    • setTrustedCertificates

      public OtlpGrpcMetricExporterBuilder setTrustedCertificates(byte[] trustedCertificatesPem)
      Sets the certificate chain to use for verifying servers when TLS is enabled. The byte[] should contain an X.509 certificate collection in PEM format. If not set, TLS connections will use the system default trusted certificates.
    • setClientTls

      public OtlpGrpcMetricExporterBuilder setClientTls(byte[] privateKeyPem, byte[] certificatePem)
      Sets ths client key and the certificate chain to use for verifying client when TLS is enabled. The key must be PKCS8, and both must be in PEM format.
    • setSslContext

      public OtlpGrpcMetricExporterBuilder setSslContext(SSLContext sslContext, X509TrustManager trustManager)
      Sets the "bring-your-own" SSLContext for use with TLS. Users should call this _or_ set raw certificate bytes, but not both.
      Since:
      1.26.0
    • addHeader

      public OtlpGrpcMetricExporterBuilder addHeader(String key, String value)
      Add a constant header to requests. If the key collides with another constant header name or a one from setHeaders(Supplier), the values from both are included. Applicable only if setChannel(ManagedChannel) is not used to set channel.
      Parameters:
      key - header key
      value - header value
      Returns:
      this builder's instance
    • setHeaders

      public OtlpGrpcMetricExporterBuilder setHeaders(Supplier<Map<String,String>> headerSupplier)
      Set the supplier of headers to add to requests. If a key from the map collides with a constant from addHeader(String, String), the values from both are included. Applicable only if setChannel(ManagedChannel) is not used to set channel.
      Since:
      1.33.0
    • setAggregationTemporalitySelector

      public OtlpGrpcMetricExporterBuilder setAggregationTemporalitySelector(io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector aggregationTemporalitySelector)
      Set the AggregationTemporalitySelector used for AggregationTemporalitySelector.getAggregationTemporality(InstrumentType).

      If unset, defaults to AggregationTemporalitySelector.alwaysCumulative().

      AggregationTemporalitySelector.deltaPreferred() is a common configuration for delta backends.

    • setDefaultAggregationSelector

      public OtlpGrpcMetricExporterBuilder setDefaultAggregationSelector(io.opentelemetry.sdk.metrics.export.DefaultAggregationSelector defaultAggregationSelector)
      Set the DefaultAggregationSelector used for MetricExporter.getDefaultAggregation(InstrumentType).

      If unset, defaults to DefaultAggregationSelector.getDefault().

      Since:
      1.16.0
    • setRetryPolicy

      public OtlpGrpcMetricExporterBuilder setRetryPolicy(@Nullable io.opentelemetry.sdk.common.export.RetryPolicy retryPolicy)
      Set the retry policy, or null to disable retry. Retry policy is RetryPolicy.getDefault() by default
      Since:
      1.28.0
    • setInternalTelemetryVersion

      public OtlpGrpcMetricExporterBuilder setInternalTelemetryVersion(io.opentelemetry.sdk.common.InternalTelemetryVersion schemaVersion)
      Sets the InternalTelemetryVersion defining which self-monitoring metrics this exporter collects.
      Since:
      1.51.0
    • setMeterProvider

      public OtlpGrpcMetricExporterBuilder setMeterProvider(io.opentelemetry.api.metrics.MeterProvider meterProvider)
      Sets the MeterProvider to use to collect metrics related to export. If not set, uses GlobalOpenTelemetry.getMeterProvider().
      Since:
      1.50.0
    • setMeterProvider

      public OtlpGrpcMetricExporterBuilder setMeterProvider(Supplier<io.opentelemetry.api.metrics.MeterProvider> meterProviderSupplier)
      Sets the MeterProvider supplier to use to collect metrics related to export. If not set, uses GlobalOpenTelemetry.getMeterProvider().
      Since:
      1.50.0
    • setMemoryMode

      public OtlpGrpcMetricExporterBuilder setMemoryMode(io.opentelemetry.sdk.common.export.MemoryMode memoryMode)
      Set the MemoryMode. If unset, defaults to DEFAULT_MEMORY_MODE.

      When memory mode is MemoryMode.REUSABLE_DATA, serialization is optimized to reduce memory allocation. Additionally, the value is used for MetricExporter.getMemoryMode(), which sends a signal to the metrics SDK to reuse memory when possible. This is safe and desirable for most use cases, but should be used with caution of wrapping and delegating to the exporter. It is not safe for the wrapping exporter to hold onto references to MetricData batches since the same data structures will be reused in subsequent calls to MetricExporter.export(Collection).

      Since:
      1.39.0
    • setServiceClassLoader

      public OtlpGrpcMetricExporterBuilder setServiceClassLoader(ClassLoader serviceClassLoader)
      Set the ClassLoader used to load the sender API. Variant of setComponentLoader(ComponentLoader).
      Since:
      1.48.0
    • setComponentLoader

      public OtlpGrpcMetricExporterBuilder setComponentLoader(io.opentelemetry.common.ComponentLoader componentLoader)
      Set the ComponentLoader used to load the sender API.
    • setExecutorService

      public OtlpGrpcMetricExporterBuilder setExecutorService(ExecutorService executorService)
      Set the ExecutorService used to execute requests.

      NOTE: By calling this method, you are opting into managing the lifecycle of the executorService. ExecutorService.shutdown() will NOT be called when this exporter is shutdown.

      Since:
      1.49.0
    • build

      public OtlpGrpcMetricExporter build()
      Constructs a new instance of the exporter based on the builder's values.
      Returns:
      a new exporter's instance