DEV Community

Cover image for OpenTelemetry Go Ent monitoring [otelent]
Alexandr Bandurchin for Uptrace

Posted on • Originally published at uptrace.dev

OpenTelemetry Go Ent monitoring [otelent]

Ent is a simple, yet powerful ORM for modeling and querying data. It can generate Go code from an Ent schema for any database.

This article will teach you how to monitor Ent performance using OpenTelemetry Ent instrumentation.

What is OpenTelemetry?

OpenTelemetry is an open-source observability framework that aims to standardize and simplify the collection, processing, and export of telemetry data from applications and systems.

OpenTelemetry supports multiple programming languages and platforms, making it suitable for a wide range of applications and environments.

OpenTelemetry enables developers to instrument their code and collect telemetry data, which can then be exported to various OpenTelemetry backends or observability platforms for analysis and visualization. The OpenTelemetry architecture provides a comprehensive framework with APIs, SDKs, and instrumentation libraries that integrate seamlessly with various application frameworks.

Go Ent instrumentation

Because Ent works on top of database/sql, you can use otelsql instrumentation with Ent:

go get github.com/uptrace/opentelemetry-go-extra/otelsql
Enter fullscreen mode Exit fullscreen mode

Usage

To instrument Ent database client, use OpenTelemetry database/sql instrumentation to patch the database driver you are using.

Example:

- client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
- if err != nil {
-   log.Fatalf("failed opening connection to sqlite: %v", err)
- }
+ import (
+   "github.com/uptrace/opentelemetry-go-extra/otelsql"
+   semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
+ )

+ db, err := otelsql.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1",
+   otelsql.WithAttributes(semconv.DBSystemSqlite),
+   otelsql.WithDBName("mydb"))
+ if err != nil {
+   panic(err)
+ }
+
+ drv := entsql.OpenDB(dialect.SQLite, db)
+ client := ent.NewClient(ent.Driver(drv))
Enter fullscreen mode Exit fullscreen mode

What is Uptrace?

Uptrace is a DataDog alternative that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues. For APM capabilities, see the OpenTelemetry Go guide and compare with top APM tools.

Uptrace Overview

Uptrace comes with an intuitive query builder, rich dashboards, alerting rules with 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 demo (no login required) or running it locally with Docker. The source code is available on GitHub.

What's next?

Ent instrumentation enables you to trace database schema operations and query execution with OpenTelemetry. For alternative ORMs, explore GORM, or for direct SQL monitoring, see database/sql instrumentation.

Top comments (0)