Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.43k stars 2.74k forks source link

Azure Failures #34616

Open mike-england opened 5 months ago

mike-england commented 5 months ago

Describe the bug I'm worried I'm opening up an old 'bug': https://github.com/Azure/azure-sdk-for-python/issues/33741 but I'm still having problems with Failures being reported to Azure Application Insights. The opentelemtry-python-contrib project has updated to include support for Flask 3 (version 1.23.0/0.44b0) and I can confirm that it's working as expected. However, when I include OTEL_PYTHON_EXCLUDED_URLS to keep one of my endpoints from reporting, they're still showing up as a request and a failed one

To Reproduce Steps to reproduce the behavior: I'm going to include some sample code in a docker file that you can try:

app.py:

from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor()

import flask

app = flask.Flask(__name__)

@app.route("/")
def test():
    print('got one')
    return "Test flask request"

@app.route("/health")
def health():
    print('health endpoint')
    return "Health request"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8080)

Dockerfile:

FROM python:3.10-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

COPY requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
COPY . /app

RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

CMD ["python", "app.py"]

requirements.txt:

Flask==3.0.0
azure-monitor-opentelemetry==1.3.0

And to run it:

docker build -t azuretelemetry . && docker run --rm -p 8080:8080 -e APPLICATIONINSIGHTS_CONNECTION_STRING=$APPLICATIONINSIGHTS_CONNECTION_STRING -e OTEL_EXPERIMENTAL_RESOURCE_DETECTORS=$OTEL_EXPERIMENTAL_RESOURCE_DETECTORS -e OTEL_PYTHON_EXCLUDED_URLS=$OTEL_PYTHON_EXCLUDED_URLS azuretelemetry

Where OTEL_PYTHON_EXCLUDED_URLS="health,swagger.*"

Expected behavior Endpoint requests are ignored

Screenshots

Screenshot 2024-03-04 at 4 01 37 PM

Any suggestions? Is this a different project that would need to take care of this? Am I doing something wrong?

kashifkhan commented 5 months ago

Thank you for the feedback @mike-england . We will investigate and get back to you asap.

jeremydvoss commented 5 months ago

I'll be looking into this.

jeremydvoss commented 5 months ago

I've confirmed that the OTEL_PYTHON_EXCLUDED_URLS works as intended with full URLs, URL endings, and even wildcards. This is a question for the Flask instrumentation itself. So, I recommend creating an issue in the OTel contrib repo instead. But, let's see if we can solve it here. can you provide the full urls of the telemetry that you want to be filtered? could you also confirm that the environment variable is successfully being set in docker and visible from the app?

mike-england commented 5 months ago

Thanks for looking into this Jeremy. I can confirm the variables being set:

env

OTEL_PYTHON_EXCLUDED_URLS=health,swagger.* OTEL_EXPERIMENTAL_RESOURCE_DETECTORS=azure_app_service

I'm accessing my localhost endpoint: http://localhost:8080/health

I can also confirm that the requests are not showing under the operation name, they just show as these phantom "None" response codes.

Are you able to run the docker image and code I sent? Maybe there's something different about my azure app insights setup?

On Wed, Mar 6, 2024 at 3:02 PM Jeremy Voss @.***> wrote:

I've confirmed that the OTEL_PYTHON_EXCLUDED_URLS works as intended with full URLs, URL endings, and even wildcards. This is a question for the Flask instrumentation itself. So, I recommend creating an issue in the OTel contrib repo https://github.com/open-telemetry/opentelemetry-python-contrib/issues instead. But, let's see if we can solve it here. can you provide the full urls of the telemetry that you want to be filtered? could you also confirm that the environment variable is successfully being set in docker and visible from the app?

— Reply to this email directly, view it on GitHub https://github.com/Azure/azure-sdk-for-python/issues/34616#issuecomment-1982001778, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJIQJCU2AXXKWGSQZ76ICWDYW6N6TAVCNFSM6AAAAABEGEK3XOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBSGAYDCNZXHA . You are receiving this because you were mentioned.Message ID: @.***>

github-actions[bot] commented 3 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jeremydvoss @lzchen.