metric

package module
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 36 Imported by: 15

README

OpenTelemetry Google Cloud Monitoring Exporter

Docs Apache License

OpenTelemetry Google Cloud Monitoring Exporter allow the user to send collected metrics to Google Cloud.

Google Cloud Monitoring provides visibility into the performance, uptime, and overall health of cloud-powered applications. It collects metrics, events, and metadata from Google Cloud, Amazon Web Services, hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch, and many others. Operations ingests that data and generates insights via dashboards, charts, and alerts. Cloud Monitoring alerting helps you collaborate by integrating with Slack, PagerDuty, and more.

Setup

Google Cloud Monitoring is a managed service provided by Google Cloud Platform. Google Cloud Monitoring requires to set up "Workspace" in advance. The guide to create a new Workspace is available on the official document.

Authentication

The Google Cloud Monitoring exporter depends upon google.FindDefaultCredentials, so the service account is automatically detected by default, but also the custom credential file (so called service_account_key.json) can be detected with specific conditions. Quoting from the document of google.FindDefaultCredentials:

  • A JSON file whose path is specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable.
  • A JSON file in a location known to the gcloud command-line tool. On Windows, this is %APPDATA%/gcloud/application_default_credentials.json. On other systems, $HOME/.config/gcloud/application_default_credentials.json.

When running code locally, you may need to specify a Google Project ID in addition to GOOGLE_APPLICATION_CREDENTIALS. This is best done using an environment variable (e.g. GOOGLE_CLOUD_PROJECT) and the metric.WithProjectID method, e.g.:

projectID := os.Getenv("GOOGLE_CLOUD_PROJECT")
opts := []mexporter.Option{
    mexporter.WithProjectID(projectID),
}

Documentation

Index

Examples

Constants

View Source
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.

Variables

This section is empty.

Functions

func DefaultResourceAttributesFilter added in v0.34.0

func DefaultResourceAttributesFilter(kv attribute.KeyValue) bool

DefaultResourceAttributesFilter is the default filter applied to resource attributes.

func New added in v0.33.0

func New(opts ...Option) (sdkmetric.Exporter, error)

New creates a new Exporter thats implements metric.Exporter.

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...))
}
Output:

func NoAttributes added in v0.34.0

func NoAttributes(attribute.KeyValue) bool

NoAttributes can be passed to WithFilteredResourceAttributes to disable adding resource attributes as metric labels.

func Version added in v0.10.0

func Version() string

Version is the current release version of the OpenTelemetry Operations Metric Exporter in use.

func WithCompression added in v0.35.0

func WithCompression(c string) func(o *options)

WithCompression sets the compression to use for gRPC requests.

func WithDestinationProjectQuota added in v0.35.0

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 added in v0.34.2

func WithDisableCreateMetricDescriptors() func(o *options)

WithDisableCreateMetricDescriptors will disable the automatic creation of MetricDescriptors when an unknown metric is set to be exported.

func WithFilteredResourceAttributes added in v0.34.0

func WithFilteredResourceAttributes(filter attribute.Filter) func(o *options)

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 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 credentail detection proecess on the doc: https://godoc.org/golang.org/x/oauth2/google#FindDefaultCredentials

func WithSumOfSquaredDeviation added in v0.42.0

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 Option

type Option func(*options)

Option is function type that is passed to the exporter initialization function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL