Skip to content

Commit 762c548

Browse files
committed
Configura ingestão de logs pelo OTel Collector
1 parent 9a7bfe8 commit 762c548

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

Makefile

+3-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,7 +193,8 @@ 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)

api/api.py

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

19-
logging.basicConfig(level=logging.DEBUG)
2019
logger = logging.getLogger(__name__)
2120
config = load_configuration()
2221

config/otel-collector-config.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
traces:
14+
receivers: [otlp]
15+
exporters: [debug]
16+
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ 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

0 commit comments

Comments
 (0)