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

feat(instrumentation/asgi): add target to metrics #1323

Merged
merged 12 commits into from
Oct 22, 2022

Commits on Sep 10, 2022

  1. feat(instrumentation/asgi): add target to metrics

    This PR adds the target information for metrics reported by instrumentation/asgi.
    
    Unfortunately, there's no ASGI standard to reliably get this information, and I was only able to get it for FastAPI.
    
    I also tried to get the info with Sanic and Starlette (encode/starlette#685), but there's nothing in the scope allowing to recreate the route.
    
    Besides the included unit tests, the logic was tested using the following app:
    
    ```python
    import io
    import fastapi
    
    app = fastapi.FastAPI()
    
    def dump_scope(scope):
        b = io.StringIO()
        print(scope, file=b)
        return b.getvalue()
    
    @app.get("/test/{id}")
    def test(id: str, req: fastapi.Request):
        print(req.scope)
        return {"target": _collect_target_attribute(req.scope), "scope": dump_scope(req.scope)}
    
    sub_app = fastapi.FastAPI()
    
    @sub_app.get("/test/{id}")
    def sub_test(id: str, req: fastapi.Request):
        print(req.scope)
        return {"target": _collect_target_attribute(req.scope), "scope": dump_scope(req.scope)}
    
    app.mount("/sub", sub_app)
    ```
    
    Partially fixes open-telemetry#1116
    
    Note to reviewers: I tried to touch as less as possible, so that we don;t require a refactor before this change. However, we could consider changing `collect_request_attributes` so that it returns both a trace attributes and a metrics attributes.
    Wihout that change we cannot add the `HTTP_TARGET` attribute to the list of metric atttributes, because it will be present but with high cardinality.
    sk- committed Sep 10, 2022
    Configuration menu
    Copy the full SHA
    086213c View commit details
    Browse the repository at this point in the history
  2. Add changelog

    sk- committed Sep 10, 2022
    Configuration menu
    Copy the full SHA
    c411055 View commit details
    Browse the repository at this point in the history

Commits on Sep 15, 2022

  1. Configuration menu
    Copy the full SHA
    0770591 View commit details
    Browse the repository at this point in the history

Commits on Sep 20, 2022

  1. Configuration menu
    Copy the full SHA
    96316a6 View commit details
    Browse the repository at this point in the history

Commits on Oct 9, 2022

  1. Update instrumentation/opentelemetry-instrumentation-asgi/tests/test_…

    …asgi_middleware.py
    
    Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
    sk- and srikanthccv committed Oct 9, 2022
    Configuration menu
    Copy the full SHA
    6bc84c9 View commit details
    Browse the repository at this point in the history
  2. Update instrumentation/opentelemetry-instrumentation-asgi/src/opentel…

    …emetry/instrumentation/asgi/__init__.py
    
    Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
    sk- and srikanthccv committed Oct 9, 2022
    Configuration menu
    Copy the full SHA
    97b7d0e View commit details
    Browse the repository at this point in the history

Commits on Oct 16, 2022

  1. Configuration menu
    Copy the full SHA
    ee55441 View commit details
    Browse the repository at this point in the history

Commits on Oct 21, 2022

  1. Configuration menu
    Copy the full SHA
    8462428 View commit details
    Browse the repository at this point in the history
  2. format code

    sk- committed Oct 21, 2022
    Configuration menu
    Copy the full SHA
    e3f8de5 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    8b313b3 View commit details
    Browse the repository at this point in the history

Commits on Oct 22, 2022

  1. fix pylint

    sk- committed Oct 22, 2022
    Configuration menu
    Copy the full SHA
    feb46b1 View commit details
    Browse the repository at this point in the history
  2. format

    sk- committed Oct 22, 2022
    Configuration menu
    Copy the full SHA
    96782ea View commit details
    Browse the repository at this point in the history