Skip to content
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
7 changes: 4 additions & 3 deletions lite_bootstrap/instruments/pyroscope_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class PyroscopeConfig(BaseConfig):
pyroscope_sample_rate: int = 100
pyroscope_tags: dict[str, str] = dataclasses.field(default_factory=dict)
pyroscope_additional_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict)
opentelemetry_service_name: str | None = None
opentelemetry_namespace: str | None = None


@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
Expand All @@ -31,11 +33,10 @@ def check_dependencies() -> bool:
return import_checker.is_pyroscope_installed

def bootstrap(self) -> None:
namespace: str | None = getattr(self.bootstrap_config, "opentelemetry_namespace", None)
namespace = self.bootstrap_config.opentelemetry_namespace
tags = ({"service_namespace": namespace} if namespace else {}) | self.bootstrap_config.pyroscope_tags
pyroscope.configure(
application_name=getattr(self.bootstrap_config, "opentelemetry_service_name", None)
or self.bootstrap_config.service_name,
application_name=self.bootstrap_config.opentelemetry_service_name or self.bootstrap_config.service_name,
server_address=self.bootstrap_config.pyroscope_endpoint,
sample_rate=self.bootstrap_config.pyroscope_sample_rate,
tags=tags,
Expand Down
14 changes: 14 additions & 0 deletions tests/instruments/test_pyroscope_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ def test_pyroscope_bootstrap_uses_opentelemetry_service_name() -> None:
assert mock_pyroscope.configure.call_args.kwargs["application_name"] == "otel-name"


def test_pyroscope_standalone_config_accepts_otel_fields() -> None:
config = PyroscopeConfig(
service_name="fallback",
pyroscope_endpoint="http://pyroscope:4040",
opentelemetry_service_name="otel-name",
opentelemetry_namespace="my-ns",
)
with patch(_PYROSCOPE_PYROSCOPE) as mock_pyroscope:
PyroscopeInstrument(bootstrap_config=config).bootstrap()
kwargs = mock_pyroscope.configure.call_args.kwargs
assert kwargs["application_name"] == "otel-name"
assert kwargs["tags"] == {"service_namespace": "my-ns"}


def test_pyroscope_bootstrap_merges_namespace_tag() -> None:
config = FreeBootstrapperConfig(
service_name="svc",
Expand Down
Loading