Skip to content

Extend Pyroscope configuration #95

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
merged 2 commits into from
Apr 25, 2025
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ class YourSettings(FastStreamSettings):

### [Pyroscope](https://pyroscope.io)

To integrate Pyroscope, specify the `pyroscope_endpoint`. The `service_name` will be used as the application name. You can also set `pyroscope_sample_rate` (default is 100).
To integrate Pyroscope, specify the `pyroscope_endpoint`.

- The `opentelemetry_service_name` will be used as the application name.
- `service_namespace` tag will be added with `opentelemetry_namespace` value.
- You can also set `pyroscope_sample_rate`, `pyroscope_auth_token`, `pyroscope_tags` and `pyroscope_additional_params` — params that will be passed to `pyroscope.configure`.

When both Pyroscope and OpenTelemetry are enabled, profile span IDs will be included in traces using [`pyroscope-otel`](https://github.com/grafana/otel-profiling-python) for correlation.

Expand Down
18 changes: 16 additions & 2 deletions microbootstrap/instruments/pyroscope_instrument.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
import typing

import pydantic # noqa: TC002
import pydantic

from microbootstrap.instruments.base import BaseInstrumentConfig, Instrument

Expand All @@ -13,9 +14,14 @@

class PyroscopeConfig(BaseInstrumentConfig):
service_name: str = "micro-service"
opentelemetry_service_name: str | None = None
opentelemetry_namespace: str | None = None

pyroscope_endpoint: pydantic.HttpUrl | None = None
pyroscope_sample_rate: int = 100
pyroscope_auth_token: str | None = None
pyroscope_tags: dict[str, str] = pydantic.Field(default_factory=dict)
pyroscope_additional_params: dict[str, typing.Any] = pydantic.Field(default_factory=dict)


class PyroscopeInstrument(Instrument[PyroscopeConfig]):
Expand All @@ -30,9 +36,17 @@ def teardown(self) -> None:

def bootstrap(self) -> None:
pyroscope.configure(
application_name=self.instrument_config.service_name,
application_name=self.instrument_config.opentelemetry_service_name or self.instrument_config.service_name,
server_address=str(self.instrument_config.pyroscope_endpoint),
auth_token=self.instrument_config.pyroscope_auth_token or "",
sample_rate=self.instrument_config.pyroscope_sample_rate,
tags=(
{"service_namespace": self.instrument_config.opentelemetry_namespace}
if self.instrument_config.opentelemetry_namespace
else {}
)
| self.instrument_config.pyroscope_tags,
**self.instrument_config.pyroscope_additional_params,
)

@classmethod
Expand Down