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
153 changes: 145 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

[tool.poetry]
name = "solnlib"
version = "8.2.0"
version = "8.2.1-beta.1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vosmolovskiy-splunk It's autogenerated and same in every PR merged before and will be corrected- https://github.com/splunk/addonfactory-solutions-library-python/pull/468/changes

description = "The Splunk Software Development Kit for Splunk Solutions"
authors = ["Splunk <addonfactory@splunk.com>"]
license = "Apache-2.0"
Expand All @@ -41,9 +41,18 @@ python = ">=3.9,<3.14"
sortedcontainers = ">=2"
defusedxml = ">=0.7"
splunk-sdk = ">=2.0.2"
opentelemetry-api = ">=1.39.1,<2"
opentelemetry-sdk = ">=1.39.1,<2"
opentelemetry-exporter-otlp-proto-grpc = ">=1.39.1,<2"
opentelemetry-api = [
{version = ">=1.45.1,<2", python = ">=3.10"},
{version = ">=1.39.1,<2", python = "<3.10"},
]
opentelemetry-sdk = [
{version = ">=1.45.1,<2", python = ">=3.10"},
{version = ">=1.39.1,<2", python = "<3.10"},
]
opentelemetry-exporter-otlp-proto-grpc = [
{version = ">=1.45.1,<2", python = ">=3.10"},
{version = ">=1.39.1,<2", python = "<3.10"},
]
grpcio = ">=1.74.0"

[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion solnlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
"utils",
]

__version__ = "8.2.0"
__version__ = "8.2.1-beta.1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version is not right

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vosmolovskiy-splunk It's autogenerated and same in every PR merged before and will be corrected- https://github.com/splunk/addonfactory-solutions-library-python/pull/468/changes

48 changes: 30 additions & 18 deletions solnlib/observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import urllib.request
from typing import Callable, ClassVar, Optional, Union
from ._observability_flush import _register_controller
from .splunkenv import get_conf_stanzas
from .splunkenv import _get_running_app_name, get_conf_stanzas
from opentelemetry.metrics import Instrument, Meter
from opentelemetry.sdk.metrics import MeterProvider, Counter, Histogram
from opentelemetry.sdk.metrics.export import (
Expand Down Expand Up @@ -392,12 +392,14 @@ def __init__(
logger: Python logger (or ``LoggerAdapter``) for all diagnostic
output. Typically the caller's own module-level logger.
ta_name: Add-on identifier, e.g. ``"Splunk_TA_myapp"``. When
*None* the value is read from the ``[id]`` stanza of
``app.conf`` via :func:`~solnlib.splunkenv.get_conf_stanzas`.
Pass it explicitly when the add-on runs outside a full Splunk
environment or to avoid the ``app.conf`` lookup.
*None* the value is read from the ``[id]`` stanza of the
``app.conf`` of the running app (detected from the main
script's path, then solnlib's own path; falling back to the
app directory name).
Pass it explicitly when the add-on runs outside a standard
``etc/apps/<app>`` layout or to avoid the ``app.conf`` lookup.
ta_version: Add-on version string, e.g. ``"3.1.0"``. When *None*
the value is read from the ``[launcher]`` stanza of
the value is read from the ``[launcher]`` stanza of the same
``app.conf``. Falls back to ``"unknown"`` if it cannot be
determined.
extra_exporters: Optional list of additional
Expand Down Expand Up @@ -433,8 +435,8 @@ def __init__(

if not ta_name:
raise ValueError(
"ta_name could not be determined: pass it explicitly or ensure "
"app.conf is readable via btool"
"ta_name could not be determined: pass it explicitly or run "
"the add-on from etc/apps/<app>"
)

resource = Resource(
Expand Down Expand Up @@ -504,19 +506,29 @@ def __init__(
)

def _read_ta_info(self) -> tuple[Optional[str], Optional[str]]:
"""Read the add-on name and version from ``app.conf``.
"""Read the add-on name and version from the owning app's ``app.conf``.

Returns a ``(ta_name, ta_version)`` tuple. Either value is
``None`` when the corresponding key is missing or when
``app.conf`` cannot be read (e.g. outside a Splunk environment).
The owning app is the one whose script is running
(``etc/apps/<app>/bin/...``), or failing that the one that bundles
solnlib. The lookup is always scoped to that app: an unscoped
``app.conf`` merge can return another installed add-on's ``[id]``
stanza.

Returns a ``(ta_name, ta_version)`` tuple. Both are ``None`` when the
owning app cannot be detected or ``app.conf`` cannot be read; the
version alone is ``None`` when ``[launcher] version`` is missing.
"""
try:
stanzas = get_conf_stanzas("app")
ta_name = stanzas.get("id", {}).get("name") or None
scoped_stanzas = (
get_conf_stanzas("app", app_name=ta_name) if ta_name else stanzas
)
ta_version = scoped_stanzas.get("launcher", {}).get("version") or None
app_name = _get_running_app_name()
if not app_name:
self._logger.info(
"Could not determine the running add-on from the script "
"or solnlib path; app.conf not read"
)
return None, None
stanzas = get_conf_stanzas("app", app_name=app_name)
ta_name = stanzas.get("id", {}).get("name") or app_name
ta_version = stanzas.get("launcher", {}).get("version") or None
return ta_name, ta_version
except Exception as error:
self._logger.info(
Expand Down
Loading
Loading