Skip to content

[FEAT] OpenTelemetry and Configuration#2

Merged
bbengfort merged 2 commits intomainfrom
config-otel
Mar 29, 2026
Merged

[FEAT] OpenTelemetry and Configuration#2
bbengfort merged 2 commits intomainfrom
config-otel

Conversation

@bbengfort
Copy link
Copy Markdown
Contributor

@bbengfort bbengfort commented Mar 29, 2026

Scope of changes

@chris-okuda this is my new service implementation pattern using rlog and otel semantics we've created in our various other libraries. I'll slowly work on getting Endeavor and Quarterdeck to more closely match this spec.

The most notable thing is the difference in how config is being used -- I'm pushing that to be more of a global variable instead of calling New and passing the config around.

Estimated PR Size:

  • Tiny
  • Small
  • Medium
  • Large
  • Huge

Acceptance criteria

This PR will be merged without review.

Author checklist

  • I have manually tested the change and/or added automation in the form of unit tests or integration tests
  • I have updated the dependencies list
  • I have added new test fixtures as needed to support added tests
  • I have added or updated the documentation
  • I have run go generate to update generated code

Note

Medium Risk
Introduces new OpenTelemetry initialization and request middleware plus switches configuration to a package-level singleton, which can affect startup behavior and observability/logging in production if misconfigured.

Overview
Adds a new pkg/telemetry module that initializes OpenTelemetry (traces/metrics/logs) via env-driven autoexport/autoprop, provides a Gin middleware hook (telemetry.Middleware()), and configures rlog to emit JSON/console logs with optional fan-out to OTEL logs.

Refactors configuration to include new runtime settings (ConsoleLog, AllowedOrigins, stricter Mode validation) and introduces a global config singleton (config.Get/MustGet/Set/Reset) used by the server and telemetry, with new unit tests. The server startup is updated to use server.New() (no config parameter), installs the observability middleware first, and switches startup/shutdown logging to rlog.

Updates developer ergonomics/docs via a new .env.template, README badge/content, and refreshes dependencies (Gin, Confire, Gimlet, OTEL, plus CORS and testing libs).

Written by Cursor Bugbot for commit 0b92ee3. Configure here.

func serve(ctx context.Context, c *cli.Command) (err error) {
var srv *server.Server
if srv, err = server.New(nil); err != nil {
if srv, err = server.New(); err != nil {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new pattern here is that we don't pass a config to New -- if we want to modify the config, we have to modify it globally.

Comment on lines +51 to +56
func (c Config) Validate() (err error) {
if c.Mode != gin.ReleaseMode && c.Mode != gin.DebugMode && c.Mode != gin.TestMode {
return confire.Invalid("", "mode", "gin mode must be one of: release, debug, test")
}
return nil
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made confire updates to make sure that this Validation function is in fact run by confire.

"go.rtnl.ai/x/rlog"
)

var testEnv = contest.Env{
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the use of the new confire testing tools.

Comment on lines +53 to +55
// Load the configuration from the environment if not provided.
if s.conf, err = config.Get(); err != nil {
return nil, fmt.Errorf("could not load configuration: %w", err)
Copy link
Copy Markdown
Contributor Author

@bbengfort bbengfort Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration is loaded rather than passed in to the service. This really only affects tests; I plan to use a Debug method for testing.

Comment on lines +118 to +120
rlog.InfoAttrs(
context.Background(),
"uptime server started",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chris-okuda rlog ftw!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of an adaptation to what you have in Endeavor.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@bbengfort bbengfort merged commit 756afe3 into main Mar 29, 2026
3 checks passed
@bbengfort bbengfort deleted the config-otel branch March 29, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant