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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ coverage.xml

# Build and docs folder/files
build/*
python/build/*
bin/*
dist/*
sdist/*
python/dist/*
python/sdist/*
docs/api/*
docs/_rst/*
docs/_build/*
Expand Down
4 changes: 2 additions & 2 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"etos_lib==4.4.2",
"etos_lib==4.5.0",
"etcd3gw~=2.3",
"uvicorn~=0.22",
"fastapi~=0.115.6",
Expand All @@ -27,7 +27,7 @@ dependencies = [
"sse-starlette~=1.6",
"opentelemetry-api~=1.21",
"opentelemetry-exporter-otlp~=1.21",
"opentelemetry-instrumentation-fastapi==0.46b0",
"opentelemetry-instrumentation-fastapi~=0.46b0",
"opentelemetry-sdk~=1.21",
"jsontas~=1.4",
"packageurl-python~=0.11",
Expand Down
32 changes: 25 additions & 7 deletions python/src/etos_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
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

Expand All @@ -41,19 +49,29 @@

DEV = os.getenv("DEV", "false").lower() == "true"
ENVIRONMENT = "development" if DEV else "production"
setup_logging("ETOS API", VERSION, ENVIRONMENT)

if os.getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"):
PROVIDER = TracerProvider(
resource=Resource.create(
{SERVICE_NAME: "etos-api", SERVICE_VERSION: VERSION, SERVICE_NAMESPACE: ENVIRONMENT}
)
if os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT"):
OTEL_RESOURCE = Resource.create(
{
SERVICE_NAME: "etos-api",
SERVICE_VERSION: VERSION,
DEPLOYMENT_ENVIRONMENT: ENVIRONMENT,
},
)

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 API", VERSION, ENVIRONMENT, OTEL_RESOURCE)

FastAPIInstrumentor().instrument_app(APP, tracer_provider=PROVIDER, excluded_urls=".*/ping")
else:
setup_logging("ETOS API", VERSION, ENVIRONMENT)

RegisterProviders()
Loading