-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make OpenTelemetry imports conditional
- Loading branch information
1 parent
6901a6e
commit 2674b32
Showing
7 changed files
with
49 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import TYPE_CHECKING, Union | ||
|
||
import prefect.settings | ||
from prefect.client.base import ServerType, determine_server_type | ||
|
||
if TYPE_CHECKING: | ||
from opentelemetry.sdk._logs import LoggerProvider | ||
from opentelemetry.sdk.metrics import MeterProvider | ||
from opentelemetry.sdk.trace import TracerProvider | ||
|
||
|
||
def setup_telemetry() -> ( | ||
Union[ | ||
tuple["TracerProvider", "MeterProvider", "LoggerProvider"], | ||
tuple[None, None, None], | ||
] | ||
): | ||
settings = prefect.settings.get_current_settings() | ||
if not settings.experiments.telemetry_enabled: | ||
return None, None, None | ||
|
||
server_type = determine_server_type() | ||
if server_type != ServerType.CLOUD: | ||
return None, None, None | ||
|
||
assert settings.api.key | ||
assert settings.api.url | ||
|
||
# This import is here to defer importing of the `opentelemetry` packages. | ||
from .instrumentation import setup_exporters | ||
|
||
return setup_exporters(settings.api.url, settings.api.key.get_secret_value()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters