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?
OpenTelemetry is an open-source observability framework for distributed tracing (including logs and errors) and OpenTelemetry metrics.
Otel allows developers to collect and export telemetry data in a vendor agnostic way. With OpenTelemetry, you can instrument your application once and then add or change vendors without changing the instrumentation, for example, here is a list popular DataDog alternatives that support OpenTelemetry.
OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.
Beego instrumentation
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 example and the reference:
What is Uptrace?
Uptrace is a source-available APM 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 started 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: