Skip to content

Conversation

@prodion23
Copy link
Collaborator

@prodion23 prodion23 commented Feb 5, 2025

After working on the ext_cap -> goagent-src -> goagent changes I realized the previous approach wouldn't work because the exporterFactory is only inited once, after that the config is static & it's really just the exporterFactory() that is invoked and needs to be aware of the new header.

I've updated the approach to instead add a WithHeaders option we can pass down to customize the exporter that will be created from factory.
This also removes the original question about hardcoding constant for the key, we'll be able to control headers from TPA, which may be nice from a maintenance perspective.

ORIGINAL

This optionally adds token header to otlpgrpc, otlphttp, or zipkin.

Q1: Do we have an expected key defined? This is currently marked as TODO- in the code.

Q2: Do we want key hardcoded constant for the header key or do we want the key also passed through TPA?

We already have a Token field in the config, if we want to customize key we will need to update config to allow a map of headers or add a TokenKey/TokenValue for ex.

Please lmk direction we want to go, this impl is straightforward; however, allowing header key specification would be more robust - but from my current understanding maybe unnecessary.

  • Unit tests assert header/metadata is send via the appended opts.

@codecov
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 90.19608% with 5 lines in your changes missing coverage. Please review.

Project coverage is 61.17%. Comparing base (f5d261a) to head (a5ed4c9).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
instrumentation/opentelemetry/init.go 90.19% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #244      +/-   ##
==========================================
+ Coverage   60.39%   61.17%   +0.77%     
==========================================
  Files          59       59              
  Lines        2654     2684      +30     
==========================================
+ Hits         1603     1642      +39     
+ Misses        973      962      -11     
- Partials       78       80       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tim-mwangi
Copy link
Collaborator

This optionally adds token header to otlpgrpc, otlphttp, or zipkin.

Q1: Do we have an expected key defined? This is currently marked as TODO- in the code.

Q2: Do we want key hardcoded constant for the header key or do we want the key also passed through TPA?

We already have a Token field in the config, if we want to customize key we will need to update config to allow a map of headers or add a TokenKey/TokenValue for ex.

Please lmk direction we want to go, this impl is straightforward; however, allowing header key specification would be more robust - but from my current understanding maybe unnecessary.

  • Unit tests assert header/metadata is send via the appended opts.

I think we can allow for configuration of the token header name but have a reasonable default.

headers map[string]string
}

func WithHeaders(headers map[string]string) ServiceOption {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

Choose a reason for hiding this comment

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

Option pattern is a fairly popular pattern in go.
More such things can be read here: https://abhinavg.net/2022/12/06/designing-go-libraries/
This guy used to lead go team at uber.

opts.headers = make(map[string]string)
}
for k, v := range headers {
opts.headers[k] = v
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can probably use maps.Copy() ref

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TIL 👍

@prodion23 prodion23 merged commit 9789c3a into main Feb 13, 2025
6 of 7 checks passed
@tim-mwangi tim-mwangi deleted the ENG-56723-add-token-header branch February 18, 2025 18:06
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.

6 participants