Skip to content

Commit 992d12d

Browse files
authored
Merge pull request #280 from jeremydvoss/vendor-instrumentations
Vendor instrumentations
2 parents 7bca8a1 + 1e84508 commit 992d12d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+5809
-50
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ exclude =
2525
target
2626
__pycache__
2727
*/build/lib/*
28+
azure-monitor-opentelemetry/azure/monitor/opentelemetry/_vendor/*

.isort.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ profile=black
1414
; docs: https://github.com/timothycrosley/isort#multi-line-output-modes
1515
multi_line_output=3
1616
skip=target
17-
skip_glob=**/gen/*,.venv*/*,venv*/*,**/proto/*,.tox/*
17+
skip_glob=**/gen/*,.venv*/*,venv*/*,**/proto/*,.tox/*, azure-monitor-opentelemetry/azure/monitor/opentelemetry/_vendor/*
1818
known_third_party=opentelemetry,psutil,pytest,redis,redis_opentracing

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Vendor Instrumentations
6+
([#280](https://github.com/microsoft/ApplicationInsights-Python/pull/280))
57
- Update samples
68
([#281](https://github.com/microsoft/ApplicationInsights-Python/pull/281))
79
- Fixed spelling

azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
SAMPLING_RATIO_ARG,
1515
)
1616
from azure.monitor.opentelemetry._types import ConfigurationValue
17+
from azure.monitor.opentelemetry._vendor.v0_38b0.opentelemetry.instrumentation.dependencies import (
18+
get_dependency_conflicts,
19+
)
20+
from azure.monitor.opentelemetry._vendor.v0_38b0.opentelemetry.instrumentation.instrumentor import (
21+
BaseInstrumentor,
22+
)
1723
from azure.monitor.opentelemetry.exporter import (
1824
ApplicationInsightsSampler,
1925
AzureMonitorLogExporter,
@@ -22,10 +28,6 @@
2228
)
2329
from azure.monitor.opentelemetry.util.configurations import _get_configurations
2430
from opentelemetry._logs import get_logger_provider, set_logger_provider
25-
from opentelemetry.instrumentation.dependencies import (
26-
get_dist_dependency_conflicts,
27-
)
28-
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
2931
from opentelemetry.metrics import set_meter_provider
3032
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
3133
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
@@ -39,15 +41,15 @@
3941
_logger = getLogger(__name__)
4042

4143

42-
_SUPPORTED_INSTRUMENTED_LIBRARIES = (
43-
"django",
44-
"fastapi",
45-
"flask",
46-
"psycopg2",
47-
"requests",
48-
"urllib",
49-
"urllib3",
50-
)
44+
_SUPPORTED_INSTRUMENTED_LIBRARIES_DEPENDENCIES_MAP = {
45+
"django": ("django >= 1.10",),
46+
"fastapi": ("fastapi ~= 0.58",),
47+
"flask": ("flask >= 1.0, < 3.0",),
48+
"psycopg2": ("psycopg2 >= 2.7.3.1",),
49+
"requests": ("requests ~= 2.0",),
50+
"urllib": tuple(),
51+
"urllib3": ("urllib3 >= 1.0.0, < 2.0.0",),
52+
}
5153

5254

5355
def configure_azure_monitor(**kwargs) -> None:
@@ -129,13 +131,18 @@ def _setup_metrics(configurations: Dict[str, ConfigurationValue]):
129131

130132
def _setup_instrumentations():
131133
# use pkg_resources for now until https://github.com/open-telemetry/opentelemetry-python/pull/3168 is merged
132-
for entry_point in iter_entry_points("opentelemetry_instrumentor"):
134+
for entry_point in iter_entry_points(
135+
"azure_monitor_opentelemetry_instrumentor"
136+
):
133137
lib_name = entry_point.name
134-
if lib_name not in _SUPPORTED_INSTRUMENTED_LIBRARIES:
138+
if lib_name not in _SUPPORTED_INSTRUMENTED_LIBRARIES_DEPENDENCIES_MAP:
135139
continue
136140
try:
137141
# Check if dependent libraries/version are installed
138-
conflict = get_dist_dependency_conflicts(entry_point.dist)
142+
instruments = _SUPPORTED_INSTRUMENTED_LIBRARIES_DEPENDENCIES_MAP[
143+
lib_name
144+
]
145+
conflict = get_dependency_conflicts(instruments)
139146
if conflict:
140147
_logger.debug(
141148
"Skipping instrumentation %s: %s",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
# --------------------------------------------------------------------------
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
# --------------------------------------------------------------------------
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
# --------------------------------------------------------------------------
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
# --------------------------------------------------------------------------

0 commit comments

Comments
 (0)