Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Unexpected response code for Azure trace when using the HTTPStatus from the http stdlib #1163

Open

Description

@JeremyVriens

Describe your environment.
I'm using the OpenCensus Azure extension (opencensus-ext-azure==1.1.7) with Python 3.10.7.

Steps to reproduce.
Create a trace with the AzureExporter (as describe in here: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-azure#trace) and add the http status code as an attribute:

import http
from opencensus.trace.attributes_helper import COMMON_ATTRIBUTES

span.add_attribute(
    attribute_key=COMMON_ATTRIBUTES["HTTP_STATUS_CODE"],
    attribute_value=http.HTTPStatus.OK,
)

What is the expected behavior?
The response code in Azure shows a string HTTPStatus.OK.

What is the actual behavior?
The response code in Azure should show 200.

Additional context.
It goes wrong because the attribute value is an IntEnum. The status_code is casted to a string (https://github.com/census-instrumentation/opencensus-python/blob/master/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py#L140-L143 and https://github.com/census-instrumentation/opencensus-python/blob/master/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py#L179-L180). The comparision with the integers goes okay, but the casting to a string gives an unexpected result here.

Activity

  1. lzchen commented on Sep 13, 2022

    @lzchen
    Contributor

    The exporter expects an int value for HTTP_STATUS_CODE attribute, not an IntEnum. http.HTTPStatus.OK.value would be the preferred attribute value. The casting to str is for backend purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions