package metric
import "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric"
Index ¶
- Constants
- func DefaultResourceAttributesFilter(kv attribute.KeyValue) bool
- func New(opts ...Option) (sdkmetric.Exporter, error)
- func NoAttributes(attribute.KeyValue) bool
- func Version() string
- func WithCompression(c string) func(o *options)
- func WithContext(ctx context.Context) func(o *options)
- func WithCreateServiceTimeSeries() func(o *options)
- func WithDestinationProjectQuota() func(o *options)
- func WithDisableCreateMetricDescriptors() func(o *options)
- func WithFilteredResourceAttributes(filter attribute.Filter) func(o *options)
- func WithMetricDescriptorTypeFormatter(f func(metricdata.Metrics) string) func(o *options)
- func WithMonitoredResourceDescription(mrType string, mrLabels []string) func(o *options)
- func WithMonitoringClient(cl *monitoring.MetricClient) func(o *options)
- func WithMonitoringClientOptions(opts ...apioption.ClientOption) func(o *options)
- func WithProjectID(id string) func(o *options)
- func WithSumOfSquaredDeviation() func(o *options)
- type MonitoredResourceDescription
- type Option
Examples ¶
Constants ¶
const ( // Deprecated: use semconv.CloudProviderKey instead. CloudKeyProvider = "cloud.provider" // Deprecated: use semconv.CloudAccountIDKey instead. CloudKeyAccountID = "cloud.account.id" // Deprecated: use semconv.CloudRegionKey instead. CloudKeyRegion = "cloud.region" // Deprecated: use semconv.CloudAvailabilityZoneKey instead. CloudKeyZone = "cloud.availability_zone" // Deprecated: use semconv.ServiceNamespaceKey instead. ServiceKeyNamespace = "service.namespace" // Deprecated: use semconv.ServiceInstanceIDKey instead. ServiceKeyInstanceID = "service.instance.id" // Deprecated: use semconv.ServiceNameKey instead. ServiceKeyName = "service.name" // Deprecated: HostType is not needed. HostType = "host" // A uniquely identifying name for the host. // Deprecated: use semconv.HostNameKey instead. HostKeyName = "host.name" // A hostname as returned by the 'hostname' command on host machine. // Deprecated: HostKeyHostName is not needed. HostKeyHostName = "host.hostname" // Deprecated: use semconv.HostIDKey instead. HostKeyID = "host.id" // Deprecated: use semconv.HostTypeKey instead. HostKeyType = "host.type" // A uniquely identifying name for the Container. // Deprecated: use semconv.ContainerNameKey instead. ContainerKeyName = "container.name" // Deprecated: use semconv.ContainerImageNameKey instead. ContainerKeyImageName = "container.image.name" // Deprecated: use semconv.ContainerImageTagKey instead. ContainerKeyImageTag = "container.image.tag" // Cloud Providers // Deprecated: use semconv.CloudProviderAWS instead. CloudProviderAWS = "aws" // Deprecated: use semconv.CloudProviderGCP instead. CloudProviderGCP = "gcp" // Deprecated: use semconv.CloudProviderAzure instead. CloudProviderAZURE = "azure" // Deprecated: Use "k8s" instead. This should not be needed. K8S = "k8s" // Deprecated: use semconv.K8SClusterNameKey instead. K8SKeyClusterName = "k8s.cluster.name" // Deprecated: use semconv.K8SNamespaceNameKey instead. K8SKeyNamespaceName = "k8s.namespace.name" // Deprecated: use semconv.K8SPodNameKey instead. K8SKeyPodName = "k8s.pod.name" // Deprecated: use semconv.K8SDeploymentNameKey instead. K8SKeyDeploymentName = "k8s.deployment.name" // Monitored Resources types // Deprecated: Use "k8s_container" instead. K8SContainer = "k8s_container" // Deprecated: Use "k8s_node" instead. K8SNode = "k8s_node" // Deprecated: Use "k8s_pod" instead. K8SPod = "k8s_pod" // Deprecated: Use "k8s_cluster" instead. K8SCluster = "k8s_cluster" // Deprecated: Use "gce_instance" instead. GCEInstance = "gce_instance" // Deprecated: Use "aws_ec2_instance" instead. AWSEC2Instance = "aws_ec2_instance" // Deprecated: Use "generic_task" instead. GenericTask = "generic_task" )
Mappings for the well-known OpenTelemetry resource label keys to applicable Monitored Resource label keys. A uniquely identifying name for the Kubernetes cluster. Kubernetes does not have cluster names as an internal concept so this may be set to any meaningful value within the environment. For example, GKE clusters have a name which can be used for this label.
Functions ¶
func DefaultResourceAttributesFilter ¶
DefaultResourceAttributesFilter is the default filter applied to resource attributes.
func New ¶
New creates a new Exporter thats implements metric.Exporter.
Code:play
Example¶
package main
import (
"context"
"log"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
mexporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric"
)
func main() {
exporter, err := mexporter.New()
if err != nil {
log.Printf("Failed to create exporter: %v", err)
return
}
// initialize a MeterProvider with that periodically exports to the GCP exporter.
provider := sdkmetric.NewMeterProvider(
sdkmetric.WithReader(sdkmetric.NewPeriodicReader(exporter)),
)
ctx := context.Background()
defer func() {
if err = provider.Shutdown(ctx); err != nil {
log.Printf("Failed to shut down meter provider: %v", err)
}
}()
// Start meter
meter := provider.Meter("github.com/GoogleCloudPlatform/opentelemetry-operations-go/example/metric")
counter, err := meter.Int64Counter("counter-foo")
if err != nil {
log.Printf("Failed to create counter: %v", err)
return
}
attrs := []attribute.KeyValue{
attribute.Key("key").String("value"),
}
counter.Add(ctx, 123, metric.WithAttributes(attrs...))
}
func NoAttributes ¶
NoAttributes can be passed to WithFilteredResourceAttributes to disable adding resource attributes as metric labels.
func Version ¶
func Version() string
Version is the current release version of the OpenTelemetry Operations Metric Exporter in use.
func WithCompression ¶
func WithCompression(c string) func(o *options)
WithCompression sets the compression to use for gRPC requests.
func WithContext ¶
WithContext allows callers to provide a context to create clients and fetch application default credentials with.
func WithCreateServiceTimeSeries ¶
func WithCreateServiceTimeSeries() func(o *options)
WithCreateServiceTimeSeries configures the exporter to use `CreateServiceTimeSeries` for creating timeseries. If this is used, metric descriptors are not exported.
func WithDestinationProjectQuota ¶
func WithDestinationProjectQuota() func(o *options)
WithDestinationProjectQuota enables per-request usage of the destination project's quota. For example, when setting gcp.project.id on a metric.
func WithDisableCreateMetricDescriptors ¶
func WithDisableCreateMetricDescriptors() func(o *options)
WithDisableCreateMetricDescriptors will disable the automatic creation of MetricDescriptors when an unknown metric is set to be exported.
func WithFilteredResourceAttributes ¶
WithFilteredResourceAttributes determinies 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 WithFilteredResourceAttributes(NoAttributes()) to disable the addition of resource attributes to metric labels.
func WithMetricDescriptorTypeFormatter ¶
func WithMetricDescriptorTypeFormatter(f func(metricdata.Metrics) string) func(o *options)
WithMetricDescriptorTypeFormatter sets the custom formatter for MetricDescriptor. Note that the format has to follow the convention defined in the official document. The default is "workload.googleapis.com/[metric name]". ref. https://cloud.google.com/monitoring/custom-metrics/creating-metrics#custom_metric_names
func WithMonitoredResourceDescription ¶
WithMonitoredResourceDescription configures the exporter to attempt to map the OpenTelemetry Resource to the provided Google MonitoredResource. The provided mrLabels would be searched for in the OpenTelemetry Resource Attributes and if found, would be included in the MonitoredResource labels.
func WithMonitoringClient ¶
func WithMonitoringClient(cl *monitoring.MetricClient) func(o *options)
WithMonitoringClient configures the client used by the exporter to write metrics to Cloud Monitoring. This option is mutually exclusive with WithMonitoringClientOptions. If both options are provided, WithMonitoringClient is used and WithMonitoringClientOptions is ignored.
func WithMonitoringClientOptions ¶
func WithMonitoringClientOptions(opts ...apioption.ClientOption) func(o *options)
WithMonitoringClientOptions add the options for Cloud Monitoring client instance. Available options are defined in.
func WithProjectID ¶
func WithProjectID(id string) func(o *options)
WithProjectID sets Google Cloud Platform project as projectID. Without using this option, it automatically detects the project ID from the default credential detection process. Please find the detailed order of the default credential detection process on the doc: https://godoc.org/golang.org/x/oauth2/google#FindDefaultCredentials
func WithSumOfSquaredDeviation ¶
func WithSumOfSquaredDeviation() func(o *options)
WithSumOfSquaredDeviation sets the SumOfSquaredDeviation field on histograms. It is an estimate, and is not the actual sum of squared deviations.
Types ¶
type MonitoredResourceDescription ¶
type MonitoredResourceDescription struct {
// contains filtered or unexported fields
}
MonitoredResourceDescription is the struct which holds information required to map OTel resource to specific Google Cloud MonitoredResource.
type Option ¶
type Option func(*options)
Option is function type that is passed to the exporter initialization function.
Source Files ¶
cloudmonitoring.go constants.go error.go metric.go option.go version.go
- Version
- v0.56.0 (latest)
- Published
- Apr 6, 2026
- Platform
- js/wasm
- Imports
- 36 packages
- Last checked
- now –
Tools for package owners.