Skip to content

Is there a way to add custom headers to all http requests and then add them to metrics? #7704

Answered by mateuszrzeszutek
tuhao1020 asked this question in Q&A
Discussion options

You must be logged in to vote

Try the following:

@AutoService(AutoConfigurationCustomizerProvider.class)
class SdkMeterProviderConfigurer implements AutoConfigurationCustomizerProvider {
  
  public void customize(AutoConfigurationCustomizer autoConfiguration) {
    autoConfiguration.addMeterProviderCustomizer((sdkMeterProviderBuilder, configProperties) -> {
      ViewBuilder viewBuilder = View.builder();
      SdkMeterProviderUtil.appendFilteredBaggageAttributes(viewBuilder, name -> name.equals("my-baggage-attribute"));
      View view = viewBuilder.build();
      return sdkMeterProviderBuilder.registerView(InstrumentSelector.builder().setName("http.client.duration").build(), view);
    });
  }
}

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@tuhao1020
Comment options

Comment options

You must be logged in to vote
1 reply
@mateuszrzeszutek
Comment options

Answer selected by tuhao1020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants