Merge pull request #255 from lzchen/instr
This commit is contained in:
Коммит
37910011df
|
@ -6,6 +6,8 @@
|
||||||
([#253](https://github.com/microsoft/ApplicationInsights-Python/pull/253))
|
([#253](https://github.com/microsoft/ApplicationInsights-Python/pull/253))
|
||||||
- Use entrypoints instead of importlib to load instrumentations
|
- Use entrypoints instead of importlib to load instrumentations
|
||||||
([#254](https://github.com/microsoft/ApplicationInsights-Python/pull/254))
|
([#254](https://github.com/microsoft/ApplicationInsights-Python/pull/254))
|
||||||
|
- Add support for FastAPI instrumentation
|
||||||
|
([#255](https://github.com/microsoft/ApplicationInsights-Python/pull/255))
|
||||||
|
|
||||||
## [1.0.0b10](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b10) - 2023-02-23
|
## [1.0.0b10](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b10) - 2023-02-23
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ The following OpenTelemetry instrumentations come bundled in with the Azure moni
|
||||||
|
|
||||||
* [OpenTelemetry Requests Instrumentation][opentelemetry_instrumentation_requests]
|
* [OpenTelemetry Requests Instrumentation][opentelemetry_instrumentation_requests]
|
||||||
* [OpenTelemetry Django Instrumentation][opentelemetry_instrumentation_django]
|
* [OpenTelemetry Django Instrumentation][opentelemetry_instrumentation_django]
|
||||||
|
* [OpenTelemetry FastApi Instrumentation][opentelemetry_instrumentation_fastapi]
|
||||||
* [OpenTelemetry Flask Instrumentation][opentelemetry_instrumentation_flask]
|
* [OpenTelemetry Flask Instrumentation][opentelemetry_instrumentation_flask]
|
||||||
* [OpenTelemetry Psycopg2 Instrumentation][opentelemetry_instrumentation_psycopg2]
|
* [OpenTelemetry Psycopg2 Instrumentation][opentelemetry_instrumentation_psycopg2]
|
||||||
|
|
||||||
|
@ -118,6 +119,7 @@ Samples are available [here][samples] to demonstrate how to utilize the above co
|
||||||
[ot_sdk_python_view_examples]: https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples/metrics/views
|
[ot_sdk_python_view_examples]: https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples/metrics/views
|
||||||
[opentelemetry_instrumentation_requests]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-requests
|
[opentelemetry_instrumentation_requests]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-requests
|
||||||
[opentelemetry_instrumentation_django]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-django
|
[opentelemetry_instrumentation_django]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-django
|
||||||
|
[opentelemetry_instrumentation_fastapi]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-fastapi
|
||||||
[opentelemetry_instrumentation_flask]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-flask
|
[opentelemetry_instrumentation_flask]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-flask
|
||||||
[opentelemetry_instrumentation_psycopg2]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-psycopg2
|
[opentelemetry_instrumentation_psycopg2]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-psycopg2
|
||||||
[opentelemetry_spec_resource]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-sdk
|
[opentelemetry_spec_resource]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-sdk
|
||||||
|
|
|
@ -36,6 +36,7 @@ _logger = getLogger(__name__)
|
||||||
_INSTRUMENTATION_CONFIG_SUFFIX = "_config"
|
_INSTRUMENTATION_CONFIG_SUFFIX = "_config"
|
||||||
_SUPPORTED_INSTRUMENTED_LIBRARIES = (
|
_SUPPORTED_INSTRUMENTED_LIBRARIES = (
|
||||||
"django",
|
"django",
|
||||||
|
"fastapi",
|
||||||
"flask",
|
"flask",
|
||||||
"psycopg2",
|
"psycopg2",
|
||||||
"requests",
|
"requests",
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
# Licensed under the MIT License. See License in the project root for
|
||||||
|
# license information.
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
import fastapi
|
||||||
|
from azure.monitor.opentelemetry import configure_azure_monitor
|
||||||
|
|
||||||
|
# Configure Azure monitor collection telemetry pipeline
|
||||||
|
configure_azure_monitor(
|
||||||
|
connection_string="<your-connection-string>",
|
||||||
|
disable_logging=True,
|
||||||
|
disable_metrics=True,
|
||||||
|
fastapi_config={"excluded_urls": "http://127.0.0.1:8000/exclude"},
|
||||||
|
tracing_export_interval_millis=15000,
|
||||||
|
)
|
||||||
|
|
||||||
|
app = fastapi.FastAPI()
|
||||||
|
|
||||||
|
|
||||||
|
# Requests made to fastapi endpoints will be automatically captured
|
||||||
|
@app.get("/")
|
||||||
|
async def root():
|
||||||
|
return {"message": "Hello World"}
|
||||||
|
|
||||||
|
|
||||||
|
# Telemetry from this endpoint will not be captured due to excluded_urls config above
|
||||||
|
@app.get("/exclude")
|
||||||
|
async def root():
|
||||||
|
return {"message": "Telemetry was not captured"}
|
|
@ -87,9 +87,10 @@ setup(
|
||||||
"azure-monitor-opentelemetry-exporter>=1.0.0b12",
|
"azure-monitor-opentelemetry-exporter>=1.0.0b12",
|
||||||
"opentelemetry-instrumentation~=0.36b0",
|
"opentelemetry-instrumentation~=0.36b0",
|
||||||
"opentelemetry-instrumentation-django~=0.36b0",
|
"opentelemetry-instrumentation-django~=0.36b0",
|
||||||
"opentelemetry-instrumentation-requests~=0.36b0",
|
"opentelemetry-instrumentation-fastapi~=0.36b0",
|
||||||
"opentelemetry-instrumentation-flask~=0.36b0",
|
"opentelemetry-instrumentation-flask~=0.36b0",
|
||||||
"opentelemetry-instrumentation-psycopg2~=0.36b0",
|
"opentelemetry-instrumentation-psycopg2~=0.36b0",
|
||||||
|
"opentelemetry-instrumentation-requests~=0.36b0",
|
||||||
"opentelemetry-api==1.15.0",
|
"opentelemetry-api==1.15.0",
|
||||||
"opentelemetry-sdk==1.15.0",
|
"opentelemetry-sdk==1.15.0",
|
||||||
],
|
],
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# -------------------------------------------------------------------------
|
||||||
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
# Licensed under the MIT License. See License in the project root for
|
||||||
|
# license information.
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
||||||
|
|
||||||
|
|
||||||
|
class TestFastApiInstrumentation(unittest.TestCase):
|
||||||
|
def test_instrument(self):
|
||||||
|
excluded_urls = "client/.*/info,healthcheck"
|
||||||
|
try:
|
||||||
|
FastAPIInstrumentor().instrument(excluded_urls=excluded_urls)
|
||||||
|
except Exception as ex: # pylint: disable=broad-except
|
||||||
|
print(ex)
|
||||||
|
self.fail(
|
||||||
|
f"Unexpected exception raised when instrumenting {FastAPIInstrumentor.__name__}"
|
||||||
|
)
|
|
@ -1,5 +1,6 @@
|
||||||
pytest
|
pytest
|
||||||
psycopg2
|
|
||||||
flask
|
|
||||||
django
|
django
|
||||||
requests
|
fastapi
|
||||||
|
flask
|
||||||
|
psycopg2
|
||||||
|
requests
|
||||||
|
|
Загрузка…
Ссылка в новой задаче