-
Notifications
You must be signed in to change notification settings - Fork 4
Add Pyroscope instrument (continuous profiling) #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7aa909d
Add Pyroscope instrumentation and example app
vrslev 30e1dd8
Add Pyroscope instrument configuration test and ensure server address…
vrslev f5b211f
Add OpentelemetryConfig and PyroscopeSpanProcessor to test_pyroscope.py
vrslev adb79fb
Adjust hello_world to be asynchronous and update create_app with pyro…
vrslev f44c5b1
Organize imports and streamline server creation in t.py
vrslev b15ad7c
Adding Litestar example application and updating pyproject.toml for i…
vrslev 20d6a04
Add Settings class and use it in Litestar app configuration
vrslev acdfe55
Adjust import comment and remove per-file ignore for INP001
vrslev 34b9612
Adjust import style and fix ruff ignore for examples directory
vrslev cf634bb
Adding PyroscopeInstrument to FastApi and FastStream bootstrappers
vrslev 27317f5
Add future import for type annotations in litestar_app.py
vrslev 85841b6
Remove example application script t.py
vrslev f993158
Adjust imports and add checks for Pyroscope availability on non-Windo…
vrslev ed86de5
Update comment to clarify pyroscope import unavailability on Windows
vrslev ce235b2
Add Pyroscope support and update instrument documentation
vrslev e9c9ee2
Updating OpenTelemetry section to include debug mode option
vrslev 4b68c17
Ensure instruments are ready before tearing them down in ApplicationB…
vrslev e27bcea
Adjust ready_condition description for PyroscopeInstrument to specify…
vrslev 6bb6b2d
Add MockSentryTransport for testing Sentry configurations
vrslev 07dfb4d
Adjusting import error handling comments for coverage and clarity
vrslev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,29 @@ | ||
from __future__ import annotations | ||
|
||
import litestar | ||
|
||
from microbootstrap import LitestarSettings | ||
from microbootstrap.bootstrappers.litestar import LitestarBootstrapper | ||
from microbootstrap.config.litestar import LitestarConfig | ||
from microbootstrap.granian_server import create_granian_server | ||
|
||
|
||
class Settings(LitestarSettings): ... | ||
|
||
|
||
settings = Settings() | ||
|
||
|
||
@litestar.get("/") | ||
async def hello_world() -> dict[str, str]: | ||
return {"hello": "world"} | ||
|
||
|
||
def create_app() -> litestar.Litestar: | ||
return ( | ||
LitestarBootstrapper(settings).configure_application(LitestarConfig(route_handlers=[hello_world])).bootstrap() | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
create_granian_server("examples.litestar_app:create_app", settings, factory=True).serve() |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,40 @@ | ||
from __future__ import annotations | ||
|
||
import pydantic # noqa: TC002 | ||
|
||
from microbootstrap.instruments.base import BaseInstrumentConfig, Instrument | ||
|
||
|
||
try: | ||
import pyroscope # type: ignore[import-untyped] | ||
except ImportError: # pragma: no cover | ||
pyroscope = None # Not supported on Windows | ||
|
||
|
||
class PyroscopeConfig(BaseInstrumentConfig): | ||
service_name: str = "micro-service" | ||
|
||
pyroscope_endpoint: pydantic.HttpUrl | None = None | ||
pyroscope_sample_rate: int = 100 | ||
|
||
|
||
class PyroscopeInstrument(Instrument[PyroscopeConfig]): | ||
instrument_name = "Pyroscope" | ||
ready_condition = "Provide pyroscope_endpoint" | ||
|
||
def is_ready(self) -> bool: | ||
return all([self.instrument_config.pyroscope_endpoint, pyroscope]) | ||
|
||
def teardown(self) -> None: | ||
pyroscope.shutdown() | ||
|
||
def bootstrap(self) -> None: | ||
pyroscope.configure( | ||
application_name=self.instrument_config.service_name, | ||
server_address=str(self.instrument_config.pyroscope_endpoint), | ||
sample_rate=self.instrument_config.pyroscope_sample_rate, | ||
) | ||
|
||
@classmethod | ||
def get_config_type(cls) -> type[PyroscopeConfig]: | ||
return PyroscopeConfig |
This file contains hidden or 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 hidden or 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 hidden or 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,37 @@ | ||
import pydantic | ||
import pytest | ||
|
||
from microbootstrap.instruments.opentelemetry_instrument import OpentelemetryConfig, OpentelemetryInstrument | ||
from microbootstrap.instruments.pyroscope_instrument import PyroscopeConfig, PyroscopeInstrument | ||
|
||
|
||
try: | ||
from pyroscope.otel import PyroscopeSpanProcessor # type: ignore[import-untyped] | ||
except ImportError: # pragma: no cover | ||
pytest.skip("pyroscope is not installed", allow_module_level=True) | ||
|
||
|
||
class TestPyroscopeInstrument: | ||
@pytest.fixture | ||
def minimal_pyroscope_config(self) -> PyroscopeConfig: | ||
return PyroscopeConfig(pyroscope_endpoint=pydantic.HttpUrl("http://localhost:4040")) | ||
|
||
def test_ok(self, minimal_pyroscope_config: PyroscopeConfig) -> None: | ||
instrument = PyroscopeInstrument(minimal_pyroscope_config) | ||
assert instrument.is_ready() | ||
instrument.bootstrap() | ||
instrument.teardown() | ||
|
||
def test_not_ready(self) -> None: | ||
instrument = PyroscopeInstrument(PyroscopeConfig(pyroscope_endpoint=None)) | ||
assert not instrument.is_ready() | ||
|
||
def test_opentelemetry_includes_pyroscope(self) -> None: | ||
otel_instrument = OpentelemetryInstrument( | ||
OpentelemetryConfig(pyroscope_endpoint=pydantic.HttpUrl("http://localhost:4040")) | ||
) | ||
otel_instrument.bootstrap() | ||
assert PyroscopeSpanProcessor in { | ||
type(one_span_processor) | ||
for one_span_processor in otel_instrument.tracer_provider._active_span_processor._span_processors # noqa: SLF001 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.