Skip to content

Commit 1556930

Browse files
feat(opentelemetry): add tracing backend and logging handler
1 parent 7c4d1f7 commit 1556930

12 files changed

Lines changed: 683 additions & 36 deletions

File tree

.github/workflows/famedly-tests.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,23 @@ jobs:
359359

360360
- run: cargo test
361361

362+
otlp:
363+
if: ${{ !failure() && !cancelled() }}
364+
runs-on: ubuntu-latest
365+
366+
steps:
367+
- name: Run actions/checkout@v4 for synapse
368+
uses: actions/checkout@v4
369+
with:
370+
path: synapse
371+
- run: |
372+
set -e
373+
DOCKER_BUILDKIT=1 sudo docker build -t famedly/synapse -f docker/Dockerfile .
374+
cd otlp-test
375+
success() { [ -s out/traces.json ] && [ -s out/logs.json ]; }
376+
(until success; do sleep 1; done && sudo docker compose down >/dev/null 2>&1) &
377+
sudo timeout 30 docker compose up && success
378+
362379
# a job which marks all the other jobs as complete, thus allowing PRs to be merged.
363380
tests-done:
364381
if: ${{ always() }}

docker/conf/homeserver.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,9 @@ trusted_key_servers:
191191

192192
password_config:
193193
enabled: true
194+
195+
{% if OTLP_BACKEND %}
196+
opentracing:
197+
enabled: true
198+
backend: otlp
199+
{% endif %}

docker/conf/log.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ handlers:
4343
# Messages will not be delayed for longer than this time.
4444
# Default value: 5 seconds
4545
period: 5
46+
{% elif OTLP_BACKEND %}
47+
otlp:
48+
class: synapse.logging.handlers.OtlpHandler
4649
{% endif %}
4750

4851
console:
@@ -84,6 +87,8 @@ root:
8487

8588
{% if LOG_FILE_PATH %}
8689
handlers: [console, buffer]
90+
{% elif OTLP_BACKEND %}
91+
handlers: [console, otlp]
8792
{% else %}
8893
handlers: [console]
8994
{% endif %}

docs/opentracing.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ OpenTracing is a semi-standard being adopted by a number of distributed
66
tracing platforms. It is a common api for facilitating vendor-agnostic
77
tracing instrumentation. That is, we can use the OpenTracing api and
88
select one of a number of tracer implementations to do the heavy lifting
9-
in the background. Our current selected implementation is Jaeger.
9+
in the background. Our current implementations are Jaeger (default) and
10+
OpenTelemetry.
1011

1112
OpenTracing is a tool which gives an insight into the causal
1213
relationship of work done in and between servers. The servers each track
@@ -74,6 +75,14 @@ opentracing:
7475
- "*.myotherhomeservers.com"
7576
```
7677
78+
To use OpenTelemetry instead of Jaeger as the `backend`:
79+
80+
```yaml
81+
opentracing:
82+
enabled: true
83+
backend: otlp
84+
```
85+
7786
## Homeserver whitelisting
7887

7988
The homeserver whitelist is configured using regular expressions. A list

docs/sample_log_config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ handlers:
5656
class: logging.StreamHandler
5757
formatter: precise
5858

59+
# A commented-out OtlpHandler based on opentelemetry-sdk that reads
60+
# its configuration from the common `OTLP_` environment variables:
61+
# Requires the extra "opentelemetry-log-handler".
62+
#otlp:
63+
# class: synapse.logging.handlers.OtlpHandler
64+
5965
loggers:
6066
synapse.storage.SQL:
6167
# beware: increasing this to DEBUG will make synapse log sensitive
@@ -70,6 +76,8 @@ root:
7076
#
7177
# Replace "buffer" with "console" to log to stderr instead.
7278
#
79+
# Add or set the handler to "otlp" after enabling it in the "handlers" section.
80+
#
7381
handlers: [buffer]
7482

7583
disable_existing_loggers: false

otlp-test/docker-compose.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
services:
2+
3+
init:
4+
image: famedly/synapse
5+
user: root
6+
command: migrate_config
7+
volumes:
8+
- ./synapse-data:/data
9+
environment:
10+
- SYNAPSE_SERVER_NAME=example.com
11+
- SYNAPSE_REPORT_STATS=no
12+
- SYNAPSE_NO_TLS=1
13+
- OTLP_BACKEND=1
14+
15+
synapse:
16+
image: famedly/synapse
17+
user: root
18+
volumes:
19+
- ./synapse-data:/data
20+
environment:
21+
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
22+
depends_on:
23+
- init
24+
- otel-collector
25+
26+
otel-collector:
27+
image: otel/opentelemetry-collector:0.86.0
28+
user: "0"
29+
command: [ "--config=/etc/otel-collector.yaml" ]
30+
volumes:
31+
- ./otel-collector.yaml:/etc/otel-collector.yaml
32+
- ./out:/etc/out

otlp-test/otel-collector.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
http:
6+
exporters:
7+
file/traces:
8+
path: /etc/out/traces.json
9+
file/logs:
10+
path: /etc/out/logs.json
11+
service:
12+
pipelines:
13+
traces:
14+
receivers: [otlp]
15+
exporters: [file/traces]
16+
logs:
17+
receivers: [otlp]
18+
exporters: [file/logs]

0 commit comments

Comments
 (0)