go.opencensus.iogo.opencensus.io/exporter/stackdriver Index | Examples | Files | Directories

package stackdriver

import "go.opencensus.io/exporter/stackdriver"

Package stackdriver contains the OpenCensus exporters for Stackdriver Monitoring and Stackdriver Tracing.

Please note that the Stackdriver exporter is currently experimental.

The package uses Application Default Credentials to authenticate. See https://developers.google.com/identity/protocols/application-default-credentials

Example

Code:play 

package main

import (
	"log"
	"net/http"

	"go.opencensus.io/exporter/stackdriver"
	"go.opencensus.io/exporter/stackdriver/propagation"
	"go.opencensus.io/plugin/ochttp"
	"go.opencensus.io/stats/view"
	"go.opencensus.io/trace"
)

func main() {
	exporter, err := stackdriver.NewExporter(stackdriver.Options{ProjectID: "google-project-id"})
	if err != nil {
		log.Fatal(err)
	}

	// Export to Stackdriver Monitoring.
	view.RegisterExporter(exporter)

	// Subscribe views to see stats in Stackdriver Monitoring.
	if err := view.Subscribe(
		ochttp.ClientLatencyView,
		ochttp.ClientResponseBytesView,
	); err != nil {
		log.Fatal(err)
	}

	// Export to Stackdriver Trace.
	trace.RegisterExporter(exporter)

	// Automatically add a Stackdriver trace header to outgoing requests:
	client := &http.Client{
		Transport: &ochttp.Transport{
			Propagation: &propagation.HTTPFormat{},
		},
	}
	_ = client // use client

	// All outgoing requests from client will include a Stackdriver Trace header.
	// See the ochttp package for how to handle incoming requests.
}

Index

Examples

Types

type Exporter

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

Exporter is a stats.Exporter and trace.Exporter implementation that uploads data to Stackdriver.

func NewExporter

func NewExporter(o Options) (*Exporter, error)

NewExporter creates a new Exporter that implements both stats.Exporter and trace.Exporter.

func (*Exporter) ExportSpan

func (e *Exporter) ExportSpan(sd *trace.SpanData)

ExportSpan exports a SpanData to Stackdriver Trace.

func (*Exporter) ExportView

func (e *Exporter) ExportView(vd *view.Data)

ExportView exports to the Stackdriver Monitoring if view data has one or more rows.

func (*Exporter) Flush

func (e *Exporter) Flush()

Flush waits for exported data to be uploaded.

This is useful if your program is ending and you do not want to lose recent stats or spans.

type Options

type Options struct {
	// ProjectID is the identifier of the Stackdriver
	// project the user is uploading the stats data to.
	// If not set, this will default to your "Application Default Credentials".
	// For details see: https://developers.google.com/accounts/docs/application-default-credentials
	ProjectID string

	// OnError is the hook to be called when there is
	// an error uploading the stats or tracing data.
	// If no custom hook is set, errors are logged.
	// Optional.
	OnError func(err error)

	// ClientOptions are additional options to be passed
	// to the underlying Stackdriver Monitoring API client.
	// Optional.
	ClientOptions []option.ClientOption

	// BundleDelayThreshold determines the max amount of time
	// the exporter can wait before uploading view data to
	// the backend.
	// Optional.
	BundleDelayThreshold time.Duration

	// BundleCountThreshold determines how many view data events
	// can be buffered before batch uploading them to the backend.
	// Optional.
	BundleCountThreshold int

	// Resource is an optional field that represents the Stackdriver
	// MonitoredResource, a resource that can be used for monitoring.
	// If no custom ResourceDescriptor is set, a default MonitoredResource
	// with type global and no resource labels will be used.
	// Optional.
	Resource *monitoredrespb.MonitoredResource

	// MetricPrefix overrides the OpenCensus prefix of a stackdriver metric.
	// Optional.
	MetricPrefix string
}

Options contains options for configuring the exporter.

Source Files

stackdriver.go stats.go trace.go trace_proto.go

Directories

PathSynopsis
exporter/stackdriver/examples
exporter/stackdriver/examples/statsCommand stackdriver is an example program that collects data for video size.
exporter/stackdriver/propagationPackage propagation implement X-Cloud-Trace-Context header propagation used by Google Cloud products.
Version
v0.6.0
Published
Mar 22, 2018
Platform
js/wasm
Imports
34 packages
Last checked
3 hours ago

Tools for package owners.