Skip to content

dragse/mojito-extension-tracing

Repository files navigation

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")
}

About

Mojito Extension for Tracing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages