Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Support for Otel Metrics #141

Open
romerod opened this issue Jan 12, 2024 · 3 comments
Open

Question: Support for Otel Metrics #141

romerod opened this issue Jan 12, 2024 · 3 comments

Comments

@romerod
Copy link

romerod commented Jan 12, 2024

Thanks for this great project.

I wanted to ask whether OpenTelemetry Metrics are also supported or whether you have planned to add support for them?

@zanio
Copy link

zanio commented May 12, 2024

It would be great to a support for metrics and logs as well

@devurandom
Copy link

Something was started in this regard a year ago: #128

and logs as well

Log support is tracked in #142.

@golightlyb
Copy link

golightlyb commented Jun 2, 2024

I can't get any metrics to show up. Here's what I have so far. What am I doing wrong? Thanks

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package main

import (
	"context"
	"log"
	"time"

	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
	"go.opentelemetry.io/otel/sdk/metric"
	"go.opentelemetry.io/otel/sdk/resource"
	semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)

func main() {
	ctx := context.Background()
	exp, err := otlpmetrichttp.New(ctx,
		otlpmetrichttp.WithEndpoint("localhost:4318"),
		otlpmetrichttp.WithInsecure(),
	)
	if err != nil {
		panic(err)
	}

	res, err := resource.New(ctx,
		resource.WithSchemaURL(semconv.SchemaURL),
		resource.WithAttributes(
			semconv.ServiceName("runtime-instrumentation-example"),
		),
	)

	if err != nil {
		log.Fatalf("failed to initialize resource: %e", err)
	}

	meterProvider := metric.NewMeterProvider(
		metric.WithResource(res),
		metric.WithReader(
			metric.NewPeriodicReader(exp, metric.WithInterval(1*time.Second)),
		),
	)
	defer func() {
		if err := meterProvider.Shutdown(ctx); err != nil {
			panic(err)
		}
	}()

	m := meterProvider.Meter("mymeter")
	counter, err := m.Int64Counter("counter")
	if err != nil {
		panic(err)
	}

	otel.SetMeterProvider(meterProvider)

	f := func() {
		for {
			counter.Add(ctx, 1)
			time.Sleep(200 * time.Millisecond)
			// meterProvider.ForceFlush(ctx) // shouldn't need
		}
	}
	go f()

	<-ctx.Done()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants