Skip to content

Support Automatic Instrumentation for OpenTelemetry #10051

@SentryMan

Description

@SentryMan

Environment Details

  • Helidon Version: 4.x
  • Helidon SE

Enhancement Description

After consuming the changes of #10032 locally, I'm trying to prepare a PR for the OpenTelemetry Java Agent to add automatic instrumentation.

It seems that we cannot get the matched pattern inside a filter, so the filter logic I have below doesn't work:

final class OpenTelemetryFilter implements Filter {

  private final Instrumenter<ServerRequest, ServerResponse> instrumenter;

  OpenTelemetryFilter(Instrumenter<ServerRequest, ServerResponse> instrumenter) {
    this.instrumenter = instrumenter;
  }

  @Override
  public void filter(FilterChain chain, RoutingRequest req, RoutingResponse res) {

    Context parentContext = Context.current();
    if (!instrumenter.shouldStart(parentContext, req)) {
      chain.proceed();
      return;
    }

    Context context = instrumenter.start(parentContext, req);

    Throwable error = null;
    try (Scope ignored = context.makeCurrent()) {
      chain.proceed();
    } catch (Throwable t) {
      error = t;
      throw t;
    } finally {
      instrumenter.end(context, req, res, error);
    }
  }
}

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions