How to push metrics to Opentelemetry using go-sdk
php Editor Xigua will introduce you how to use go-sdk to push indicators to Opentelemetry. Opentelemetry is an open source observation framework that helps developers collect and analyze application metric data. Using go-sdk, you can easily push custom metrics to Opentelemetry and visualize and monitor them through dashboards. This article will introduce you to the installation and configuration process of go-sdk in detail, as well as how to write code to push indicator data to Opentelemetry, and give some practical examples and best practices. Whether you are a novice or an experienced developer, you can get useful information and guidance from this article to help you better use go-sdk to push indicator data to Opentelemetry.
Question content
I tried to use go-sdk to push metrics to opentelemetry, but I didn't find any documentation about it. So far I've tried using this code but don't know what the next step is, to be honest I'm a bit confused with the provider and reader stuff, I'm new to monitoring
func main() { ctx := context.Background() res, err := resource.New(ctx, resource.WithAttributes(semconv.ServiceName("my-service"))) if err != nil { panic(err) } ctx, cancel := context.WithTimeout(ctx, time.Second) defer cancel() conn, err := grpc.DialContext(ctx, "localhost:4317", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) if err != nil { panic(err) } metricExporter, err := otlpmetricgrpc.New(ctx, otlpmetricgrpc.WithGRPCConn(conn)) if err != nil { panic(err) } exporter, err := prometheus.New() if err != nil { panic(err) } provider := metric.NewMeterProvider(metric.WithReader(exporter)) meter := provider.Meter("github.com/open-telemetry/opentelemetry-go/example/prometheus") counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter")) if err != nil { panic(err) } counter.Add(ctx, 5) reader := metric.NewPeriodicReader(metricExporter, metric.WithInterval(1*time.Second)) }
The source information I have so far is from the example here and the example here
Workaround
Firstly, it's worth noting that the OTel Go Metrics API and SDK Currently considered unstable. I'll try to focus my answer on higher-level items included in the stable OpenTelemetry metrics specification so that it doesn't become obsolete. Any go-specific content below is subject to change.
It looks like you are trying to set up two different types of exporters. The Prometheus exporter is scraped by Prometheus, and the otelmetricgrpc
exporter creates a connection to push metrics through OTLP to a sink such as the OpenTelemetry Collector. You may only need one or the other, not both. The first example you linked is really just for tracking, not metrics, but the principle is roughly the same.
The entry point for any metric in the OpenTelemetry SDK is the meter provider
. Instrument providers handle metric-related configuration, aggregation, and data export. This is also how users obtain meters
. Each code module usually has its own instrumentation. Create based on this instrumentation metrics and record data points based on these metrics. All indicator points are aggregated and flowed back through the metering provider.
In order to read metrics from a meter provider, you need some kind of metric reader
. If you are trying to push metrics using a protocol such as OTLP, you can use a tool like Periodic Export Metrics Reader, which periodically collects metrics from metering providers and exports them using an exporter.
If you are trying to use a pull-based metrics system (such as Prometheus), the exporter acts like a metrics reader and reads the metrics every time the metrics system requests the crawl endpoint. This is what is done in the second example you linked. serveMetrics
The function opens a web server that listens on port 2223 and handles requests to localhost:2223/metrics
. Each time a GET
request comes into this endpoint, aggregated metrics are configured based on the instrumentation provider and returned in the response body. This allows systems like Prometheus to periodically request metrics from your application.
The above is the detailed content of How to push metrics to Opentelemetry using go-sdk. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The Lantern Festival is coming soon. Ace Racing has specially prepared a Lantern Festival riddle guessing activity for everyone. If you guess the riddles and successfully answer 6 questions correctly, you can receive gold coin rewards. If you accumulate a certain number of riddles, you can also get generous rewards. Specific details Let’s take a look at the details of this event. Is Ace Racing Post-Holiday Syndrome: The real experienced drivers have already begun to prepare for the Lantern Festival. Hey, dear drivers, they all say that the Spring Festival is not the end until after the Lantern Festival. We welcome the lantern festival, eat glutinous rice balls, and set off fireworks...the Festival of Speed is everywhere In the festive and lively atmosphere of the festival, Xili has also prepared some interesting lantern riddles that "only real experienced drivers" can get for everyone to warm up in advance. Let's guess together~ (PS: Drivers can go to today's public account Tweet to see the answer!) How about it, riders?

Collapse Star Dome Railway Where Are You Going Mikhail achievement guide. With the update to version 2.2 of Honkai Dome Railway, there are a lot of new content in the game that can be experienced. I believe that many friends have encountered some difficulties when completing the achievement "Where Are You Going, Mikhail?" I don’t know how to complete it, so today I will take you through the detailed process. Guide to the Collapsed Star Railroad Where Are You Going Mikhail 1. When we inherited the capabilities of the Tongtun Pioneers and solved the crisis in Sinokonni, everything settled and we returned to the top of Flowing Dream Reef. The transfer point is the one marked in the picture below; 2. After reaching it, go straight forward, look at Mikhail again, and investigate the balcony in front of him; 3. After completing the investigation, you can obtain the achievement Mikhail

With the popularity of Douyin, the problems commonly faced by users are also gradually increasing. The most worrying one is the problem of Douyin's traffic limit. Douyin's traffic limit may lead to a significant reduction in the number of views, likes and comments on users' videos, thereby affecting users' income and exposure opportunities. 1. How to solve Douyin’s traffic limit? 1. Improve content quality The core competitiveness of Douyin lies in content. Only high-quality content can attract more users. Therefore, improving content quality is the key to solving Douyin’s current limiting problem. Creators need to focus on content innovation, attract users with unique perspectives and creativity, and at the same time ensure that the content is interesting, educational and practical. Only in this way can the user experience be continuously improved and user stickiness increased. 2. Adjust the release time. Douyin’s traffic distribution has a time pattern.

ELON peaked at $0.0000005196 in 2023 and has been declining ever since. Our Dogelon Mars price prediction estimates the price by the end of 2024 at $0.0000001409. According to our Dogelon Mars price prediction for 2025, ELON is trading at $0.0000004709.

The article brought to you today is about QQ mailbox software. Do you know how to apply for QQ backup mailbox with QQ mailbox? The following content brings you the method of applying for QQ backup mailbox with QQ mailbox. Let us take a look below. . After logging in to your QQ mailbox, you can look for an icon with a triangle logo on the homepage of your mailbox. If you can't find the icon, you can view detailed annotations on the image to help locate it. After finding it, click the 3-corner logo, and then click the Apply for Backup Email button. After clicking, we click the email account button in the upper right corner of the page that just came out. After clicking, we enter the new registration email name, password, mobile phone number and other operations and then click the registration button. After the registration is completed, we return to the email page just now and click on the box that just popped up to enter the account number.

On March 18, the dual-end interactive mobile game "Taris World" independently developed by Beijing Ledong Excellence and distributed by Tencent started its final test on the eve of the eve. "Taris World" has more or less features from occupation to gameplay. It pays tribute to the classics, and I believe that players who like MMO games can find a new world again. Looking back on the overseas testing in November last year, the super high game quality attracted a large number of overseas players and many MMORPG anchors to rush to play. After the final test was launched on the eve of the national server at 10 o'clock on March 18, a large number of players flocked to the game. In "Taris World", even if some players did not qualify for the test, tens of thousands of people lined up in just a few minutes. Nowadays, the popularity of the final test on the eve of the national server can be said to be even greater. (Picture source comes from the Internet) Since "

When using the Steam mobile token, I find that the token has disappeared. What should I do? If there is no token, the security verification of the Steam account cannot be performed. How do we retrieve the Steam mobile token? The editor below will teach you how to appeal for lost Steam mobile token. The appeal tutorial is as follows: 1. Enter the Steam customer service page steam customer service and select the option in the red box 2. Select the corresponding content according to your own situation. If your account has been stolen or your password has been lost, generally select the option in the first red box. 3. Select the option in the red box 4. Enter your account name (login ID, not personal nickname), bound email address, or bound mobile phone number, and then click

1. Open the WeChat app, find the transfer message that needs to be returned, and click to enter. 2. In the transfer details interface, find and click the [Return] option. 3. In the pop-up window, click the [Return] button to return the transferred money.
