Skip to content
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

Add init_otel() function #545

Merged
merged 2 commits into from
Nov 19, 2024
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: 3 additions & 3 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Summary of changes between Splunk OTel Python major versions 1 and 2.

### Version 2

| Function name | Operation | Arguments |
|----------------|---------------------------------------|-----------|
| `start_otel()` | Configures tracing, metrics, and logs | None |
| Function name | Operation | Arguments |
|---------------|----------------------------------------|-----------|
| `init_otel()` | Initializes tracing, metrics, and logs | None |
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this missed in the rename?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch! Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed here: #547


## Environment Variables

Expand Down
12 changes: 12 additions & 0 deletions src/splunk_otel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from splunk_otel.configurator import SplunkConfigurator
from splunk_otel.distro import SplunkDistro


def init_splunk_otel():
"""
Initializes OpenTelemetry Python components (exporters, tracer providers, meter providers, resources etc.).
Like auto instrumentation (`opentelemetry-instrument`) but without loading instrumentors.
"""
sd = SplunkDistro()
sd.configure()
sc = SplunkConfigurator()
sc.configure()
32 changes: 32 additions & 0 deletions tests/ott_init_otel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Mapping, Optional, Sequence

from oteltest.telemetry import count_spans
from ott_lib import project_path, trace_loop

NUM_SPANS = 12

if __name__ == "__main__":
from splunk_otel import init_splunk_otel

init_splunk_otel()
trace_loop(NUM_SPANS)


class ConfigureOtelTest:
def environment_variables(self) -> Mapping[str, str]:
return {}

def requirements(self) -> Sequence[str]:
return [project_path(), "oteltest"]

def wrapper_command(self) -> str:
return ""

def on_start(self) -> Optional[float]:
pass

def on_stop(self, tel, stdout: str, stderr: str, returncode: int) -> None:
assert count_spans(tel) == NUM_SPANS

def is_http(self) -> bool:
return False
Loading