senders

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: Apache-2.0 Imports: 19 Imported by: 32

Documentation

Overview

Example (Sender)
package main

import (
	"github.com/wavefronthq/wavefront-sdk-go/histogram"
	wavefront "github.com/wavefronthq/wavefront-sdk-go/senders"
)

func main() {
	sender, err := wavefront.NewSender("http://localhost")
	if err != nil {
		// handle error
	}

	// Wavefront metrics data format
	// <metricName> <metricValue> [<timestamp>] source=<source> [pointTags]
	// Example: "new-york.power.usage 42422 1533529977 source=localhost datacenter=dc1"
	err = sender.SendMetric("new-york.power.usage", 42422.0, 0, "go_test", map[string]string{"env": "test"})
	if err != nil {
		// handle err
	}

	// When you use a Sender SDK, you won’t see span-level RED metrics by default unless you use the Wavefront proxy and define a custom tracing port (TracingPort). See Instrument Your Application with Wavefront Sender SDKs for details.
	// Wavefront Tracing Span Data format
	// <tracingSpanName> source=<source> [pointTags] <start_millis> <duration_milliseconds>
	// Example:
	// "getAllUsers source=localhost traceId=7b3bf470-9456-11e8-9eb6-529269fb1459
	// spanId=0313bafe-9457-11e8-9eb6-529269fb1459 parent=2f64e538-9457-11e8-9eb6-529269fb1459
	// application=Wavefront http.method=GET 1552949776000 343"
	err = sender.SendSpan("getAllUsers", 1552949776000, 343, "localhost",
		"7b3bf470-9456-11e8-9eb6-529269fb1459",
		"0313bafe-9457-11e8-9eb6-529269fb1459",
		[]string{"2f64e538-9457-11e8-9eb6-529269fb1459"},
		nil,
		[]wavefront.SpanTag{
			{Key: "application", Value: "Wavefront"},
			{Key: "service", Value: "istio"},
			{Key: "http.method", Value: "GET"},
		},
		nil)
	if err != nil {
		// handle err
	}

	// Wavefront delta counter format
	// <metricName> <metricValue> source=<source> [pointTags]
	// Example: "lambda.thumbnail.generate 10 source=thumbnail_service image-format=jpeg"
	err = sender.SendDeltaCounter("lambda.thumbnail.generate", 10.0, "thumbnail_service", map[string]string{"format": "jpeg"})
	if err != nil {
		// handle err
	}

	// Wavefront Histogram data format
	// {!M | !H | !D} [<timestamp>] #<count> <mean> [centroids] <histogramName> source=<source> [pointTags]
	// Example: You can choose to send to at most 3 bins - Minute/Hour/Day
	// "!M 1533529977 #20 30.0 #10 5.1 request.latency source=appServer1 region=us-west"
	// "!H 1533529977 #20 30.0 #10 5.1 request.latency source=appServer1 region=us-west"
	// "!D 1533529977 #20 30.0 #10 5.1 request.latency source=appServer1 region=us-west"

	centroids := []histogram.Centroid{
		{
			Value: 30.0,
			Count: 20,
		},
		{
			Value: 5.1,
			Count: 10,
		},
	}

	hgs := map[histogram.Granularity]bool{
		histogram.MINUTE: true,
		histogram.HOUR:   true,
		histogram.DAY:    true,
	}

	err = sender.SendDistribution("request.latency", centroids, hgs, 0, "appServer1", map[string]string{"region": "us-west"})
	if err != nil {
		// handle err
	}

	if err := sender.Flush(); err != nil {
		// handle error
	}
	sender.Close()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSPOption added in v0.14.0

type CSPOption func(any)

A CSPOption sets optional configuration for CSP Authentication

func CSPBaseURL added in v0.14.0

func CSPBaseURL(baseURL string) CSPOption

CSPBaseURL sets an alternative base URL for the CSP server

func CSPOrgID added in v0.14.0

func CSPOrgID(orgID string) CSPOption

CSPOrgID sets an explicit orgID for Client Credentials authentication

type DistributionSender

type DistributionSender interface {
	// SendDistribution sends a distribution of metrics to Wavefront with optional timestamp and tags.
	// Each centroid is a 2-dimensional entity with the first dimension the mean value
	// and the second dimension the count of points in the centroid.
	// The granularity informs the set of intervals (minute, hour, and/or day) by which the
	// histogram data should be aggregated.
	SendDistribution(name string, centroids []histogram.Centroid, hgs map[histogram.Granularity]bool, ts int64, source string, tags map[string]string) error
}

DistributionSender Interface for sending distributions to Wavefront

type EventSender

type EventSender interface {
	// SendEvent sends an event to Wavefront with optional tags
	SendEvent(name string, startMillis, endMillis int64, source string, tags map[string]string, setters ...event.Option) error
}

EventSender Interface for sending events to Wavefront. NOT yet supported.

type MetricSender

type MetricSender interface {
	// SendMetric sends a single metric to Wavefront with optional timestamp and tags.
	SendMetric(name string, value float64, ts int64, source string, tags map[string]string) error

	// SendDeltaCounter sends a delta counter (counter aggregated at the Wavefront service) to Wavefront.
	// the timestamp for a delta counter is assigned at the server side.
	SendDeltaCounter(name string, value float64, source string, tags map[string]string) error
}

MetricSender Interface for sending metrics to Wavefront

type MultiSender added in v0.9.8

type MultiSender interface {
	Sender
}

MultiSender Interface for sending metrics, distributions and spans to multiple Wavefront services at the same time

func NewMultiSender added in v0.9.8

func NewMultiSender(senders ...Sender) MultiSender

NewMultiSender creates a new Wavefront MultiClient

type Option added in v0.9.8

type Option func(*configuration)

Option Wavefront client configuration options

func APIToken added in v0.14.0

func APIToken(apiToken string) Option

APIToken configures the sender to use a Wavefront API Token for authentication

func BatchSize added in v0.9.8

func BatchSize(n int) Option

BatchSize set max batch of data sent per flush interval. Defaults to 10,000. recommended not to exceed 40,000.

func CSPAPIToken added in v0.14.0

func CSPAPIToken(cspAPIToken string, options ...CSPOption) Option

CSPAPIToken configures the sender to use a CSP API Token for authentication

func CSPClientCredentials added in v0.14.0

func CSPClientCredentials(clientID string, clientSecret string, options ...CSPOption) Option

CSPClientCredentials configures the sender to use a CSP Client Credentials for authentication

func FlushInterval added in v0.13.0

func FlushInterval(interval time.Duration) Option

FlushInterval set the interval at which to flush data to Wavefront. Defaults to 1 Second.

func FlushIntervalSeconds added in v0.9.8

func FlushIntervalSeconds(n int) Option

FlushIntervalSeconds set the interval (in seconds) at which to flush data to Wavefront. Defaults to 1 Second.

func HTTPClient added in v0.15.0

func HTTPClient(client *http.Client) Option

HTTPClient sets the http.Client used to send data to Wavefront. Overrides TLSConfigOptions and Timeout.

func MaxBufferSize added in v0.9.8

func MaxBufferSize(n int) Option

MaxBufferSize set the size of internal buffers beyond which received data is dropped. Defaults to 50,000.

func MetricsPort added in v0.9.10

func MetricsPort(port int) Option

MetricsPort sets the port on which to report metrics. Default is 2878.

func SDKMetricsTags added in v0.9.10

func SDKMetricsTags(tags map[string]string) Option

SDKMetricsTags adds the additional tags provided in tags to all internal metrics this library reports. Clients can use multiple SDKMetricsTags calls when creating a sender. In that case, the sender sends all the tags from each of the SDKMetricsTags calls in addition to the standard "pid" and "version" tags to all internal metrics. The "pid" tag is the process ID; the "version" tag is the version of this SDK.

func SendInternalMetrics added in v0.14.0

func SendInternalMetrics(enabled bool) Option

SendInternalMetrics turns sending of internal SDK metrics on/off.

func TLSConfigOptions added in v0.12.0

func TLSConfigOptions(tlsCfg *tls.Config) Option

TLSConfigOptions sets the tls.Config used by the HTTP Client to send data to Wavefront.

func Timeout added in v0.12.0

func Timeout(timeout time.Duration) Option

Timeout sets the HTTP timeout. Defaults to 10 seconds.

func TracesPort added in v0.9.10

func TracesPort(port int) Option

TracesPort sets the port on which to report traces. Default is 30001.

type Sender

type Sender interface {
	MetricSender
	DistributionSender
	SpanSender
	EventSender
	internal.Flusher
	Close()
	// contains filtered or unexported methods
}

Sender Interface for sending metrics, distributions and spans to Wavefront

func NewSender added in v0.9.8

func NewSender(wfURL string, setters ...Option) (Sender, error)

NewSender creates a Sender using the provided URL and Options

Example (Direct)
package main

import (
	wavefront "github.com/wavefronthq/wavefront-sdk-go/senders"
)

func main() {
	// For Direct Ingestion endpoints, by default all data is sent to port 80
	// or port 443 for unencrypted or encrypted connections, respectively.

	// Direct Ingestion requires authentication.

	// Wavefront API tokens:
	// Set your API token using the APIToken Option
	// 11111111-2222-3333-4444-555555555555 is your API token with direct ingestion permission.
	sender, err := wavefront.NewSender("https://surf.wavefront.com",
		wavefront.APIToken("11111111-2222-3333-4444-555555555555"))

	// CSP API tokens:
	// Set your API token using the CSPAPIToken Option
	// <MY-CSP-TOKEN> is your CSP API token with the aoa:directDataIngestion scope.
	sender, err = wavefront.NewSender("https://surf.wavefront.com",
		wavefront.CSPAPIToken("<MY-CSP-TOKEN>"))

	// CSP Client Credentials:
	// Set your API token using the CSPClientCredentials Option
	sender, err = wavefront.NewSender("https://surf.wavefront.com",
		wavefront.CSPClientCredentials("<MY-CLIENT_ID>", "<MY-CLIENT_SECRET>"))

	// CSP Authentication strategies also support additional options
	sender, err = wavefront.NewSender("https://surf.wavefront.com",
		wavefront.CSPClientCredentials(
			"<MY-CLIENT_ID>",
			"<MY-CLIENT_SECRET>",
			wavefront.CSPBaseURL("<MY-NONSTANDARD-CSP-HOST>"),
			wavefront.CSPOrgID("<MY-ORG-ID>"),
		))

	sender, err = wavefront.NewSender("https://surf.wavefront.com",
		wavefront.CSPAPIToken(
			"<MY-CSP-TOKEN>",
			wavefront.CSPBaseURL("<MY-NONSTANDARD-CSP-HOST>"),
		))

	if err != nil {
		// handle error
	}
	err = sender.Flush()
	if err != nil {
		// handle error
	}
	sender.Close()
}
Output:

Example (Options)
package main

import (
	"crypto/tls"
	"net/http"
	"time"

	wavefront "github.com/wavefronthq/wavefront-sdk-go/senders"
)

func main() {
	// NewSender accepts optional arguments. Use these if you need to set non-default ports for your Wavefront Proxy, tune batching parameters, or set tags for internal SDK metrics.
	sender, err := wavefront.NewSender(
		"http://localhost",
		wavefront.BatchSize(20000),                // Send batches of 20,000.
		wavefront.FlushInterval(5*time.Second),    // Flush every 5 seconds.
		wavefront.MetricsPort(4321),               // Use port 4321 for metrics.
		wavefront.TracesPort(40001),               // Use port 40001 for traces.
		wavefront.Timeout(15),                     // Set an HTTP timeout in seconds (default is 10s)
		wavefront.SendInternalMetrics(false),      // Don't send internal ~sdk.go.* metrics
		wavefront.TLSConfigOptions(&tls.Config{}), // Set TLS config options.
		wavefront.HTTPClient(&http.Client{
			Timeout: 15 * time.Second,
			Transport: &http.Transport{
				TLSClientConfig: &tls.Config{},
				IdleConnTimeout: 4 * time.Second,
			},
		}), // Provide a fully configured http.Client
	)

	if err != nil {
		// handle error
	}
	sender.Close()
}
Output:

Example (Proxy)
package main

import (
	wavefront "github.com/wavefronthq/wavefront-sdk-go/senders"
)

func main() {
	// For Proxy endpoints, by default metrics and histograms are sent to
	// port 2878 and traces are sent to port 30001.
	sender, err := wavefront.NewSender("http://localhost")

	// To use non-default ports, specify the metric/histogram port in the url,
	// and set the port for traces using the TracesPort Option.
	sender, err = wavefront.NewSender("https://localhost:4443",
		wavefront.TracesPort(55555))

	if err != nil {
		// handle error
	}

	err = sender.Flush()
	if err != nil {
		// handle error
	}
	sender.Close()
}
Output:

func NewWavefrontNoOpClient added in v0.9.9

func NewWavefrontNoOpClient() (Sender, error)

NewWavefrontNoOpClient returns a Wavefront Client instance for which all operations are no-ops.

type SpanLog

type SpanLog struct {
	Timestamp int64
	Fields    map[string]string
}

type SpanSender

type SpanSender interface {
	// SendSpan sends a tracing span to Wavefront.
	// traceID, spanId, parentIds and preceding spanIds are expected to be UUID strings.
	// parents and preceding spans can be empty for a root span.
	// span tag keys can be repeated (example: "user"="foo" and "user"="bar")
	// span logs are currently omitted
	SendSpan(name string, startMillis, durationMillis int64, source, traceID, spanID string, parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog) error
}

SpanSender Interface for sending tracing spans to Wavefront

type SpanTag

type SpanTag struct {
	Key   string
	Value string
}

Jump to

Keyboard shortcuts

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