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

Auto-configure EventLoggerProvider #11623

Open
swar8080 opened this issue Jun 18, 2024 · 2 comments
Open

Auto-configure EventLoggerProvider #11623

swar8080 opened this issue Jun 18, 2024 · 2 comments
Labels
enhancement New feature or request needs triage New issue that requires triage

Comments

@swar8080
Copy link
Contributor

swar8080 commented Jun 18, 2024

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

We're looking to use the Events API but currently have to build an EventLogger manually. It's error-prone getting the manual set-up to use all the auto-configuration that we're used to the java agent doing for us. For example, our attempt is:

  <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-api-incubator</artifactId>
  </dependency>
  <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
    <version>${opentelemetry.version}</version>
  </dependency>
  <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-sdk-extension-autoconfigure-spi</artifactId>
    <version>${opentelemetry.version}</version>
  </dependency>
  <dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-resources</artifactId>
    <version>${opentelemetry.javaagent.version}-alpha</version>
  </dependency>
  <dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-exporter-otlp</artifactId>
    <version>${opentelemetry.version}</version>
  </dependency>
...
  @Bean
  EventLogger otelEventLogger() {
    var autoOtelSdk = AutoConfiguredOpenTelemetrySdk.builder().build();
    var otelConfig = AutoConfigureUtil.getConfig(autoOtelSdk);
    if (otelConfig == null) {
      logger.info(
          "No OTEL ConfigProperties available for EventLogger. Using empty configuration instead");
      otelConfig = DefaultConfigProperties.create(new HashMap<>());
    }

    Resource resource = Resource.getDefault();
    ServiceLoader<ResourceProvider> serviceLoader = ServiceLoader.load(ResourceProvider.class);
    for (ResourceProvider provider : serviceLoader) {
      Resource provided = provider.createResource(otelConfig);
      resource = resource.merge(provided);
    }

    OtlpGrpcLogRecordExporter exporter =
        OtlpGrpcLogRecordExporter.builder()
            .setRetryPolicy(
                RetryPolicy.builder()
                    .setMaxAttempts(5)
                    .setMaxBackoff(Duration.ofSeconds(3L))
                    .build())
            .build();
    BatchLogRecordProcessor processor =
        BatchLogRecordProcessor.builder(exporter)
            .setMeterProvider(GlobalOpenTelemetry.getMeterProvider())
            .build();
    SdkLoggerProvider loggerProvider =
        SdkLoggerProvider.builder().setResource(resource).addLogRecordProcessor(processor).build();

    EventLoggerProvider eventLoggerProvider = SdkEventLoggerProvider.create(loggerProvider);
    return eventLoggerProvider.eventLoggerBuilder("com.demo").build();
  }

Describe the solution you'd like

Have the javaagent auto-configure the EventLoggerProvider and expose it for applications.

@jack-berg had a suggestion for how to do this: https://cloud-native.slack.com/archives/C014L2KCTE3/p1718657558881159?thread_ts=1718293157.542669&cid=C014L2KCTE3

Describe alternatives you've considered

  • Agent extension?
  • Manual set-up

Additional context

Any guesses if packaging our manual set-up in an agent extension would work as a temporary solution? Or would the call GlobalEventLoggerProvider.set happen using a different class loader than what's available to the application?

@swar8080 swar8080 added enhancement New feature or request needs triage New issue that requires triage labels Jun 18, 2024
@JonasKunz
Copy link
Contributor

I also stumbled across this issue. In fact, the SDK shipped with the agent does configure the GlobalEventLoggerProvider.
This means if you for example write an agent extension or custom instrumentation, it will be able to access the GlobalEventLoggerProvider.

What however is not yet implemented is to support the GlobalEventLoggerProvider via the opentelemetry-api-instrumentation: That instrumentation is responsible for redirecting opentelemtry-API classes shipped with the instrumented application to the opentelemetry-SDK contained in the agent.
This redirection is not yet implemented there for the GlobalEventLoggerProvider.

@trask
Copy link
Member

trask commented Dec 2, 2024

the event api (as currently implemented) is going away, so unless this is urgently needed, I'd suggest waiting for open-telemetry/opentelemetry-java#6761 (also see https://github.com/open-telemetry/opentelemetry-specification/blob/main/oteps/0265-event-vision.md#api)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage New issue that requires triage
Projects
None yet
Development

No branches or pull requests

3 participants