Skip to content

Commit b35f269

Browse files
authored
Configura ingestão de logs pelo OTel Collector (#70)
2 parents 9a7bfe8 + 8363d35 commit b35f269

File tree

6 files changed

+67
-6
lines changed

6 files changed

+67
-6
lines changed

Dockerfile

-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ RUN chmod 644 censo.csv
1515
ADD https://raw.githubusercontent.com/okfn-brasil/querido-diario-data-processing/main/config/themes_config.json themes_config.json
1616
RUN chmod 644 themes_config.json
1717

18-
RUN opentelemetry-bootstrap -a install
19-
2018
USER gazette

Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ load-data:
135135

136136
.PHONY: re-run
137137
re-run: setup-environment wait-opensearch wait-database
138-
$(call run-command, opentelemetry-instrument --traces_exporter console --metrics_exporter console --logs_exporter console --service_name querido-diario-api python main)
138+
$(call run-command, opentelemetry-instrument python main)
139139

140140
.PHONY: runshell
141141
runshell:
@@ -193,10 +193,15 @@ start-otel-collector:
193193
podman run -d --rm -ti \
194194
--name $(OTEL_COLLECTOR_CONTAINER_NAME) \
195195
--pod $(POD_NAME) \
196-
docker.io/otel/opentelemetry-collector-contrib:0.97.0
196+
--volume $(PWD)/config/otel-collector-config.yaml:/etc/otel-collector-config.yaml \
197+
docker.io/otel/opentelemetry-collector-contrib:0.97.0 "--config=/etc/otel-collector-config.yaml"
197198

198199
stop-otel-collector:
199200
podman rm --force --ignore $(OTEL_COLLECTOR_CONTAINER_NAME)
200201

201202
wait-otel-collector:
202203
$(call wait-for, localhost:4317)
204+
205+
otel-auto-instrumentation-list:
206+
@echo "These packages were detected and can be auto-instrumented (maybe add/update them in requirements.txt):"
207+
@$(call run-command, opentelemetry-bootstrap -a requirements)

api/api.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
from themed_excerpts import ThemedExcerptAccessInterface, ThemedExcerptAccessInterface
1717
from themed_excerpts.themed_excerpt_access import ThemedExcerptRequest
1818

19-
logging.basicConfig(level=logging.DEBUG)
19+
2020
logger = logging.getLogger(__name__)
21+
logger.setLevel(logging.INFO)
22+
2123
config = load_configuration()
2224

2325
app = FastAPI(

config/otel-collector-config.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
endpoint: 0.0.0.0:4317
6+
exporters:
7+
debug:
8+
verbosity: detailed
9+
processors:
10+
batch:
11+
service:
12+
pipelines:
13+
logs:
14+
receivers: [otlp]
15+
exporters: [debug]
16+
processors: [batch]
17+
traces:
18+
receivers: [otlp]
19+
exporters: [debug]
20+
processors: [batch]
21+
metrics:
22+
receivers: [otlp]
23+
exporters: [debug]
24+
processors: [batch]

config/sample.env

+14
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@ THEMED_EXCERPT_EMBEDDING_SCORE_FIELD=excerpt_embedding_score
3232
THEMED_EXCERPT_TFIDF_SCORE_FIELD=excerpt_tfidf_score
3333
THEMED_EXCERPT_FRAGMENT_SIZE=10000
3434
THEMED_EXCERPT_NUMBER_OF_FRAGMENTS=1
35+
36+
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
37+
OTEL_PYTHON_LOG_CORRELATION=true
38+
OTEL_PYTHON_LOG_LEVEL=debug
39+
OTEL_PYTHON_LOG_FORMAT="%(asctime)s %(levelname)s [%(name)s] [%(filename)s:%(lineno)d] [trace_id=%(otelTraceID)s span_id=%(otelSpanID)s resource.service.name=%(otelServiceName)s trace_sampled=%(otelTraceSampled)s] - %(message)s"
40+
OTEL_SERVICE_NAME=querido-diario-api
41+
OTEL_LOGS_EXPORTER=console,otlp
42+
OTEL_TRACES_EXPORTER=console,otlp
43+
OTEL_METRICS_EXPORTER=console,otlp
44+
OTEL_EXPORTER_OTLP_INSECURE=true
45+
OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4317
46+
47+
# valor alto para não atrapalhar tanto a leitura dos logs durante o desenvolvimento
48+
OTEL_METRIC_EXPORT_INTERVAL=60000

requirements.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,22 @@ psycopg2==2.8.5
88
SQLAlchemy==1.3.19
99
opensearch-py==2.3.2
1010
mailjet-rest==1.3.4
11-
opentelemetry-distro==0.44b0
11+
opentelemetry-distro==0.45b0
12+
opentelemetry-exporter-otlp==1.24.0
13+
opentelemetry-instrumentation==0.45b0
14+
opentelemetry-instrumentation-asyncio==0.45b0
15+
opentelemetry-instrumentation-aws-lambda==0.45b0
16+
opentelemetry-instrumentation-dbapi==0.45b0
17+
opentelemetry-instrumentation-logging==0.45b0
18+
opentelemetry-instrumentation-sqlite3==0.45b0
19+
opentelemetry-instrumentation-urllib==0.45b0
20+
opentelemetry-instrumentation-wsgi==0.45b0
21+
opentelemetry-instrumentation-asgi==0.45b0
22+
opentelemetry-instrumentation-fastapi==0.45b0
23+
opentelemetry-instrumentation-grpc==0.45b0
24+
opentelemetry-instrumentation-psycopg2==0.45b0
25+
opentelemetry-instrumentation-requests==0.45b0
26+
opentelemetry-instrumentation-sqlalchemy==0.45b0
27+
opentelemetry-instrumentation-starlette==0.45b0
28+
opentelemetry-instrumentation-tortoiseorm==0.45b0
29+
opentelemetry-instrumentation-urllib3==0.45b0

0 commit comments

Comments
 (0)