Skip to content

Commit

Permalink
feat(opentelemetry): improve setup
Browse files Browse the repository at this point in the history
Add missing service name on traces, and exclude /_healthcheck (and /_health) paths.
Also add /_healthcheck and deprecate /_health as others projects.
  • Loading branch information
gfyrag committed Nov 23, 2022
1 parent 8447e4c commit 02ed410
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ EXPOSE 8080

ENTRYPOINT ["payments"]

ENV OTEL_SERVICE_NAME payments

CMD ["server"]
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ services:
ports:
- "27017:27017/tcp"

jaeger:
image: jaegertracing/opentelemetry-all-in-one
ports:
- "16686:16686/tcp"

payments:
image: golang:1.19.3-alpine3.16
depends_on:
Expand All @@ -28,3 +33,8 @@ services:
environment:
DEBUG: ${DEBUG:-"true"}
MONGODB_URI: mongodb://root:root@mongodb:27017
MONGODB_DATABASE: payments
OTEL_SERVICE_NAME: payments
OTEL_TRACES: "true"
OTEL_TRACES_EXPORTER: jaeger
OTEL_TRACES_EXPORTER_JAEGER_ENDPOINT: http://jaeger:14268/api/traces
11 changes: 6 additions & 5 deletions internal/app/api/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
authBearerAudienceFlag = "auth-bearer-audience"
authBearerAudiencesWildcardFlag = "auth-bearer-audiences-wildcard"

serviceName = "Payments"
serviceName = "payments"
)

func HTTPModule() fx.Option {
Expand Down Expand Up @@ -76,18 +76,19 @@ func HTTPModule() fx.Option {
func httpRouter(db *mongo.Database, client *mongo.Client, handlers []connectorHandler) (*mux.Router, error) {
rootMux := mux.NewRouter()

if viper.GetBool(otelTracesFlag) {
rootMux.Use(otelmux.Middleware(serviceName))
}

rootMux.Use(recoveryHandler(httpRecoveryFunc))
rootMux.Use(httpCorsHandler())
rootMux.Use(httpServeFunc)

// Deprecated
rootMux.Path("/_health").Handler(healthHandler(client))
// Deprecated
rootMux.Path("/_live").Handler(liveHandler())

rootMux.Path("/_healthcheck").Handler(healthHandler(client))

authGroup := rootMux.Name("authenticated").Subrouter()
authGroup.Use(otelmux.Middleware(serviceName))

if methods := sharedAuthMethods(); len(methods) > 0 {
authGroup.Use(sharedauth.Middleware(methods...))
Expand Down

0 comments on commit 02ed410

Please sign in to comment.