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 stop-sending option #474

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.next-release.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

* add dynamically disabled instrumentation capability - #422
* add disable all instrumentations option - #471
* add stop-sending option - #474
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
*/
package co.elastic.otel;

import co.elastic.otel.config.DynamicInstrumentation;
import co.elastic.otel.dynamicconfig.BlockableLogRecordExporter;
import co.elastic.otel.dynamicconfig.BlockableMetricExporter;
import co.elastic.otel.dynamicconfig.BlockableSpanExporter;
import co.elastic.otel.dynamicconfig.DynamicConfiguration;
import co.elastic.otel.dynamicconfig.DynamicInstrumentation;
import com.google.auto.service.AutoService;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
Expand Down Expand Up @@ -48,12 +52,22 @@ public class ElasticAutoConfigurationCustomizerProvider

@Override
public void customize(AutoConfigurationCustomizer autoConfiguration) {
autoConfiguration.addMetricExporterCustomizer(
(metricexporter, configProperties) ->
BlockableMetricExporter.createCustomInstance(metricexporter));
autoConfiguration.addSpanExporterCustomizer(
(spanExporter, configProperties) ->
BlockableSpanExporter.createCustomInstance(spanExporter));
autoConfiguration.addLogRecordExporterCustomizer(
(logExporter, configProperties) ->
BlockableLogRecordExporter.createCustomInstance(logExporter));

autoConfiguration.addPropertiesCustomizer(
ElasticAutoConfigurationCustomizerProvider::propertiesCustomizer);
autoConfiguration.addTracerProviderCustomizer(
(providerBuilder, properties) -> {
DynamicInstrumentation.setTracerConfigurator(
providerBuilder, DynamicInstrumentation.UpdatableConfigurator.INSTANCE);
providerBuilder, DynamicConfiguration.UpdatableConfigurator.INSTANCE);
return providerBuilder;
});
}
Expand Down
97 changes: 0 additions & 97 deletions custom/src/main/java/co/elastic/otel/ElasticSpanExporter.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.dynamicconfig;

import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import java.util.Collection;
import javax.annotation.Nonnull;

public class BlockableLogRecordExporter implements LogRecordExporter {
private static volatile BlockableLogRecordExporter INSTANCE;

private volatile boolean sendingLogs = true;
private final LogRecordExporter delegate;

public static BlockableLogRecordExporter getInstance() {
return INSTANCE;
}

public static BlockableLogRecordExporter createCustomInstance(LogRecordExporter exporter) {
INSTANCE = new BlockableLogRecordExporter(exporter);
return INSTANCE;
}

private BlockableLogRecordExporter(LogRecordExporter delegate) {
this.delegate = delegate;
}

public void setSendingLogs(boolean send) {
sendingLogs = send;
}

public boolean sendingLogs() {
return sendingLogs;
}

@Override
public CompletableResultCode export(@Nonnull Collection<LogRecordData> collection) {
if (sendingLogs) {
return delegate.export(collection);
} else {
return CompletableResultCode.ofSuccess();
}
}

@Override
public CompletableResultCode flush() {
return delegate.flush();
}

@Override
public CompletableResultCode shutdown() {
return delegate.shutdown();
}

@Override
public void close() {
delegate.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.dynamicconfig;

import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.metrics.Aggregation;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import java.util.Collection;
import javax.annotation.Nonnull;

public class BlockableMetricExporter implements MetricExporter {
private static volatile BlockableMetricExporter INSTANCE;

private volatile boolean sendingMetrics = true;
private final MetricExporter delegate;

public static BlockableMetricExporter getInstance() {
return INSTANCE;
}

public static BlockableMetricExporter createCustomInstance(MetricExporter exporter) {
INSTANCE = new BlockableMetricExporter(exporter);
return INSTANCE;
}

private BlockableMetricExporter(MetricExporter delegate) {
this.delegate = delegate;
}

public void setSendingMetrics(boolean send) {
sendingMetrics = send;
}

public boolean sendingMetrics() {
return sendingMetrics;
}

@Override
public AggregationTemporality getAggregationTemporality(@Nonnull InstrumentType instrumentType) {
return delegate.getAggregationTemporality(instrumentType);
}

@Override
public Aggregation getDefaultAggregation(@Nonnull InstrumentType instrumentType) {
return delegate.getDefaultAggregation(instrumentType);
}

@Override
public CompletableResultCode export(@Nonnull Collection<MetricData> metrics) {
if (sendingMetrics) {
return delegate.export(metrics);
} else {
return CompletableResultCode.ofSuccess();
}
}

@Override
public CompletableResultCode flush() {
return delegate.flush();
}

@Override
public CompletableResultCode shutdown() {
return delegate.shutdown();
}

@Override
public void close() {
delegate.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.dynamicconfig;

import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.util.Collection;
import javax.annotation.Nonnull;

public class BlockableSpanExporter implements SpanExporter {
private static volatile BlockableSpanExporter INSTANCE;

private volatile boolean sendingSpans = true;
private final SpanExporter delegate;

public static BlockableSpanExporter getInstance() {
return INSTANCE;
}

public static BlockableSpanExporter createCustomInstance(SpanExporter exporter) {
INSTANCE = new BlockableSpanExporter(exporter);
return INSTANCE;
}

private BlockableSpanExporter(SpanExporter delegate) {
this.delegate = delegate;
}

public void setSendingSpans(boolean send) {
sendingSpans = send;
}

public boolean sendingSpans() {
return sendingSpans;
}

@Override
public CompletableResultCode export(@Nonnull Collection<SpanData> spans) {
if (sendingSpans) {
return delegate.export(spans);
} else {
return CompletableResultCode.ofSuccess();
}
}

@Override
public CompletableResultCode flush() {
return delegate.flush();
}

@Override
public CompletableResultCode shutdown() {
return delegate.shutdown();
}
}
Loading
Loading