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

DefaultOpenTelemetryFactory should allow to override histogram buckets #381

Open
tompoch opened this issue Aug 22, 2023 · 0 comments
Open

Comments

@tompoch
Copy link

tompoch commented Aug 22, 2023

Feature description

The DefaultOpenTelemetryFactory does not provide any means to call AutoConfiguredOpenTelemetrySdkBuilder#addMeterProviderCustomizer while creating the OpenTelemetry instance.

In my case I would like to register view for one of the histograms reported to use other than default buckets (ExplicitBucketHistogramUtils#DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES)

As a workaround I am using the following factory

    @Singleton
    @Replaces(value = OpenTelemetry.class, factory = DefaultOpenTelemetryFactory.class)
    protected OpenTelemetry openTelemetryWithViews(ApplicationConfiguration applicationConfiguration,
            @Property(name = "otel") @MapFormat(transformation = FLAT) Map<String, String> otelConfig,
            @Nullable IdGenerator idGenerator,
            @Nullable SpanProcessor spanProcessor,
            @Nullable ResourceProvider resourceProvider,
            List<ViewRegistration> viewRegistrations) {

        Map<String, String> otel = otelConfig.entrySet().stream().collect(Collectors.toMap(
                e -> "otel." + e.getKey(),
                Map.Entry::getValue
        ));

        otel.putIfAbsent(SERVICE_NAME_KEY, applicationConfiguration.getName().orElse(""));
        otel.putIfAbsent(DEFAULT_TRACES_EXPORTER, NONE);
        otel.putIfAbsent(DEFAULT_METRICS_EXPORTER, NONE);
        otel.putIfAbsent(DEFAULT_LOGS_EXPORTER, NONE);

        AutoConfiguredOpenTelemetrySdkBuilder sdk = AutoConfiguredOpenTelemetrySdk.builder()
                .setResultAsGlobal(Boolean.parseBoolean(otel.getOrDefault(REGISTER_GLOBAL, StringUtils.FALSE)))
                .addPropertiesSupplier(() -> otel)
                .addTracerProviderCustomizer((tracerProviderBuilder, ignored) -> {
                            if (idGenerator != null) {
                                tracerProviderBuilder.setIdGenerator(idGenerator);
                            }
                            if (spanProcessor != null) {
                                tracerProviderBuilder.addSpanProcessor(spanProcessor);
                            }
                            if (resourceProvider != null) {
                                tracerProviderBuilder.setResource(resourceProvider.resource());
                            }
                            return tracerProviderBuilder;
                        }
                )
                .addMeterProviderCustomizer((sdkMeterProviderBuilder, configProperties) -> {
                            viewRegistrations.forEach(
                                    vr -> sdkMeterProviderBuilder.registerView(vr.getSelector(), vr.getView()));
                            return sdkMeterProviderBuilder;
                        }
                );

        return sdk.build().getOpenTelemetrySdk();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant