Skip to content

Commit bbd09cb

Browse files
authored
Merge pull request #13 from ifsp-projects/feat/add-filter
Feat: Implement open telemetry
2 parents 799f629 + f4df3ad commit bbd09cb

File tree

8 files changed

+1719
-9
lines changed

8 files changed

+1719
-9
lines changed

.github/workflows/cd.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ jobs:
8181
source: ".env"
8282
target: "/home/gcpuser/app"
8383

84+
- name: Copy OTel config to VM
85+
uses: appleboy/scp-action@master
86+
with:
87+
host: ${{ env.VM_HOST }}
88+
username: gcpuser
89+
key: ${{ secrets.VM_SSH_KEY }}
90+
source: "devops/otel/collector-config.prod.yaml"
91+
target: "/opt/otel"
92+
strip_components: 2
93+
8494
- name: Deploy via SSH
8595
uses: appleboy/ssh-action@master
8696
env:
@@ -89,27 +99,43 @@ jobs:
8999
IMAGE_TAG: ${{ github.sha }}
90100
CONTAINER_NAME: api-ifsp
91101
REGION: ${{ env.REGION }}
102+
GRAFANA_CLOUD_OTLP_ENDPOINT: ${{ secrets.GRAFANA_CLOUD_OTLP_ENDPOINT }}
103+
GRAFANA_CLOUD_AUTH: ${{ secrets.GRAFANA_CLOUD_AUTH }}
92104
with:
93105
host: ${{ env.VM_HOST }}
94106
username: gcpuser
95107
key: ${{ secrets.VM_SSH_KEY }}
96-
envs: REGISTRY_URL,IMAGE_REPOSITORY,IMAGE_TAG,CONTAINER_NAME,REGION
108+
envs: REGISTRY_URL,IMAGE_REPOSITORY,IMAGE_TAG,CONTAINER_NAME,REGION,GRAFANA_CLOUD_OTLP_ENDPOINT,GRAFANA_CLOUD_AUTH
97109
script: |
98110
until sudo docker info >/dev/null 2>&1; do sleep 3; done
99111
100112
TOKEN=$(curl -sf "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" \
101113
-H "Metadata-Flavor: Google" | python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")
102-
103114
echo $TOKEN | sudo docker login -u oauth2accesstoken --password-stdin https://$REGION-docker.pkg.dev
104115
105-
sudo docker pull $REGISTRY_URL/$IMAGE_REPOSITORY:$IMAGE_TAG
116+
sudo docker network create observability 2>/dev/null || true
106117
107-
sudo docker stop $CONTAINER_NAME 2>/dev/null || true
108-
sudo docker rm $CONTAINER_NAME 2>/dev/null || true
118+
sudo docker rm -f otel-collector 2>/dev/null || true
119+
sudo docker run -d \
120+
--name otel-collector \
121+
--restart always \
122+
--network observability \
123+
--memory 128m \
124+
--cpus 0.15 \
125+
-p 127.0.0.1:4317:4317 \
126+
-p 127.0.0.1:4318:4318 \
127+
-v /opt/otel/collector-config.prod.yaml:/etc/otelcol-contrib/config.yaml:ro \
128+
-e GRAFANA_CLOUD_OTLP_ENDPOINT="$GRAFANA_CLOUD_OTLP_ENDPOINT" \
129+
-e GRAFANA_CLOUD_AUTH="$GRAFANA_CLOUD_AUTH" \
130+
otel/opentelemetry-collector-contrib:0.96.0
109131
132+
sudo docker pull $REGISTRY_URL/$IMAGE_REPOSITORY:$IMAGE_TAG
133+
sudo docker stop $CONTAINER_NAME 2>/dev/null || true
134+
sudo docker rm $CONTAINER_NAME 2>/dev/null || true
110135
sudo docker run -d \
111136
--name $CONTAINER_NAME \
112137
--restart unless-stopped \
138+
--network observability \
113139
--env-file /home/gcpuser/app/.env \
114140
-p 80:8000 \
115141
$REGISTRY_URL/$IMAGE_REPOSITORY:$IMAGE_TAG
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
endpoint: 0.0.0.0:4317
6+
7+
exporters:
8+
debug:
9+
verbosity: detailed
10+
prometheus:
11+
endpoint: 0.0.0.0:8889
12+
send_timestamps: true
13+
14+
processors:
15+
batch:
16+
attributes:
17+
actions:
18+
- action: insert
19+
key: env
20+
value: "${DEPLOY_ENV}"
21+
22+
extensions:
23+
zpages:
24+
endpoint: 0.0.0.0:55679
25+
26+
service:
27+
extensions: [zpages]
28+
pipelines:
29+
metrics:
30+
receivers: [otlp]
31+
processors: [batch, attributes]
32+
exporters: [prometheus]
33+
traces:
34+
receivers: [otlp]
35+
processors: [batch]
36+
exporters: [debug]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
endpoint: 0.0.0.0:4317
6+
http:
7+
endpoint: 0.0.0.0:4318
8+
9+
processors:
10+
memory_limiter:
11+
check_interval: 1s
12+
limit_mib: 100
13+
spike_limit_mib: 20
14+
batch:
15+
timeout: 10s
16+
send_batch_size: 1024
17+
filter/drop_health:
18+
traces:
19+
span:
20+
- 'attributes["http.target"] == "/health"'
21+
- 'attributes["http.target"] == "/metrics"'
22+
23+
exporters:
24+
otlphttp/grafana:
25+
endpoint: ${env:GRAFANA_CLOUD_OTLP_ENDPOINT}
26+
headers:
27+
Authorization: "Basic ${env:GRAFANA_CLOUD_AUTH}"
28+
compression: gzip
29+
retry_on_failure:
30+
enabled: true
31+
initial_interval: 5s
32+
max_interval: 30s
33+
max_elapsed_time: 120s
34+
sending_queue:
35+
enabled: true
36+
queue_size: 1000
37+
38+
extensions:
39+
health_check:
40+
endpoint: 0.0.0.0:13133
41+
42+
service:
43+
extensions: [health_check]
44+
pipelines:
45+
traces:
46+
receivers: [otlp]
47+
processors: [memory_limiter, filter/drop_health, batch]
48+
exporters: [otlphttp/grafana]
49+
metrics:
50+
receivers: [otlp]
51+
processors: [memory_limiter, batch]
52+
exporters: [otlphttp/grafana]
53+

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
"@fastify/cookie": "^11.0.2",
2020
"@fastify/cors": "^11.1.0",
2121
"@fastify/jwt": "^10.0.0",
22+
"@fastify/otel": "^0.17.1",
23+
"@opentelemetry/api": "^1.9.0",
24+
"@opentelemetry/auto-instrumentations-node": "^0.71.0",
25+
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.213.0",
26+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.213.0",
27+
"@opentelemetry/instrumentation-fastify": "^0.57.0",
28+
"@opentelemetry/instrumentation-http": "^0.213.0",
29+
"@opentelemetry/otlp-exporter-base": "^0.213.0",
30+
"@opentelemetry/resources": "^2.6.0",
31+
"@opentelemetry/sdk-metrics": "^2.6.0",
32+
"@opentelemetry/sdk-node": "^0.213.0",
33+
"@opentelemetry/semantic-conventions": "^1.40.0",
2234
"@prisma/adapter-pg": "7",
2335
"@prisma/client": "^7.4.2",
2436
"@prisma/client-runtime-utils": "^7.4.2",

0 commit comments

Comments
 (0)