Skip to content

Commit

Permalink
Add Open Telemetry logging signals (#43)
Browse files Browse the repository at this point in the history
Add Open Telemetry logging signals to increase observability for ETOS Suite Starter.
This enables correlation between logging and other Open Telemetry Signals.
  • Loading branch information
fredjn authored Feb 5, 2025
1 parent f16687f commit 13fff4d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"etos_lib==4.3.1",
"etos_lib==4.5.0",
"opentelemetry-api~=1.21",
"opentelemetry-exporter-otlp~=1.21",
"opentelemetry-sdk~=1.21"
"opentelemetry-sdk~=1.21",
"opentelemetry-instrumentation-logging~=0.46b0"
]

[project.urls]
Expand Down
42 changes: 27 additions & 15 deletions src/suite_starter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@
# limitations under the License.
"""ETOS suite starter module."""
import os
from importlib.metadata import version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, version

from etos_lib.logging.logger import setup_logging
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME, SERVICE_NAMESPACE, SERVICE_VERSION, Resource
from opentelemetry.sdk.resources import (
DEPLOYMENT_ENVIRONMENT,
SERVICE_NAME,
SERVICE_VERSION,
OTELResourceDetector,
ProcessResourceDetector,
Resource,
get_aggregated_resources,
)
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

from etos_lib.logging.logger import setup_logging

# The suite starter shall not send logs to RabbitMQ as it
# is too early in the ETOS test run.
os.environ["ETOS_ENABLE_SENDING_LOGS"] = "false"
Expand All @@ -37,19 +44,24 @@
BASE = os.path.dirname(os.path.abspath(__file__))
DEV = os.getenv("DEV", "false").lower() == "true"
ENVIRONMENT = "development" if DEV else "production"
setup_logging("ETOS Suite Starter", VERSION, ENVIRONMENT)
OTEL_RESOURCE = Resource.create(
{
SERVICE_NAME: "etos-suite-starter",
SERVICE_VERSION: VERSION,
DEPLOYMENT_ENVIRONMENT: ENVIRONMENT,
}
)


if os.getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"):
PROVIDER = TracerProvider(
resource=Resource.create(
{
SERVICE_NAME: "etos-suite-starter",
SERVICE_VERSION: VERSION,
SERVICE_NAMESPACE: ENVIRONMENT,
}
)
)
if os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT"):
OTEL_RESOURCE = get_aggregated_resources(
[OTELResourceDetector(), ProcessResourceDetector()],
).merge(OTEL_RESOURCE)
PROVIDER = TracerProvider(resource=OTEL_RESOURCE)
EXPORTER = OTLPSpanExporter()
PROCESSOR = BatchSpanProcessor(EXPORTER)
PROVIDER.add_span_processor(PROCESSOR)
trace.set_tracer_provider(PROVIDER)
setup_logging("ETOS Suite Starter", VERSION, ENVIRONMENT, OTEL_RESOURCE)
else:
setup_logging("ETOS Suite Starter", VERSION, ENVIRONMENT)

0 comments on commit 13fff4d

Please sign in to comment.