ddspanname

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 4 Imported by: 0

README

OpenTelemetry Go DataDog Span Name Formatter

From:

From

To:

From

Description

When using the Go OpenTelemetry instrumentation with DataDog, it uses the instrumentation name as the operation name (like go.opentelemetry.io_contrib_instrumentation_github.com_gorilla_mux_otelmux.server), and tries to guess the span name for some types of spans (like http) and only uses the real span name if guessing failed.

This results in ugly span names in the DataDog UI, like can be seen on the "From" image above.

This library returns a custom trace.TracerProvider instance that can be sent to instrumentations via an option like WithTracerProvider, which wraps the underlying provider and sets the operation.name and resource.name attributes that DataDog uses in its UI.

The contrib directory contains implementations for common packages following the same naming patterns as the official DataDog Go library.

Usage

import (
    "net/http"

    ddspanname "github.com/RangelReale/opentelemetry-go-datadog-spanname"
    "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

func main() {
    client := &http.Client{
        Transport: otelhttp.NewTransport(nil,
            otelhttp.WithTracerProvider(ddspanname.NewTracerProvider("http.request")),
        ),
    }
    // ...
}

Using contrib:

import (
    "net/http"

    snhttp "github.com/RangelReale/opentelemetry-go-datadog-spanname/contrib/net/http"
    "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

func main() {
    client := &http.Client{
        Transport: otelhttp.NewTransport(nil,
            otelhttp.WithTracerProvider(snhttp.NewTransport()),
            otelhttp.WithSpanNameFormatter(snhttp.TransportSpanNameFormatter),
        ),
    }
    // ...	
}

Author

Rangel Reale (rangelreale@gmail.com)

Documentation

Index

Constants

View Source
const (
	DDOperationNameKey = attribute.Key("operation.name")
	DDResourceNameKey  = attribute.Key("resource.name")
)

Variables

This section is empty.

Functions

func NewTracer

func NewTracer(base trace.Tracer, operationName string, opts ...TracerOption) trace.Tracer

NewTracer creates a trace.Tracer which sets the attributes "operation.name" and "resource.name", so that DataDog span names are formatted correctly.

func NewTracerProvider

func NewTracerProvider(operationName string, opts ...Option) trace.TracerProvider

NewTracerProvider creates a trace.TracerProvider that returns a trace.Tracer which sets the attributes "operation.name" and "resource.name", so that DataDog span names are formatted correctly.

Types

type OperationNameFormatter

type OperationNameFormatter func(ctx context.Context, operationName string) string

type Option

type Option func(*tracerProvider)

func WithOperationNameFormatter

func WithOperationNameFormatter(operationNameFormatter OperationNameFormatter) Option

WithOperationNameFormatter sets a function to customize the operation name.

func WithSpanNameFormatter

func WithSpanNameFormatter(spanNameFormatter SpanNameFormatter) Option

WithSpanNameFormatter sets a function to customize the span name.

func WithTracerProvider

func WithTracerProvider(base trace.TracerProvider) Option

WithTracerProvider sets a base trace.TracerProvider. If not set, the global trace provider will be used.

type SpanNameFormatter

type SpanNameFormatter func(ctx context.Context, operationName string, spanName string) string

type TracerOption

type TracerOption func(*tracer)

func WithTracerOperationNameFormatter

func WithTracerOperationNameFormatter(operationNameFormatter OperationNameFormatter) TracerOption

WithTracerOperationNameFormatter sets a function to customize the operation name.

func WithTracerSpanNameFormatter

func WithTracerSpanNameFormatter(spanNameFormatter SpanNameFormatter) TracerOption

WithTracerSpanNameFormatter sets a function to customize the span name.

Directories

Path Synopsis
contrib

Jump to

Keyboard shortcuts

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