Skip to content

Initial code: add otregistrar package - #1

Merged
dfinkel merged 2 commits into
mainfrom
otregistrar_init
Sep 11, 2025
Merged

Initial code: add otregistrar package#1
dfinkel merged 2 commits into
mainfrom
otregistrar_init

Conversation

@dfinkel

@dfinkel dfinkel commented Sep 11, 2025

Copy link
Copy Markdown
Contributor
  • otregistrar package & go.mod file
    Add a package that takes care of iterating over struct fields and using
    the field-types+struct tags to register otel instruments with a passed
    otel Meter.

  • Add github actions

@sergiosalvatore sergiosalvatore changed the title Initial code: add otregitrar package Initial code: add otregistrar package Sep 11, 2025

@sergiosalvatore sergiosalvatore left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A couple minor comments -- and the otel API is 😱

Comment thread otregistrar/registrar.go Outdated
}
*t = mt
default:
// interatively unwrap pointers/interfaces:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: s/interatively/iteratively/

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.

fixed.

Comment thread otregistrar/registrar.go Outdated
fi := f.Addr().Interface()
switch t := fi.(type) {
case *metric.Int64Counter:
if !ok {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm fairly certain this is the ok from L76, but the context is sort of lost from there. Perhaps we should rename it to tagFound or something like that. Otherwise, I'm a little unclear about what isn't "ok" here...

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 made it metricNameOK to match the convention.
It made more sense when the if !ok { continue } was next to the Tag.Lookup call, but I had to move this down to the individual cases to support recursing into struct-typed fields.

Add a package that simplifies registration by iterating over struct
fields and using the field-types+struct tags to register otel
instruments with a passed otel `Meter`.

@sergiosalvatore sergiosalvatore left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@dfinkel
dfinkel merged commit a42777c into main Sep 11, 2025
4 checks passed
@dfinkel
dfinkel deleted the otregistrar_init branch September 11, 2025 19:46
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.

2 participants