Wavefront OpenTracing Go SDK
Contact our support team if you have any questions (support@wavefront.com). Thank you!
This is the Wavefront by VMware OpenTracing SDK for Go that provides distributed tracing support for Wavefront.
Before you start implementing, let us make sure you are using the correct SDK!
Note:
- This is the Wavefront by VMware OpenTracing SDK for Go!
If this SDK is not what you were looking for, see the table given below.
- See instrument your application for tracing for more information.
SDK Type | SDK Description | Supported Languages |
---|---|---|
OpenTracing SDK | Implements the OpenTracing specification. Lets you define, collect, and report custom trace data from any part of your application code. Automatically derives RED metrics from the reported spans. |
|
Metrics SDK | Implements a standard metrics library. Lets you define, collect, and report custom business metrics and histograms from any part of your application code. |
|
Framework SDK | Reports predefined traces, metrics, and histograms from the APIs of a supported app framework. Lets you get started quickly with minimal code changes. |
|
Sender SDK | Lets you send raw values to Wavefront for storage as metrics, histograms, or traces, e.g., to import CSV data into Wavefront. |
|
import (
"github.com/wavefronthq/wavefront-opentracing-sdk-go/reporter"
"github.com/wavefronthq/wavefront-opentracing-sdk-go/tracer"
"github.com/wavefronthq/wavefront-sdk-go/application"
"github.com/wavefronthq/wavefront-sdk-go/senders"
)
Tracer is an OpenTracing interface for creating spans and propagating them across arbitrary transports.
This SDK provides a WavefrontTracer
that implements the Tracer
interface to create spans and send them to Wavefront. A WaverfrontTracer
:
The steps for creating a WavefrontTracer
are:
Tags
instance to specify metadata about your application.Sender
instance to send trace data to Wavefront.WavefrontSpanReporter
instance to report trace data to Wavefront.WavefrontTracer
instance.The following code sample creates a Tracer. For details of each step, see the sections below.
func NewGlobalTracer(serviceName string) io.Closer {
config := &wavefront.ProxyConfiguration{
Host: "<PROXY_IP/PROXY_FQDN>",
TracingPort: <PROXY_TRACING_PORT>,
}
sender, err := wavefront.NewProxySender(config)
if err != nil {
log.Printf("Couldn't create Wavefront Sender: %s\n", err.Error())
os.Exit(1)
}
appTags := application.New(applicationName, serviceName)
directrep := wfreporter.New(sender, appTags)
consolerep := wfreporter.NewConsoleSpanReporter(serviceName)
reporter := wfreporter.NewCompositeSpanReporter(directrep, consolerep)
tracer := wftracer.New(reporter)
opentracing.SetGlobalTracer(tracer)
return ioutil.NopCloser(nil)
}
Application tags determine the metadata (span tags) that are included with every span reported to Wavefront. These tags enable you to filter and query trace data in Wavefront.
You encapsulate application tags in a Tags
object. See Application Tags for details.
The following example specifies values for the 2 required tags (application
and service
).
Example:
appTags := application.New("OrderingApp", "inventory")
The Wavefront sender object implements the low-level interface for sending data to Wavefront. You can choose to send data using the Wavefront proxy or direct ingestion.
If you have already set up a Wavefront sender for another SDK that runs in the same process, use that one. For details, see Share a Wavefront Sender.
Otherwise, set up a Wavefront Sender to configure a proxy Sender
or a direct Sender
.
The following example configures a direct Sender
with default direct ingestion properties.
Example:
directCfg := &senders.DirectConfiguration{
Server: "https://INSTANCE.wavefront.com",
Token: "YOUR_API_TOKEN",
}
sender, err := senders.NewDirectSender(directCfg)
if err != nil {
panic(err)
}
You must create a WavefrontSpanReporter
to report trace data to Wavefront. Optionally, you can create a CompositeSpanReporter
to send data to Wavefront and print it to the console.
WavefrontSpanReporter
To create a WavefrontSpanReporter
, you specify:
Sender
or a direct Sender
.Tags
instance from Step 1.This example creates a WavefrontSpanReporter
that assigns the default source (the hostname) to the reported spans.
Example:
reporter := reporter.New(sender, appTags)
This example creates a WavefrontSpanReporter
that assigns the specified source to the reported spans.
Example:
reporter := reporter.New(sender, appTags, reporter.Source("app1.foo.com"))
Optionally, you can add custom span-level tags to propagate RED metrics. See Custom Span-Level Tags for RED Metrics for details.
Example:
reporter := reporter.New(sender, appTags, reporter.RedMetricsCustomTagKeys([2]string{"env", "location"}))
A CompositeSpanReporter
enables you to chain a WavefrontSpanReporter
to another reporter, such as a ConsoleSpanReporter
. A console reporter is useful for debugging.
wfReporter := reporter.New(sender, appTags, reporter.Source("app1.foo.com"))
clReporter := reporter.NewConsoleSpanReporter("app1.foo.com") //Specify the same source you used for the WavefrontSpanReporter
reporter := reporter.NewCompositeSpanReporter(wfReporter, clReporter)
To create a WavefrontTracer
, you initialize it with the Reporter
instance you created in the previous step:
tracer := tracer.New(reporter)
Optionally, you can create the WavefrontTracer
with one or more sampling strategies. See the sampling documentation for details.
tracer.New(reporter, WithSampler(sampler))
To create a global tracer, you initialize it with the WavefrontTracer
you created in the previous step:
opentracing.InitGlobalTracer(tracer)
Note: After you initialize the global tracer, completed spans are automatically reported to Wavefront and you do not need to start the reporter explicitly.
You can instrument your application to emit one or more logs with a span, and examine the logs from the Tracing UI.
Use the OpenTracing Span object’s LogFields() method in your application.
See the context propagation documentation for details on propagating span contexts across process boundaries.
See the RED metrics documentation for details on the out-of-the-box metrics and histograms that are provided.
See the diagnostic metrics documentation for details on the internal metrics that this SDK collects and reports to Wavefront.