Compare commits
	
		
			22 Commits
		
	
	
		
			v0.9.3
			...
			11b2c2487c
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 11b2c2487c | |||
| c7e42a7544 | |||
| 8d6297a0cb | |||
| 340cf67515 | |||
| f5cb3456b1 | |||
| f0c3bc6b9e | |||
| 00cb0d0421 | |||
| ede5bc92f7 | |||
| 063ff0f1d0 | |||
| 2310ac574c | |||
| cb0c87d200 | |||
| 92e78f533a | |||
| d4c6ecbefd | |||
| e1d58c0094 | |||
| 9cee9037e4 | |||
| 318115690d | |||
| 8b4bb890be | |||
| e841e11168 | |||
| 7c78416948 | |||
| 31fc6dca16 | |||
| 41d539a607 | |||
| a875f0bb22 | 
							
								
								
									
										29
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					# v0.12.1
 | 
				
			||||||
 | 
					* feat: Implement custom OpenTelemetry span name formatting for HTTP requests.
 | 
				
			||||||
 | 
					* refactor: Streamline OpenTelemetry handler integration by removing custom wrapper.
 | 
				
			||||||
 | 
					## v0.12.2
 | 
				
			||||||
 | 
					* chore: Update Go module dependencies, including OpenTelemetry, gRPC Gateway, gRPC, and Protobuf.
 | 
				
			||||||
 | 
					* chore: Add new test suites for logging, OpenTelemetry initialization, gRPC server setup, and HTTP server setup.
 | 
				
			||||||
 | 
					* chore: Enhance configuration loading tests to cover file and environment variable sources.
 | 
				
			||||||
 | 
					* chore: Improve config test comparison robustness using JSON marshaling.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# v0.12.0
 | 
				
			||||||
 | 
					* feat: Add support for excluding HTTP request paths from logging using configurable regular expressions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# v0.11.1:
 | 
				
			||||||
 | 
					* docs: Add comprehensive package-level documentation for the `http` package.
 | 
				
			||||||
 | 
					* docs: Improve documentation for the `InitHTTPServer` function.
 | 
				
			||||||
 | 
					* feat: Introduce specific logging for HTTP 204 (No Content) responses, omitting body logging.
 | 
				
			||||||
 | 
					* fix: Enhance error handling and logging for empty or unreadable HTTP response bodies.
 | 
				
			||||||
 | 
					* chore: Refine HTTP response log messages for improved clarity and consistency.
 | 
				
			||||||
 | 
					* docs: Update documentation for the `Flush` method in `LoggingResponseWriter`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# v0.11.0:
 | 
				
			||||||
 | 
					*   Updated `github.com/prometheus/client_golang` dependency to v1.23.0.
 | 
				
			||||||
 | 
					*   Updated `google.golang.org/grpc` dependency to v1.74.2.
 | 
				
			||||||
 | 
					*   Added a `replace` directive for `github.com/prometheus/otlptranslator`.
 | 
				
			||||||
 | 
					*   Renamed `initOTEL` function to `InitOTEL` and added a check to prevent re-initialization.
 | 
				
			||||||
 | 
					*   Improved `dummyHealthCheck` to ensure a positive random duration.
 | 
				
			||||||
 | 
					*   Added comprehensive package, struct, and function comments across `pkg/app`, `pkg/config`, `pkg/logging`, `pkg/otel`, `pkg/srv/grpc`, and `pkg/srv/http` for improved clarity.
 | 
				
			||||||
 | 
					*   Corrected typos in `TODO.md` for "implementing" and "support".
 | 
				
			||||||
 | 
					*   Added a new item to `TODO.md` for early OpenTelemetry initialization.
 | 
				
			||||||
							
								
								
									
										6
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								TODO.md
									
									
									
									
									
								
							@@ -1,11 +1,15 @@
 | 
				
			|||||||
# TODO
 | 
					# TODO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- [ ] Add ability to initialize OTEL early (before app runs)
 | 
				
			||||||
 | 
					- [ ] Spruce up the README
 | 
				
			||||||
 | 
					- [ ] Create generic interface for implementing a service
 | 
				
			||||||
 | 
					- [ ] Create config sample not called demo, so it is more easily reused
 | 
				
			||||||
- [ ] Expand config test case to cover GRPC config
 | 
					- [ ] Expand config test case to cover GRPC config
 | 
				
			||||||
- [ ] Expand tracing
 | 
					- [ ] Expand tracing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Done
 | 
					## Done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- [x] Test and troubleshoot GRPC Gateway supprot
 | 
					- [x] Test and troubleshoot GRPC Gateway support
 | 
				
			||||||
- [x] Finish implementing GRPC service support
 | 
					- [x] Finish implementing GRPC service support
 | 
				
			||||||
- [x] Unit tests
 | 
					- [x] Unit tests
 | 
				
			||||||
- [x] Pattern for extending config
 | 
					- [x] Pattern for extending config
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										70
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										70
									
								
								go.mod
									
									
									
									
									
								
							@@ -3,50 +3,62 @@ module gitea.libretechconsulting.com/rmcguire/go-app
 | 
				
			|||||||
go 1.24.2
 | 
					go 1.24.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
 | 
						buf.build/go/protovalidate v0.14.0
 | 
				
			||||||
	github.com/caarlos0/env/v11 v11.3.1
 | 
						github.com/caarlos0/env/v11 v11.3.1
 | 
				
			||||||
	github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2
 | 
						github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2
 | 
				
			||||||
	github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3
 | 
						github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2
 | 
				
			||||||
	github.com/prometheus/client_golang v1.22.0
 | 
						github.com/prometheus/client_golang v1.23.0
 | 
				
			||||||
	github.com/rs/zerolog v1.34.0
 | 
						github.com/rs/zerolog v1.34.0
 | 
				
			||||||
	github.com/swaggest/jsonschema-go v0.3.73
 | 
						github.com/stretchr/testify v1.11.1
 | 
				
			||||||
	go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0
 | 
						github.com/swaggest/jsonschema-go v0.3.78
 | 
				
			||||||
	go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0
 | 
						go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0
 | 
				
			||||||
	go.opentelemetry.io/otel v1.35.0
 | 
						go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0
 | 
				
			||||||
	go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.35.0
 | 
						go.opentelemetry.io/otel v1.38.0
 | 
				
			||||||
	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0
 | 
						go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.38.0
 | 
				
			||||||
	go.opentelemetry.io/otel/exporters/prometheus v0.57.0
 | 
						go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0
 | 
				
			||||||
	go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.35.0
 | 
						go.opentelemetry.io/otel/exporters/prometheus v0.60.0
 | 
				
			||||||
	go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.35.0
 | 
						go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.38.0
 | 
				
			||||||
	go.opentelemetry.io/otel/metric v1.35.0
 | 
						go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.38.0
 | 
				
			||||||
	go.opentelemetry.io/otel/sdk v1.35.0
 | 
						go.opentelemetry.io/otel/metric v1.38.0
 | 
				
			||||||
	go.opentelemetry.io/otel/sdk/metric v1.35.0
 | 
						go.opentelemetry.io/otel/sdk v1.38.0
 | 
				
			||||||
	go.opentelemetry.io/otel/trace v1.35.0
 | 
						go.opentelemetry.io/otel/sdk/metric v1.38.0
 | 
				
			||||||
	google.golang.org/grpc v1.72.0
 | 
						go.opentelemetry.io/otel/trace v1.38.0
 | 
				
			||||||
 | 
						google.golang.org/grpc v1.75.0
 | 
				
			||||||
	gopkg.in/yaml.v3 v3.0.1
 | 
						gopkg.in/yaml.v3 v3.0.1
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
 | 
						buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.8-20250717185734-6c6e0d3c608e.1 // indirect
 | 
				
			||||||
 | 
						cel.dev/expr v0.24.0 // indirect
 | 
				
			||||||
 | 
						github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
 | 
				
			||||||
	github.com/beorn7/perks v1.0.1 // indirect
 | 
						github.com/beorn7/perks v1.0.1 // indirect
 | 
				
			||||||
	github.com/cenkalti/backoff/v4 v4.3.0 // indirect
 | 
						github.com/cenkalti/backoff/v5 v5.0.3 // indirect
 | 
				
			||||||
	github.com/cespare/xxhash/v2 v2.3.0 // indirect
 | 
						github.com/cespare/xxhash/v2 v2.3.0 // indirect
 | 
				
			||||||
 | 
						github.com/davecgh/go-spew v1.1.1 // indirect
 | 
				
			||||||
	github.com/felixge/httpsnoop v1.0.4 // indirect
 | 
						github.com/felixge/httpsnoop v1.0.4 // indirect
 | 
				
			||||||
	github.com/go-logr/logr v1.4.2 // indirect
 | 
						github.com/go-logr/logr v1.4.3 // indirect
 | 
				
			||||||
	github.com/go-logr/stdr v1.2.2 // indirect
 | 
						github.com/go-logr/stdr v1.2.2 // indirect
 | 
				
			||||||
 | 
						github.com/google/cel-go v0.26.1 // indirect
 | 
				
			||||||
	github.com/google/uuid v1.6.0 // indirect
 | 
						github.com/google/uuid v1.6.0 // indirect
 | 
				
			||||||
 | 
						github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
 | 
				
			||||||
	github.com/mattn/go-colorable v0.1.14 // indirect
 | 
						github.com/mattn/go-colorable v0.1.14 // indirect
 | 
				
			||||||
	github.com/mattn/go-isatty v0.0.20 // indirect
 | 
						github.com/mattn/go-isatty v0.0.20 // indirect
 | 
				
			||||||
	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
 | 
						github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
 | 
				
			||||||
 | 
						github.com/pmezard/go-difflib v1.0.0 // indirect
 | 
				
			||||||
	github.com/prometheus/client_model v0.6.2 // indirect
 | 
						github.com/prometheus/client_model v0.6.2 // indirect
 | 
				
			||||||
	github.com/prometheus/common v0.63.0 // indirect
 | 
						github.com/prometheus/common v0.65.0 // indirect
 | 
				
			||||||
	github.com/prometheus/procfs v0.16.1 // indirect
 | 
						github.com/prometheus/otlptranslator v0.0.2 // indirect
 | 
				
			||||||
	github.com/swaggest/refl v1.3.1 // indirect
 | 
						github.com/prometheus/procfs v0.17.0 // indirect
 | 
				
			||||||
 | 
						github.com/stoewer/go-strcase v1.3.1 // indirect
 | 
				
			||||||
 | 
						github.com/swaggest/refl v1.4.0 // indirect
 | 
				
			||||||
	go.opentelemetry.io/auto/sdk v1.1.0 // indirect
 | 
						go.opentelemetry.io/auto/sdk v1.1.0 // indirect
 | 
				
			||||||
	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
 | 
						go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect
 | 
				
			||||||
	go.opentelemetry.io/proto/otlp v1.6.0 // indirect
 | 
						go.opentelemetry.io/proto/otlp v1.7.1 // indirect
 | 
				
			||||||
	golang.org/x/net v0.39.0 // indirect
 | 
						golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect
 | 
				
			||||||
	golang.org/x/sys v0.32.0 // indirect
 | 
						golang.org/x/net v0.43.0 // indirect
 | 
				
			||||||
	golang.org/x/text v0.24.0 // indirect
 | 
						golang.org/x/sys v0.35.0 // indirect
 | 
				
			||||||
	google.golang.org/genproto/googleapis/api v0.0.0-20250428153025-10db94c68c34 // indirect
 | 
						golang.org/x/text v0.28.0 // indirect
 | 
				
			||||||
	google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34 // indirect
 | 
						google.golang.org/genproto/googleapis/api v0.0.0-20250826171959-ef028d996bc1 // indirect
 | 
				
			||||||
	google.golang.org/protobuf v1.36.6 // indirect
 | 
						google.golang.org/genproto/googleapis/rpc v0.0.0-20250826171959-ef028d996bc1 // indirect
 | 
				
			||||||
 | 
						google.golang.org/protobuf v1.36.8 // indirect
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										148
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										148
									
								
								go.sum
									
									
									
									
									
								
							@@ -1,3 +1,11 @@
 | 
				
			|||||||
 | 
					buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.8-20250717185734-6c6e0d3c608e.1 h1:sjY1k5uszbIZfv11HO2keV4SLhNA47SabPO886v7Rvo=
 | 
				
			||||||
 | 
					buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.8-20250717185734-6c6e0d3c608e.1/go.mod h1:8EQ5GzyGJQ5tEIwMSxCl8RKJYsjCpAwkdcENoioXT6g=
 | 
				
			||||||
 | 
					buf.build/go/protovalidate v0.14.0 h1:kr/rC/no+DtRyYX+8KXLDxNnI1rINz0imk5K44ZpZ3A=
 | 
				
			||||||
 | 
					buf.build/go/protovalidate v0.14.0/go.mod h1:+F/oISho9MO7gJQNYC2VWLzcO1fTPmaTA08SDYJZncA=
 | 
				
			||||||
 | 
					cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY=
 | 
				
			||||||
 | 
					cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
 | 
				
			||||||
 | 
					github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
 | 
				
			||||||
 | 
					github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
 | 
				
			||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
 | 
					github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
 | 
				
			||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
 | 
					github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
 | 
				
			||||||
github.com/bool64/dev v0.2.39 h1:kP8DnMGlWXhGYJEZE/J0l/gVBdbuhoPGL+MJG4QbofE=
 | 
					github.com/bool64/dev v0.2.39 h1:kP8DnMGlWXhGYJEZE/J0l/gVBdbuhoPGL+MJG4QbofE=
 | 
				
			||||||
@@ -6,31 +14,36 @@ github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
 | 
				
			|||||||
github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs=
 | 
					github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs=
 | 
				
			||||||
github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA=
 | 
					github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA=
 | 
				
			||||||
github.com/caarlos0/env/v11 v11.3.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U=
 | 
					github.com/caarlos0/env/v11 v11.3.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U=
 | 
				
			||||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
 | 
					github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
 | 
				
			||||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
 | 
					github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
 | 
				
			||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
 | 
					github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
 | 
				
			||||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
 | 
					github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
 | 
				
			||||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
 | 
					github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
 | 
				
			||||||
 | 
					github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
				
			||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
					github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
				
			||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
					github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
				
			||||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
 | 
					github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
 | 
				
			||||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
 | 
					github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
 | 
				
			||||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
 | 
					github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
 | 
				
			||||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
 | 
					github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
 | 
				
			||||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
 | 
					github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
 | 
				
			||||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
 | 
					github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
 | 
				
			||||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
 | 
					github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
 | 
				
			||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 | 
					github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 | 
				
			||||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
 | 
					github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
 | 
				
			||||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
 | 
					github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
 | 
				
			||||||
 | 
					github.com/google/cel-go v0.26.1 h1:iPbVVEdkhTX++hpe3lzSk7D3G3QSYqLGoHOcEio+UXQ=
 | 
				
			||||||
 | 
					github.com/google/cel-go v0.26.1/go.mod h1:A9O8OU9rdvrK5MQyrqfIxo1a0u4g3sF8KB6PUIaryMM=
 | 
				
			||||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
 | 
					github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
 | 
				
			||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
 | 
					github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
 | 
				
			||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
 | 
					github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
 | 
				
			||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 | 
					github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 | 
				
			||||||
 | 
					github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrRoT6yV5+wkrOpcszoIsO4+4ds248=
 | 
				
			||||||
 | 
					github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk=
 | 
				
			||||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 h1:sGm2vDRFUrQJO/Veii4h4zG2vvqG6uWNkBHSTqXOZk0=
 | 
					github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 h1:sGm2vDRFUrQJO/Veii4h4zG2vvqG6uWNkBHSTqXOZk0=
 | 
				
			||||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2/go.mod h1:wd1YpapPLivG6nQgbf7ZkG1hhSOXDhhn4MLTknx2aAc=
 | 
					github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2/go.mod h1:wd1YpapPLivG6nQgbf7ZkG1hhSOXDhhn4MLTknx2aAc=
 | 
				
			||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 h1:5ZPtiqj0JL5oKWmcsq4VMaAW5ukBEgSGXEN89zeH1Jo=
 | 
					github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU=
 | 
				
			||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3/go.mod h1:ndYquD05frm2vACXE1nsccT4oJzjhw2arTS2cpUD1PI=
 | 
					github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
 | 
				
			||||||
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
 | 
					github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
 | 
				
			||||||
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
 | 
					github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
 | 
				
			||||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
 | 
					github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
 | 
				
			||||||
@@ -53,14 +66,16 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
 | 
				
			|||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 | 
					github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 | 
				
			||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 | 
					github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 | 
				
			||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
					github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
				
			||||||
github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q=
 | 
					github.com/prometheus/client_golang v1.23.0 h1:ust4zpdl9r4trLY/gSjlm07PuiBq2ynaXXlptpfy8Uc=
 | 
				
			||||||
github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0=
 | 
					github.com/prometheus/client_golang v1.23.0/go.mod h1:i/o0R9ByOnHX0McrTMTyhYvKE4haaf2mW08I+jGAjEE=
 | 
				
			||||||
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
 | 
					github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
 | 
				
			||||||
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
 | 
					github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
 | 
				
			||||||
github.com/prometheus/common v0.63.0 h1:YR/EIY1o3mEFP/kZCD7iDMnLPlGyuU2Gb3HIcXnA98k=
 | 
					github.com/prometheus/common v0.65.0 h1:QDwzd+G1twt//Kwj/Ww6E9FQq1iVMmODnILtW1t2VzE=
 | 
				
			||||||
github.com/prometheus/common v0.63.0/go.mod h1:VVFF/fBIoToEnWRVkYoXEkq3R3paCoxG9PXP74SnV18=
 | 
					github.com/prometheus/common v0.65.0/go.mod h1:0gZns+BLRQ3V6NdaerOhMbwwRbNh9hkGINtQAsP5GS8=
 | 
				
			||||||
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
 | 
					github.com/prometheus/otlptranslator v0.0.2 h1:+1CdeLVrRQ6Psmhnobldo0kTp96Rj80DRXRd5OSnMEQ=
 | 
				
			||||||
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
 | 
					github.com/prometheus/otlptranslator v0.0.2/go.mod h1:P8AwMgdD7XEr6QRUJ2QWLpiAZTgTE2UYgjlu3svompI=
 | 
				
			||||||
 | 
					github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
 | 
				
			||||||
 | 
					github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
 | 
				
			||||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
 | 
					github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
 | 
				
			||||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
 | 
					github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
 | 
				
			||||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
 | 
					github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
 | 
				
			||||||
@@ -68,69 +83,82 @@ github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
 | 
				
			|||||||
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
 | 
					github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
 | 
				
			||||||
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
 | 
					github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
 | 
				
			||||||
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
 | 
					github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
 | 
				
			||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
 | 
					github.com/stoewer/go-strcase v1.3.1 h1:iS0MdW+kVTxgMoE1LAZyMiYJFKlOzLooE4MxjirtkAs=
 | 
				
			||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 | 
					github.com/stoewer/go-strcase v1.3.1/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
 | 
				
			||||||
 | 
					github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 | 
				
			||||||
 | 
					github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 | 
				
			||||||
 | 
					github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
 | 
				
			||||||
 | 
					github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
				
			||||||
 | 
					github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 | 
				
			||||||
 | 
					github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 | 
				
			||||||
 | 
					github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
 | 
				
			||||||
 | 
					github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
 | 
				
			||||||
github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ=
 | 
					github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ=
 | 
				
			||||||
github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU=
 | 
					github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU=
 | 
				
			||||||
github.com/swaggest/jsonschema-go v0.3.73 h1:gU1pBzF3pkZ1GDD3dRMdQoCjrA0sldJ+QcM7aSSPgvc=
 | 
					github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw=
 | 
				
			||||||
github.com/swaggest/jsonschema-go v0.3.73/go.mod h1:qp+Ym2DIXHlHzch3HKz50gPf2wJhKOrAB/VYqLS2oJU=
 | 
					github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g=
 | 
				
			||||||
github.com/swaggest/refl v1.3.1 h1:XGplEkYftR7p9cz1lsiwXMM2yzmOymTE9vneVVpaOh4=
 | 
					github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k=
 | 
				
			||||||
github.com/swaggest/refl v1.3.1/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA=
 | 
					github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA=
 | 
				
			||||||
github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
 | 
					github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
 | 
				
			||||||
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
 | 
					github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
 | 
				
			||||||
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
 | 
					github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
 | 
				
			||||||
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
 | 
					github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
 | 
				
			||||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
 | 
					go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
 | 
				
			||||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
 | 
					go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
 | 
				
			||||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 h1:x7wzEgXfnzJcHDwStJT+mxOz4etr2EcexjqhBvmoakw=
 | 
					go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0 h1:YH4g8lQroajqUwWbq/tr2QX1JFmEXaDLgG+ew9bLMWo=
 | 
				
			||||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0/go.mod h1:rg+RlpR5dKwaS95IyyZqj5Wd4E13lk/msnTS0Xl9lJM=
 | 
					go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0/go.mod h1:fvPi2qXDqFs8M4B4fmJhE92TyQs9Ydjlg3RvfUp+NbQ=
 | 
				
			||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 h1:sbiXRNDSWJOTobXh5HyQKjq6wUC5tNybqjIqDpAY4CU=
 | 
					go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 h1:RbKq8BG0FI8OiXhBfcRtqqHcZcka+gU3cskNuf05R18=
 | 
				
			||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0/go.mod h1:69uWxva0WgAA/4bu2Yy70SLDBwZXuQ6PbBpbsa5iZrQ=
 | 
					go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0/go.mod h1:h06DGIukJOevXaj/xrNjhi/2098RZzcLTbc0jDAUbsg=
 | 
				
			||||||
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
 | 
					go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
 | 
				
			||||||
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
 | 
					go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.35.0 h1:QcFwRrZLc82r8wODjvyCbP7Ifp3UANaBSmhDSFjnqSc=
 | 
					go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.38.0 h1:vl9obrcoWVKp/lwl8tRE33853I8Xru9HFbw/skNeLs8=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.35.0/go.mod h1:CXIWhUomyWBG/oY2/r/kLp6K/cmx9e/7DLpBuuGdLCA=
 | 
					go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.38.0/go.mod h1:GAXRxmLJcVM3u22IjTg74zWBrRCKq8BnOqUVLodpcpw=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 h1:1fTNlAIJZGWLP5FVu0fikVry1IsiUnXjf7QFvoNN3Xw=
 | 
					go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 h1:GqRJVj7UmLjCVyVJ3ZFLdPRmhDUp2zFmQe3RHIOsw24=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0/go.mod h1:zjPK58DtkqQFn+YUMbx0M2XV3QgKU0gS9LeGohREyK4=
 | 
					go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0/go.mod h1:ri3aaHSmCTVYu2AWv44YMauwAQc0aqI9gHKIcSbI1pU=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0 h1:m639+BofXTvcY1q8CGs4ItwQarYtJPOWmVobfM1HpVI=
 | 
					go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0 h1:lwI4Dc5leUqENgGuQImwLo4WnuXFPetmPpkLi2IrX54=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0/go.mod h1:LjReUci/F4BUyv+y4dwnq3h/26iNOeC3wAIqgvTIZVo=
 | 
					go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0/go.mod h1:Kz/oCE7z5wuyhPxsXDuaPteSWqjSBD5YaSdbxZYGbGk=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/prometheus v0.57.0 h1:AHh/lAP1BHrY5gBwk8ncc25FXWm/gmmY3BX258z5nuk=
 | 
					go.opentelemetry.io/otel/exporters/prometheus v0.60.0 h1:cGtQxGvZbnrWdC2GyjZi0PDKVSLWP/Jocix3QWfXtbo=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/prometheus v0.57.0/go.mod h1:QpFWz1QxqevfjwzYdbMb4Y1NnlJvqSGwyuU0B4iuc9c=
 | 
					go.opentelemetry.io/otel/exporters/prometheus v0.60.0/go.mod h1:hkd1EekxNo69PTV4OWFGZcKQiIqg0RfuWExcPKFvepk=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.35.0 h1:PB3Zrjs1sG1GBX51SXyTSoOTqcDglmsk7nT6tkKPb/k=
 | 
					go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.38.0 h1:wm/Q0GAAykXv83wzcKzGGqAnnfLFyFe7RslekZuv+VI=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.35.0/go.mod h1:U2R3XyVPzn0WX7wOIypPuptulsMcPDPs/oiSVOMVnHY=
 | 
					go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.38.0/go.mod h1:ra3Pa40+oKjvYh+ZD3EdxFZZB0xdMfuileHAm4nNN7w=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.35.0 h1:T0Ec2E+3YZf5bgTNQVet8iTDW7oIk03tXHq+wkwIDnE=
 | 
					go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.38.0 h1:kJxSDN4SgWWTjG/hPp3O7LCGLcHXFlvS2/FFOrwL+SE=
 | 
				
			||||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.35.0/go.mod h1:30v2gqH+vYGJsesLWFov8u47EpYTcIQcBjKpI6pJThg=
 | 
					go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.38.0/go.mod h1:mgIOzS7iZeKJdeB8/NYHrJ48fdGc71Llo5bJ1J4DWUE=
 | 
				
			||||||
go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
 | 
					go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
 | 
				
			||||||
go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
 | 
					go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
 | 
				
			||||||
go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
 | 
					go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=
 | 
				
			||||||
go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
 | 
					go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=
 | 
				
			||||||
go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o=
 | 
					go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM=
 | 
				
			||||||
go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w=
 | 
					go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA=
 | 
				
			||||||
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
 | 
					go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
 | 
				
			||||||
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
 | 
					go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
 | 
				
			||||||
go.opentelemetry.io/proto/otlp v1.6.0 h1:jQjP+AQyTf+Fe7OKj/MfkDrmK4MNVtw2NpXsf9fefDI=
 | 
					go.opentelemetry.io/proto/otlp v1.7.1 h1:gTOMpGDb0WTBOP8JaO72iL3auEZhVmAQg4ipjOVAtj4=
 | 
				
			||||||
go.opentelemetry.io/proto/otlp v1.6.0/go.mod h1:cicgGehlFuNdgZkcALOCh3VE6K/u2tAjzlRhDwmVpZc=
 | 
					go.opentelemetry.io/proto/otlp v1.7.1/go.mod h1:b2rVh6rfI/s2pHWNlB7ILJcRALpcNDzKhACevjI+ZnE=
 | 
				
			||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 | 
					go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 | 
				
			||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
 | 
					go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
 | 
				
			||||||
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
 | 
					golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b h1:DXr+pvt3nC887026GRP39Ej11UATqWDmWuS99x26cD0=
 | 
				
			||||||
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
 | 
					golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4=
 | 
				
			||||||
 | 
					golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
 | 
				
			||||||
 | 
					golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
 | 
					golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
 | 
				
			||||||
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
 | 
					golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
 | 
				
			||||||
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
 | 
					golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
 | 
				
			||||||
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
 | 
					golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
 | 
				
			||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250428153025-10db94c68c34 h1:0PeQib/pH3nB/5pEmFeVQJotzGohV0dq4Vcp09H5yhE=
 | 
					gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
 | 
				
			||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250428153025-10db94c68c34/go.mod h1:0awUlEkap+Pb1UMeJwJQQAdJQrt3moU7J2moTy69irI=
 | 
					gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
 | 
				
			||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34 h1:h6p3mQqrmT1XkHVTfzLdNz1u7IhINeZkz67/xTbOuWs=
 | 
					google.golang.org/genproto/googleapis/api v0.0.0-20250826171959-ef028d996bc1 h1:APHvLLYBhtZvsbnpkfknDZ7NyH4z5+ub/I0u8L3Oz6g=
 | 
				
			||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
 | 
					google.golang.org/genproto/googleapis/api v0.0.0-20250826171959-ef028d996bc1/go.mod h1:xUjFWUnWDpZ/C0Gu0qloASKFb6f8/QXiiXhSPFsD668=
 | 
				
			||||||
google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM=
 | 
					google.golang.org/genproto/googleapis/rpc v0.0.0-20250826171959-ef028d996bc1 h1:pmJpJEvT846VzausCQ5d7KreSROcDqmO388w5YbnltA=
 | 
				
			||||||
google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
 | 
					google.golang.org/genproto/googleapis/rpc v0.0.0-20250826171959-ef028d996bc1/go.mod h1:GmFNa4BdJZ2a8G+wCe9Bg3wwThLrJun751XstdJt5Og=
 | 
				
			||||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
 | 
					google.golang.org/grpc v1.75.0 h1:+TW+dqTd2Biwe6KKfhE5JpiYIBWq865PhKGSXiivqt4=
 | 
				
			||||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
 | 
					google.golang.org/grpc v1.75.0/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
 | 
				
			||||||
 | 
					google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
 | 
				
			||||||
 | 
					google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
 | 
				
			||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
					gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
				
			||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
 | 
					gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
 | 
				
			||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
 | 
					gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
 | 
				
			||||||
 | 
					gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
					gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					// Package app provides methods to configure, run, and stop
 | 
				
			||||||
 | 
					// a go-app.
 | 
				
			||||||
package app
 | 
					package app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
@@ -11,6 +13,8 @@ import (
 | 
				
			|||||||
	httpopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
 | 
						httpopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// App is the main application struct, holding its context, configurations,
 | 
				
			||||||
 | 
					// and various services like HTTP and gRPC.
 | 
				
			||||||
type App struct {
 | 
					type App struct {
 | 
				
			||||||
	AppContext    context.Context
 | 
						AppContext    context.Context
 | 
				
			||||||
	HTTP          *httpopts.AppHTTP
 | 
						HTTP          *httpopts.AppHTTP
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -62,7 +62,12 @@ func (a *App) initHTTP(ctx context.Context) error {
 | 
				
			|||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *App) initOTEL() {
 | 
					func (a *App) InitOTEL() {
 | 
				
			||||||
 | 
						if a.tracer != nil {
 | 
				
			||||||
 | 
							a.l.Debug().Msg("superfluous call of already configured app otel")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var otelShutdown shutdownFunc
 | 
						var otelShutdown shutdownFunc
 | 
				
			||||||
	a.AppContext, otelShutdown = otel.Init(a.AppContext)
 | 
						a.AppContext, otelShutdown = otel.Init(a.AppContext)
 | 
				
			||||||
	a.shutdownFuncs = append(a.shutdownFuncs, otelShutdown)
 | 
						a.shutdownFuncs = append(a.shutdownFuncs, otelShutdown)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,7 @@ func (a *App) monitor() {
 | 
				
			|||||||
	a.appDone <- nil // Notify app
 | 
						a.appDone <- nil // Notify app
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Typically invoked when AppContext is done
 | 
					// Shutdown is typically invoked when AppContext is done
 | 
				
			||||||
// or Server has exited. Not intended to be called
 | 
					// or Server has exited. Not intended to be called
 | 
				
			||||||
// manually
 | 
					// manually
 | 
				
			||||||
func (a *App) Shutdown() {
 | 
					func (a *App) Shutdown() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,7 +35,7 @@ func (a *App) MustRun() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Start OTEL
 | 
						// Start OTEL
 | 
				
			||||||
	// Registers a NO-OP provider if not enabled
 | 
						// Registers a NO-OP provider if not enabled
 | 
				
			||||||
	a.initOTEL()
 | 
						a.InitOTEL()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// With OTEL ready, create an init span to track startup
 | 
						// With OTEL ready, create an init span to track startup
 | 
				
			||||||
	ctx, initSpan := a.tracer.Start(a.AppContext, "init")
 | 
						ctx, initSpan := a.tracer.Start(a.AppContext, "init")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,11 +6,11 @@ import (
 | 
				
			|||||||
	js "github.com/swaggest/jsonschema-go"
 | 
						js "github.com/swaggest/jsonschema-go"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Generates json schema for app's config.AppConfig
 | 
					// Schema generates json schema for app's config.AppConfig
 | 
				
			||||||
func (app *App) Schema() ([]byte, error) {
 | 
					func (a *App) Schema() ([]byte, error) {
 | 
				
			||||||
	r := js.Reflector{}
 | 
						r := js.Reflector{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s, err := r.Reflect(*app.cfg)
 | 
						s, err := r.Reflect(*a.cfg)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -18,7 +18,7 @@ func (app *App) Schema() ([]byte, error) {
 | 
				
			|||||||
	return json.MarshalIndent(s, "", "  ")
 | 
						return json.MarshalIndent(s, "", "  ")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Generates json schema for custom config
 | 
					// CustomSchema generates json schema for custom config
 | 
				
			||||||
// which embeds *config.AppConfig into it
 | 
					// which embeds *config.AppConfig into it
 | 
				
			||||||
// Panics if no *config.AppConfig is embedded into custom
 | 
					// Panics if no *config.AppConfig is embedded into custom
 | 
				
			||||||
// config type
 | 
					// config type
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,7 @@ import (
 | 
				
			|||||||
	"gitea.libretechconsulting.com/rmcguire/go-app/pkg/logging"
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/logging"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Helper function to return a context loaded up with
 | 
					// MustSetupConfigAndLogging is a helper function to return a context loaded up with
 | 
				
			||||||
// config.AppConfig and a logger
 | 
					// config.AppConfig and a logger
 | 
				
			||||||
func MustSetupConfigAndLogging(ctx context.Context) context.Context {
 | 
					func MustSetupConfigAndLogging(ctx context.Context) context.Context {
 | 
				
			||||||
	ctx, err := config.LoadConfig(ctx)
 | 
						ctx, err := config.LoadConfig(ctx)
 | 
				
			||||||
@@ -24,7 +24,7 @@ func MustSetupConfigAndLogging(ctx context.Context) context.Context {
 | 
				
			|||||||
	return ctx
 | 
						return ctx
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Unmarshal config into a custom type
 | 
					// MustSetupConfigAndLoggingInto will unmarshal config into a custom type
 | 
				
			||||||
// Type MUST include *config.AppConfig
 | 
					// Type MUST include *config.AppConfig
 | 
				
			||||||
// Stored in context as *config.AppConfig but can be asserted back
 | 
					// Stored in context as *config.AppConfig but can be asserted back
 | 
				
			||||||
func MustSetupConfigAndLoggingInto[T any](ctx context.Context, into T) (context.Context, T) {
 | 
					func MustSetupConfigAndLoggingInto[T any](ctx context.Context, into T) (context.Context, T) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,7 @@ import (
 | 
				
			|||||||
	"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Used to unmarshal config and environment into a custom type
 | 
					// MustLoadConfigInto is used to unmarshal config and environment into a custom type
 | 
				
			||||||
// that overloads *config.AppConfig. Will perform normal env
 | 
					// that overloads *config.AppConfig. Will perform normal env
 | 
				
			||||||
// substitutions for AppConfig, but env overrides for custom type
 | 
					// substitutions for AppConfig, but env overrides for custom type
 | 
				
			||||||
// are up to the caller.
 | 
					// are up to the caller.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,123 +0,0 @@
 | 
				
			|||||||
package app
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"bufio"
 | 
					 | 
				
			||||||
	"context"
 | 
					 | 
				
			||||||
	"flag"
 | 
					 | 
				
			||||||
	"io"
 | 
					 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"regexp"
 | 
					 | 
				
			||||||
	"testing"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/rs/zerolog"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func TestMustSetupConfigAndLogging(t *testing.T) {
 | 
					 | 
				
			||||||
	// Configure app and logger
 | 
					 | 
				
			||||||
	type inputs struct {
 | 
					 | 
				
			||||||
		envs map[string]string
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	type outputs struct {
 | 
					 | 
				
			||||||
		appName        string
 | 
					 | 
				
			||||||
		logLevel       zerolog.Level
 | 
					 | 
				
			||||||
		logRegexChecks []*regexp.Regexp
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	tests := []struct {
 | 
					 | 
				
			||||||
		name   string
 | 
					 | 
				
			||||||
		inputs inputs
 | 
					 | 
				
			||||||
		want   outputs
 | 
					 | 
				
			||||||
	}{
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "Test json logging with short timestamp",
 | 
					 | 
				
			||||||
			inputs: inputs{
 | 
					 | 
				
			||||||
				envs: map[string]string{
 | 
					 | 
				
			||||||
					"APP_NAME":            "testapp",
 | 
					 | 
				
			||||||
					"APP_LOG_LEVEL":       "warn",
 | 
					 | 
				
			||||||
					"APP_LOG_FORMAT":      "json",
 | 
					 | 
				
			||||||
					"APP_LOG_TIME_FORMAT": "short",
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			want: outputs{
 | 
					 | 
				
			||||||
				appName:  "testapp",
 | 
					 | 
				
			||||||
				logLevel: zerolog.WarnLevel,
 | 
					 | 
				
			||||||
				logRegexChecks: []*regexp.Regexp{
 | 
					 | 
				
			||||||
					regexp.MustCompile(`^\{.*time":"\d{1,}:\d{2}`),
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			name: "Test json logging with unix timestamp",
 | 
					 | 
				
			||||||
			inputs: inputs{
 | 
					 | 
				
			||||||
				envs: map[string]string{
 | 
					 | 
				
			||||||
					"APP_NAME":            "testapp",
 | 
					 | 
				
			||||||
					"APP_LOG_LEVEL":       "info",
 | 
					 | 
				
			||||||
					"APP_LOG_FORMAT":      "json",
 | 
					 | 
				
			||||||
					"APP_LOG_TIME_FORMAT": "unix",
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			want: outputs{
 | 
					 | 
				
			||||||
				appName:  "testapp",
 | 
					 | 
				
			||||||
				logLevel: zerolog.InfoLevel,
 | 
					 | 
				
			||||||
				logRegexChecks: []*regexp.Regexp{
 | 
					 | 
				
			||||||
					regexp.MustCompile(`time":\d+,`),
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for _, tt := range tests {
 | 
					 | 
				
			||||||
		t.Run(tt.name, func(t *testing.T) {
 | 
					 | 
				
			||||||
			// Set environment variables
 | 
					 | 
				
			||||||
			for key, val := range tt.inputs.envs {
 | 
					 | 
				
			||||||
				os.Setenv(key, val)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Prepare config in context
 | 
					 | 
				
			||||||
			ctx := MustSetupConfigAndLogging(context.Background())
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Retrieve config and logger from prepared context
 | 
					 | 
				
			||||||
			cfg := config.MustFromCtx(ctx)
 | 
					 | 
				
			||||||
			logger := zerolog.Ctx(ctx)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Check wants
 | 
					 | 
				
			||||||
			if cfg.Name != tt.want.appName {
 | 
					 | 
				
			||||||
				t.Errorf("Expected app name %s, got %s", tt.want.appName, cfg.Name)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if logger.GetLevel() != tt.want.logLevel {
 | 
					 | 
				
			||||||
				t.Errorf("Expected log level %#v, got %#v", tt.want.logLevel, logger.GetLevel())
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Send and capture a log
 | 
					 | 
				
			||||||
			r, w := io.Pipe()
 | 
					 | 
				
			||||||
			testLogger := logger.Output(w)
 | 
					 | 
				
			||||||
			scanner := bufio.NewScanner(r)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			go func() {
 | 
					 | 
				
			||||||
				testLogger.Error().Msg("test message")
 | 
					 | 
				
			||||||
				w.Close()
 | 
					 | 
				
			||||||
			}()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			logOut := make([]byte, 0)
 | 
					 | 
				
			||||||
			if scanner.Scan() {
 | 
					 | 
				
			||||||
				logOut = scanner.Bytes()
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Check all expressions
 | 
					 | 
				
			||||||
			for _, expr := range tt.want.logRegexChecks {
 | 
					 | 
				
			||||||
				if !expr.Match(logOut) {
 | 
					 | 
				
			||||||
					t.Errorf("Regex %s did not match log %s", expr.String(), logOut)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Super annoying need to reset due to app framework package
 | 
					 | 
				
			||||||
			// using flag.Parse() and go test also using it
 | 
					 | 
				
			||||||
			testlog := flag.Lookup("test.testlogfile").Value.String()
 | 
					 | 
				
			||||||
			flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
 | 
					 | 
				
			||||||
			flag.String("test.testlogfile", testlog, "")
 | 
					 | 
				
			||||||
			flag.String("test.paniconexit0", "", "")
 | 
					 | 
				
			||||||
			flag.String("test.v", "", "")
 | 
					 | 
				
			||||||
			flag.Parse()
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,3 +1,7 @@
 | 
				
			|||||||
 | 
					// Package config provides types and methods for managing
 | 
				
			||||||
 | 
					// app config. A go-app configuration can be extended by any type
 | 
				
			||||||
 | 
					// that embeds AppConfig, and has helpers to generate json
 | 
				
			||||||
 | 
					// schema merged with the custom type's fields
 | 
				
			||||||
package config
 | 
					package config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
@@ -6,6 +10,7 @@ import (
 | 
				
			|||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
						"regexp"
 | 
				
			||||||
	"runtime/debug"
 | 
						"runtime/debug"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -13,15 +18,15 @@ import (
 | 
				
			|||||||
	"gopkg.in/yaml.v3"
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// To be set by ldflags in go build command or
 | 
					// Version is to be set by ldflags in go build command or
 | 
				
			||||||
// retrieved from build meta below
 | 
					// retrieved from build meta below.
 | 
				
			||||||
var Version = "(devel)"
 | 
					var Version = "(devel)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Calling this will try to load from config if -config is
 | 
					// LoadConfig will try to load from config if -config is
 | 
				
			||||||
// provided as a file, and will apply any environment overrides
 | 
					// provided as a file, and will apply any environment overrides
 | 
				
			||||||
// on-top of configuration defaults.
 | 
					// on-top of configuration defaults.
 | 
				
			||||||
// Config is stored in returned context, and can be retrieved
 | 
					// Config is stored in returned context, and can be retrieved
 | 
				
			||||||
// using config.FromCtx(ctx)
 | 
					// using config.FromCtx(ctx).
 | 
				
			||||||
func LoadConfig(ctx context.Context) (context.Context, error) {
 | 
					func LoadConfig(ctx context.Context) (context.Context, error) {
 | 
				
			||||||
	configPath := flag.String("config", "", "Path to the configuration file")
 | 
						configPath := flag.String("config", "", "Path to the configuration file")
 | 
				
			||||||
	flag.Parse()
 | 
						flag.Parse()
 | 
				
			||||||
@@ -40,6 +45,8 @@ func LoadConfig(ctx context.Context) (context.Context, error) {
 | 
				
			|||||||
	return ctx, nil
 | 
						return ctx, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// loadConfig loads the application configuration from the specified path,
 | 
				
			||||||
 | 
					// applying environment variable overrides.
 | 
				
			||||||
func loadConfig(configPath string) (*AppConfig, error) {
 | 
					func loadConfig(configPath string) (*AppConfig, error) {
 | 
				
			||||||
	cfg := *DefaultConfig
 | 
						cfg := *DefaultConfig
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -69,6 +76,8 @@ func loadConfig(configPath string) (*AppConfig, error) {
 | 
				
			|||||||
	return &cfg, nil
 | 
						return &cfg, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// prepareConfig enriches and validates the AppConfig, parsing duration strings
 | 
				
			||||||
 | 
					// for HTTP timeouts.
 | 
				
			||||||
func prepareConfig(cfg *AppConfig) error {
 | 
					func prepareConfig(cfg *AppConfig) error {
 | 
				
			||||||
	var errs error
 | 
						var errs error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -97,15 +106,23 @@ func prepareConfig(cfg *AppConfig) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Prepare user-provided expressions, panic up-front if invalid
 | 
				
			||||||
 | 
						cfg.HTTP.excludeRegexps = make([]*regexp.Regexp, len(cfg.HTTP.LogExcludePathRegexps))
 | 
				
			||||||
 | 
						for i, re := range cfg.HTTP.LogExcludePathRegexps {
 | 
				
			||||||
 | 
							cfg.HTTP.excludeRegexps[i] = regexp.MustCompile(re)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return errs
 | 
						return errs
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Returns read timeout, write timeout, and idle timeout, in that order
 | 
					// Timeouts returns read timeout, write timeout, and idle timeout, in that order.
 | 
				
			||||||
// nil if unset
 | 
					// Returns nil if unset.
 | 
				
			||||||
func (h *HTTPConfig) Timeouts() (*time.Duration, *time.Duration, *time.Duration) {
 | 
					func (h *HTTPConfig) Timeouts() (*time.Duration, *time.Duration, *time.Duration) {
 | 
				
			||||||
	return h.rT, h.wT, h.iT
 | 
						return h.rT, h.wT, h.iT
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getVersion returns the application version, preferring the build info version
 | 
				
			||||||
 | 
					// over the compile-time set Version variable.
 | 
				
			||||||
func getVersion() string {
 | 
					func getVersion() string {
 | 
				
			||||||
	if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "(devel)" {
 | 
						if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "(devel)" {
 | 
				
			||||||
		return info.Main.Version
 | 
							return info.Main.Version
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ package config
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -61,9 +62,110 @@ func Test_loadConfig(t *testing.T) {
 | 
				
			|||||||
			want:    testDefaultConfig,
 | 
								want:    testDefaultConfig,
 | 
				
			||||||
			wantErr: false,
 | 
								wantErr: false,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "Load from file",
 | 
				
			||||||
 | 
								args: args{configPath: "./testdata/config.yaml"},
 | 
				
			||||||
 | 
								want: &AppConfig{
 | 
				
			||||||
 | 
									Name:        "test-app",
 | 
				
			||||||
 | 
									Environment: "development",
 | 
				
			||||||
 | 
									Version:     getVersion(),
 | 
				
			||||||
 | 
									Logging: &LogConfig{
 | 
				
			||||||
 | 
										Enabled:    true,
 | 
				
			||||||
 | 
										Level:      "debug",
 | 
				
			||||||
 | 
										Format:     LogFormatJSON,
 | 
				
			||||||
 | 
										Output:     "stderr",
 | 
				
			||||||
 | 
										TimeFormat: TimeFormatLong,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									HTTP: &HTTPConfig{
 | 
				
			||||||
 | 
										Enabled:      true,
 | 
				
			||||||
 | 
										Listen:       "127.0.0.1:9090",
 | 
				
			||||||
 | 
										LogRequests:  false,
 | 
				
			||||||
 | 
										ReadTimeout:  "10s",
 | 
				
			||||||
 | 
										WriteTimeout: "10s",
 | 
				
			||||||
 | 
										IdleTimeout:  "1m",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									GRPC: &GRPCConfig{
 | 
				
			||||||
 | 
										Enabled:               false,
 | 
				
			||||||
 | 
										Listen:                "127.0.0.1:8081",
 | 
				
			||||||
 | 
										LogRequests:           false,
 | 
				
			||||||
 | 
										EnableReflection:      true,
 | 
				
			||||||
 | 
										EnableInstrumentation: true,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									OTEL: &OTELConfig{
 | 
				
			||||||
 | 
										Enabled:            true,
 | 
				
			||||||
 | 
										PrometheusEnabled:  true,
 | 
				
			||||||
 | 
										PrometheusPath:     "/metrics",
 | 
				
			||||||
 | 
										StdoutEnabled:      false,
 | 
				
			||||||
 | 
										MetricIntervalSecs: 30,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "Load from env",
 | 
				
			||||||
 | 
								args: args{configPath: ""},
 | 
				
			||||||
 | 
								want: &AppConfig{
 | 
				
			||||||
 | 
									Name:        "test-app-env",
 | 
				
			||||||
 | 
									Environment: "production",
 | 
				
			||||||
 | 
									Version:     getVersion(),
 | 
				
			||||||
 | 
									Logging: &LogConfig{
 | 
				
			||||||
 | 
										Enabled:    false,
 | 
				
			||||||
 | 
										Level:      "error",
 | 
				
			||||||
 | 
										Format:     LogFormatConsole,
 | 
				
			||||||
 | 
										Output:     "stdout",
 | 
				
			||||||
 | 
										TimeFormat: TimeFormatUnix,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									HTTP: &HTTPConfig{
 | 
				
			||||||
 | 
										Enabled:      false,
 | 
				
			||||||
 | 
										Listen:       "0.0.0.0:80",
 | 
				
			||||||
 | 
										LogRequests:  true,
 | 
				
			||||||
 | 
										ReadTimeout:  "15s",
 | 
				
			||||||
 | 
										WriteTimeout: "15s",
 | 
				
			||||||
 | 
										IdleTimeout:  "2m",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									GRPC: &GRPCConfig{
 | 
				
			||||||
 | 
										Enabled:               true,
 | 
				
			||||||
 | 
										Listen:                "0.0.0.0:443",
 | 
				
			||||||
 | 
										LogRequests:           true,
 | 
				
			||||||
 | 
										EnableReflection:      false,
 | 
				
			||||||
 | 
										EnableInstrumentation: false,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									OTEL: &OTELConfig{
 | 
				
			||||||
 | 
										Enabled:            false,
 | 
				
			||||||
 | 
										PrometheusEnabled:  false,
 | 
				
			||||||
 | 
										PrometheusPath:     "/metricsz",
 | 
				
			||||||
 | 
										StdoutEnabled:      true,
 | 
				
			||||||
 | 
										MetricIntervalSecs: 60,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, tt := range tests {
 | 
						for _, tt := range tests {
 | 
				
			||||||
		t.Run(tt.name, func(t *testing.T) {
 | 
							t.Run(tt.name, func(t *testing.T) {
 | 
				
			||||||
 | 
								if tt.name == "Load from env" {
 | 
				
			||||||
 | 
									os.Setenv("APP_NAME", "test-app-env")
 | 
				
			||||||
 | 
									os.Setenv("APP_ENVIRONMENT", "production")
 | 
				
			||||||
 | 
									os.Setenv("APP_LOG_ENABLED", "false")
 | 
				
			||||||
 | 
									os.Setenv("APP_LOG_LEVEL", "error")
 | 
				
			||||||
 | 
									os.Setenv("APP_LOG_FORMAT", "console")
 | 
				
			||||||
 | 
									os.Setenv("APP_LOG_OUTPUT", "stdout")
 | 
				
			||||||
 | 
									os.Setenv("APP_LOG_TIME_FORMAT", "unix")
 | 
				
			||||||
 | 
									os.Setenv("APP_HTTP_ENABLED", "false")
 | 
				
			||||||
 | 
									os.Setenv("APP_HTTP_LISTEN", "0.0.0.0:80")
 | 
				
			||||||
 | 
									os.Setenv("APP_HTTP_LOG_REQUESTS", "true")
 | 
				
			||||||
 | 
									os.Setenv("APP_HTTP_READ_TIMEOUT", "15s")
 | 
				
			||||||
 | 
									os.Setenv("APP_HTTP_WRITE_TIMEOUT", "15s")
 | 
				
			||||||
 | 
									os.Setenv("APP_HTTP_IDLE_TIMEOUT", "2m")
 | 
				
			||||||
 | 
									os.Setenv("APP_GRPC_ENABLED", "true")
 | 
				
			||||||
 | 
									os.Setenv("APP_GRPC_LISTEN", "0.0.0.0:443")
 | 
				
			||||||
 | 
									os.Setenv("APP_GRPC_LOG_REQUESTS", "true")
 | 
				
			||||||
 | 
									os.Setenv("APP_GRPC_ENABLE_REFLECTION", "false")
 | 
				
			||||||
 | 
									os.Setenv("APP_GRPC_ENABLE_INSTRUMENTATION", "false")
 | 
				
			||||||
 | 
									os.Setenv("APP_OTEL_ENABLED", "false")
 | 
				
			||||||
 | 
									os.Setenv("APP_OTEL_PROMETHEUS_ENABLED", "false")
 | 
				
			||||||
 | 
									os.Setenv("APP_OTEL_PROMETHEUS_PATH", "/metricsz")
 | 
				
			||||||
 | 
									os.Setenv("APP_OTEL_STDOUT_ENABLED", "true")
 | 
				
			||||||
 | 
									os.Setenv("APP_OTEL_METRIC_INTERVAL_SECS", "60")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			got, err := loadConfig(tt.args.configPath)
 | 
								got, err := loadConfig(tt.args.configPath)
 | 
				
			||||||
			if (err != nil) != tt.wantErr {
 | 
								if (err != nil) != tt.wantErr {
 | 
				
			||||||
				t.Errorf("loadConfig() error = %v, wantErr %v", err, tt.wantErr)
 | 
									t.Errorf("loadConfig() error = %v, wantErr %v", err, tt.wantErr)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,10 +9,12 @@ type appConfigKey uint8
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const appConfigCtxKey appConfigKey = iota
 | 
					const appConfigCtxKey appConfigKey = iota
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *AppConfig) AddToCtx(ctx context.Context) context.Context {
 | 
					// AddToCtx adds the AppConfig to the provided context.
 | 
				
			||||||
	return context.WithValue(ctx, appConfigCtxKey, a)
 | 
					func (ac *AppConfig) AddToCtx(ctx context.Context) context.Context {
 | 
				
			||||||
 | 
						return context.WithValue(ctx, appConfigCtxKey, ac)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// MustFromCtx retrieves the AppConfig from the context, or panics if not found.
 | 
				
			||||||
func MustFromCtx(ctx context.Context) *AppConfig {
 | 
					func MustFromCtx(ctx context.Context) *AppConfig {
 | 
				
			||||||
	cfg, err := FromCtx(ctx)
 | 
						cfg, err := FromCtx(ctx)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -21,6 +23,7 @@ func MustFromCtx(ctx context.Context) *AppConfig {
 | 
				
			|||||||
	return cfg
 | 
						return cfg
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FromCtx retrieves the AppConfig from the context.
 | 
				
			||||||
func FromCtx(ctx context.Context) (*AppConfig, error) {
 | 
					func FromCtx(ctx context.Context) (*AppConfig, error) {
 | 
				
			||||||
	ctxData := ctx.Value(appConfigCtxKey)
 | 
						ctxData := ctx.Value(appConfigCtxKey)
 | 
				
			||||||
	if ctxData == nil {
 | 
						if ctxData == nil {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								pkg/config/testdata/config.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								pkg/config/testdata/config.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					name: test-app
 | 
				
			||||||
 | 
					logging:
 | 
				
			||||||
 | 
					  level: debug
 | 
				
			||||||
 | 
					http:
 | 
				
			||||||
 | 
					  listen: "127.0.0.1:9090"
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
package config
 | 
					package config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Default Settings
 | 
					// DefaultConfig provides a default application configuration.
 | 
				
			||||||
var DefaultConfig = &AppConfig{
 | 
					var DefaultConfig = &AppConfig{
 | 
				
			||||||
	Environment: "development",
 | 
						Environment: "development",
 | 
				
			||||||
	Version:     getVersion(),
 | 
						Version:     getVersion(),
 | 
				
			||||||
@@ -23,6 +23,7 @@ type AppConfig struct {
 | 
				
			|||||||
	GRPC    *GRPCConfig `yaml:"grpc,omitempty" json:"grpc,omitempty"`
 | 
						GRPC    *GRPCConfig `yaml:"grpc,omitempty" json:"grpc,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// HTTPEnabled returns true if HTTP is enabled in the AppConfig.
 | 
				
			||||||
func (ac *AppConfig) HTTPEnabled() bool {
 | 
					func (ac *AppConfig) HTTPEnabled() bool {
 | 
				
			||||||
	if ac.HTTP != nil && ac.HTTP.Enabled {
 | 
						if ac.HTTP != nil && ac.HTTP.Enabled {
 | 
				
			||||||
		return true
 | 
							return true
 | 
				
			||||||
@@ -30,6 +31,7 @@ func (ac *AppConfig) HTTPEnabled() bool {
 | 
				
			|||||||
	return false
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GRPCEnabled returns true if gRPC is enabled in the AppConfig.
 | 
				
			||||||
func (ac *AppConfig) GRPCEnabled() bool {
 | 
					func (ac *AppConfig) GRPCEnabled() bool {
 | 
				
			||||||
	if ac.GRPC != nil && ac.GRPC.Enabled {
 | 
						if ac.GRPC != nil && ac.GRPC.Enabled {
 | 
				
			||||||
		return true
 | 
							return true
 | 
				
			||||||
@@ -37,6 +39,7 @@ func (ac *AppConfig) GRPCEnabled() bool {
 | 
				
			|||||||
	return false
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// OTELEnabled returns true if OpenTelemetry is enabled in the AppConfig.
 | 
				
			||||||
func (ac *AppConfig) OTELEnabled() bool {
 | 
					func (ac *AppConfig) OTELEnabled() bool {
 | 
				
			||||||
	if ac.OTEL != nil && ac.OTEL.Enabled {
 | 
						if ac.OTEL != nil && ac.OTEL.Enabled {
 | 
				
			||||||
		return true
 | 
							return true
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,7 @@ type GRPCConfig struct {
 | 
				
			|||||||
	Enabled               bool   `yaml:"enabled" env:"APP_GRPC_ENABLED" json:"enabled,omitempty"`
 | 
						Enabled               bool   `yaml:"enabled" env:"APP_GRPC_ENABLED" json:"enabled,omitempty"`
 | 
				
			||||||
	Listen                string `yaml:"listen" env:"APP_GRPC_LISTEN" json:"listen,omitempty"`
 | 
						Listen                string `yaml:"listen" env:"APP_GRPC_LISTEN" json:"listen,omitempty"`
 | 
				
			||||||
	LogRequests           bool   `yaml:"logRequests" env:"APP_GRPC_LOG_REQUESTS" json:"logRequests,omitempty"`
 | 
						LogRequests           bool   `yaml:"logRequests" env:"APP_GRPC_LOG_REQUESTS" json:"logRequests,omitempty"`
 | 
				
			||||||
 | 
						EnableProtovalidate   bool   `yaml:"enableProtovalidate" env:"APP_GRPC_ENABLE_PROTOVALIDATE" json:"enableProtovalidate,omitempty" default:"false" description:"Add a chain unary and streaming interceptor for buf.build/go/protovalidate"`
 | 
				
			||||||
	EnableReflection      bool   `yaml:"enableReflection" env:"APP_GRPC_ENABLE_REFLECTION" json:"enableReflection,omitempty"`
 | 
						EnableReflection      bool   `yaml:"enableReflection" env:"APP_GRPC_ENABLE_REFLECTION" json:"enableReflection,omitempty"`
 | 
				
			||||||
	EnableInstrumentation bool   `yaml:"enableInstrumentation" env:"APP_GRPC_ENABLE_INSTRUMENTATION" json:"enableInstrumentation,omitempty"` // requires OTEL
 | 
						EnableInstrumentation bool   `yaml:"enableInstrumentation" env:"APP_GRPC_ENABLE_INSTRUMENTATION" json:"enableInstrumentation,omitempty"` // requires OTEL
 | 
				
			||||||
	EnableGRPCGateway     bool   `yaml:"enableGRPCGateway" json:"enableGRPCGateway,omitempty" env:"APP_GRPC_ENABLE_GATEWAY" default:"true"`
 | 
						EnableGRPCGateway     bool   `yaml:"enableGRPCGateway" json:"enableGRPCGateway,omitempty" env:"APP_GRPC_ENABLE_GATEWAY" default:"true"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,10 @@
 | 
				
			|||||||
package config
 | 
					package config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "time"
 | 
					import (
 | 
				
			||||||
 | 
						"regexp"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var defaultHTTPConfig = &HTTPConfig{
 | 
					var defaultHTTPConfig = &HTTPConfig{
 | 
				
			||||||
	Enabled: true,
 | 
						Enabled: true,
 | 
				
			||||||
@@ -12,15 +16,25 @@ var defaultHTTPConfig = &HTTPConfig{
 | 
				
			|||||||
	IdleTimeout:  "1m",
 | 
						IdleTimeout:  "1m",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// HTTP Configuration
 | 
					// HTTPConfig provides HTTP server Configuration
 | 
				
			||||||
type HTTPConfig struct {
 | 
					type HTTPConfig struct {
 | 
				
			||||||
	Enabled               bool     `yaml:"enabled" env:"APP_HTTP_ENABLED" json:"enabled,omitempty"`
 | 
						Enabled               bool     `yaml:"enabled" env:"APP_HTTP_ENABLED" json:"enabled,omitempty"`
 | 
				
			||||||
	Listen                string   `yaml:"listen,omitempty" env:"APP_HTTP_LISTEN" json:"listen,omitempty"`
 | 
						Listen                string   `yaml:"listen,omitempty" env:"APP_HTTP_LISTEN" json:"listen,omitempty"`
 | 
				
			||||||
	LogRequests           bool     `yaml:"logRequests" env:"APP_HTTP_LOG_REQUESTS" json:"logRequests,omitempty"`
 | 
						LogRequests           bool     `yaml:"logRequests" env:"APP_HTTP_LOG_REQUESTS" json:"logRequests,omitempty"`
 | 
				
			||||||
 | 
						LogExcludePathRegexps []string `yaml:"logExcludePathRegexps" env:"APP_HTTP_LOG_EXCLUDE_PATH_REGEXPS" json:"logExcludePathRegexps,omitempty"`
 | 
				
			||||||
	ReadTimeout           string   `yaml:"readTimeout" env:"APP_HTTP_READ_TIMEOUT" json:"readTimeout,omitempty"`    // Go duration (e.g. 10s)
 | 
						ReadTimeout           string   `yaml:"readTimeout" env:"APP_HTTP_READ_TIMEOUT" json:"readTimeout,omitempty"`    // Go duration (e.g. 10s)
 | 
				
			||||||
	WriteTimeout          string   `yaml:"writeTimeout" env:"APP_HTTP_WRITE_TIMEOUT" json:"writeTimeout,omitempty"` // Go duration (e.g. 10s)
 | 
						WriteTimeout          string   `yaml:"writeTimeout" env:"APP_HTTP_WRITE_TIMEOUT" json:"writeTimeout,omitempty"` // Go duration (e.g. 10s)
 | 
				
			||||||
	IdleTimeout           string   `yaml:"idleTimeout" env:"APP_HTTP_IDLE_TIMEOUT" json:"idleTimeout,omitempty"`    // Go duration (e.g. 10s)
 | 
						IdleTimeout           string   `yaml:"idleTimeout" env:"APP_HTTP_IDLE_TIMEOUT" json:"idleTimeout,omitempty"`    // Go duration (e.g. 10s)
 | 
				
			||||||
 | 
						excludeRegexps        []*regexp.Regexp
 | 
				
			||||||
	rT                    *time.Duration
 | 
						rT                    *time.Duration
 | 
				
			||||||
	wT                    *time.Duration
 | 
						wT                    *time.Duration
 | 
				
			||||||
	iT                    *time.Duration
 | 
						iT                    *time.Duration
 | 
				
			||||||
 | 
						lock                  sync.RWMutex
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (h *HTTPConfig) GetExcludeRegexps() []*regexp.Regexp {
 | 
				
			||||||
 | 
						h.lock.RLock()
 | 
				
			||||||
 | 
						defer h.lock.RUnlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return h.excludeRegexps
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ var defaultLoggingConfig = &LogConfig{
 | 
				
			|||||||
	TimeFormat: TimeFormatLong,
 | 
						TimeFormat: TimeFormatLong,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Logging Configuration
 | 
					// LogConfig provides Logging Configuration
 | 
				
			||||||
type LogConfig struct {
 | 
					type LogConfig struct {
 | 
				
			||||||
	Enabled    bool       `yaml:"enabled,omitempty" env:"APP_LOG_ENABLED" json:"enabled,omitempty"`
 | 
						Enabled    bool       `yaml:"enabled,omitempty" env:"APP_LOG_ENABLED" json:"enabled,omitempty"`
 | 
				
			||||||
	Level      string     `yaml:"level,omitempty" env:"APP_LOG_LEVEL" json:"level,omitempty"`
 | 
						Level      string     `yaml:"level,omitempty" env:"APP_LOG_LEVEL" json:"level,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ var defaultOTELConfig = &OTELConfig{
 | 
				
			|||||||
	MetricIntervalSecs: 30,
 | 
						MetricIntervalSecs: 30,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// OTEL Configuration
 | 
					// OtelConfig provides OTEL Configuration
 | 
				
			||||||
type OTELConfig struct {
 | 
					type OTELConfig struct {
 | 
				
			||||||
	Enabled            bool   `yaml:"enabled,omitempty" env:"APP_OTEL_ENABLED" json:"enabled,omitempty"`
 | 
						Enabled            bool   `yaml:"enabled,omitempty" env:"APP_OTEL_ENABLED" json:"enabled,omitempty"`
 | 
				
			||||||
	PrometheusEnabled  bool   `yaml:"prometheusEnabled,omitempty" env:"APP_OTEL_PROMETHEUS_ENABLED" json:"prometheusEnabled,omitempty"`
 | 
						PrometheusEnabled  bool   `yaml:"prometheusEnabled,omitempty" env:"APP_OTEL_PROMETHEUS_ENABLED" json:"prometheusEnabled,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					// Package logging provides a centralized logging utility using zerolog,
 | 
				
			||||||
 | 
					// with configurable output formats and log levels.
 | 
				
			||||||
package logging
 | 
					package logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										133
									
								
								pkg/logging/logging_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										133
									
								
								pkg/logging/logging_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,133 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					package logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/rs/zerolog"
 | 
				
			||||||
 | 
						"github.com/stretchr/testify/assert"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestMustInitLogging(t *testing.T) {
 | 
				
			||||||
 | 
						cfg := &config.AppConfig{
 | 
				
			||||||
 | 
							Logging: &config.LogConfig{
 | 
				
			||||||
 | 
								Level:  "info",
 | 
				
			||||||
 | 
								Format: "json",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ctx := cfg.AddToCtx(context.Background())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ctx = MustInitLogging(ctx)
 | 
				
			||||||
 | 
						logger := zerolog.Ctx(ctx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.NotNil(t, logger)
 | 
				
			||||||
 | 
						assert.Equal(t, zerolog.InfoLevel, logger.GetLevel())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestConfigureLogger(t *testing.T) {
 | 
				
			||||||
 | 
						type args struct {
 | 
				
			||||||
 | 
							cfg *config.LogConfig
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						tests := []struct {
 | 
				
			||||||
 | 
							name      string
 | 
				
			||||||
 | 
							args      args
 | 
				
			||||||
 | 
							level     zerolog.Level
 | 
				
			||||||
 | 
							wantJSON  bool
 | 
				
			||||||
 | 
							wantTime  bool
 | 
				
			||||||
 | 
							assertion func(t *testing.T, output string)
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "json logger",
 | 
				
			||||||
 | 
								args: args{
 | 
				
			||||||
 | 
									cfg: &config.LogConfig{
 | 
				
			||||||
 | 
										Level:  "debug",
 | 
				
			||||||
 | 
										Format: "json",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								level:    zerolog.DebugLevel,
 | 
				
			||||||
 | 
								wantJSON: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "console logger",
 | 
				
			||||||
 | 
								args: args{
 | 
				
			||||||
 | 
									cfg: &config.LogConfig{
 | 
				
			||||||
 | 
										Level:  "warn",
 | 
				
			||||||
 | 
										Format: "console",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								level:    zerolog.WarnLevel,
 | 
				
			||||||
 | 
								wantJSON: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "with time",
 | 
				
			||||||
 | 
								args: args{
 | 
				
			||||||
 | 
									cfg: &config.LogConfig{
 | 
				
			||||||
 | 
										Level:      "info",
 | 
				
			||||||
 | 
										Format:     "json",
 | 
				
			||||||
 | 
										TimeFormat: "unix",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								level:    zerolog.InfoLevel,
 | 
				
			||||||
 | 
								wantJSON: true,
 | 
				
			||||||
 | 
								wantTime: true,
 | 
				
			||||||
 | 
								assertion: func(t *testing.T, output string) {
 | 
				
			||||||
 | 
									var log map[string]interface{}
 | 
				
			||||||
 | 
									err := json.Unmarshal([]byte(output), &log)
 | 
				
			||||||
 | 
									assert.NoError(t, err)
 | 
				
			||||||
 | 
									assert.Contains(t, log, "time")
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "without time",
 | 
				
			||||||
 | 
								args: args{
 | 
				
			||||||
 | 
									cfg: &config.LogConfig{
 | 
				
			||||||
 | 
										Level:      "info",
 | 
				
			||||||
 | 
										Format:     "json",
 | 
				
			||||||
 | 
										TimeFormat: "off",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								level:    zerolog.InfoLevel,
 | 
				
			||||||
 | 
								wantJSON: true,
 | 
				
			||||||
 | 
								wantTime: false,
 | 
				
			||||||
 | 
								assertion: func(t *testing.T, output string) {
 | 
				
			||||||
 | 
									var log map[string]interface{}
 | 
				
			||||||
 | 
									err := json.Unmarshal([]byte(output), &log)
 | 
				
			||||||
 | 
									assert.NoError(t, err)
 | 
				
			||||||
 | 
									assert.NotContains(t, log, "time")
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, tt := range tests {
 | 
				
			||||||
 | 
							t.Run(tt.name, func(t *testing.T) {
 | 
				
			||||||
 | 
								// Capture output
 | 
				
			||||||
 | 
								old := os.Stderr
 | 
				
			||||||
 | 
								r, w, _ := os.Pipe()
 | 
				
			||||||
 | 
								os.Stderr = w
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								logger, err := configureLogger(tt.args.cfg)
 | 
				
			||||||
 | 
								assert.NoError(t, err)
 | 
				
			||||||
 | 
								assert.Equal(t, tt.level, logger.GetLevel())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								logger.Info().Msg("test")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								w.Close()
 | 
				
			||||||
 | 
								os.Stderr = old
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var buf bytes.Buffer
 | 
				
			||||||
 | 
								io.Copy(&buf, r)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								output := buf.String()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if tt.assertion != nil {
 | 
				
			||||||
 | 
									tt.assertion(t, output)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					// Package otel provides OpenTelemetry initialization and configuration for tracing and metrics.
 | 
				
			||||||
package otel
 | 
					package otel
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
@@ -39,6 +40,7 @@ var (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const defMetricInterval = 15 * time.Second
 | 
					const defMetricInterval = 15 * time.Second
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Init prepares otel, loading a tracer and meter stored in appp context.
 | 
				
			||||||
// Context must carry config.AppConfig
 | 
					// Context must carry config.AppConfig
 | 
				
			||||||
func Init(ctx context.Context) (context.Context, func(context.Context) error) {
 | 
					func Init(ctx context.Context) (context.Context, func(context.Context) error) {
 | 
				
			||||||
	cfg := config.MustFromCtx(ctx)
 | 
						cfg := config.MustFromCtx(ctx)
 | 
				
			||||||
@@ -232,7 +234,7 @@ func (s *settings) newMeterProvider(ctx context.Context) (*metric.MeterProvider,
 | 
				
			|||||||
	return meterProvider, nil
 | 
						return meterProvider, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Creates a new tracer from the global opentelemetry provider
 | 
					// NewTracer creates a new tracer from the global opentelemetry provider
 | 
				
			||||||
func NewTracer(options ...trace.TracerOption) trace.Tracer {
 | 
					func NewTracer(options ...trace.TracerOption) trace.Tracer {
 | 
				
			||||||
	return opentelemetry.GetTracerProvider().Tracer(
 | 
						return opentelemetry.GetTracerProvider().Tracer(
 | 
				
			||||||
		os.Getenv("OTEL_SERVICE_NAME"),
 | 
							os.Getenv("OTEL_SERVICE_NAME"),
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										66
									
								
								pkg/otel/otel_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								pkg/otel/otel_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					package otel
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/stretchr/testify/assert"
 | 
				
			||||||
 | 
						"go.opentelemetry.io/otel/metric/noop"
 | 
				
			||||||
 | 
						"go.opentelemetry.io/otel/trace"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestInit(t *testing.T) {
 | 
				
			||||||
 | 
						cfg := &config.AppConfig{
 | 
				
			||||||
 | 
							Name: "test-app",
 | 
				
			||||||
 | 
							OTEL: &config.OTELConfig{
 | 
				
			||||||
 | 
								Enabled: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ctx := cfg.AddToCtx(context.Background())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ctx, shutdown := Init(ctx)
 | 
				
			||||||
 | 
						defer shutdown(context.Background())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.NotNil(t, ctx.Value(ctxKeyTracer))
 | 
				
			||||||
 | 
						assert.NotNil(t, ctx.Value(ctxKeyMeter))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestInit_Disabled(t *testing.T) {
 | 
				
			||||||
 | 
						cfg := &config.AppConfig{
 | 
				
			||||||
 | 
							Name: "test-app",
 | 
				
			||||||
 | 
							OTEL: &config.OTELConfig{
 | 
				
			||||||
 | 
								Enabled: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ctx := cfg.AddToCtx(context.Background())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ctx, shutdown := Init(ctx)
 | 
				
			||||||
 | 
						defer shutdown(context.Background())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.NotNil(t, ctx.Value(ctxKeyTracer))
 | 
				
			||||||
 | 
						assert.NotNil(t, ctx.Value(ctxKeyMeter))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestContextFuncs(t *testing.T) {
 | 
				
			||||||
 | 
						tracer := trace.NewNoopTracerProvider().Tracer("test")
 | 
				
			||||||
 | 
						meter := noop.NewMeterProvider().Meter("test")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ctx := context.Background()
 | 
				
			||||||
 | 
						ctx = AddTracerToCtx(ctx, tracer)
 | 
				
			||||||
 | 
						ctx = AddMeterToCtx(ctx, meter)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.Equal(t, tracer, MustTracerFromCtx(ctx))
 | 
				
			||||||
 | 
						assert.Equal(t, meter, MustMeterFromCtx(ctx))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestContextFuncs_Panic(t *testing.T) {
 | 
				
			||||||
 | 
						assert.Panics(t, func() {
 | 
				
			||||||
 | 
							MustTracerFromCtx(context.Background())
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						assert.Panics(t, func() {
 | 
				
			||||||
 | 
							MustMeterFromCtx(context.Background())
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					// Package grpc provides a gRPC server implementation with OpenTelemetry integration
 | 
				
			||||||
 | 
					// and gRPC Gateway for RESTful API exposure.
 | 
				
			||||||
package grpc
 | 
					package grpc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
@@ -29,8 +31,9 @@ type appGRPCServer struct {
 | 
				
			|||||||
	doneChan     chan error
 | 
						doneChan     chan error
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Returns a shutdown func, a channel indicating done / error,
 | 
					// InitGRPCServer initializes and starts a gRPC server.
 | 
				
			||||||
// and an up-front error if server fails to start
 | 
					// It returns a shutdown function, a channel to signal completion or error,
 | 
				
			||||||
 | 
					// and an error if the server fails to start.
 | 
				
			||||||
func InitGRPCServer(ctx context.Context, opts *opts.GRPCOpts) (
 | 
					func InitGRPCServer(ctx context.Context, opts *opts.GRPCOpts) (
 | 
				
			||||||
	func(context.Context) error, <-chan error, error,
 | 
						func(context.Context) error, <-chan error, error,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										111
									
								
								pkg/srv/grpc/grpc_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								pkg/srv/grpc/grpc_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,111 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					package grpc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/stretchr/testify/assert"
 | 
				
			||||||
 | 
						"google.golang.org/grpc"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Mock gRPC service
 | 
				
			||||||
 | 
					type mockService struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MockServiceServer interface {
 | 
				
			||||||
 | 
						TestMethod(context.Context, *mockRequest) (*mockResponse, error)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type mockRequest struct{}
 | 
				
			||||||
 | 
					type mockResponse struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *mockService) TestMethod(ctx context.Context, req *mockRequest) (*mockResponse, error) {
 | 
				
			||||||
 | 
						return &mockResponse{}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var _MockService_serviceDesc = grpc.ServiceDesc{
 | 
				
			||||||
 | 
						ServiceName: "test.MockService",
 | 
				
			||||||
 | 
						HandlerType: (*MockServiceServer)(nil),
 | 
				
			||||||
 | 
						Methods: []grpc.MethodDesc{
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								MethodName: "TestMethod",
 | 
				
			||||||
 | 
								Handler: func(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 | 
				
			||||||
 | 
									in := new(mockRequest)
 | 
				
			||||||
 | 
									if err := dec(in); err != nil {
 | 
				
			||||||
 | 
										return nil, err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									if interceptor == nil {
 | 
				
			||||||
 | 
										return srv.(MockServiceServer).TestMethod(ctx, in)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									info := &grpc.UnaryServerInfo{
 | 
				
			||||||
 | 
										Server:     srv,
 | 
				
			||||||
 | 
										FullMethod: "/test.MockService/TestMethod",
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 | 
				
			||||||
 | 
										return srv.(MockServiceServer).TestMethod(ctx, req.(*mockRequest))
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return interceptor(ctx, in, info, handler)
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						Streams:  []grpc.StreamDesc{},
 | 
				
			||||||
 | 
						Metadata: "mock.proto",
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestInitGRPCServer(t *testing.T) {
 | 
				
			||||||
 | 
						cfg := &config.AppConfig{
 | 
				
			||||||
 | 
							Name: "test-app",
 | 
				
			||||||
 | 
							GRPC: &config.GRPCConfig{
 | 
				
			||||||
 | 
								Enabled: true,
 | 
				
			||||||
 | 
								Listen:  "127.0.0.1:0", // Use random available port
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ctx := cfg.AddToCtx(context.Background())
 | 
				
			||||||
 | 
						ctx, _ = otel.Init(ctx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						grpcOpts := &opts.GRPCOpts{
 | 
				
			||||||
 | 
							GRPCConfig: cfg.GRPC,
 | 
				
			||||||
 | 
							AppGRPC: &opts.AppGRPC{
 | 
				
			||||||
 | 
								Services: []*opts.GRPCService{
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										Name:    "mock",
 | 
				
			||||||
 | 
										Type:    &_MockService_serviceDesc,
 | 
				
			||||||
 | 
										Service: &mockService{},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						shutdown, done, err := InitGRPCServer(ctx, grpcOpts)
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						assert.NotNil(t, shutdown)
 | 
				
			||||||
 | 
						assert.NotNil(t, done)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Shutdown the server
 | 
				
			||||||
 | 
						err = shutdown(context.Background())
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestInitGRPCServer_NoServices(t *testing.T) {
 | 
				
			||||||
 | 
						cfg := &config.AppConfig{
 | 
				
			||||||
 | 
							Name: "test-app",
 | 
				
			||||||
 | 
							GRPC: &config.GRPCConfig{
 | 
				
			||||||
 | 
								Enabled: true,
 | 
				
			||||||
 | 
								Listen:  "127.0.0.1:0",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ctx := cfg.AddToCtx(context.Background())
 | 
				
			||||||
 | 
						ctx, _ = otel.Init(ctx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						grpcOpts := &opts.GRPCOpts{
 | 
				
			||||||
 | 
							GRPCConfig: cfg.GRPC,
 | 
				
			||||||
 | 
							AppGRPC:    &opts.AppGRPC{},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, _, err := InitGRPCServer(ctx, grpcOpts)
 | 
				
			||||||
 | 
						assert.Error(t, err)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -8,19 +8,19 @@ import (
 | 
				
			|||||||
	"github.com/rs/zerolog/log"
 | 
						"github.com/rs/zerolog/log"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// A grpc logging middleware compatible logger
 | 
					// GRPCLogger is a grpc logging middleware compatible logger
 | 
				
			||||||
// implementation using a zerolog logger, either from
 | 
					// implementation using a zerolog logger, either from
 | 
				
			||||||
// the global logger or a context logger
 | 
					// the global logger or a context logger.
 | 
				
			||||||
type GRPCLogger struct {
 | 
					type GRPCLogger struct {
 | 
				
			||||||
	logger zerolog.Logger
 | 
						logger zerolog.Logger
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Returns a grpcLogger using the global zerolog Logger
 | 
					// NewGRPCLogger returns a grpcLogger using the global zerolog Logger.
 | 
				
			||||||
func NewGRPCLogger() *GRPCLogger {
 | 
					func NewGRPCLogger() *GRPCLogger {
 | 
				
			||||||
	return &GRPCLogger{logger: log.Logger}
 | 
						return &GRPCLogger{logger: log.Logger}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Returns a grpcLogger using the zerolog logger in the provided context
 | 
					// NewGRPCContextLogger returns a grpcLogger using the zerolog logger in the provided context.
 | 
				
			||||||
func NewGRPCContextLogger(ctx context.Context) *GRPCLogger {
 | 
					func NewGRPCContextLogger(ctx context.Context) *GRPCLogger {
 | 
				
			||||||
	logger := log.Ctx(ctx)
 | 
						logger := log.Ctx(ctx)
 | 
				
			||||||
	return &GRPCLogger{logger: *logger}
 | 
						return &GRPCLogger{logger: *logger}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,9 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"buf.build/go/protovalidate"
 | 
				
			||||||
	grpclogging "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
 | 
						grpclogging "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
 | 
				
			||||||
 | 
						protovalidate_middleware "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/protovalidate"
 | 
				
			||||||
	"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
 | 
						"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
 | 
				
			||||||
	"go.opentelemetry.io/otel"
 | 
						"go.opentelemetry.io/otel"
 | 
				
			||||||
	"go.opentelemetry.io/otel/attribute"
 | 
						"go.opentelemetry.io/otel/attribute"
 | 
				
			||||||
@@ -29,6 +31,7 @@ func (a *appGRPCServer) prepGRPCServer(spanCtx context.Context) error {
 | 
				
			|||||||
	// Prepare GRPC Server Opts
 | 
						// Prepare GRPC Server Opts
 | 
				
			||||||
	a.prepareOTEL(ctx)
 | 
						a.prepareOTEL(ctx)
 | 
				
			||||||
	a.prepareLogging(ctx)
 | 
						a.prepareLogging(ctx)
 | 
				
			||||||
 | 
						a.prepareProtovalidate(ctx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Chain interceptors for unary RPCs
 | 
						// Chain interceptors for unary RPCs
 | 
				
			||||||
	a.serverOpts = append(a.serverOpts,
 | 
						a.serverOpts = append(a.serverOpts,
 | 
				
			||||||
@@ -69,6 +72,28 @@ func (a *appGRPCServer) prepGRPCServer(spanCtx context.Context) error {
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// prepareProtovalidate() adds interceptors for buf.build protovalidate
 | 
				
			||||||
 | 
					func (a *appGRPCServer) prepareProtovalidate(spanCtx context.Context) {
 | 
				
			||||||
 | 
						_, span := a.tracer.Start(spanCtx, "appgrpc.init.prepare.protovalidate", trace.WithAttributes(
 | 
				
			||||||
 | 
							attribute.Bool("grpc.server.protovalidate", a.opts.EnableProtovalidate)))
 | 
				
			||||||
 | 
						defer span.End()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !a.opts.EnableProtovalidate {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validator, err := protovalidate.New()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							span.RecordError(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						a.opts.UnaryInterceptors = append(a.opts.UnaryInterceptors,
 | 
				
			||||||
 | 
							protovalidate_middleware.UnaryServerInterceptor(validator))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						a.opts.StreamInterceptors = append(a.opts.StreamInterceptors,
 | 
				
			||||||
 | 
							protovalidate_middleware.StreamServerInterceptor(validator))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *appGRPCServer) prepareOTEL(spanCtx context.Context) {
 | 
					func (a *appGRPCServer) prepareOTEL(spanCtx context.Context) {
 | 
				
			||||||
	_, span := a.tracer.Start(spanCtx, "appgrpc.init.prepare.otel", trace.WithAttributes(
 | 
						_, span := a.tracer.Start(spanCtx, "appgrpc.init.prepare.otel", trace.WithAttributes(
 | 
				
			||||||
		attribute.Bool("grpc.server.instrumented", a.opts.EnableInstrumentation)))
 | 
							attribute.Bool("grpc.server.instrumented", a.opts.EnableInstrumentation)))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,6 @@
 | 
				
			|||||||
 | 
					// Package http provides functionality for setting up and managing HTTP servers.
 | 
				
			||||||
 | 
					// It includes features for health checks, Prometheus metrics, OpenTelemetry
 | 
				
			||||||
 | 
					// tracing, and custom middleware integration.
 | 
				
			||||||
package http
 | 
					package http
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
@@ -7,6 +10,7 @@ import (
 | 
				
			|||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
						"regexp"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -24,6 +28,7 @@ import (
 | 
				
			|||||||
var (
 | 
					var (
 | 
				
			||||||
	httpMeter                   metric.Meter
 | 
						httpMeter                   metric.Meter
 | 
				
			||||||
	httpTracer                  trace.Tracer
 | 
						httpTracer                  trace.Tracer
 | 
				
			||||||
 | 
						httpPatternWithMethodRegexp = regexp.MustCompile(`(\w+) .*`)
 | 
				
			||||||
	defReadTimeout              = 10 * time.Second
 | 
						defReadTimeout              = 10 * time.Second
 | 
				
			||||||
	defWriteTimeout             = 10 * time.Second
 | 
						defWriteTimeout             = 10 * time.Second
 | 
				
			||||||
	defIdleTimeout              = 15 * time.Second
 | 
						defIdleTimeout              = 15 * time.Second
 | 
				
			||||||
@@ -36,19 +41,12 @@ func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
 | 
				
			|||||||
		mux = &http.ServeMux{}
 | 
							mux = &http.ServeMux{}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// NOTE: Wraps handle func with otelhttp handler and
 | 
					 | 
				
			||||||
	// inserts route tag
 | 
					 | 
				
			||||||
	otelHandleFunc := func(pattern string, handlerFunc func(http.ResponseWriter, *http.Request)) {
 | 
					 | 
				
			||||||
		handler := otelhttp.WithRouteTag(pattern, http.HandlerFunc(handlerFunc))
 | 
					 | 
				
			||||||
		mux.Handle(pattern, handler) // Associate pattern with handler
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	healthChecks := handleHealthCheckFunc(opts.Ctx, opts.HealthChecks...)
 | 
						healthChecks := handleHealthCheckFunc(opts.Ctx, opts.HealthChecks...)
 | 
				
			||||||
	otelHandleFunc("/health", healthChecks)
 | 
						mux.HandleFunc("/health", healthChecks)
 | 
				
			||||||
	otelHandleFunc("/", healthChecks)
 | 
						mux.HandleFunc("/", healthChecks)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, f := range opts.Funcs {
 | 
						for _, f := range opts.Funcs {
 | 
				
			||||||
		otelHandleFunc(f.Path, f.HandlerFunc)
 | 
							mux.HandleFunc(f.Path, f.HandlerFunc)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Prometheus metrics endpoint
 | 
						// Prometheus metrics endpoint
 | 
				
			||||||
@@ -71,12 +69,12 @@ func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
 | 
				
			|||||||
		if h.StripPrefix {
 | 
							if h.StripPrefix {
 | 
				
			||||||
			h.Handler = http.StripPrefix(h.Prefix[:len(h.Prefix)-1], h.Handler)
 | 
								h.Handler = http.StripPrefix(h.Prefix[:len(h.Prefix)-1], h.Handler)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		mux.Handle(h.Prefix, h.Handler)
 | 
							mux.Handle(h.Prefix, otelhttp.WithRouteTag(h.Prefix, h.Handler))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Add OTEL, skip health-check spans
 | 
						// Add OTEL instrumentation, filter noise, set span names
 | 
				
			||||||
	// NOTE: Add any other span exclusions here
 | 
					 | 
				
			||||||
	handler := otelhttp.NewHandler(mux, "/",
 | 
						handler := otelhttp.NewHandler(mux, "/",
 | 
				
			||||||
 | 
							// TODO: Make configurable similar to config.http.LogExcludePathRegexps
 | 
				
			||||||
		otelhttp.WithFilter(func(r *http.Request) bool {
 | 
							otelhttp.WithFilter(func(r *http.Request) bool {
 | 
				
			||||||
			switch r.URL.Path {
 | 
								switch r.URL.Path {
 | 
				
			||||||
			case "/health":
 | 
								case "/health":
 | 
				
			||||||
@@ -86,6 +84,18 @@ func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
 | 
				
			|||||||
			default:
 | 
								default:
 | 
				
			||||||
				return true
 | 
									return true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
							otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
 | 
				
			||||||
 | 
								endpoint := r.URL.Path
 | 
				
			||||||
 | 
								if _, pattern := mux.Handler(r); pattern != "" {
 | 
				
			||||||
 | 
									endpoint = pattern
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if httpPatternWithMethodRegexp.MatchString(endpoint) {
 | 
				
			||||||
 | 
									return endpoint
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return fmt.Sprintf("%s %s", r.Method, endpoint)
 | 
				
			||||||
		}))
 | 
							}))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set timeouts from defaults, override
 | 
						// Set timeouts from defaults, override
 | 
				
			||||||
@@ -133,8 +143,8 @@ func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Returns a shutdown func and a done channel if the
 | 
					// InitHTTPServer returns a shutdown func and a done channel if the
 | 
				
			||||||
// server aborts abnormally. Returns error on failure to start
 | 
					// server aborts abnormally. Returns error on failure to start.
 | 
				
			||||||
func InitHTTPServer(opts *opts.AppHTTP) (
 | 
					func InitHTTPServer(opts *opts.AppHTTP) (
 | 
				
			||||||
	func(context.Context) error, <-chan any, error,
 | 
						func(context.Context) error, <-chan any, error,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,7 +55,7 @@ func handleHealthCheckFunc(ctx context.Context, hcFuncs ...opts.HealthCheckFunc)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func dummyHealthCheck(ctx context.Context) error {
 | 
					func dummyHealthCheck(ctx context.Context) error {
 | 
				
			||||||
	workFor := rand.Intn(750)
 | 
						workFor := rand.Intn(740) + 10 // ensure positive
 | 
				
			||||||
	ticker := time.NewTicker(time.Duration(time.Duration(workFor) * time.Millisecond))
 | 
						ticker := time.NewTicker(time.Duration(time.Duration(workFor) * time.Millisecond))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	select {
 | 
						select {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,12 +3,15 @@ package http
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"errors"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"regexp"
 | 
						"regexp"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/rs/zerolog"
 | 
						"github.com/rs/zerolog"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var ExcludeFromLogging = regexp.MustCompile(`\/(ready|live|metrics)$`)
 | 
					var ExcludeFromLogging = regexp.MustCompile(`\/(ready|live|metrics)$`)
 | 
				
			||||||
@@ -20,12 +23,22 @@ type LoggingResponseWriter struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func loggingMiddleware(appCtx context.Context, next http.Handler) http.Handler {
 | 
					func loggingMiddleware(appCtx context.Context, next http.Handler) http.Handler {
 | 
				
			||||||
 | 
						appConfig := config.MustFromCtx(appCtx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
						return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
		if ExcludeFromLogging.Match([]byte(r.URL.Path)) {
 | 
							if ExcludeFromLogging.Match([]byte(r.URL.Path)) {
 | 
				
			||||||
			next.ServeHTTP(w, r)
 | 
								next.ServeHTTP(w, r)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// User-configurable logging exclusions
 | 
				
			||||||
 | 
							for _, re := range appConfig.HTTP.GetExcludeRegexps() {
 | 
				
			||||||
 | 
								if re.MatchString(r.URL.Path) {
 | 
				
			||||||
 | 
									next.ServeHTTP(w, r)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		log := zerolog.Ctx(appCtx)
 | 
							log := zerolog.Ctx(appCtx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		start := time.Now()
 | 
							start := time.Now()
 | 
				
			||||||
@@ -41,29 +54,42 @@ func loggingMiddleware(appCtx context.Context, next http.Handler) http.Handler {
 | 
				
			|||||||
			Dur("duration", time.Since(start)).
 | 
								Dur("duration", time.Since(start)).
 | 
				
			||||||
			Msg("http request served")
 | 
								Msg("http request served")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Log response body
 | 
								// Log response with body if not 204
 | 
				
			||||||
 | 
							if lrr.statusCode == http.StatusNoContent {
 | 
				
			||||||
 | 
								trcLog := log.Trace().
 | 
				
			||||||
 | 
									Str("path", r.URL.Path).
 | 
				
			||||||
 | 
									Int("statusCode", lrr.statusCode)
 | 
				
			||||||
 | 
								trcLog.Msg("http response (no content)") // Explicitly log 204
 | 
				
			||||||
 | 
								return                                   // No body to log for 204 No Content
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		trcLog := log.Trace().
 | 
							trcLog := log.Trace().
 | 
				
			||||||
			Str("path", r.URL.Path).
 | 
								Str("path", r.URL.Path).
 | 
				
			||||||
			Int("statusCode", lrr.statusCode)
 | 
								Int("statusCode", lrr.statusCode)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Check if it's JSON
 | 
					 | 
				
			||||||
		firstByte, err := lrr.body.ReadByte()
 | 
							firstByte, err := lrr.body.ReadByte()
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			trcLog.Err(errors.New("invalid response body")).Send()
 | 
								if err == io.EOF {
 | 
				
			||||||
			return
 | 
									// Body is empty, which might be valid for some non-204 responses.
 | 
				
			||||||
 | 
									trcLog.Msg("http response (empty body)")
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									// Other error reading the body. Wrap the original error for context.
 | 
				
			||||||
 | 
									trcLog.Err(fmt.Errorf("error reading response body: %w", err)).Send()
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		lrr.body.UnreadByte()
 | 
								return // No further body processing if there was an error or it was empty
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							lrr.body.UnreadByte() // Put the byte back for Bytes() to read
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if firstByte == '{' {
 | 
							if firstByte == '{' {
 | 
				
			||||||
			trcLog = trcLog.RawJSON("response", lrr.body.Bytes())
 | 
								trcLog = trcLog.RawJSON("response", lrr.body.Bytes())
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			trcLog = trcLog.Bytes("response", lrr.body.Bytes())
 | 
								trcLog = trcLog.Bytes("response", lrr.body.Bytes())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		trcLog.Msg("response payload")
 | 
							trcLog.Msg("http response")
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Implement Flush to support the http.Flusher interface
 | 
					// Flush implements the http.Flusher interface to allow flushing buffered data.
 | 
				
			||||||
func (w *LoggingResponseWriter) Flush() {
 | 
					func (w *LoggingResponseWriter) Flush() {
 | 
				
			||||||
	if flusher, ok := w.ResponseWriter.(http.Flusher); ok {
 | 
						if flusher, ok := w.ResponseWriter.(http.Flusher); ok {
 | 
				
			||||||
		flusher.Flush()
 | 
							flusher.Flush()
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										88
									
								
								pkg/srv/http/http_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								pkg/srv/http/http_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					package http
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"net/http/httptest"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/stretchr/testify/assert"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
 | 
				
			||||||
 | 
						"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestInitHTTPServer(t *testing.T) {
 | 
				
			||||||
 | 
						cfg := &config.AppConfig{
 | 
				
			||||||
 | 
							Name: "test-app",
 | 
				
			||||||
 | 
							HTTP: &config.HTTPConfig{
 | 
				
			||||||
 | 
								Enabled: true,
 | 
				
			||||||
 | 
								Listen:  "127.0.0.1:0", // Use random available port
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							OTEL: &config.OTELConfig{
 | 
				
			||||||
 | 
								Enabled: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ctx := cfg.AddToCtx(context.Background())
 | 
				
			||||||
 | 
						ctx, _ = otel.Init(ctx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						httpOpts := &opts.AppHTTP{
 | 
				
			||||||
 | 
							Ctx: ctx,
 | 
				
			||||||
 | 
							Funcs: []opts.HTTPFunc{
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Path: "/test",
 | 
				
			||||||
 | 
									HandlerFunc: func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
										w.WriteHeader(http.StatusOK)
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						shutdown, done, err := InitHTTPServer(httpOpts)
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						assert.NotNil(t, shutdown)
 | 
				
			||||||
 | 
						assert.NotNil(t, done)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Shutdown the server
 | 
				
			||||||
 | 
						err = shutdown(context.Background())
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHealthCheck(t *testing.T) {
 | 
				
			||||||
 | 
						req := httptest.NewRequest("GET", "/health", nil)
 | 
				
			||||||
 | 
						w := httptest.NewRecorder()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						handleHealthCheckFunc(context.Background())(w, req)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp := w.Result()
 | 
				
			||||||
 | 
						body, _ := io.ReadAll(resp.Body)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.Equal(t, http.StatusOK, resp.StatusCode)
 | 
				
			||||||
 | 
						assert.Equal(t, "ok", string(body))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestLoggingMiddleware(t *testing.T) {
 | 
				
			||||||
 | 
						cfg := &config.AppConfig{
 | 
				
			||||||
 | 
							Name: "test-app",
 | 
				
			||||||
 | 
							HTTP: &config.HTTPConfig{
 | 
				
			||||||
 | 
								LogRequests: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ctx := cfg.AddToCtx(context.Background())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
							w.WriteHeader(http.StatusOK)
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						middleware := loggingMiddleware(ctx, handler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						req := httptest.NewRequest("GET", "/test", nil)
 | 
				
			||||||
 | 
						w := httptest.NewRecorder()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						middleware.ServeHTTP(w, req)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.Equal(t, http.StatusOK, w.Code)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user