Skip to content

Commit ef523df

Browse files
committed
Add observability to OE and PDP
1 parent eef05e8 commit ef523df

File tree

21 files changed

+585
-30
lines changed

21 files changed

+585
-30
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ mocks/mock-dmt/Config.toml
4949
# Allow .choreo directories for WSO2 Choreo deployment
5050
!**/.choreo/
5151
!**/.choreo/**
52+
53+
# Database data directories (local development)
54+
exchange/pdp-data/
55+
exchange/ce-data/

exchange/consent-engine/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ func main() {
4040
// Setup logging
4141
utils.SetupLogging(cfg.Logging.Format, cfg.Logging.Level)
4242

43+
// Initialize monitoring/observability (optional - can be disabled via ENABLE_OBSERVABILITY=false)
44+
// Services will continue to function normally even if observability is disabled
45+
if monitoring.IsObservabilityEnabled() {
46+
monitoringConfig := monitoring.DefaultConfig("consent-engine")
47+
if err := monitoring.Initialize(monitoringConfig); err != nil {
48+
slog.Warn("Failed to initialize monitoring (service will continue)", "error", err)
49+
}
50+
} else {
51+
slog.Info("Observability disabled via environment variable")
52+
}
53+
4354
slog.Info("Starting consent engine",
4455
"environment", cfg.Environment,
4556
"port", cfg.Service.Port,

exchange/docker-compose.yml

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,46 @@
33
# docker compose --env-file .env.production up --build
44

55
services:
6+
pdp-db:
7+
image: postgres:16-alpine
8+
container_name: pdp-db-${ENVIRONMENT:-local}
9+
environment:
10+
- POSTGRES_USER=${POSTGRES_USER:-postgres}
11+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
12+
- POSTGRES_DB=${POSTGRES_DB:-testdb}
13+
ports:
14+
- "${PDP_DB_PORT:-5433}:5432"
15+
healthcheck:
16+
test: ["CMD-SHELL", "pg_isready -U postgres"]
17+
interval: 5s
18+
timeout: 5s
19+
retries: 5
20+
networks:
21+
- opendif-network
22+
volumes:
23+
- ./pdp-data:/var/lib/postgresql/data
24+
restart: unless-stopped
25+
26+
ce-db:
27+
image: postgres:16-alpine
28+
container_name: ce-db-${ENVIRONMENT:-local}
29+
environment:
30+
- POSTGRES_USER=${POSTGRES_USER:-postgres}
31+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
32+
- POSTGRES_DB=${CE_DB_NAME:-consent_db}
33+
ports:
34+
- "${CE_DB_PORT:-5434}:5432"
35+
healthcheck:
36+
test: ["CMD-SHELL", "pg_isready -U postgres"]
37+
interval: 5s
38+
timeout: 5s
39+
retries: 5
40+
networks:
41+
- opendif-network
42+
volumes:
43+
- ./ce-data:/var/lib/postgresql/data
44+
restart: unless-stopped
45+
646
policy-decision-point:
747
build:
848
context: .
@@ -21,7 +61,19 @@ services:
2161
- LOG_LEVEL=${LOG_LEVEL:-info}
2262
- LOG_FORMAT=${LOG_FORMAT:-text}
2363
- SERVICE_NAME=policy-decision-point
64+
- ENABLE_OBSERVABILITY=${ENABLE_OBSERVABILITY:-true}
65+
- OTEL_METRICS_ENABLED=${OTEL_METRICS_ENABLED:-true}
2466
- OTEL_METRICS_EXPORTER=${OTEL_METRICS_EXPORTER:-prometheus}
67+
- CHOREO_OPENDIF_DATABASE_HOSTNAME=pdp-db
68+
- CHOREO_OPENDIF_DATABASE_PORT=5432
69+
- CHOREO_OPENDIF_DATABASE_USERNAME=${POSTGRES_USER:-postgres}
70+
- CHOREO_OPENDIF_DATABASE_PASSWORD=${POSTGRES_PASSWORD:-password}
71+
- CHOREO_OPENDIF_DATABASE_DATABASENAME=${POSTGRES_DB:-testdb}
72+
- DB_SSLMODE=disable
73+
- RUN_MIGRATION=true
74+
depends_on:
75+
pdp-db:
76+
condition: service_healthy
2577
healthcheck:
2678
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8082/health"]
2779
interval: 30s
@@ -49,12 +101,30 @@ services:
49101
- PORT=8081
50102
- LOG_LEVEL=${LOG_LEVEL:-info}
51103
- LOG_FORMAT=${LOG_FORMAT:-text}
104+
- SERVICE_NAME=consent-engine
105+
- ENABLE_OBSERVABILITY=${ENABLE_OBSERVABILITY:-true}
106+
- OTEL_METRICS_ENABLED=${OTEL_METRICS_ENABLED:-true}
107+
- OTEL_METRICS_EXPORTER=${OTEL_METRICS_EXPORTER:-prometheus}
108+
- CHOREO_OPENDIF_DATABASE_HOSTNAME=ce-db
109+
- CHOREO_OPENDIF_DATABASE_PORT=5432
110+
- CHOREO_OPENDIF_DATABASE_USERNAME=${POSTGRES_USER:-postgres}
111+
- CHOREO_OPENDIF_DATABASE_PASSWORD=${POSTGRES_PASSWORD:-password}
112+
- CHOREO_OPENDIF_DATABASE_DATABASENAME=${CE_DB_NAME:-consent_db}
113+
- DB_SSLMODE=disable
114+
- RUN_MIGRATION=true
115+
- ASGARDEO_JWKS_URL=${ASGARDEO_JWKS_URL:-https://www.googleapis.com/oauth2/v3/certs}
116+
- ASGARDEO_ISSUER=${ASGARDEO_ISSUER:-https://accounts.google.com}
117+
- ASGARDEO_AUDIENCE=${ASGARDEO_AUDIENCE:-test-audience}
118+
- ASGARDEO_ORG_NAME=${ASGARDEO_ORG_NAME:-test-org}
119+
depends_on:
120+
ce-db:
121+
condition: service_healthy
52122
healthcheck:
53123
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8081/health"]
54124
interval: 30s
55125
timeout: 10s
56126
retries: 3
57-
start_period: 10s
127+
start_period: 30s
58128
restart: unless-stopped
59129
networks:
60130
- opendif-network
@@ -77,7 +147,18 @@ services:
77147
- LOG_LEVEL=${LOG_LEVEL:-info}
78148
- LOG_FORMAT=${LOG_FORMAT:-text}
79149
- SERVICE_NAME=orchestration-engine
150+
- ENABLE_OBSERVABILITY=${ENABLE_OBSERVABILITY:-true}
151+
- OTEL_METRICS_ENABLED=${OTEL_METRICS_ENABLED:-true}
80152
- OTEL_METRICS_EXPORTER=${OTEL_METRICS_EXPORTER:-prometheus}
153+
- CONFIG_PATH=/app/config/config.json
154+
- DB_HOST=${DB_HOST?DB_HOST is required}
155+
- DB_PORT=${DB_PORT:-5432}
156+
- DB_USER=${DB_USER:-postgres}
157+
- DB_PASSWORD=${DB_PASSWORD?DB_PASSWORD is required}
158+
- DB_NAME=${DB_NAME:-orchestration_engine}
159+
- DB_SSLMODE=${DB_SSLMODE:-disable}
160+
volumes:
161+
- ./minimal-config.json:/app/config/config.json:ro
81162
healthcheck:
82163
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:4000/health"]
83164
interval: 30s

exchange/minimal-config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ceUrl": "http://consent-engine:8081",
3+
"pdpUrl": "http://policy-decision-point:8082",
4+
"providers": [],
5+
"argMappings": []
6+
}

exchange/orchestration-engine/go.mod

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,46 @@ require (
1414

1515
require github.com/go-chi/chi/v5 v5.2.3
1616

17+
require github.com/gov-dx-sandbox/exchange/shared/monitoring v0.0.0
18+
19+
require (
20+
github.com/beorn7/perks v1.0.1 // indirect
21+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
22+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
23+
github.com/go-logr/logr v1.4.2 // indirect
24+
github.com/go-logr/stdr v1.2.2 // indirect
25+
github.com/google/uuid v1.6.0 // indirect
26+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
27+
github.com/klauspost/compress v1.17.9 // indirect
28+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
29+
github.com/prometheus/client_golang v1.20.5 // indirect
30+
github.com/prometheus/client_model v0.6.1 // indirect
31+
github.com/prometheus/common v0.60.1 // indirect
32+
github.com/prometheus/procfs v0.15.1 // indirect
33+
go.opentelemetry.io/otel v1.32.0 // indirect
34+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.32.0 // indirect
35+
go.opentelemetry.io/otel/exporters/prometheus v0.54.0 // indirect
36+
go.opentelemetry.io/otel/metric v1.32.0 // indirect
37+
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
38+
go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect
39+
go.opentelemetry.io/otel/trace v1.32.0 // indirect
40+
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
41+
golang.org/x/net v0.30.0 // indirect
42+
golang.org/x/sys v0.27.0 // indirect
43+
golang.org/x/text v0.20.0 // indirect
44+
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
45+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
46+
google.golang.org/grpc v1.67.1 // indirect
47+
google.golang.org/protobuf v1.35.1 // indirect
48+
)
49+
1750
require (
1851
github.com/davecgh/go-spew v1.1.1 // indirect
1952
github.com/golang-jwt/jwt/v5 v5.3.0
2053
github.com/pmezard/go-difflib v1.0.0 // indirect
2154
gopkg.in/yaml.v3 v3.0.1 // indirect
2255
)
2356

57+
replace github.com/gov-dx-sandbox/exchange/shared/monitoring => ../shared/monitoring
58+
2459
replace github.com/gov-dx-sandbox/audit-service => ../../audit-service
Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,88 @@
1+
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
2+
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
3+
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
4+
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
5+
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
6+
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
17
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
28
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
39
github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE=
410
github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
11+
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
12+
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
13+
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
14+
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
15+
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
516
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
617
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
18+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
19+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
20+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
21+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
722
github.com/graphql-go/graphql v0.8.1 h1:p7/Ou/WpmulocJeEx7wjQy611rtXGQaAcXGqanuMMgc=
823
github.com/graphql-go/graphql v0.8.1/go.mod h1:nKiHzRM0qopJEwCITUuIsxk9PlVlwIiiI8pnJEhordQ=
24+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 h1:ad0vkEBuk23VJzZR9nkLVG0YAoN9coASF1GusYX6AlU=
25+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0/go.mod h1:igFoXX2ELCW06bol23DWPB5BEWfZISOzSP5K2sbLea0=
26+
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
27+
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
28+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
29+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
30+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
31+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
32+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
33+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
934
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
1035
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
36+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
37+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
1138
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1239
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
40+
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
41+
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
42+
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
43+
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
44+
github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc=
45+
github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw=
46+
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
47+
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
48+
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
49+
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
1350
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
1451
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
52+
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
53+
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
54+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.32.0 h1:t/Qur3vKSkUCcDVaSumWF2PKHt85pc7fRvFuoVT8qFU=
55+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.32.0/go.mod h1:Rl61tySSdcOJWoEgYZVtmnKdA0GeKrSqkHC1t+91CH8=
56+
go.opentelemetry.io/otel/exporters/prometheus v0.54.0 h1:rFwzp68QMgtzu9PgP3jm9XaMICI6TsofWWPcBDKwlsU=
57+
go.opentelemetry.io/otel/exporters/prometheus v0.54.0/go.mod h1:QyjcV9qDP6VeK5qPyKETvNjmaaEc7+gqjh4SS0ZYzDU=
58+
go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=
59+
go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
60+
go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
61+
go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
62+
go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU=
63+
go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=
64+
go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
65+
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
66+
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
67+
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
68+
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
69+
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
1570
golang.org/x/oauth2 v0.32.0 h1:jsCblLleRMDrxMN29H3z/k1KliIvpLgCkE6R8FXXNgY=
1671
golang.org/x/oauth2 v0.32.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
17-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
72+
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
73+
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
74+
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
75+
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
76+
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g=
77+
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4=
78+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 h1:XVhgTWWV3kGQlwJHR3upFWZeTsei6Oks1apkZSeonIE=
79+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
80+
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
81+
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
82+
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
83+
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
1884
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
85+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
86+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
1987
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2088
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

exchange/orchestration-engine/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@ import (
1010
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/middleware"
1111
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/provider"
1212
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/server"
13+
"github.com/gov-dx-sandbox/exchange/shared/monitoring"
1314
)
1415

1516
func main() {
1617
logger.Init()
1718

19+
// Initialize monitoring/observability (optional - can be disabled via ENABLE_OBSERVABILITY=false)
20+
// Services will continue to function normally even if observability is disabled
21+
if monitoring.IsObservabilityEnabled() {
22+
monitoringConfig := monitoring.DefaultConfig("orchestration-engine")
23+
if err := monitoring.Initialize(monitoringConfig); err != nil {
24+
logger.Log.Warn("Failed to initialize monitoring (service will continue)", "error", err)
25+
}
26+
} else {
27+
logger.Log.Info("Observability disabled via environment variable")
28+
}
29+
1830
// Load configuration with proper error handling
1931
config, err := configs.LoadConfig()
2032
if err != nil {

exchange/orchestration-engine/provider/provider.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"fmt"
77
"net/http"
88
"sync"
9+
"time"
910

1011
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/logger"
1112
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/pkg/auth"
13+
"github.com/gov-dx-sandbox/exchange/shared/monitoring"
1214
"golang.org/x/oauth2/clientcredentials"
1315
)
1416

@@ -47,7 +49,7 @@ func NewProvider(serviceKey, serviceUrl, schemaID string, authConfig *auth.AuthC
4749
}
4850

4951
// PerformRequest performs the HTTP request to the provider with necessary authentication.
50-
func (p *Provider) PerformRequest(ctx context.Context, reqBody []byte) (*http.Response, error) {
52+
func (p *Provider) PerformRequest(ctx context.Context, reqBody []byte) (resp *http.Response, err error) {
5153
// 1. Create Request
5254
req, err := http.NewRequestWithContext(ctx, "POST", p.ServiceUrl, bytes.NewBuffer(reqBody))
5355
if err != nil {
@@ -56,21 +58,29 @@ func (p *Provider) PerformRequest(ctx context.Context, reqBody []byte) (*http.Re
5658

5759
req.Header.Set("Content-Type", "application/json")
5860

61+
start := time.Now()
62+
defer func() {
63+
monitoring.RecordExternalCall(p.ServiceKey, "provider_request", time.Since(start), err)
64+
}()
65+
5966
if p.Auth != nil {
6067
switch p.Auth.Type {
6168
case auth.AuthTypeOAuth2:
6269
if p.OAuth2Config == nil {
63-
logger.Log.Error("OAuth2Config is nil", "providerKey", p.ServiceKey)
64-
return nil, fmt.Errorf("OAuth2Config is nil")
70+
err = fmt.Errorf("OAuth2Config is nil")
71+
logger.Log.Error(err.Error(), "providerKey", p.ServiceKey)
72+
return
6573
}
6674

6775
client := p.OAuth2Config.Client(ctx)
68-
return client.Do(req) // Use context with request
76+
resp, err = client.Do(req)
77+
return
6978
case auth.AuthTypeAPIKey:
7079
req.Header.Set(p.Auth.APIKeyName, p.Auth.APIKeyValue)
7180
}
7281
}
7382

7483
// Default client execution (for API Key or no auth)
75-
return p.Client.Do(req)
84+
resp, err = p.Client.Do(req)
85+
return
7686
}

0 commit comments

Comments
 (0)