Monitor Beego with OpenTelemetry Instrumentation

OpenTelemetry Beego is an OpenTelemetry instrumentation for the Beego web framework, a popular open-source web framework for building web applications in Go.

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

What is Beego?

Beego is an open source web framework written in Go. It follows the Model-View-Controller (MVC) architectural pattern and provides a set of tools and features for rapidly building web applications and APIs. Beego focuses on simplicity, scalability, and modularity.

What is OpenTelemetry?

OpenTelemetryopen in new window defines APIs and protocols for collecting telemetry data such as metrics, traces, and logs, and provides a variety of libraries, agents, and integrations for popular programming languages and technologies.

OpenTelemetry is an open and vendor-neutral solution that provides a unified approach to observability, making it easier for organizations to manage the complexity of their cloud-native infrastructure. It enables organizations to collect telemetry from their applications and send it to a variety of of distributed tracing toolsopen in new window.

OpenTelemetry Beego

OpenTelemetry Beego allows developers to monitor the performance and behavior of their Beego applications, providing insights into application usage patterns, resource utilization, and performance bottlenecks.

To install otelbeego OpenTelemetry instrumentation:

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

Usage

To integrate OpenTelemetry with Beego, you can use the OpenTelemetry Go SDK to instrument your Beego application and collect telemetry data. By adding OpenTelemetry instrumentation to your application, you can collect distributed traces, metrics, and logs, adding observability to your Beego-based web application.

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 APMopen in new window for OpenTelemetry that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.

Uptrace Overview

Uptrace comes with an intuitive query builder, rich dashboards, alerting rules, notifications, and integrations for most languages and frameworks.

Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.

In just a few minutes, you can try Uptrace by visiting the cloud demoopen in new window (no login required) or running it locally with Dockeropen in new window. The source code is available on GitHubopen in new window.

What's next?

By using OpenTelemetry with Beego, you can leverage the capabilities of both frameworks to build scalable, observable, and high-performance web applications.

Next, instrument more operations to get a more detailed picture. Try to prioritize network calls, disk operations, database queries, error and logs.

You can also create your own instrumentations using OpenTelemetry Go Tracing APIopen in new window.

Last Updated: