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

Support Cutsom OperationMetrics、AttributesExtractor、ContextCustomizer in Instrumenter #12250

Open
pepeshore opened this issue Sep 14, 2024 · 2 comments
Labels
contribution welcome Request makes sense, maintainers probably won't have time, contribution would be welcome enhancement New feature or request

Comments

@pepeshore
Copy link

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

We forked this code repository and made several significant modifications to support our clients. These changes mainly involved adding some attributes to certain spans and modifying the names and dimensions of metrics. Consequently, merging the latest open-source code will result in many conflicts. We hope to receive support in providing some extension mechanisms that allow us to expand functionality without modifying this code repository.

Describe the solution you'd like

We expecte the following fields in io.opentelemetry.instrumentation.api.instrumenter.Instrumenter can be customized

  • spanNameExtractor
  • attributesExtractors
  • contextCustomizers
  • operationListeners

pseudo code

public final class TomcatInstrumenterFactory {

  private TomcatInstrumenterFactory() {}

  public static <REQUEST, RESPONSE> Instrumenter<Request, Response> create(
      String instrumentationName, ServletAccessor<REQUEST, RESPONSE> accessor,
      HttpServerAttributesGetter<Request, Response> httpAttributesGetter) {
    TomcatNetAttributesGetter netAttributesGetter = new TomcatNetAttributesGetter()

    return Instrumenter.<Request, Response>builder(
            GlobalOpenTelemetry.get(),
            instrumentationName,
            HttpSpanNameExtractor.create(httpAttributesGetter))
        .addAttributesExtractor(
            HttpServerAttributesExtractor.builder(httpAttributesGetter, netAttributesGetter)
                .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders())
                .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders())
                .build())
        .addAttributesExtractor(
          loadCustomAttributesExtractor(instrumentationName)
         )
        .addContextCustomizer(
          loadContextCustomizer(instrumentationName)
         )
        .addOperationMetrics(HttpServerMetrics.get())
        .addOperationMetrics(loadCustomOperationMetrics())
        .buildServerInstrumenter(TomcatRequestGetter.INSTANCE)
  }

  
  public AttributesExtractor loadCustomAttributesExtractor(String instrumentationName) {
    throw new UnsupportedException();
  }


  public ContextCustomizer loadContextCustomizer(String instrumentationName) {
    throw new UnsupportedException();
  }

  public OperationMetrics loadCustomOperationMetrics(String instrumentationName)) {
    throw new UnsupportedException();  
  }

}

Describe alternatives you've considered

No response

Additional context

No response

@pepeshore pepeshore added enhancement New feature or request needs triage New issue that requires triage labels Sep 14, 2024
@trask
Copy link
Member

trask commented Sep 16, 2024

I would support this, some kind of SPI that a Java agent extension could use to add these things to the existing instrumentations

cc @steverao @ralf0131 who I believe have similar need

@trask trask added contribution welcome Request makes sense, maintainers probably won't have time, contribution would be welcome and removed needs triage New issue that requires triage labels Sep 16, 2024
@steverao
Copy link
Contributor

I would support this, some kind of SPI that a Java agent extension could use to add these things to the existing instrumentations

cc @steverao @ralf0131 who I believe have similar need

In fact, @pepeshore is also our colleague.😂 He is focusing on relevant field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome Request makes sense, maintainers probably won't have time, contribution would be welcome enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants