Class MetricConfiguration.Builder
- java.lang.Object
-
- com.google.cloud.opentelemetry.metric.MetricConfiguration.Builder
-
- Enclosing class:
- MetricConfiguration
public abstract static class MetricConfiguration.Builder extends java.lang.ObjectBuilder forMetricConfiguration.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description MetricConfigurationbuild()Builds aMetricConfiguration.abstract MetricConfiguration.BuildersetCredentials(com.google.auth.Credentials newCredentials)Set the credentials to use when writing metrics.abstract MetricConfiguration.BuildersetDeadline(java.time.Duration deadline)Set the deadline for exporting batches of metric timeseries.abstract MetricConfiguration.BuildersetDescriptorStrategy(MetricDescriptorStrategy strategy)Set the policy for sending metric descriptors, e.g.abstract MetricConfiguration.BuildersetInstrumentationLibraryLabelsEnabled(boolean instrumentationLibraryLabelsEnabled)Sets theMetricConfigurationto configure the exporter to add instrumentation library labels as metric attributes during export.abstract MetricConfiguration.BuildersetMetricServiceEndpoint(java.lang.String endpoint)Sets the endpoint where to write Metrics.abstract MetricConfiguration.BuildersetMetricServiceSettings(com.google.cloud.monitoring.v3.MetricServiceSettings metricServiceSettings)Sets the options used to configure theMetricServiceClientused to interact with the Cloud Monitoring API.abstract MetricConfiguration.BuildersetMonitoredResourceDescription(MonitoredResourceDescription monitoredResourceDescription)Sets theMonitoredResourceDescriptionthat is used to map OpenTelemetryResources to Google specificMonitoredResources.abstract MetricConfiguration.BuildersetPrefix(java.lang.String prefix)Set the prefix prepended to metric names.MetricConfiguration.BuildersetProjectId(java.lang.String projectId)Sets the GCP project id where the metrics should be written.abstract MetricConfiguration.BuildersetResourceAttributesFilter(java.util.function.Predicate<io.opentelemetry.api.common.AttributeKey<?>> filter)Set a filter to determine which resource attributes to add to metrics as metric labels.abstract MetricConfiguration.BuildersetUseServiceTimeSeries(boolean useServiceTimeSeries)Sets theMetricConfigurationto configure the exporter to write metrics viaMetricServiceClient.createServiceTimeSeries(String, List)method.
-
-
-
Method Detail
-
setProjectId
public final MetricConfiguration.Builder setProjectId(java.lang.String projectId)
Sets the GCP project id where the metrics should be written. The project ID should be a valid, non-null and non-empty String.- Parameters:
projectId- the cloud project id.- Returns:
- this.
-
setPrefix
public abstract MetricConfiguration.Builder setPrefix(java.lang.String prefix)
Set the prefix prepended to metric names.
-
setCredentials
public abstract MetricConfiguration.Builder setCredentials(com.google.auth.Credentials newCredentials)
Set the credentials to use when writing metrics.
-
setDeadline
public abstract MetricConfiguration.Builder setDeadline(java.time.Duration deadline)
Set the deadline for exporting batches of metric timeseries.
-
setDescriptorStrategy
public abstract MetricConfiguration.Builder setDescriptorStrategy(MetricDescriptorStrategy strategy)
Set the policy for sending metric descriptors, e.g. always, never or once.
-
setMetricServiceEndpoint
public abstract MetricConfiguration.Builder setMetricServiceEndpoint(java.lang.String endpoint)
Sets the endpoint where to write Metrics. Defaults to monitoring.googleapis.com:443.
-
setUseServiceTimeSeries
public abstract MetricConfiguration.Builder setUseServiceTimeSeries(boolean useServiceTimeSeries)
Sets theMetricConfigurationto configure the exporter to write metrics viaMetricServiceClient.createServiceTimeSeries(String, List)method. By default, this is false.- Parameters:
useServiceTimeSeries- a boolean indicating whether to useMetricServiceClient.createServiceTimeSeries(String, List)method for writing metrics to Google Cloud Monitoring.- Returns:
- this
-
setMonitoredResourceDescription
public abstract MetricConfiguration.Builder setMonitoredResourceDescription(MonitoredResourceDescription monitoredResourceDescription)
Sets theMonitoredResourceDescriptionthat is used to map OpenTelemetryResources to Google specificMonitoredResources.- Parameters:
monitoredResourceDescription- theMonitoredResourceDescriptionobject responsible for providing mapping between the customMonitoredResourceand the expected labels.- Returns:
- this.
-
setResourceAttributesFilter
public abstract MetricConfiguration.Builder setResourceAttributesFilter(java.util.function.Predicate<io.opentelemetry.api.common.AttributeKey<?>> filter)
Set a filter to determine which resource attributes to add to metrics as metric labels. By default, it adds service.name, service.namespace, and service.instance.id. This is recommended to avoid writing duplicate timeseries against the same monitored resource. Use setResourceAttributesFilter(NO_RESOURCE_ATTRIBUTES) to disable the addition of resource attributes to metric labels.- Parameters:
filter- APredicatethat determines if a resource attribute would be added as a metric label- Returns:
- this.
-
setMetricServiceSettings
public abstract MetricConfiguration.Builder setMetricServiceSettings(com.google.cloud.monitoring.v3.MetricServiceSettings metricServiceSettings)
Sets the options used to configure theMetricServiceClientused to interact with the Cloud Monitoring API. This is for advanced usage and must be configured carefully.Providing MetricServiceSettings will cause the exporter to ignore the values configured using:
The intended effect of setting these values in the configuration should instead be achieved by configuring the
MetricServiceSettingsobject.- Parameters:
metricServiceSettings- theMetricServiceSettingscontaining the configured options.- Returns:
- this.
-
setInstrumentationLibraryLabelsEnabled
public abstract MetricConfiguration.Builder setInstrumentationLibraryLabelsEnabled(boolean instrumentationLibraryLabelsEnabled)
Sets theMetricConfigurationto configure the exporter to add instrumentation library labels as metric attributes during export.Enabling instrumentation library labels adds the following metric attributes to exported metric data points:
- instrumentation_source
- instrumentation_version
InstrumentationScopeInfo.- Parameters:
instrumentationLibraryLabelsEnabled- boolean indicating whether to add instrumentation library labels.- Returns:
- this.
-
build
public MetricConfiguration build()
Builds aMetricConfiguration.- Returns:
- a
MetricsConfiguration.
-
-