gcp

package module
v0.0.0-...-806a58a Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

GCP Resource detector

The GCP resource detector supports detecting resources on:

  • Google Compute Engine (GCE)
  • Google Kubernetes Engine (GKE)
  • Google App Engine (GAE)
  • Cloud Run
  • Cloud Functions

Usage

ctx := context.Background()
// Detect your resources
res, err := resource.New(ctx,
    // Use the GCP resource detector!
    resource.WithDetectors(gcp.NewDetector()),
    // Keep the default detectors
    resource.WithTelemetrySDK(),
    // Add your own custom attributes to identify your application
    resource.WithAttributes(
        semconv.ServiceNameKey.String("my-application"),
        semconv.ServiceNamespaceKey.String("my-company-frontend-team"),
    ),
)
if err != nil {
    // Handle err
}
// Use the resource in your tracerprovider (or meterprovider)
tp := trace.NewTracerProvider(
    // ... other options
    trace.WithResource(res),
)

Setting Kubernetes attributes

Previous iterations of GCP resource detection attempted to detect container.name, k8s.pod.name and k8s.namespace.name. When using this detector, you should use this in your Pod Spec to set these using OTEL_RESOURCE_ATTRIBUTES:

env:
- name: POD_NAME
  valueFrom:
    fieldRef:
      fieldPath: metadata.name
- name: NAMESPACE_NAME
  valueFrom:
    fieldRef:
      fieldPath: metadata.namespace
- name: CONTAINER_NAME
  value: my-container-name
- name: OTEL_RESOURCE_ATTRIBUTES
  value: k8s.pod.name=$(POD_NAME),k8s.namespace.name=$(NAMESPACE_NAME),k8s.container.name=$(CONTAINER_NAME)

To have a detector unpack the OTEL_RESOURCE_ATTRIBUTES envvar, use the WithFromEnv option:

...
// Detect your resources
res, err := resource.New(ctx,
    resource.WithDetectors(gcp.NewDetector()),
    resource.WithTelemetrySDK(),
    resource.WithFromEnv(), // unpacks OTEL_RESOURCE_ATTRIBUTES
    // Add your own custom attributes to identify your application
    resource.WithAttributes(
        semconv.ServiceNameKey.String("my-application"),
        semconv.ServiceNamespaceKey.String("my-company-frontend-team"),
    ),
)
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCloudFunction deprecated

func NewCloudFunction() resource.Detector

NewCloudFunction will return a GCP Cloud Function resource detector.

Deprecated: Use gcp.NewDetector() instead, which sets the same resource attributes.

func NewDetector

func NewDetector() resource.Detector

NewDetector returns a resource detector which detects resource attributes on: * Google Compute Engine (GCE). * Google Kubernetes Engine (GKE). * Google App Engine (GAE). * Cloud Run. * Cloud Functions.

func SemVersion deprecated

func SemVersion() string

SemVersion is the semantic version to be supplied to tracer/meter creation.

Deprecated: Use Version instead.

func Version

func Version() string

Version is the current release version of the GCP resource detector.

Types

type CloudRun deprecated

type CloudRun struct {
	// contains filtered or unexported fields
}

CloudRun collects resource information of Cloud Run instance.

Deprecated: Use gcp.NewDetector() instead. Note that it sets faas.* resource attributes instead of service.* attributes.

func NewCloudRun deprecated

func NewCloudRun() *CloudRun

NewCloudRun creates a CloudRun detector.

Deprecated: Use gcp.NewDetector() instead. Note that it sets faas.* resource attributes instead of service.* attributes.

func (*CloudRun) Detect

func (c *CloudRun) Detect(ctx context.Context) (*resource.Resource, error)

Detect detects associated resources when running on Cloud Run hosts. NOTE: the service.namespace attribute is currently hardcoded to be "cloud-run-managed". This may change in the future, please do not rely on this behavior yet.

type GCE deprecated

type GCE struct{}

GCE collects resource information of GCE computing instances.

Deprecated: Use gcp.NewDetector() instead, which sets the same resource attributes on GCE.

func (*GCE) Detect

func (gce *GCE) Detect(ctx context.Context) (*resource.Resource, error)

Detect detects associated resources when running on GCE hosts.

type GKE deprecated

type GKE struct{}

GKE collects resource information of GKE computing instances.

Deprecated: Use gcp.NewDetector() instead, which does NOT detect container, pod, and namespace attributes. Set those using name using the OTEL_RESOURCE_ATTRIBUTES env var instead.

func (*GKE) Detect

func (gke *GKE) Detect(ctx context.Context) (*resource.Resource, error)

Detect detects associated resources when running in GKE environment.

Jump to

Keyboard shortcuts

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