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

Otelhttp metrics are not exporter to prometheus with meter option #5964

Open
kirill-lokhmatov opened this issue Jul 31, 2024 · 1 comment
Open
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelhttp invalid This doesn't seem right response needed Waiting on user input before progress can be made

Comments

@kirill-lokhmatov
Copy link

kirill-lokhmatov commented Jul 31, 2024

Description

Environment

  • OS: linux
  • Architecture: x64
  • Go Version: 1.21
  • otelhttp version: v0.52.0

Steps To Reproduce

`

   prometheusExporter, err := prometheus.New(
	prometheus.WithoutTargetInfo(),
	prometheus.WithoutScopeInfo())
if err != nil {
	return nil, err
}
provider := metric.NewMeterProvider(
	metric.WithReader(prometheusExporter),
)
loggedHttpTransport := transport.NewLoggedHttpTransport(logger)
client := &http.Client{
	Transport: otelhttp.NewTransport(otelhttp.WithMeterProvider(provider))}```

No metrics in prom (i am doing the same when working with otelsql and see the metrics)

Expected behavior

Http client metrics are exported to prometheus (like in otelsql)

@kirill-lokhmatov kirill-lokhmatov added area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelhttp labels Jul 31, 2024
@kirill-lokhmatov kirill-lokhmatov changed the title Otelhhttp metrics are not exporter to prometheus with meter option Otelhttp metrics are not exporter to prometheus with meter option Jul 31, 2024
@dmathieu
Copy link
Member

Could you provide us with actually runnable steps to reproduce?
I have tried reproducing with an adaptation from the prometheus example, and I am properly getting metrics.

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

package main

import (
	"io"
	"log"
	"net/http"

	"github.com/prometheus/client_golang/prometheus/promhttp"

	"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
	"go.opentelemetry.io/otel/exporters/prometheus"
	"go.opentelemetry.io/otel/sdk/metric"
)

func main() {
	exporter, err := prometheus.New()
	if err != nil {
		log.Fatal(err)
	}
	provider := metric.NewMeterProvider(metric.WithReader(exporter))

	helloHandler := func(w http.ResponseWriter, req *http.Request) {
		_, _ = io.WriteString(w, "Hello, world!\n")
	}

	otelHandler := otelhttp.NewHandler(
		http.HandlerFunc(helloHandler),
		"Hello",
		otelhttp.WithMeterProvider(provider),
	)

	http.Handle("/metrics", promhttp.Handler())
	http.Handle("/hello", otelHandler)
	err = http.ListenAndServe(":7777", nil)
	if err != nil {
		log.Fatal(err)
	}
}

@MrAlias MrAlias added invalid This doesn't seem right response needed Waiting on user input before progress can be made labels Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelhttp invalid This doesn't seem right response needed Waiting on user input before progress can be made
Projects
None yet
Development

No branches or pull requests

3 participants