Skip to content

Commit 49b239b

Browse files
committed
Added first test.
1 parent de56cd3 commit 49b239b

File tree

11 files changed

+120
-10
lines changed

11 files changed

+120
-10
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.PHONY: all build test clean lint install
2+
3+
all: build test lint
4+
5+
build:
6+
./tools/build.sh
7+
8+
test:
9+
./tools/test.sh
10+
11+
lint:
12+
./tools/lint.sh
13+
14+
install: build
15+
pip install dist/*.whl
16+
17+
clean:
18+
rm -rf .build
19+
rm -rf dist
20+
rm -rf .test
21+
rm -rf .tox
22+
rm -rf .venv

opentelemetry-configurator-gcp/pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "opentelemetry-configurator-gcp"
7+
dynamic = ["version"]
8+
dependencies = [
9+
"opentelemetry-api >= 1.30.0, <2",
10+
"opentelemetry-sdk >= 1.30.0, <2",
11+
"opentelemetry-exporter-gcp-logging >= 1.9.0a0, <2",
12+
"opentelemetry-exporter-gcp-trace >= 1.9.0, <2",
13+
"opentelemetry-exporter-gcp-monitoring >= 1.9.0a0, <2",
14+
"opentelemetry-resourcedetector-gcp >= 1.9.0a0, <2",
15+
]
716

817
[project.entry-points.opentelemetry_configurator]
918
gcp = "opentelemetry.configurator.gcp:GcpConfigurator"
19+
20+
[tool.hatch.build.targets.sdist]
21+
include = ["*.py"]
22+
23+
[tool.hatch.build.targets.wheel]
24+
packages = ["src/opentelemetry"]
25+
26+
[tool.hatch.version]
27+
path = "src/opentelemetry/configurator/gcp/version.py"

opentelemetry-configurator-gcp/src/opentelemetry/configurator/gcp/configurator.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional, Callable
2+
13
from .flags import (
24
is_metrics_exporter_enabled,
35
is_logs_exporter_enabled,
@@ -24,14 +26,14 @@ def __init__(
2426
logs_exporter_enabled:Optional[bool]=None,
2527
traces_exporter_enabled:Optional[bool]=None,
2628
resource_detector_enabled:Optional[bool]=None):
27-
self._metrics_exporter_enabled = _bool_with_flag_default(
28-
metrics_exporter_enabled, is_metrics_exporter_enabled)
29-
self._logs_exporter_enabled = _bool_with_flag_default(
30-
logs_exporter_enabled, is_logs_exporter_enabled)
31-
self._traces_exporter_enabled = _bool_with_flag_default(
32-
traces_exporter_enabled, is_traces_exporter_enabled)
33-
self._resource_detector_enabled = _bool_with_flag_default(
34-
resource_detector_enabled, is_resource_detector_enabled)
29+
self._metrics_exporter_enabled = _bool_with_flag_default(
30+
metrics_exporter_enabled, is_metrics_exporter_enabled)
31+
self._logs_exporter_enabled = _bool_with_flag_default(
32+
logs_exporter_enabled, is_logs_exporter_enabled)
33+
self._traces_exporter_enabled = _bool_with_flag_default(
34+
traces_exporter_enabled, is_traces_exporter_enabled)
35+
self._resource_detector_enabled = _bool_with_flag_default(
36+
resource_detector_enabled, is_resource_detector_enabled)
3537

3638
def configure(self):
3739
resource = get_resource(include_gcp_detector=self._resource_detector_enabled)

opentelemetry-configurator-gcp/src/opentelemetry/configurator/gcp/flags.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import gcloud_env
1+
import os
2+
3+
from . import gcloud_env
24

35

46
def _str_to_optional_bool(s):

opentelemetry-configurator-gcp/src/opentelemetry/configurator/gcp/logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _get_entrypoint_script_name():
2323
main_script_path = sys.argv[0]
2424
if not main_script_path:
2525
main_script_path = sys.executable
26-
simple_script_name = os.path.basename(main_scripot_path).rstrip('.py')
26+
simple_script_name = os.path.basename(main_script_path).rstrip('.py')
2727
return simple_script_name
2828

2929

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
opentelemetry-api==1.30.0
2+
opentelemetry-sdk==1.30.0
3+
opentelemetry-exporter-gcp-logging==1.9.0a0
4+
opentelemetry-exporter-gcp-trace==1.9.0
5+
opentelemetry-exporter-gcp-monitoring==1.9.0a0
6+
opentelemetry-resourcedetector-gcp==1.9.0a0
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR=$(cd $(dirname ${BASH_SOURCE:-0}); pwd)
4+
PROJECT_DIR=$(readlink -f "${SCRIPT_DIR}/..")
5+
TESTS_DIR="${PROJECT_DIR}/tests"
6+
TESTS_ENV="${PROJECT_DIR}/.test/.test-venv"
7+
8+
function main() {
9+
if [ ! -d "${TESTS_ENV}" ] ; then
10+
mkdir -p "${TESTS_ENV}"
11+
fi
12+
if [ ! -d "${TESTS_ENV}/bin" ] ; then
13+
python3 -m venv "${TESTS_ENV}"
14+
fi
15+
16+
source "${TESTS_ENV}/bin/activate"
17+
pip install -r "${TESTS_DIR}/requirements.txt"
18+
python3 "$@"
19+
}
20+
21+
main "$@"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!./run_with_env.sh
2+
import unittest
3+
4+
import sys
5+
sys.path.append('../src')
6+
7+
from opentelemetry.configurator.gcp import OpenTelemetryGcpConfigurator
8+
9+
class ManualTestWithDefaultParameters(unittest.TestCase):
10+
11+
def test_does_not_crash(self):
12+
OpenTelemetryGcpConfigurator().configure()
13+
14+
15+
if __name__ == '__main__':
16+
unittest.main()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR=$(cd $(dirname ${BASH_SOURCE:-0}); pwd)
4+
PROJECT_DIR=$(readlink -f "${SCRIPT_DIR}/..")
5+
BUILD_DIR="${PROJECT_DIR}/.build"
6+
BUILD_ENV="${BUILD_DIR}/.venv"
7+
8+
function main() {
9+
if [ ! -d "${BUILD_ENV}" ] ; then
10+
mkdir -p "${BUILD_ENV}"
11+
fi
12+
if [ ! -d "${BUILD_ENV}/bin" ] ; then
13+
python3 -m venv "${BUILD_ENV}"
14+
fi
15+
16+
source "${BUILD_ENV}/bin/activate"
17+
pip install build
18+
19+
cd "${PROJECT_DIR}"
20+
python3 -m build
21+
}
22+
23+
main

opentelemetry-configurator-gcp/tools/lint.sh

Whitespace-only changes.

0 commit comments

Comments
 (0)