Deep Desai
08/17/2023, 4:46 AMVishal Sharma
08/17/2023, 5:22 AMDeep Desai
08/17/2023, 6:13 AMmeter:=otel.Meter("queue")
counter,err:=meter.Int64Counter("adduser")
if err!=nil{
return
}
counter.Add(c.Request.Context(),1)
sample codeSrikanth Chekuri
08/17/2023, 8:57 AMstdout
exporter and confirm if the instrumentation is working?Deep Desai
08/17/2023, 8:58 AMSrikanth Chekuri
08/17/2023, 8:59 AMand all other thingsWhat are these all other things? Please use stdout exporter for metrics and see if the custom metrics is written to console.
Deep Desai
08/17/2023, 9:00 AMfunc 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
08/18/2023, 6:51 AMDeep Desai
08/21/2023, 5:03 AM