Skip to content

Conversation

emdneto
Copy link
Member

@emdneto emdneto commented Jun 24, 2024

Description

Part of this #2453 and based on #2002

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Sample below

import os
import httpx
import asyncio
import logging

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
from opentelemetry.sdk.trace.export import (
    BatchSpanProcessor,
    ConsoleSpanExporter,
)
# Specify "http", "http/dup" or ""
os.environ["OTEL_SEMCONV_STABILITY_OPT_IN"] = "http/dup"
logging.basicConfig(level=logging.DEBUG)

HTTPXClientInstrumentor().instrument()

provider = TracerProvider()
processor = BatchSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
tracer = trace.get_tracer("my.tracer.name")

def sync_request():
    with httpx.Client() as client:
        response = client.get("https://example.com", timeout=1)
        logging.info(f"Sync response status: {response.status_code}")

async def async_request():
    async with httpx.AsyncClient() as client:
        response = await client.get("https://example.com", timeout=1)
        logging.info(f"Async response status: {response.status_code}")

async def main():
    await async_request()

sync_request()
asyncio.run(main())

HTTPXClientInstrumentor().uninstrument()

with httpx.Client() as client:
        HTTPXClientInstrumentor.instrument_client(client)
        response = client.get("https://example.com")

Old semconv with envvar set to "default" or "":

    "status": {
        "status_code": "UNSET"
    },
    "attributes": {
        "http.method": "GET",
        "http.url": "https://example.com/",
        "http.status_code": 200
    },

New semconv with envvar set to "http" exception, error, and ok:

    "status": {
        "status_code": "ERROR",
        "description": "ConnectTimeout: timed out"
    },
    "attributes": {
        "http.request.method": "GET",
        "url.full": "https://example.com:8443/",
        "server.address": "example.com",
        "network.peer.address": "example.com",
        "server.port": 8443,
        "network.peer.port": 8443,
        "error.type": "ConnectTimeout"
    },
    "status": {
        "status_code": "ERROR"
    },
    "attributes": {
        "http.request.method": "GET",
        "url.full": "https://example.com/ok",
        "server.address": "example.com",
        "network.peer.address": "example.com",
        "http.response.status_code": 404,
        "error.type": "404",
        "network.protocol.version": "1.1"
    },
    "status": {
        "status_code": "UNSET"
    },
    "attributes": {
        "http.request.method": "GET",
        "url.full": "https://example.com/",
        "server.address": "example.com",
        "network.peer.address": "example.com",
        "http.response.status_code": 200,
        "network.protocol.version": "1.1"
    },

Both semconv with envvar set to "http/dup":

    "name": "GET",
    "kind": "SpanKind.CLIENT",
    "status": {
        "status_code": "UNSET"
    },
    "attributes": {
        "http.method": "GET",
        "http.request.method": "GET",
        "http.url": "https://example.com/",
        "url.full": "https://example.com/",
        "http.host": "example.com",
        "server.address": "example.com",
        "network.peer.address": "example.com",
        "http.status_code": 200,
        "http.response.status_code": 200,
        "http.flavor": "1.1",
        "network.protocol.version": "1.1"
    },

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@emdneto emdneto requested a review from a team June 28, 2024 17:19
@emdneto emdneto force-pushed the httpx-semconv-migration branch from 603bc46 to 409897f Compare June 28, 2024 17:32
@emdneto emdneto requested review from lzchen and xrmx July 2, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants