Merge pull request #255 from lzchen/instr

This commit is contained in:
Leighton Chen 2023-03-07 12:58:38 -08:00 коммит произвёл GitHub
Родитель 9a3a8b6dc6 aa01eee5b0
Коммит 37910011df
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 62 добавлений и 4 удалений

Просмотреть файл

@ -6,6 +6,8 @@
([#253](https://github.com/microsoft/ApplicationInsights-Python/pull/253))
- Use entrypoints instead of importlib to load instrumentations
([#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

Просмотреть файл

@ -12,6 +12,7 @@ The following OpenTelemetry instrumentations come bundled in with the Azure moni
* [OpenTelemetry Requests Instrumentation][opentelemetry_instrumentation_requests]
* [OpenTelemetry Django Instrumentation][opentelemetry_instrumentation_django]
* [OpenTelemetry FastApi Instrumentation][opentelemetry_instrumentation_fastapi]
* [OpenTelemetry Flask Instrumentation][opentelemetry_instrumentation_flask]
* [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
[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_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_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

Просмотреть файл

@ -36,6 +36,7 @@ _logger = getLogger(__name__)
_INSTRUMENTATION_CONFIG_SUFFIX = "_config"
_SUPPORTED_INSTRUMENTED_LIBRARIES = (
"django",
"fastapi",
"flask",
"psycopg2",
"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",
"opentelemetry-instrumentation~=0.36b0",
"opentelemetry-instrumentation-django~=0.36b0",
"opentelemetry-instrumentation-requests~=0.36b0",
"opentelemetry-instrumentation-fastapi~=0.36b0",
"opentelemetry-instrumentation-flask~=0.36b0",
"opentelemetry-instrumentation-psycopg2~=0.36b0",
"opentelemetry-instrumentation-requests~=0.36b0",
"opentelemetry-api==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
psycopg2
flask
django
fastapi
flask
psycopg2
requests