opencensus-python icon indicating copy to clipboard operation
opencensus-python copied to clipboard

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

Open JeremyVriens opened this issue 2 years ago • 1 comments

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.

JeremyVriens avatar Sep 12 '22 14:09 JeremyVriens

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.

lzchen avatar Sep 13 '22 16:09 lzchen