opentelemetry

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: Apache-2.0 Imports: 18 Imported by: 24

README

OpenTelemetry Collector Example

This file contains a description of how to launch OpenTelemetry container with Jaeger and Zipkin for spans and Prometheus for metrics using Docker.

Collector

First, you need to clone repository and switch to the folder with docker-compose file:

git clone git@github.com:open-telemetry/opentelemetry-collector-contrib.git
cd opentelemetry-collector-contrib/examples/demo

Before running docker-compose you need to expose port 4317 for otel-collector container inside docker-compose.yaml

Run docker-compose file:

docker-compose up -d

The example exposes the following backends:

Using spans and metrics in tests

After running docker-compose you can enable spans and metrics inside any test using the following code:

log.EnableTracing(true)
os.Setenv("TELEMETRY", "true")
spanExporter := opentelemetry.InitSpanExporter(ctx, "0.0.0.0:4317")
metricExporter := opentelemetry.InitMetricExporter(ctx, "0.0.0.0:4317")
o := opentelemetry.Init(ctx, spanExporter, metricExporter, "NSM")
defer o.Close()

Metrics are disabled in tests by default. You can create simple metrics chain element to test them:

type metricsServer struct {
}
func NewServer() networkservice.NetworkServiceServer {
	return &metricsServer{}
}
func (c *metricsServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
	request.Connection.GetCurrentPathSegment().Metrics = make(map[string]string)
	request.Connection.GetCurrentPathSegment().Metrics["my_nsm_metric"] = "10000"
	return next.Server(ctx).Request(ctx, request)
}
func (c *metricsServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) {
	return next.Server(ctx).Close(ctx, conn)
}

Clean up

To clean up docker containers run docker-compose down in opentelemetry-collector-contrib/examples/demo folder

Documentation

Overview

Package opentelemetry provides a set of utilities for assisting with telemetry data

Package opentelemetry provides a set of utilities for assisting with telemetry data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(ctx context.Context, spanExporter sdktrace.SpanExporter, metricReader sdkmetric.Reader, service string) io.Closer

Init - creates opentelemetry tracer and meter providers

func InitOPTLMetricExporter added in v1.11.0

func InitOPTLMetricExporter(ctx context.Context, exporterURL string, exportInterval time.Duration) sdkmetric.Reader

InitOPTLMetricExporter - returns an instance of OpenTelemetry Metric Exporter.

func InitPrometheusMetricExporter added in v1.11.0

func InitPrometheusMetricExporter(ctx context.Context) sdkmetric.Reader

InitPrometheusMetricExporter - returns an instance of Prometheus Metric Exporter.

func InitSpanExporter

func InitSpanExporter(ctx context.Context, exporterURL string) trace.SpanExporter

InitSpanExporter - returns an instance of OpenTelemetry Span Exporter.

func IsEnabled

func IsEnabled() bool

IsEnabled returns true if opentelemetry enabled

Types

This section is empty.

Jump to

Keyboard shortcuts

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