mojito_extension_tracing

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: MIT Imports: 12 Imported by: 0

README

Tracing for Mojito

PRs Welcome

Tracing for Mojito provides easy tracking and configuration of OpenTracing Provider.

SonarCloud Report


Supported Exporter

Documentation

Enabling Tracing

Enabling Open-Telemetry Tracing is as simple as registering a middleware on your router.

import (
    tracing_extension "github.com/dragse/mojito-extension-tracing"
    "github.com/go-mojito/mojito"
)

func init() {
    tracing_extension.Configure(
        tracing_extension.JAEGER, // Use JAEGER as Provider
        "mojito-service", map[string]any{
            "environment": "productive", // Custom Tags for all Traces
        },
        mojito_extension_tracing.ExporterConfig{
            ProviderURL: "http://localhost:14268/api/traces", // Jaeger Endpoint
    })
}

func main() {
    mojito.WithMiddleware(tracing_extension.Middleware)
}

Custom more detailed Tracing

For more detailed Information you can trace every single function which is dynamically connected to the method Tracing

import (
	tracing_extension "github.com/dragse/mojito-extension-tracing"
	"github.com/go-mojito/mojito"
	"go.opentelemetry.io/otel/attribute"
	"time"
)
func HomeHandler(ctx mojito.RendererContext, cache mojito.Cache) {
	span := tracing_extension.StartTracing(ctx, "Home Handler")
	defer span.End()

	span.AddEvent("Load Cache")
	var lastVisit time.Time
	cache.GetOrDefault("lastVisit", &lastVisit, time.Now())
	span.SetAttributes(attribute.String("lastVisit", lastVisit.String()))
	span.AddEvent("Set new lastVisit-Variable")
	cache.Set("lastVisit", time.Now())

	span.AddEvent("Set Render-Information")
	ctx.ViewBag().Set("lastVisit", lastVisit)
	ctx.MustView("home")
}

Documentation

Index

Constants

View Source
const METADATA_NAME = "open-telemetry_ctx"

Variables

This section is empty.

Functions

func Configure

func Configure(exporterType Exporter, name string, env map[string]any, config ExporterConfig) error

func ConfigureWithCustomTracerProvider

func ConfigureWithCustomTracerProvider(tracer *tracesdk.TracerProvider) error

func Middleware

func Middleware(ctx mojito.Context, next func() error) error

func StartTracing

func StartTracing(mojitoCtx mojito.Context, name string) trace.Span

Types

type Exporter

type Exporter string
const (
	JAEGER         Exporter = "jaeger"
	PROMETHEUS     Exporter = "prometheus"
	OTEL_COLLECTOR Exporter = "otel-collector"
	OPENCENSUS     Exporter = "opencensus"
)

type ExporterConfig

type ExporterConfig struct {
	ProviderURL string
}

Jump to

Keyboard shortcuts

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