-
Notifications
You must be signed in to change notification settings - Fork 19
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
Comments
It would be great to a support for metrics and logs as well |
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
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?
The text was updated successfully, but these errors were encountered: