Monitor Beego with OpenTelemetry Instrumentation

beego is an open-source, high-performance web framework for the Go programming language. It can be used to develop RESTful APIs, web apps and backend services.

This article will teach you how to monitor Beego performance using OpenTelemetry observability framework.

What is OpenTelemetry?

OpenTelemetryopen in new window is an open-source observability framework for distributed tracingopen in new window (including logs and errors) and metricsopen in new window.

Otel allows developers to collect and export telemetry data in a vendor agnostic way. With OpenTelemetry, you can instrumentopen in new window your application once and then add or change vendors without changing the instrumentation, for example, here is a list popular DataDog alternativesopen in new window that support OpenTelemetry.

OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.

Installation

To install Beego OpenTelemetry instrumentation:

go get go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego

Usage

You can instrument Beego by installing with OpenTelemetry middleware:

import (
	"github.com/astaxie/beego"
	"go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego"
)

mware := otelbeego.NewOTelBeegoMiddleWare("service-name")
beego.RunWithMiddleWares(":7777", mware)

Instrumenting templates rendering

To instrument templates rendering, disable autorender and use helpers from otelbeego package:

import "go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego"

beego.BConfig.WebConfig.AutoRender = false

err := otelbeego.Render(&c.Controller)

See the exampleopen in new window and the reference:

What is Uptrace?

Uptrace is an open source and blazingly fast distributed tracing tool powered by OpenTelemetry and ClickHouse. It allows you to identify and fix bugs in production faster knowing what conditions lead to which errors.

You can get startedopen in new window with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.

What's next?

Next, instrument more operations, for example, database queries, errors, and logs. You can also learn about OpenTelemetry Go Tracing API to create your own instrumentations.

Popular instrumentations:

Last Updated: