File tree Expand file tree Collapse file tree 5 files changed +56
-1
lines changed
azure-monitor-opentelemetry
azure/monitor/opentelemetry Expand file tree Collapse file tree 5 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ The following OpenTelemetry instrumentations come bundled in with the Azure moni
12
12
13
13
* [ OpenTelemetry Requests Instrumentation] [ opentelemetry_instrumentation_requests ]
14
14
* [ OpenTelemetry Django Instrumentation] [ opentelemetry_instrumentation_django ]
15
+ * [ OpenTelemetry FastApi Instrumentation] [ opentelemetry_instrumentation_fastapi ]
15
16
* [ OpenTelemetry Flask Instrumentation] [ opentelemetry_instrumentation_flask ]
16
17
* [ OpenTelemetry Psycopg2 Instrumentation] [ opentelemetry_instrumentation_psycopg2 ]
17
18
@@ -118,6 +119,7 @@ Samples are available [here][samples] to demonstrate how to utilize the above co
118
119
[ ot_sdk_python_view_examples ] : https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples/metrics/views
119
120
[ opentelemetry_instrumentation_requests ] : https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-requests
120
121
[ opentelemetry_instrumentation_django ] : https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-django
122
+ [ opentelemetry_instrumentation_fastapi ] : https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-fastapi
121
123
[ opentelemetry_instrumentation_flask ] : https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-flask
122
124
[ opentelemetry_instrumentation_psycopg2 ] : https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-psycopg2
123
125
[ opentelemetry_spec_resource ] : https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-sdk
Original file line number Diff line number Diff line change 36
36
_INSTRUMENTATION_CONFIG_SUFFIX = "_config"
37
37
_SUPPORTED_INSTRUMENTED_LIBRARIES = (
38
38
"django" ,
39
+ "fastapi" ,
39
40
"flask" ,
40
41
"psycopg2" ,
41
42
"requests" ,
Original file line number Diff line number Diff line change
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ import fastapi
7
+ from azure .monitor .opentelemetry import configure_azure_monitor
8
+
9
+ # Configure Azure monitor collection telemetry pipeline
10
+ configure_azure_monitor (
11
+ connection_string = "<your-connection-string>" ,
12
+ disable_logging = True ,
13
+ disable_metrics = True ,
14
+ instrumentations = ["fastapi" ],
15
+ fastapi_config = {"excluded_urls" : "http://127.0.0.1:8000/exclude" },
16
+ tracing_export_interval_millis = 15000 ,
17
+ )
18
+
19
+ app = fastapi .FastAPI ()
20
+
21
+ # Requests made to fastapi endpoints will be automatically captured
22
+ @app .get ("/" )
23
+ async def root ():
24
+ return {"message" : "Hello World" }
25
+
26
+
27
+ # Telemetry from this endpoint will not be captured due to excluded_urls config above
28
+ @app .get ("/exclude" )
29
+ async def root ():
30
+ return {"message" : "Telemetry was not captured" }
Original file line number Diff line number Diff line change 87
87
"azure-monitor-opentelemetry-exporter>=1.0.0b12" ,
88
88
"opentelemetry-instrumentation~=0.36b0" ,
89
89
"opentelemetry-instrumentation-django~=0.36b0" ,
90
- "opentelemetry-instrumentation-requests ~=0.36b0" ,
90
+ "opentelemetry-instrumentation-fastapi ~=0.36b0" ,
91
91
"opentelemetry-instrumentation-flask~=0.36b0" ,
92
92
"opentelemetry-instrumentation-psycopg2~=0.36b0" ,
93
+ "opentelemetry-instrumentation-requests~=0.36b0" ,
93
94
"opentelemetry-api==1.15.0" ,
94
95
"opentelemetry-sdk==1.15.0" ,
95
96
],
Original file line number Diff line number Diff line change
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+
7
+ import unittest
8
+
9
+ from opentelemetry .instrumentation .fastapi import FastAPIInstrumentor
10
+
11
+
12
+ class TestFastApiInstrumentation (unittest .TestCase ):
13
+ def test_instrument (self ):
14
+ excluded_urls = "client/.*/info,healthcheck"
15
+ try :
16
+ FastAPIInstrumentor ().instrument (excluded_urls = excluded_urls )
17
+ except Exception as ex : # pylint: disable=broad-except
18
+ print (ex )
19
+ self .fail (
20
+ f"Unexpected exception raised when instrumenting { FastAPIInstrumentor .__name__ } "
21
+ )
You can’t perform that action at this time.
0 commit comments