Hi, I am trying to send custom metrics using otel....
# general
d
Hi, I am trying to send custom metrics using otel. But I am unable to see them on the signoz dashboard. Do we have to do any configuration for custom metrics
v
@Srikanth Chekuri Can you please help here?
d
Copy code
meter:=otel.Meter("queue")
counter,err:=meter.Int64Counter("adduser")
if err!=nil{
   return
}
counter.Add(c.Request.Context(),1)
sample code
s
If you are not able to see they it’s most probably not received. Can you use
stdout
exporter and confirm if the instrumentation is working?
d
instrumentation specific to metrics?? As the trace and all other things are working
s
and all other things
What are these all other things? Please use stdout exporter for metrics and see if the custom metrics is written to console.
d
sure will check that, other things means traces and host metrics
will confirm after checking stdout exporter for metrics
@Srikanth Chekuri: I cant see it after enabling stdout
below is the init tracer function used
Copy code
func initTracer() func(context.Context) error {

   secureOption := otlptracegrpc.WithTLSCredentials(credentials.NewClientTLSFromCert(nil, ""))
   if len(insecure) > 0 {
      secureOption = otlptracegrpc.WithInsecure()
   }

   exporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
   if err != nil {
      log.Fatalf("failed to initialize stdout export pipeline: %v", err)
   }

   tracer, err := otlptrace.New(
      context.Background(),
      otlptracegrpc.NewClient(
         secureOption,
         otlptracegrpc.WithEndpoint(collectorURL),
      ),
   )

   if err != nil {
      log.Fatal(err)
   }
   resources, err := resource.New(
      context.Background(),
      resource.WithAttributes(
         attribute.String("service.name", serviceName),
         attribute.String("library.language", "go"),
      ),
   )
   if err != nil {
      log.Println("Could not set resources: ", err)
   }

   otel.SetTracerProvider(
      sdktrace.NewTracerProvider(
         sdktrace.WithSampler(sdktrace.AlwaysSample()),
         sdktrace.WithBatcher(tracer),
         sdktrace.WithBatcher(exporter),
         sdktrace.WithResource(resources),
      ),
   )

   return tracer.Shutdown
}
@Srikanth Chekuri: gentle reminder on this
s
You haven’t set up the metric exporter pipeline for otlp/stdout (the above one is a trace pipeline). Please do, and the metrics will show up.
d
Thanks was able to get the metrics