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

Add support for OpenTelemetry configuration in Helidon SE #9595

Open
hyder opened this issue Dec 13, 2024 · 1 comment
Open

Add support for OpenTelemetry configuration in Helidon SE #9595

hyder opened this issue Dec 13, 2024 · 1 comment
Labels
4.x Version 4.x enhancement New feature or request P3 telemetry

Comments

@hyder
Copy link

hyder commented Dec 13, 2024

Environment Details

  • Helidon Version: 4.1.5
  • Helidon SE
  • JDK version: 21
  • OS:
  • Docker version (if applicable):

Problem Description

otel configuration is not currently loaded by Helidon:

otel:
  sdk.disabled: false
  service.name: "todo:front"
  traces.exporter: otlp

We can work around this for now using the following code:

    private static Map<String, String> telemetryConfig(Config config) {
        Config otelConfig = config.get("otel");
        Map<String, String> result = new HashMap<>();
        otelConfig.asMap().ifPresent(result::putAll);
        result.putIfAbsent("otel.metrics.exporter", "none");
        result.putIfAbsent("otel.logs.exporter", "none");
        return result;
    }

    private static void  prepareOpenTelemetry(Config config) {
        String serviceName = config.get("otel.service.name").asString().orElse("HELIDON_SE_SERVICE");
        OpenTelemetry openTelemetry = AutoConfiguredOpenTelemetrySdk.builder()
                .addPropertiesCustomizer(x -> telemetryConfig(config))
                .addResourceCustomizer((r, props) -> r.toBuilder()
                        .put(SERVICE_NAME, serviceName)
                        .build())
                .build()
                .getOpenTelemetrySdk();
        if (openTelemetry == null) {
            openTelemetry = OpenTelemetry.noop();
        }
        io.opentelemetry.api.trace.Tracer otelTracer = openTelemetry.getTracer(serviceName);
        Tracer helidonTracer = HelidonOpenTelemetry.create(openTelemetry, otelTracer, Map.of());
        Contexts.globalContext().register(helidonTracer);
    }

However, it would be preferable to be able to load these either by config file or by environment variables.

Steps to reproduce

@tjquinno
Copy link
Member

BTW the code above is very similar to the current initialization code that runs in Helidon MP, which, because it complies with the MP Telemetry spec, allows otel configuration to appear at the "top level" of MP configuration.

I furnished the above code to Ali as a way to quickly replicate that functionality in an SE app.

We will need to consider carefully where in the config hierarchy we would want to expose the otel settings in SE config.

Other tracing providers (Jaeger, Zipkin) have historically taken their settings from the tracing section. The specific config keys within tracing that are supported would depend on which tracing provider is in use. From that perspective and for consistency we might locate the OTel settings under tracing, perhaps without the otel prefix. That, of course, would be inconsistent with the MP Telemetry approach.

About environment variables... Helidon Config supports environment variables as a config source by default.

Further, OpenTelemetry itself checks for various environment variables and varies its behavior accordingly. So that is another workaround unless/until Helidon SE supports OTel configuration in its own config.

@m0mus m0mus added enhancement New feature or request P3 4.x Version 4.x telemetry labels Dec 19, 2024
@m0mus m0mus moved this from Triage to Normal priority in Backlog Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x enhancement New feature or request P3 telemetry
Projects
Status: Normal priority
Development

No branches or pull requests

3 participants