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

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

Open
JeremyVriens opened this issue Sep 12, 2022 · 1 comment
Labels
azure Microsoft Azure bug

Comments

@JeremyVriens
Copy link
Contributor

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.

@lzchen
Copy link
Contributor

lzchen commented Sep 13, 2022

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 lzchen added the azure Microsoft Azure label Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
azure Microsoft Azure bug
Projects
None yet
2 participants