Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default value for header setter extension #34412

Closed
f7o opened this issue Aug 6, 2024 · 7 comments
Closed

default value for header setter extension #34412

f7o opened this issue Aug 6, 2024 · 7 comments
Assignees
Labels

Comments

@f7o
Copy link
Contributor

f7o commented Aug 6, 2024

Component(s)

extension/headerssetter

Is your feature request related to a problem? Please describe.

When using the header setter with from_context configuration set, and the key is not set within context from receiver, the header is set to nil on the exporter.

Describe the solution you'd like

  extensions:
    headers_setter:
      headers:
        - action: upsert
          key: X-TENANT
          from_context: X-TENANT
          default_value: my-tenant-1 # new proposed config field

Describe alternatives you've considered

Allow to specify a default value per header action in case X-TENANT on the provided context is empty/nil

Additional context

No response

@f7o f7o added enhancement New feature or request needs triage New item requiring triage labels Aug 6, 2024
Copy link
Contributor

github-actions bot commented Aug 6, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@Frapschen
Copy link
Contributor

@f7o Makes sense to me, are you interested in contribute it?

@f7o
Copy link
Contributor Author

f7o commented Aug 6, 2024

@Frapschen yeah, sure

@Frapschen Frapschen removed the needs triage New item requiring triage label Aug 7, 2024
f7o added a commit to f7o/opentelemetry-collector-contrib that referenced this issue Aug 7, 2024
* default value config
* set default value in context source if metadata empty

fixes open-telemetry#34412
@f7o
Copy link
Contributor Author

f7o commented Aug 8, 2024

oh wait a minute. looking at the code I believe this functionally could be achieved by something like this:

headers:
- action: upsert
  key: X-TENANT
  from_context: X-TENANT
- action: insert
  key: X-TENANT
  value: some-tenant

I believe it would first try to set it from context, even if it's empty. But second set the value only if first header does not set it.
I'll test this before continue implementing the new config field.

@jpkrohling have you had this use case before?

@jpkrohling
Copy link
Member

I believe that's correct: an upsert of a fixed value would cause it to act as a default value.

@f7o
Copy link
Contributor Author

f7o commented Aug 27, 2024

I tried the following

        - action: upsert
          key: X-NAMESPACE
          from_context: X-TENANT
        - action: insert
          key: X-NAMESPACE
          value: sre-test

This apparently does not work if X-TENANT is not provided in upstream metadata. I'll continue implement the default_value config. It does not add the header at all, once I enable the header upstream the first rule matches and picks and sets the header from upstream.

f7o added a commit to f7o/opentelemetry-collector-contrib that referenced this issue Sep 8, 2024
* default value config
* set default value in context source if metadata empty

fixes open-telemetry#34412
f7o added a commit to f7o/opentelemetry-collector-contrib that referenced this issue Sep 9, 2024
* default value config
* set default value in context source if metadata empty

fixes open-telemetry#34412
jpkrohling added a commit that referenced this issue Sep 18, 2024
**Description:** <Describe what has changed.>
* default value config
* set default value in context source if metadata empty

**Link to tracking Issue: #34412

**Testing:** tbd

**Documentation:** see README.md

---------

Co-authored-by: Juraci Paixão Kröhling <juraci@kroehling.de>
@jpkrohling
Copy link
Member

Closed via #34455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants