open-telemetry / open-telemetry/opentelemetry-python-contrib

Incorrect warning log with multiple http clients - "will cause conflicting metrics identities"

Open
#3,895 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe your environment

OS: MacOS
Python version: 3.13.5
Package version: 0.59b0

What happened?

I wanted to customize the bucket configuration for all http.client.request.duration. But in doing so, I get a WARNING log that looks like this:

2025-10-23 21:03:14.948 | WARNING  | opentelemetry.sdk.metrics._internal.metric_reader_storage:_handle_view_instrument_match:280 - Views <opentelemetry.sdk.metrics._internal.view.View object at 0x7fa931864d60> and <opentelemetry.sdk.metrics._internal.view.View object at 0x7fa931864d60> will cause conflicting metrics identities

Note that this compares the exact same view object (same memory addresses). This appears to happen in scenarios where multiple http clients are used, such as requests and httpx

Steps to Reproduce
  1. Use the opt-in semantic conventions (http)
  2. Initialize metrics with a View for http.client.request.duration with custom buckets
  3. Instrument both httpx and requests
  4. Call httpx and requests, the 2nd call will emit this warning

Here's a standalone Python script, just run as-is:

import logging.config
import os
from datetime import timedelta

from opentelemetry import metrics

logging.config.dictConfig(
    {
        "version": 1,
        "handlers": {
            "stderr": {
                "class": "logging.StreamHandler",
                "stream": "ext://sys.stderr",
            }
        },
        "root": {"level": "INFO", "handlers": ["stderr"]},
    }
)
from opentelemetry.exporter.prometheus import PrometheusMetricReader
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.view import ExplicitBucketHistogramAggregation, View

provider = MeterProvider(
    metric_readers=[PrometheusMetricReader()],
    views=[
        View(
            instrument_name="http.client.request.duration",
            aggregation=ExplicitBucketHistogramAggregation(
                boundaries=tuple(
                    bucket.total_seconds()
                    for bucket in (
                        timedelta(milliseconds=100),
                        timedelta(milliseconds=250),
                        timedelta(milliseconds=500),
                        timedelta(seconds=1),
                        timedelta(seconds=5),
                        timedelta(seconds=15),
                    )
                ),
            ),
        )
    ],
)

metrics.set_meter_provider(provider)

os.environ["OTEL_SEMCONV_STABILITY_OPT_IN"] = (
    "http"  # Opt-in to the latest semconv standards, see https://github.com/open-telemetry/semantic-conventions/blob/903e839a263e32e947314b94af7f8fa9d6739058/docs/http/http-spans.md
)

HTTPXClientInstrumentor().instrument()
RequestsInstrumentor().instrument()

import httpx
import requests

requests.get("https://google.com", timeout=5)
httpx.get("https://google.com")

This will be the output to stderr:

Views <opentelemetry.sdk.metrics._internal.view.View object at 0x10715c1f0> and <opentelemetry.sdk.metrics._internal.view.View object at 0x10715c1f0> will cause conflicting metrics identities
HTTP Request: GET https://google.com "HTTP/1.1 301 Moved Permanently"
Expected Result

No warning emitted

Actual Result

Views <opentelemetry.sdk.metrics._internal.view.View object at 0x10715c1f0> and <opentelemetry.sdk.metrics._internal.view.View object at 0x10715c1f0> will cause conflicting metrics identities

Additional context

Maybe the fix is to add another case to see if the View objects being compared are exactly the same?

Would you like to implement a fix?

None

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at opentelemetry.sdk.metrics._internal.metric_reader_storage._handle_view_instrument_match and reproduce the warning with the provided script, using both the httpx and requests instrumentations. Check how the same View is handled when both clients record http.client.request.duration. Done means the reproduction emits no conflicting-metrics-identities warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.