Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions azure-monitor-opentelemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
_INSTRUMENTATION_CONFIG_SUFFIX = "_config"
_SUPPORTED_INSTRUMENTED_LIBRARIES = (
"django",
"fastapi",
"flask",
"psycopg2",
"requests",
Expand Down
30 changes: 30 additions & 0 deletions azure-monitor-opentelemetry/samples/tracing/http_fastapi.py
Original file line number Diff line number Diff line change
@@ -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"}
3 changes: 2 additions & 1 deletion azure-monitor-opentelemetry/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@
"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",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -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__}"
)
7 changes: 4 additions & 3 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest
psycopg2
flask
django
requests
fastapi
flask
psycopg2
requests