Custom Go instrumentation for Splunk Observability Cloud 🔗
Instrumenting applications using the Splunk Distribution of OpenTelemetry Go and instrumentation libraries covers most needs. Writing custom instrumentation for your application is only necessary when, for example, you need to add custom attributes to spans or need to manually generate spans and metrics.
Create custom traces 🔗
To create custom spans and traces, follow these steps:
Import the OpenTelemetry API:
import "go.opentelemetry.io/otel"
Create a tracer for your spans:
tracer := otel.Tracer("ExampleService")
To create a span, you need a handle on a
context.Context
instance. You can also set the tags. For example:func() { ctx, span := tracer.Start(ctx, "hello", trace.WithAttributes(attribute.String("foo", "bar"))) defer span.End() // your logic for "hello" span }()
See the OpenTelemetry Traces API documentation for additional information.
Create custom metrics 🔗
You can create custom metrics of type counter (sum with delta aggregation temporality), cumulative counter (sum), and gauge.
To create custom metrics, follow these steps:
Import the OpenTelemetry API:
import "go.opentelemetry.io/otel"
Create a meter:
meter := otel.Meter("ExampleService")
Create an instrument to take measurements:
counter, err := meter.Int64Counter( "business.requests.count", metric.WithUnit("{request}"), metric.WithDescription("The numer of business requests."), ) if err != nil { // handle error (e.g. log it) }
Perform the measurements:
counter.Add(ctx, 1);
See the OpenTelemetry Metrics API docs for additional information.
OpenTelemetry Go instrument types 🔗
The following table shows the equivalences between OpenTelemetry instrument types and Splunk Observability Cloud metric types.
OpenTelemetry Go |
Splunk Observability Cloud |
---|---|
|
Cumulative counter |
|
Histogram types generate three separate metrics in Splunk Observability Cloud:
Buckets have a dimension |
|
Cumulative counter |
|
Gauge |
|
Gauge |
|
Gauge |
|
Cumulative counter |
|
Histogram types generate the following separate metrics in Splunk Observability Cloud:
Buckets have a dimension |
|
Cumulative counter |
|
Gauge |
|
Gauge |
|
Gauge |